Skip to content

Commit 02f0547

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

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
159159
* fall-back to the usual case.
160160
*/
161161
}
162-
buf = read_object_with_reference(oid.hash, exp_type, &size, NULL);
162+
buf = read_object_with_reference(&oid, exp_type, &size, NULL);
163163
break;
164164

165165
default:

builtin/grep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
452452
object = parse_object_or_die(oid, oid_to_hex(oid));
453453

454454
grep_read_lock();
455-
data = read_object_with_reference(object->oid.hash, tree_type,
455+
data = read_object_with_reference(&object->oid, tree_type,
456456
&size, NULL);
457457
grep_read_unlock();
458458

@@ -614,7 +614,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
614614
int hit, len;
615615

616616
grep_read_lock();
617-
data = read_object_with_reference(obj->oid.hash, tree_type,
617+
data = read_object_with_reference(&obj->oid, tree_type,
618618
&size, NULL);
619619
grep_read_unlock();
620620

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ static void add_preferred_base(struct object_id *oid)
13511351
if (window <= num_preferred_base++)
13521352
return;
13531353

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);
13551355
if (!data)
13561356
return;
13571357

cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,10 +1431,10 @@ extern int df_name_compare(const char *name1, int len1, int mode1, const char *n
14311431
extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
14321432
extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
14331433

1434-
extern void *read_object_with_reference(const unsigned char *sha1,
1434+
extern void *read_object_with_reference(const struct object_id *oid,
14351435
const char *required_type,
14361436
unsigned long *size,
1437-
unsigned char *sha1_ret);
1437+
struct object_id *oid_ret);
14381438

14391439
extern struct object *peel_to_type(const char *name, int namelen,
14401440
struct object *o, enum object_type);

fast-import.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,8 +2583,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
25832583
oidcpy(&commit_oid, &commit_oe->idx.oid);
25842584
} else if (!get_oid(p, &commit_oid)) {
25852585
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);
25882589
if (!buf || size < 46)
25892590
die("Not a valid commit: %s", p);
25902591
free(buf);
@@ -2653,9 +2654,8 @@ static void parse_from_existing(struct branch *b)
26532654
unsigned long size;
26542655
char *buf;
26552656

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);
26592659
parse_from_commit(b, buf, size);
26602660
free(buf);
26612661
}
@@ -2732,8 +2732,9 @@ static struct hash_list *parse_merge(unsigned int *count)
27322732
oidcpy(&n->oid, &oe->idx.oid);
27332733
} else if (!get_oid(from, &n->oid)) {
27342734
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);
27372738
if (!buf || size < 46)
27382739
die("Not a valid commit: %s", from);
27392740
free(buf);

sha1_file.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,29 +1399,29 @@ void *read_sha1_file_extended(const unsigned char *sha1,
13991399
return NULL;
14001400
}
14011401

1402-
void *read_object_with_reference(const unsigned char *sha1,
1402+
void *read_object_with_reference(const struct object_id *oid,
14031403
const char *required_type_name,
14041404
unsigned long *size,
1405-
unsigned char *actual_sha1_return)
1405+
struct object_id *actual_oid_return)
14061406
{
14071407
enum object_type type, required_type;
14081408
void *buffer;
14091409
unsigned long isize;
1410-
unsigned char actual_sha1[20];
1410+
struct object_id actual_oid;
14111411

14121412
required_type = type_from_string(required_type_name);
1413-
hashcpy(actual_sha1, sha1);
1413+
oidcpy(&actual_oid, oid);
14141414
while (1) {
14151415
int ref_length = -1;
14161416
const char *ref_type = NULL;
14171417

1418-
buffer = read_sha1_file(actual_sha1, &type, &isize);
1418+
buffer = read_sha1_file(actual_oid.hash, &type, &isize);
14191419
if (!buffer)
14201420
return NULL;
14211421
if (type == required_type) {
14221422
*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);
14251425
return buffer;
14261426
}
14271427
/* Handle references */
@@ -1435,15 +1435,15 @@ void *read_object_with_reference(const unsigned char *sha1,
14351435
}
14361436
ref_length = strlen(ref_type);
14371437

1438-
if (ref_length + 40 > isize ||
1438+
if (ref_length + GIT_SHA1_HEXSZ > isize ||
14391439
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)) {
14411441
free(buffer);
14421442
return NULL;
14431443
}
14441444
free(buffer);
14451445
/* Now we have the ID of the referred-to object in
1446-
* actual_sha1. Check again. */
1446+
* actual_oid. Check again. */
14471447
}
14481448
}
14491449

tree-walk.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)
8484
void *buf = NULL;
8585

8686
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);
8988
if (!buf)
9089
die("unable to read tree %s", oid_to_hex(oid));
9190
}
@@ -534,7 +533,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob
534533
unsigned long size;
535534
struct object_id root;
536535

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);
538537
if (!tree)
539538
return -1;
540539

@@ -601,9 +600,9 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
601600
void *tree;
602601
struct object_id root;
603602
unsigned long size;
604-
tree = read_object_with_reference(current_tree_oid.hash,
603+
tree = read_object_with_reference(&current_tree_oid,
605604
tree_type, &size,
606-
root.hash);
605+
&root);
607606
if (!tree)
608607
goto done;
609608

0 commit comments

Comments
 (0)