Skip to content

Commit 834bc47

Browse files
bk2204gitster
authored andcommitted
builtin/unpack-objects: convert to struct object_id
Convert struct delta_info and struct object_info, as well as the various functions, to use struct object_id. Convert several hard-coded 20 values to GIT_SHA1_RAWSZ. Among the functions converted is a caller of lookup_blob, which we will convert shortly. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6a492b commit 834bc47

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

builtin/unpack-objects.c

+32-32
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static void *get_data(unsigned long size)
127127
}
128128

129129
struct delta_info {
130-
unsigned char base_sha1[20];
130+
struct object_id base_oid;
131131
unsigned nr;
132132
off_t base_offset;
133133
unsigned long size;
@@ -137,13 +137,13 @@ struct delta_info {
137137

138138
static struct delta_info *delta_list;
139139

140-
static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1,
140+
static void add_delta_to_list(unsigned nr, const struct object_id *base_oid,
141141
off_t base_offset,
142142
void *delta, unsigned long size)
143143
{
144144
struct delta_info *info = xmalloc(sizeof(*info));
145145

146-
hashcpy(info->base_sha1, base_sha1);
146+
oidcpy(&info->base_oid, base_oid);
147147
info->base_offset = base_offset;
148148
info->size = size;
149149
info->delta = delta;
@@ -154,7 +154,7 @@ static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1,
154154

155155
struct obj_info {
156156
off_t offset;
157-
unsigned char sha1[20];
157+
struct object_id oid;
158158
struct object *obj;
159159
};
160160

@@ -170,9 +170,9 @@ static unsigned nr_objects;
170170
*/
171171
static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
172172
{
173-
unsigned char sha1[20];
173+
struct object_id oid;
174174

175-
if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), sha1) < 0)
175+
if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), oid.hash) < 0)
176176
die("failed to write object %s", oid_to_hex(&obj->oid));
177177
obj->flags |= FLAG_WRITTEN;
178178
}
@@ -237,19 +237,19 @@ static void write_object(unsigned nr, enum object_type type,
237237
void *buf, unsigned long size)
238238
{
239239
if (!strict) {
240-
if (write_sha1_file(buf, size, typename(type), obj_list[nr].sha1) < 0)
240+
if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0)
241241
die("failed to write object");
242242
added_object(nr, type, buf, size);
243243
free(buf);
244244
obj_list[nr].obj = NULL;
245245
} else if (type == OBJ_BLOB) {
246246
struct blob *blob;
247-
if (write_sha1_file(buf, size, typename(type), obj_list[nr].sha1) < 0)
247+
if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0)
248248
die("failed to write object");
249249
added_object(nr, type, buf, size);
250250
free(buf);
251251

