Convert lookup_replace_object to struct object_id
Convert both the argument and the return value to be pointers to struct object_id. Update the callers and their internals to deal with the new type. Remove several temporaries which are no longer needed. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 12, 2018 at 02:27 UTC
b383a13cc0dbed752b69d7ad249bc857b9d3607b
6 files changed
+42
-59
builtin/mktag.c
+2
-5
@@ -24,14 +24,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
24
enum object_type type;
25
unsigned long size;
26
void *buffer = read_object_file(oid, &type, &size);
27
- const unsigned char *repl = lookup_replace_object(oid->hash);
27
+ const struct object_id *repl = lookup_replace_object(oid);
28
29
if (buffer) {
30
- struct object_id reploid;
31
- hashcpy(reploid.hash, repl);
32
-
30
if (type == type_from_string(expected_type))
34
- ret = check_object_signature(&reploid, buffer, size, expected_type);
31
+ ret = check_object_signature(repl, buffer, size, expected_type);
32
free(buffer);
33
}
34
return ret;
cache.h
+4
-4
@@ -1197,7 +1197,7 @@ static inline void *read_object_file(const struct object_id *oid, enum object_ty
1197
* This internal function is only declared here for the benefit of
1198
* lookup_replace_object(). Please do not call it directly.
1199
*/
1200
-extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
1200
+extern const struct object_id *do_lookup_replace_object(const struct object_id *oid);
1201
1202
/*
1203
* If object sha1 should be replaced, return the replacement object's
@@ -1205,11 +1205,11 @@ extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
1205
* either sha1 or a pointer to a permanently-allocated value. When
1206
* object replacement is suppressed, always return sha1.
1207
*/
1208
-static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
1208
+static inline const struct object_id *lookup_replace_object(const struct object_id *oid)
1209
{
1210
if (!check_replace_refs)
1211
- return sha1;
1212
- return do_lookup_replace_object(sha1);
1211
+ return oid;
1212
+ return do_lookup_replace_object(oid);
1213
}
1214
1215
/* Read and unpack an object file into memory, write memory to an object file */
object.c
+4
-10
@@ -244,7 +244,7 @@ struct object *parse_object(const struct object_id *oid)
244
unsigned long size;
245
enum object_type type;
246
int eaten;
247
- const unsigned char *repl = lookup_replace_object(oid->hash);
247
+ const struct object_id *repl = lookup_replace_object(oid);
248
void *buffer;
249
struct object *obj;
250
@@ -255,10 +255,7 @@ struct object *parse_object(const struct object_id *oid)
255
if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
256
(!obj && has_object_file(oid) &&
257
oid_object_info(oid, NULL) == OBJ_BLOB)) {
258
- struct object_id reploid;
259
- hashcpy(reploid.hash, repl);
260
-
261
- if (check_object_signature(&reploid, NULL, 0, NULL) < 0) {
258
+ if (check_object_signature(repl, NULL, 0, NULL) < 0) {
259
error("sha1 mismatch %s", oid_to_hex(oid));
260
return NULL;
261
}
@@ -268,12 +265,9 @@ struct object *parse_object(const struct object_id *oid)
265
266
buffer = read_object_file(oid, &type, &size);
267
if (buffer) {
271
- struct object_id reploid;
272
- hashcpy(reploid.hash, repl);
273
-
274
- if (check_object_signature(&reploid, buffer, size, type_name(type)) < 0) {
268
+ if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
269
free(buffer);
276
- error("sha1 mismatch %s", sha1_to_hex(repl));
270
+ error("sha1 mismatch %s", oid_to_hex(repl));
271
return NULL;
272
}
273
replace_object.c
+7
-7
@@ -92,16 +92,16 @@ static void prepare_replace_object(void)
92
#define MAXREPLACEDEPTH 5
93
94
/*
95
- * If a replacement for object sha1 has been set up, return the
95
+ * If a replacement for object oid has been set up, return the
96
* replacement object's name (replaced recursively, if necessary).
97
- * The return value is either sha1 or a pointer to a
97
+ * The return value is either oid or a pointer to a
98
* permanently-allocated value. This function always respects replace
99
* references, regardless of the value of check_replace_refs.
100
*/
101
-const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
101
+const struct object_id *do_lookup_replace_object(const struct object_id *oid)
102
{
103
int pos, depth = MAXREPLACEDEPTH;
104
- const unsigned char *cur = sha1;
104
+ const struct object_id *cur = oid;
105
106
prepare_replace_object();
107
@@ -109,11 +109,11 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
109
do {
110
if (--depth < 0)
111
die("replace depth too high for object %s",
112
- sha1_to_hex(sha1));
112
+ oid_to_hex(oid));
113
114
- pos = replace_object_pos(cur);
114
+ pos = replace_object_pos(cur->hash);
115
if (0 <= pos)
116
- cur = replace_object[pos]->replacement.hash;
116
+ cur = &replace_object[pos]->replacement;
117
} while (0 <= pos);
118
119
return cur;
sha1_file.c
+20
-22
@@ -1227,22 +1227,20 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
1227
static struct object_info blank_oi = OBJECT_INFO_INIT;
1228
struct pack_entry e;
1229
int rtype;
1230
- const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
1231
- lookup_replace_object(oid->hash) :
1232
- oid->hash;
1230
+ const struct object_id *real = oid;
1231
int already_retried = 0;
1234
- struct object_id realoid;
1232
1236
- hashcpy(realoid.hash, real);
1233
+ if (flags & OBJECT_INFO_LOOKUP_REPLACE)
1234
+ real = lookup_replace_object(oid);
1235
1238
- if (is_null_sha1(real))
1236
+ if (is_null_oid(real))
1237
return -1;
1238
1239
if (!oi)
1240
oi = &blank_oi;
1241
1242
if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
1245
- struct cached_object *co = find_cached_object(real);
1243
+ struct cached_object *co = find_cached_object(real->hash);
1244
if (co) {
1245
if (oi->typep)
1246
*(oi->typep) = co->type;
@@ -1262,16 +1260,16 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
1260
}
1261
1262
while (1) {
1265
- if (find_pack_entry(real, &e))
1263
+ if (find_pack_entry(real->hash, &e))
1264
break;
1265
1266
/* Most likely it's a loose object. */
1269
- if (!sha1_loose_object_info(real, oi, flags))
1267
+ if (!sha1_loose_object_info(real->hash, oi, flags))
1268
return 0;
1269
1270
/* Not a loose object; someone else may have just packed it. */
1271
reprepare_packed_git();
1274
- if (find_pack_entry(real, &e))
1272
+ if (find_pack_entry(real->hash, &e))
1273
break;
1274
1275
/* Check if it is a missing object */
@@ -1281,7 +1279,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
1279
* TODO Investigate haveing fetch_object() return
1280
* TODO error/success and stopping the music here.
1281
*/
1284
- fetch_object(repository_format_partial_clone, real);
1282
+ fetch_object(repository_format_partial_clone, real->hash);
1283
already_retried = 1;
1284
continue;
1285
}
@@ -1297,8 +1295,8 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
1295
return 0;
1296
rtype = packed_object_info(e.p, e.offset, oi);
1297
if (rtype < 0) {
1300
- mark_bad_packed_object(e.p, real);
1301
- return oid_object_info_extended(&realoid, oi, 0);
1298
+ mark_bad_packed_object(e.p, real->hash);
1299
+ return oid_object_info_extended(real, oi, 0);
1300
} else if (oi->whence == OI_PACKED) {
1301
oi->u.packed.offset = e.offset;
1302
oi->u.packed.pack = e.p;
@@ -1372,11 +1370,11 @@ void *read_object_file_extended(const struct object_id *oid,
1370
const struct packed_git *p;
1371
const char *path;
1372
struct stat st;
1375
- const unsigned char *repl = lookup_replace ? lookup_replace_object(oid->hash)
1376
- : oid->hash;
1373
+ const struct object_id *repl = lookup_replace ? lookup_replace_object(oid)
1374
+ : oid;
1375
1376
errno = 0;
1379
- data = read_object(repl, type, size);
1377
+ data = read_object(repl->hash, type, size);
1378
if (data)
1379
return data;
1380
@@ -1384,17 +1382,17 @@ void *read_object_file_extended(const struct object_id *oid,
1382
die_errno("failed to read object %s", oid_to_hex(oid));
1383
1384
/* die if we replaced an object with one that does not exist */
1387
- if (repl != oid->hash)
1385
+ if (repl != oid)
1386
die("replacement %s not found for %s",
1389
- sha1_to_hex(repl), oid_to_hex(oid));
1387
+ oid_to_hex(repl), oid_to_hex(oid));
1388
1391
- if (!stat_sha1_file(repl, &st, &path))
1389
+ if (!stat_sha1_file(repl->hash, &st, &path))
1390
die("loose object %s (stored in %s) is corrupt",
1393
- sha1_to_hex(repl), path);
1391
+ oid_to_hex(repl), path);
1392
1395
- if ((p = has_packed_and_bad(repl)) != NULL)
1393
+ if ((p = has_packed_and_bad(repl->hash)) != NULL)
1394
die("packed object %s (stored in %s) is corrupt",
1397
- sha1_to_hex(repl), p->pack_name);
1395
+ oid_to_hex(repl), p->pack_name);
1396
1397
return NULL;
1398
}
streaming.c
+5
-11
@@ -105,19 +105,16 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
105
return st->vtbl->read(st, buf, sz);
106
}
107
108
-static enum input_source istream_source(const unsigned char *sha1,
108
+static enum input_source istream_source(const struct object_id *oid,
109
enum object_type *type,
110
struct object_info *oi)
111
{
112
unsigned long size;
113
int status;
114
- struct object_id oid;
115
-
116
- hashcpy(oid.hash, sha1);
114
115
oi->typep = type;
116
oi->sizep = &size;
120
- status = oid_object_info_extended(&oid, oi, 0);
117
+ status = oid_object_info_extended(oid, oi, 0);
118
if (status < 0)
119
return stream_error;
120
@@ -140,18 +137,15 @@ struct git_istream *open_istream(const struct object_id *oid,
137
{
138
struct git_istream *st;
139
struct object_info oi = OBJECT_INFO_INIT;
143
- const unsigned char *real = lookup_replace_object(oid->hash);
140
+ const struct object_id *real = lookup_replace_object(oid);
141
enum input_source src = istream_source(real, type, &oi);
145
- struct object_id realoid;
146
-
147
- hashcpy(realoid.hash, real);
142
143
if (src < 0)
144
return NULL;
145
146
st = xmalloc(sizeof(*st));
153
- if (open_istream_tbl[src](st, &oi, &realoid, type)) {
154
- if (open_istream_incore(st, &oi, &realoid, type)) {
147
+ if (open_istream_tbl[src](st, &oi, real, type)) {
148
+ if (open_istream_incore(st, &oi, real, type)) {
149
free(st);
150
return NULL;
151
}