Skip to content

Commit b383a13

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b4f5aca commit b383a13

File tree

6 files changed

+42
-59
lines changed

6 files changed

+42
-59
lines changed

builtin/mktag.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
2424
enum object_type type;
2525
unsigned long size;
2626
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);
2828

2929
if (buffer) {
30-
struct object_id reploid;
31-
hashcpy(reploid.hash, repl);
32-
3330
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);
3532
free(buffer);
3633
}
3734
return ret;

cache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,19 +1197,19 @@ static inline void *read_object_file(const struct object_id *oid, enum object_ty
11971197
* This internal function is only declared here for the benefit of
11981198
* lookup_replace_object(). Please do not call it directly.
11991199
*/
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);
12011201

12021202
/*
12031203
* If object sha1 should be replaced, return the replacement object's
12041204
* name (replaced recursively, if necessary). The return value is
12051205
* either sha1 or a pointer to a permanently-allocated value. When
12061206
* object replacement is suppressed, always return sha1.
12071207
*/
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)
12091209
{
12101210
if (!check_replace_refs)
1211-
return sha1;
1212-
return do_lookup_replace_object(sha1);
1211+
return oid;
1212+
return do_lookup_replace_object(oid);
12131213
}
12141214

12151215
/* Read and unpack an object file into memory, write memory to an object file */

object.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ struct object *parse_object(const struct object_id *oid)
244244
unsigned long size;
245245
enum object_type type;
246246
int eaten;
247-
const unsigned char *repl = lookup_replace_object(oid->hash);
247+
const struct object_id *repl = lookup_replace_object(oid);
248248
void *buffer;
249249
struct object *obj;
250250

@@ -255,10 +255,7 @@ struct object *parse_object(const struct object_id *oid)
255255
if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
256256
(!obj && has_object_file(oid) &&
257257
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) {
262259
error("sha1 mismatch %s", oid_to_hex(oid));
263260
return NULL;
264261
}
@@ -268,12 +265,9 @@ struct object *parse_object(const struct object_id *oid)
268265

269266
buffer = read_object_file(oid, &type, &size);
270267
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) {
275269
free(buffer);
276-
error("sha1 mismatch %s", sha1_to_hex(repl));
270+
error("sha1 mismatch %s", oid_to_hex(repl));
277271
return NULL;
278272
}
279273

replace_object.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,28 @@ static void prepare_replace_object(void)
9292
#define MAXREPLACEDEPTH 5
9393

9494
/*
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
9696
* 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
9898
* permanently-allocated value. This function always respects replace
9999
* references, regardless of the value of check_replace_refs.
100100
*/
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)
102102
{
103103
int pos, depth = MAXREPLACEDEPTH;
104-
const unsigned char *cur = sha1;
104+
const struct object_id *cur = oid;
105105

106106
prepare_replace_object();
107107

108108
/* Try to recursively replace the object */
109109
do {
110110
if (--depth < 0)
111111
die("replace depth too high for object %s",
112-
sha1_to_hex(sha1));
112+
oid_to_hex(oid));
113113

114-
pos = replace_object_pos(cur);
114+
pos = replace_object_pos(cur->hash);
115115
if (0 <= pos)
116-
cur = replace_object[pos]->replacement.hash;
116+
cur = &replace_object[pos]->replacement;
117117
} while (0 <= pos);
118118

119119
return cur;

sha1_file.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,22 +1227,20 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
12271227
static struct object_info blank_oi = OBJECT_INFO_INIT;
12281228
struct pack_entry e;
12291229
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;
12331231
int already_retried = 0;
1234-
struct object_id realoid;
12351232

1236-
hashcpy(realoid.hash, real);
1233+
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
1234+
real = lookup_replace_object(oid);
12371235

1238-
if (is_null_sha1(real))
1236+
if (is_null_oid(real))
12391237
return -1;
12401238

12411239
if (!oi)
12421240
oi = &blank_oi;
12431241

12441242
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);
12461244
if (co) {
12471245
if (oi->typep)
12481246
*(oi->typep) = co->type;
@@ -1262,16 +1260,16 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
12621260
}
12631261

12641262
while (1) {
1265-
if (find_pack_entry(real, &e))
1263+
if (find_pack_entry(real->hash, &e))
12661264
break;
12671265

12681266
/* 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))
12701268
return 0;
12711269

12721270
/* Not a loose object; someone else may have just packed it. */
12731271
reprepare_packed_git();
1274-
if (find_pack_entry(real, &e))
1272+
if (find_pack_entry(real->hash, &e))
12751273
break;
12761274

12771275
/* 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
12811279
* TODO Investigate haveing fetch_object() return
12821280
* TODO error/success and stopping the music here.
12831281
*/
1284-
fetch_object(repository_format_partial_clone, real);
1282+
fetch_object(repository_format_partial_clone, real->hash);
12851283
already_retried = 1;
12861284
continue;
12871285
}
@@ -1297,8 +1295,8 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
12971295
return 0;
12981296
rtype = packed_object_info(e.p, e.offset, oi);
12991297
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);
13021300
} else if (oi->whence == OI_PACKED) {
13031301
oi->u.packed.offset = e.offset;
13041302
oi->u.packed.pack = e.p;
@@ -1372,29 +1370,29 @@ void *read_object_file_extended(const struct object_id *oid,
13721370
const struct packed_git *p;
13731371
const char *path;
13741372
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;
13771375

13781376
errno = 0;
1379-
data = read_object(repl, type, size);
1377+
data = read_object(repl->hash, type, size);
13801378
if (data)
13811379
return data;
13821380

13831381
if (errno && errno != ENOENT)
13841382
die_errno("failed to read object %s", oid_to_hex(oid));
13851383

13861384
/* die if we replaced an object with one that does not exist */
1387-
if (repl != oid->hash)
1385+
if (repl != oid)
13881386
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));
13901388

1391-
if (!stat_sha1_file(repl, &st, &path))
1389+
if (!stat_sha1_file(repl->hash, &st, &path))
13921390
die("loose object %s (stored in %s) is corrupt",
1393-
sha1_to_hex(repl), path);
1391+
oid_to_hex(repl), path);
13941392

1395-
if ((p = has_packed_and_bad(repl)) != NULL)
1393+
if ((p = has_packed_and_bad(repl->hash)) != NULL)
13961394
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);
13981396

13991397
return NULL;
14001398
}

streaming.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,16 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
105105
return st->vtbl->read(st, buf, sz);
106106
}
107107

108-
static enum input_source istream_source(const unsigned char *sha1,
108+
static enum input_source istream_source(const struct object_id *oid,
109109
enum object_type *type,
110110
struct object_info *oi)
111111
{
112112
unsigned long size;
113113
int status;
114-
struct object_id oid;
115-
116-
hashcpy(oid.hash, sha1);
117114

118115
oi->typep = type;
119116
oi->sizep = &size;
120-
status = oid_object_info_extended(&oid, oi, 0);
117+
status = oid_object_info_extended(oid, oi, 0);
121118
if (status < 0)
122119
return stream_error;
123120

@@ -140,18 +137,15 @@ struct git_istream *open_istream(const struct object_id *oid,
140137
{
141138
struct git_istream *st;
142139
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);
144141
enum input_source src = istream_source(real, type, &oi);
145-
struct object_id realoid;
146-
147-
hashcpy(realoid.hash, real);
148142

149143
if (src < 0)
150144
return NULL;
151145

152146
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)) {
155149
free(st);
156150
return NULL;
157151
}

0 commit comments

Comments
 (0)