252-
blob = lookup_blob(obj_list[nr].sha1);
252+
blob = lookup_blob(obj_list[nr].oid.hash);
253253
if (blob)
254254
blob->object.flags |= FLAG_WRITTEN;
255255
else
@@ -258,9 +258,9 @@ static void write_object(unsigned nr, enum object_type type,
258258
} else {
259259
struct object *obj;
260260
int eaten;
261-
hash_sha1_file(buf, size, typename(type), obj_list[nr].sha1);
261+
hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash);
262262
added_object(nr, type, buf, size);
263-
obj = parse_object_buffer(obj_list[nr].sha1, type, size, buf, &eaten);
263+
obj = parse_object_buffer(obj_list[nr].oid.hash, type, size, buf, &eaten);
264264
if (!obj)
265265
die("invalid %s", typename(type));
266266
add_object_buffer(obj, buf, size);
@@ -296,7 +296,7 @@ static void added_object(unsigned nr, enum object_type type,
296296
struct delta_info *info;
297297

298298
while ((info = *p) != NULL) {
299-
if (!hashcmp(info->base_sha1, obj_list[nr].sha1) ||
299+
if (!oidcmp(&info->base_oid, &obj_list[nr].oid) ||
300300
info->base_offset == obj_list[nr].offset) {
301301
*p = info->next;
302302
p = &delta_list;
@@ -320,12 +320,12 @@ static void unpack_non_delta_entry(enum object_type type, unsigned long size,
320320
free(buf);
321321
}
322322

323-
static int resolve_against_held(unsigned nr, const unsigned char *base,
323+
static int resolve_against_held(unsigned nr, const struct object_id *base,
324324
void *delta_data, unsigned long delta_size)
325325
{
326326
struct object *obj;
327327
struct obj_buffer *obj_buffer;
328-
obj = lookup_object(base);
328+
obj = lookup_object(base->hash);
329329
if (!obj)
330330
return 0;
331331
obj_buffer = lookup_object_buffer(obj);
@@ -341,25 +341,25 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
341341
{
342342
void *delta_data, *base;
343343
unsigned long base_size;
344-
unsigned char base_sha1[20];
344+
struct object_id base_oid;
345345

346346
if (type == OBJ_REF_DELTA) {
347-
hashcpy(base_sha1, fill(20));
348-
use(20);
347+
hashcpy(base_oid.hash, fill(GIT_SHA1_RAWSZ));
348+
use(GIT_SHA1_RAWSZ);
349349
delta_data = get_data(delta_size);
350350
if (dry_run || !delta_data) {
351351
free(delta_data);
352352
return;
353353
}
354-
if (has_sha1_file(base_sha1))
354+
if (has_object_file(&base_oid))
355355
; /* Ok we have this one */
356-
else if (resolve_against_held(nr, base_sha1,
356+
else if (resolve_against_held(nr, &base_oid,
357357
delta_data, delta_size))
358358
return; /* we are done */
359359
else {
360360
/* cannot resolve yet --- queue it */
361-
hashclr(obj_list[nr].sha1);
362-
add_delta_to_list(nr, base_sha1, 0, delta_data, delta_size);
361+
oidclr(&obj_list[nr].oid);
362+
add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size);
363363
return;
364364
}
365365
} else {
@@ -399,8 +399,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
399399
} else if (base_offset > obj_list[mid].offset) {
400400
lo = mid + 1;
401401
} else {
402-
hashcpy(base_sha1, obj_list[mid].sha1);
403-
base_found = !is_null_sha1(base_sha1);
402+
oidcpy(&base_oid, &obj_list[mid].oid);
403+
base_found = !is_null_oid(&base_oid);
404404
break;
405405
}
406406
}
@@ -409,19 +409,19 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
409409
* The delta base object is itself a delta that
410410
* has not been resolved yet.
411411
*/
412-
hashclr(obj_list[nr].sha1);
413-
add_delta_to_list(nr, null_sha1, base_offset, delta_data, delta_size);
412+
oidclr(&obj_list[nr].oid);
413+
add_delta_to_list(nr, &null_oid, base_offset, delta_data, delta_size);
414414
return;
415415
}
416416
}
417417

418-
if (resolve_against_held(nr, base_sha1, delta_data, delta_size))
418+
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
419419
return;
420420

421-
base = read_sha1_file(base_sha1, &type, &base_size);
421+
base = read_sha1_file(base_oid.hash, &type, &base_size);
422422
if (!base) {
423423
error("failed to read delta-pack base object %s",
424-
sha1_to_hex(base_sha1));
424+
oid_to_hex(&base_oid));
425425
if (!recover)
426426
exit(1);
427427
has_errors = 1;
@@ -505,7 +505,7 @@ static void unpack_all(void)
505505
int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
506506
{
507507
int i;
508-
unsigned char sha1[20];
508+
struct object_id oid;
509509

510510
check_replace_refs = 0;
511511

@@ -566,12 +566,12 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
566566
git_SHA1_Init(&ctx);
567567
unpack_all();
568568
git_SHA1_Update(&ctx, buffer, offset);
569-
git_SHA1_Final(sha1, &ctx);
569+
git_SHA1_Final(oid.hash, &ctx);
570570
if (strict)
571571
write_rest();
572-
if (hashcmp(fill(20), sha1))
572+
if (hashcmp(fill(GIT_SHA1_RAWSZ), oid.hash))
573573
die("final sha1 did not match");
574-
use(20);
574+
use(GIT_SHA1_RAWSZ);
575575

576576
/* Write the last part of the buffer to stdout */
577577
while (len) {

0 commit comments

Comments
 (0)