Skip to content

Commit f4e54d0

Browse files
bk2204peff
authored andcommitted
Convert struct ref to use object_id.
Use struct object_id in three fields in struct ref and convert all the necessary places that use it. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent b419aa2 commit f4e54d0

18 files changed

+151
-151
lines changed

builtin/clone.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static void write_remote_refs(const struct ref *local_refs)
559559
for (r = local_refs; r; r = r->next) {
560560
if (!r->peer_ref)
561561
continue;
562-
if (ref_transaction_create(t, r->peer_ref->name, r->old_sha1,
562+
if (ref_transaction_create(t, r->peer_ref->name, r->old_oid.hash,
563563
0, NULL, &err))
564564
die("%s", err.buf);
565565
}
@@ -579,9 +579,9 @@ static void write_followtags(const struct ref *refs, const char *msg)
579579
continue;
580580
if (ends_with(ref->name, "^{}"))
581581
continue;
582-
if (!has_sha1_file(ref->old_sha1))
582+
if (!has_object_file(&ref->old_oid))
583583
continue;
584-
update_ref(msg, ref->name, ref->old_sha1,
584+
update_ref(msg, ref->name, ref->old_oid.hash,
585585
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
586586
}
587587
}
@@ -601,7 +601,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
601601
if (!ref)
602602
return -1;
603603

604-
hashcpy(sha1, ref->old_sha1);
604+
hashcpy(sha1, ref->old_oid.hash);
605605
*rm = ref->next;
606606
return 0;
607607
}
@@ -650,12 +650,12 @@ static void update_head(const struct ref *our, const struct ref *remote,
650650
/* Local default branch link */
651651
create_symref("HEAD", our->name, NULL);
652652
if (!option_bare) {
653-
update_ref(msg, "HEAD", our->old_sha1, NULL, 0,
653+
update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0,
654654
UPDATE_REFS_DIE_ON_ERR);
655655
install_branch_config(0, head, option_origin, our->name);
656656
}
657657
} else if (our) {
658-
struct commit *c = lookup_commit_reference(our->old_sha1);
658+
struct commit *c = lookup_commit_reference(our->old_oid.hash);
659659
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
660660
update_ref(msg, "HEAD", c->object.sha1,
661661
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
@@ -665,7 +665,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
665665
* HEAD points to a branch but we don't know which one.
666666
* Detach HEAD in all these cases.
667667
*/
668-
update_ref(msg, "HEAD", remote->old_sha1,
668+
update_ref(msg, "HEAD", remote->old_oid.hash,
669669
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
670670
}
671671
}
@@ -1016,7 +1016,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10161016
* remote HEAD check.
10171017
*/
10181018
for (ref = refs; ref; ref = ref->next)
1019-
if (is_null_sha1(ref->old_sha1)) {
1019+
if (is_null_oid(&ref->old_oid)) {
10201020
complete_refs_before_fetch = 0;
10211021
break;
10221022
}

builtin/fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
1717
unsigned char sha1[20];
1818

1919
if (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) {
20-
hashcpy(ref->old_sha1, sha1);
20+
hashcpy(ref->old_oid.hash, sha1);
2121
name += 41;
2222
namelen -= 41;
2323
}
@@ -210,7 +210,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
210210

211211
while (ref) {
212212
printf("%s %s\n",
213-
sha1_to_hex(ref->old_sha1), ref->name);
213+
oid_to_hex(&ref->old_oid), ref->name);
214214
ref = ref->next;
215215
}
216216

builtin/fetch.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
196196
{
197197
struct ref *rm = *head;
198198
while (rm) {
199-
if (!hashcmp(rm->old_sha1, sha1))
199+
if (!hashcmp(rm->old_oid.hash, sha1))
200200
return 1;
201201
rm = rm->next;
202202
}
@@ -224,8 +224,8 @@ static void find_non_local_tags(struct transport *transport,
224224
* as one to ignore by setting util to NULL.
225225
*/
226226
if (ends_with(ref->name, "^{}")) {
227-
if (item && !has_sha1_file(ref->old_sha1) &&
228-
!will_fetch(head, ref->old_sha1) &&
227+
if (item && !has_object_file(&ref->old_oid) &&
228+
!will_fetch(head, ref->old_oid.hash) &&
229229
!has_sha1_file(item->util) &&
230230
!will_fetch(head, item->util))
231231
item->util = NULL;
@@ -251,7 +251,7 @@ static void find_non_local_tags(struct transport *transport,
251251
continue;
252252

253253
item = string_list_insert(&remote_refs, ref->name);
254-
item->util = (void *)ref->old_sha1;
254+
item->util = (void *)&ref->old_oid;
255255
}
256256
string_list_clear(&existing_refs, 1);
257257

@@ -273,7 +273,7 @@ static void find_non_local_tags(struct transport *transport,
273273
{
274274
struct ref *rm = alloc_ref(item->string);
275275
rm->peer_ref = alloc_ref(item->string);
276-
hashcpy(rm->old_sha1, item->util);
276+
oidcpy(&rm->old_oid, item->util);
277277
**tail = rm;
278278
*tail = &rm->next;
279279
}
@@ -419,8 +419,8 @@ static int s_update_ref(const char *action,
419419
transaction = ref_transaction_begin(&err);
420420
if (!transaction ||
421421
ref_transaction_update(transaction, ref->name,
422-
ref->new_sha1,
423-
check_old ? ref->old_sha1 : NULL,
422+
ref->new_oid.hash,
423+
check_old ? ref->old_oid.hash : NULL,
424424
0, msg, &err))
425425
goto fail;
426426

@@ -453,11 +453,11 @@ static int update_local_ref(struct ref *ref,
453453
struct branch *current_branch = branch_get(NULL);
454454
const char *pretty_ref = prettify_refname(ref->name);
455455

456-
type = sha1_object_info(ref->new_sha1, NULL);
456+
type = sha1_object_info(ref->new_oid.hash, NULL);
457457
if (type < 0)
458-
die(_("object %s not found"), sha1_to_hex(ref->new_sha1));
458+
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
459459

460-
if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
460+
if (!oidcmp(&ref->old_oid, &ref->new_oid)) {
461461
if (verbosity > 0)
462462
strbuf_addf(display, "= %-*s %-*s -> %s",
463463
TRANSPORT_SUMMARY(_("[up to date]")),
@@ -468,7 +468,7 @@ static int update_local_ref(struct ref *ref,
468468
if (current_branch &&
469469
!strcmp(ref->name, current_branch->name) &&
470470
!(update_head_ok || is_bare_repository()) &&
471-
!is_null_sha1(ref->old_sha1)) {
471+
!is_null_oid(&ref->old_oid)) {
472472
/*
473473
* If this is the head, and it's not okay to update
474474
* the head, and the old value of the head isn't empty...
@@ -480,7 +480,7 @@ static int update_local_ref(struct ref *ref,
480480
return 1;
481481
}
482482

483-
if (!is_null_sha1(ref->old_sha1) &&
483+
if (!is_null_oid(&ref->old_oid) &&
484484
starts_with(ref->name, "refs/tags/")) {
485485
int r;
486486
r = s_update_ref("updating tag", ref, 0);
@@ -492,8 +492,8 @@ static int update_local_ref(struct ref *ref,
492492
return r;
493493
}
494494

495-
current = lookup_commit_reference_gently(ref->old_sha1, 1);
496-
updated = lookup_commit_reference_gently(ref->new_sha1, 1);
495+
current = lookup_commit_reference_gently(ref->old_oid.hash, 1);
496+
updated = lookup_commit_reference_gently(ref->new_oid.hash, 1);
497497
if (!current || !updated) {
498498
const char *msg;
499499
const char *what;
@@ -517,7 +517,7 @@ static int update_local_ref(struct ref *ref,
517517

518518
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
519519
(recurse_submodules != RECURSE_SUBMODULES_ON))
520-
check_for_new_submodule_commits(ref->new_sha1);
520+
check_for_new_submodule_commits(ref->new_oid.hash);
521521
r = s_update_ref(msg, ref, 0);
522522
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
523523
r ? '!' : '*',
@@ -532,10 +532,10 @@ static int update_local_ref(struct ref *ref,
532532
int r;
533533
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
534534
strbuf_addstr(&quickref, "..");
535-
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
535+
strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV);
536536
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
537537
(recurse_submodules != RECURSE_SUBMODULES_ON))
538-
check_for_new_submodule_commits(ref->new_sha1);
538+
check_for_new_submodule_commits(ref->new_oid.hash);
539539
r = s_update_ref("fast-forward", ref, 1);
540540
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
541541
r ? '!' : ' ',
@@ -549,10 +549,10 @@ static int update_local_ref(struct ref *ref,
549549
int r;
550550
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
551551
strbuf_addstr(&quickref, "...");
552-
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
552+
strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV);
553553
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
554554
(recurse_submodules != RECURSE_SUBMODULES_ON))
555-
check_for_new_submodule_commits(ref->new_sha1);
555+
check_for_new_submodule_commits(ref->new_oid.hash);
556556
r = s_update_ref("forced-update", ref, 1);
557557
strbuf_addf(display, "%c %-*s %-*s -> %s (%s)",
558558
r ? '!' : '+',
@@ -580,7 +580,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
580580
if (!ref)
581581
return -1; /* end of the list */
582582
*rm = ref->next;
583-
hashcpy(sha1, ref->old_sha1);
583+
hashcpy(sha1, ref->old_oid.hash);
584584
return 0;
585585
}
586586

@@ -631,7 +631,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
631631
continue;
632632
}
633633

634-
commit = lookup_commit_reference_gently(rm->old_sha1, 1);
634+
commit = lookup_commit_reference_gently(rm->old_oid.hash, 1);
635635
if (!commit)
636636
rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;
637637

@@ -640,8 +640,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
640640

641641
if (rm->peer_ref) {
642642
ref = alloc_ref(rm->peer_ref->name);
643-
hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
644-
hashcpy(ref->new_sha1, rm->old_sha1);
643+
oidcpy(&ref->old_oid, &rm->peer_ref->old_oid);
644+
oidcpy(&ref->new_oid, &rm->old_oid);
645645
ref->force = rm->peer_ref->force;
646646
}
647647

@@ -686,7 +686,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
686686
/* fall-through */
687687
case FETCH_HEAD_MERGE:
688688
fprintf(fp, "%s\t%s\t%s",
689-
sha1_to_hex(rm->old_sha1),
689+
oid_to_hex(&rm->old_oid),
690690
merge_status_marker,
691691
note.buf);
692692
for (i = 0; i < url_len; ++i)
@@ -928,7 +928,7 @@ static int do_fetch(struct transport *transport,
928928
rm->peer_ref->name);
929929
if (peer_item) {
930930
struct object_id *old_oid = peer_item->util;
931-
hashcpy(rm->peer_ref->old_sha1, old_oid->hash);
931+
oidcpy(&rm->peer_ref->old_oid, old_oid);
932932
}
933933
}
934934
}

builtin/ls-remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
125125
continue;
126126
if (!tail_match(pattern, ref->name))
127127
continue;
128-
printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);
128+
printf("%s %s\n", oid_to_hex(&ref->old_oid), ref->name);
129129
status = 0; /* we found something */
130130
}
131131
return status;

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static void show_one_alternate_sha1(const unsigned char sha1[20], void *unused)
246246
static void collect_one_alternate_ref(const struct ref *ref, void *data)
247247
{
248248
struct sha1_array *sa = data;
249-
sha1_array_append(sa, ref->old_sha1);
249+
sha1_array_append(sa, ref->old_oid.hash);
250250
}
251251

252252
static void write_head_info(void)

builtin/remote.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static int get_push_ref_states(const struct ref *remote_refs,
401401

402402
if (!ref->peer_ref)
403403
continue;
404-
hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
404+
oidcpy(&ref->new_oid, &ref->peer_ref->new_oid);
405405

406406
item = string_list_append(&states->push,
407407
abbrev_branch(ref->peer_ref->name));
@@ -410,14 +410,14 @@ static int get_push_ref_states(const struct ref *remote_refs,
410410
info->forced = ref->force;
411411
info->dest = xstrdup(abbrev_branch(ref->name));
412412

413-
if (is_null_sha1(ref->new_sha1)) {
413+
if (is_null_oid(&ref->new_oid)) {
414414
info->status = PUSH_STATUS_DELETE;
415-
} else if (!hashcmp(ref->old_sha1, ref->new_sha1))
415+
} else if (!oidcmp(&ref->old_oid, &ref->new_oid))
416416
info->status = PUSH_STATUS_UPTODATE;
417-
else if (is_null_sha1(ref->old_sha1))
417+
else if (is_null_oid(&ref->old_oid))
418418
info->status = PUSH_STATUS_CREATE;
419-
else if (has_sha1_file(ref->old_sha1) &&
420-
ref_newer(ref->new_sha1, ref->old_sha1))
419+
else if (has_object_file(&ref->old_oid) &&
420+
ref_newer(ref->new_oid.hash, ref->old_oid.hash))
421421
info->status = PUSH_STATUS_FASTFORWARD;
422422
else
423423
info->status = PUSH_STATUS_OUTOFDATE;

connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
166166
if (!check_ref(name, flags))
167167
continue;
168168
ref = alloc_ref(buffer + 41);
169-
hashcpy(ref->old_sha1, old_sha1);
169+
hashcpy(ref->old_oid.hash, old_sha1);
170170
*list = ref;
171171
list = &ref->next;
172172
got_at_least_one_head = 1;

fetch-pack.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static void send_request(struct fetch_pack_args *args,
238238

239239
static void insert_one_alternate_ref(const struct ref *ref, void *unused)
240240
{
241-
rev_list_insert_ref(NULL, ref->old_sha1);
241+
rev_list_insert_ref(NULL, ref->old_oid.hash);
242242
}
243243

244244
#define INITIAL_FLUSH 16
@@ -280,7 +280,7 @@ static int find_common(struct fetch_pack_args *args,
280280

281281
fetching = 0;
282282
for ( ; refs ; refs = refs->next) {
283-
unsigned char *remote = refs->old_sha1;
283+
unsigned char *remote = refs->old_oid.hash;
284284
const char *remote_hex;
285285
struct object *o;
286286

@@ -570,7 +570,7 @@ static void filter_refs(struct fetch_pack_args *args,
570570
continue;
571571
if (get_sha1_hex(ref->name, sha1) ||
572572
ref->name[40] != '\0' ||
573-
hashcmp(sha1, ref->old_sha1))
573+
hashcmp(sha1, ref->old_oid.hash))
574574
continue;
575575

576576
ref->matched = 1;
@@ -583,7 +583,7 @@ static void filter_refs(struct fetch_pack_args *args,
583583

584584
static void mark_alternate_complete(const struct ref *ref, void *unused)
585585
{
586-
mark_complete(ref->old_sha1);
586+
mark_complete(ref->old_oid.hash);
587587
}
588588

589589
static int everything_local(struct fetch_pack_args *args,
@@ -599,10 +599,10 @@ static int everything_local(struct fetch_pack_args *args,
599599
for (ref = *refs; ref; ref = ref->next) {
600600
struct object *o;
601601

602-
if (!has_sha1_file(ref->old_sha1))
602+
if (!has_object_file(&ref->old_oid))
603603
continue;
604604

605-
o = parse_object(ref->old_sha1);
605+
o = parse_object(ref->old_oid.hash);
606606
if (!o)
607607
continue;
608608

@@ -630,7 +630,7 @@ static int everything_local(struct fetch_pack_args *args,
630630
* Don't mark them common yet; the server has to be told so first.
631631
*/
632632
for (ref = *refs; ref; ref = ref->next) {
633-
struct object *o = deref_tag(lookup_object(ref->old_sha1),
633+
struct object *o = deref_tag(lookup_object(ref->old_oid.hash),
634634
NULL, 0);
635635

636636
if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@@ -646,7 +646,7 @@ static int everything_local(struct fetch_pack_args *args,
646646
filter_refs(args, refs, sought, nr_sought);
647647

648648
for (retval = 1, ref = *refs; ref ; ref = ref->next) {
649-
const unsigned char *remote = ref->old_sha1;
649+
const unsigned char *remote = ref->old_oid.hash;
650650
struct object *o;
651651

652652
o = lookup_object(remote);
@@ -985,7 +985,7 @@ static void update_shallow(struct fetch_pack_args *args,
985985
if (!si->nr_ours && !si->nr_theirs)
986986
return;
987987
for (i = 0; i < nr_sought; i++)
988-
sha1_array_append(&ref, sought[i]->old_sha1);
988+
sha1_array_append(&ref, sought[i]->old_oid.hash);
989989
si->ref = &ref;
990990

991991
if (args->update_shallow) {

0 commit comments

Comments
 (0)