sha1_file: convert read_object_with_reference to object_id

Convert read_object_with_reference to take pointers to struct object_id. Update the internals of the function accordingly. 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 02f0547eaaeeec3446b77a29593f9233cf94d626
7 files changed +28 -28
builtin/cat-file.c
+1 -1
@@ -159,7 +159,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
159 * fall-back to the usual case.
160 */
161 }
162 - buf = read_object_with_reference(oid.hash, exp_type, &size, NULL);
162 + buf = read_object_with_reference(&oid, exp_type, &size, NULL);
163 break;
164
165 default:
builtin/grep.c
+2 -2
@@ -452,7 +452,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
452 object = parse_object_or_die(oid, oid_to_hex(oid));
453
454 grep_read_lock();
455 - data = read_object_with_reference(object->oid.hash, tree_type,
455 + data = read_object_with_reference(&object->oid, tree_type,
456 &size, NULL);
457 grep_read_unlock();
458
@@ -614,7 +614,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
614 int hit, len;
615
616 grep_read_lock();
617 - data = read_object_with_reference(obj->oid.hash, tree_type,
617 + data = read_object_with_reference(&obj->oid, tree_type,
618 &size, NULL);
619 grep_read_unlock();
620
builtin/pack-objects.c
+1 -1
@@ -1351,7 +1351,7 @@ static void add_preferred_base(struct object_id *oid)
1351 if (window <= num_preferred_base++)
1352 return;
1353
1354 - data = read_object_with_reference(oid->hash, tree_type, &size, tree_oid.hash);
1354 + data = read_object_with_reference(oid, tree_type, &size, &tree_oid);
1355 if (!data)
1356 return;
1357
cache.h
+2 -2
@@ -1431,10 +1431,10 @@ extern int df_name_compare(const char *name1, int len1, int mode1, const char *n
1431 extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
1432 extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
1433
1434 -extern void *read_object_with_reference(const unsigned char *sha1,
1434 +extern void *read_object_with_reference(const struct object_id *oid,
1435 const char *required_type,
1436 unsigned long *size,
1437 - unsigned char *sha1_ret);
1437 + struct object_id *oid_ret);
1438
1439 extern struct object *peel_to_type(const char *name, int namelen,
1440 struct object *o, enum object_type);
fast-import.c
+8 -7
@@ -2583,8 +2583,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
2583 oidcpy(&commit_oid, &commit_oe->idx.oid);
2584 } else if (!get_oid(p, &commit_oid)) {
2585 unsigned long size;
2586 - char *buf = read_object_with_reference(commit_oid.hash,
2587 - commit_type, &size, commit_oid.hash);
2586 + char *buf = read_object_with_reference(&commit_oid,
2587 + commit_type, &size,
2588 + &commit_oid);
2589 if (!buf || size < 46)
2590 die("Not a valid commit: %s", p);
2591 free(buf);
@@ -2653,9 +2654,8 @@ static void parse_from_existing(struct branch *b)
2654 unsigned long size;
2655 char *buf;
2656
2656 - buf = read_object_with_reference(b->oid.hash,
2657 - commit_type, &size,
2658 - b->oid.hash);
2657 + buf = read_object_with_reference(&b->oid, commit_type, &size,
2658 + &b->oid);
2659 parse_from_commit(b, buf, size);
2660 free(buf);
2661 }
@@ -2732,8 +2732,9 @@ static struct hash_list *parse_merge(unsigned int *count)
2732 oidcpy(&n->oid, &oe->idx.oid);
2733 } else if (!get_oid(from, &n->oid)) {
2734 unsigned long size;
2735 - char *buf = read_object_with_reference(n->oid.hash,
2736 - commit_type, &size, n->oid.hash);
2735 + char *buf = read_object_with_reference(&n->oid,
2736 + commit_type,
2737 + &size, &n->oid);
2738 if (!buf || size < 46)
2739 die("Not a valid commit: %s", from);
2740 free(buf);
sha1_file.c
+10 -10
@@ -1399,29 +1399,29 @@ void *read_sha1_file_extended(const unsigned char *sha1,
1399 return NULL;
1400 }
1401
1402 -void *read_object_with_reference(const unsigned char *sha1,
1402 +void *read_object_with_reference(const struct object_id *oid,
1403 const char *required_type_name,
1404 unsigned long *size,
1405 - unsigned char *actual_sha1_return)
1405 + struct object_id *actual_oid_return)
1406 {
1407 enum object_type type, required_type;
1408 void *buffer;
1409 unsigned long isize;
1410 - unsigned char actual_sha1[20];
1410 + struct object_id actual_oid;
1411
1412 required_type = type_from_string(required_type_name);
1413 - hashcpy(actual_sha1, sha1);
1413 + oidcpy(&actual_oid, oid);
1414 while (1) {
1415 int ref_length = -1;
1416 const char *ref_type = NULL;
1417
1418 - buffer = read_sha1_file(actual_sha1, &type, &isize);
1418 + buffer = read_sha1_file(actual_oid.hash, &type, &isize);
1419 if (!buffer)
1420 return NULL;
1421 if (type == required_type) {
1422 *size = isize;
1423 - if (actual_sha1_return)
1424 - hashcpy(actual_sha1_return, actual_sha1);
1423 + if (actual_oid_return)
1424 + oidcpy(actual_oid_return, &actual_oid);
1425 return buffer;
1426 }
1427 /* Handle references */
@@ -1435,15 +1435,15 @@ void *read_object_with_reference(const unsigned char *sha1,
1435 }
1436 ref_length = strlen(ref_type);
1437
1438 - if (ref_length + 40 > isize ||
1438 + if (ref_length + GIT_SHA1_HEXSZ > isize ||
1439 memcmp(buffer, ref_type, ref_length) ||
1440 - get_sha1_hex((char *) buffer + ref_length, actual_sha1)) {
1440 + get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
1441 free(buffer);
1442 return NULL;
1443 }
1444 free(buffer);
1445 /* Now we have the ID of the referred-to object in
1446 - * actual_sha1. Check again. */
1446 + * actual_oid. Check again. */
1447 }
1448 }
1449
tree-walk.c
+4 -5
@@ -84,8 +84,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)
84 void *buf = NULL;
85
86 if (oid) {
87 - buf = read_object_with_reference(oid->hash, tree_type, &size,
88 - NULL);
87 + buf = read_object_with_reference(oid, tree_type, &size, NULL);
88 if (!buf)
89 die("unable to read tree %s", oid_to_hex(oid));
90 }
@@ -534,7 +533,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob
533 unsigned long size;
534 struct object_id root;
535
537 - tree = read_object_with_reference(tree_oid->hash, tree_type, &size, root.hash);
536 + tree = read_object_with_reference(tree_oid, tree_type, &size, &root);
537 if (!tree)
538 return -1;
539
@@ -601,9 +600,9 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
600 void *tree;
601 struct object_id root;
602 unsigned long size;
604 - tree = read_object_with_reference(current_tree_oid.hash,
603 + tree = read_object_with_reference(&current_tree_oid,
604 tree_type, &size,
606 - root.hash);
605 + &root);
606 if (!tree)
607 goto done;
608