Skip to content

Commit 1e43ed9

Browse files
bk2204gitster
authored andcommitted
Convert remaining callers of lookup_commit_reference* to object_id
There are a small number of remaining callers of lookup_commit_reference and lookup_commit_reference_gently that still need to be converted to struct object_id. Convert these. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7422ab5 commit 1e43ed9

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

notes-merge.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ int notes_merge(struct notes_merge_options *o,
535535
struct notes_tree *local_tree,
536536
unsigned char *result_sha1)
537537
{
538-
unsigned char local_sha1[20], remote_sha1[20];
538+
struct object_id local_oid, remote_oid;
539539
struct commit *local, *remote;
540540
struct commit_list *bases = NULL;
541541
const unsigned char *base_sha1, *base_tree_sha1;
@@ -549,46 +549,46 @@ int notes_merge(struct notes_merge_options *o,
549549
o->local_ref, o->remote_ref);
550550

551551
/* Dereference o->local_ref into local_sha1 */
552-
if (read_ref_full(o->local_ref, 0, local_sha1, NULL))
552+
if (read_ref_full(o->local_ref, 0, local_oid.hash, NULL))
553553
die("Failed to resolve local notes ref '%s'", o->local_ref);
554554
else if (!check_refname_format(o->local_ref, 0) &&
555-
is_null_sha1(local_sha1))
555+
is_null_oid(&local_oid))
556556
local = NULL; /* local_sha1 == null_sha1 indicates unborn ref */
557-
else if (!(local = lookup_commit_reference(local_sha1)))
557+
else if (!(local = lookup_commit_reference(local_oid.hash)))
558558
die("Could not parse local commit %s (%s)",
559-
sha1_to_hex(local_sha1), o->local_ref);
560-
trace_printf("\tlocal commit: %.7s\n", sha1_to_hex(local_sha1));
559+
oid_to_hex(&local_oid), o->local_ref);
560+
trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid));
561561

562562
/* Dereference o->remote_ref into remote_sha1 */
563-
if (get_sha1(o->remote_ref, remote_sha1)) {
563+
if (get_oid(o->remote_ref, &remote_oid)) {
564564
/*
565565
* Failed to get remote_sha1. If o->remote_ref looks like an
566566
* unborn ref, perform the merge using an empty notes tree.
567567
*/
568568
if (!check_refname_format(o->remote_ref, 0)) {
569-
hashclr(remote_sha1);
569+
oidclr(&remote_oid);
570570
remote = NULL;
571571
} else {
572572
die("Failed to resolve remote notes ref '%s'",
573573
o->remote_ref);
574574
}
575-
} else if (!(remote = lookup_commit_reference(remote_sha1))) {
575+
} else if (!(remote = lookup_commit_reference(remote_oid.hash))) {
576576
die("Could not parse remote commit %s (%s)",
577-
sha1_to_hex(remote_sha1), o->remote_ref);
577+
oid_to_hex(&remote_oid), o->remote_ref);
578578
}
579-
trace_printf("\tremote commit: %.7s\n", sha1_to_hex(remote_sha1));
579+
trace_printf("\tremote commit: %.7s\n", oid_to_hex(&remote_oid));
580580

581581
if (!local && !remote)
582582
die("Cannot merge empty notes ref (%s) into empty notes ref "
583583
"(%s)", o->remote_ref, o->local_ref);
584584
if (!local) {
585585
/* result == remote commit */
586-
hashcpy(result_sha1, remote_sha1);
586+
hashcpy(result_sha1, remote_oid.hash);
587587
goto found_result;
588588
}
589589
if (!remote) {
590590
/* result == local commit */
591-
hashcpy(result_sha1, local_sha1);
591+
hashcpy(result_sha1, local_oid.hash);
592592
goto found_result;
593593
}
594594
assert(local && remote);

ref-filter.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
20902090
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
20912091
{
20922092
struct ref_filter *rf = opt->value;
2093-
unsigned char sha1[20];
2093+
struct object_id oid;
20942094
int no_merged = starts_with(opt->long_name, "no");
20952095

20962096
if (rf->merge) {
@@ -2105,10 +2105,10 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
21052105
? REF_FILTER_MERGED_OMIT
21062106
: REF_FILTER_MERGED_INCLUDE;
21072107

2108-
if (get_sha1(arg, sha1))
2108+
if (get_oid(arg, &oid))
21092109
die(_("malformed object name %s"), arg);
21102110

2111-
rf->merge_commit = lookup_commit_reference_gently(sha1, 0);
2111+
rf->merge_commit = lookup_commit_reference_gently(oid.hash, 0);
21122112
if (!rf->merge_commit)
21132113
return opterror(opt, "must point to a commit", 0);
21142114

sequencer.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list)
12221222

12231223
static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
12241224
{
1225-
unsigned char commit_sha1[20];
1225+
struct object_id commit_oid;
12261226
char *end_of_object_name;
12271227
int i, saved, status, padding;
12281228

@@ -1271,7 +1271,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
12711271
end_of_object_name = (char *) bol + strcspn(bol, " \t\n");
12721272
saved = *end_of_object_name;
12731273
*end_of_object_name = '\0';
1274-
status = get_sha1(bol, commit_sha1);
1274+
status = get_oid(bol, &commit_oid);
12751275
*end_of_object_name = saved;
12761276

12771277
item->arg = end_of_object_name + strspn(end_of_object_name, " \t");
@@ -1280,7 +1280,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
12801280
if (status < 0)
12811281
return -1;
12821282

1283-
item->commit = lookup_commit_reference(commit_sha1);
1283+
item->commit = lookup_commit_reference(commit_oid.hash);
12841284
return !item->commit;
12851285
}
12861286

@@ -2281,24 +2281,24 @@ static int single_pick(struct commit *cmit, struct replay_opts *opts)
22812281
int sequencer_pick_revisions(struct replay_opts *opts)
22822282
{
22832283
struct todo_list todo_list = TODO_LIST_INIT;
2284-
unsigned char sha1[20];
2284+
struct object_id oid;
22852285
int i, res;
22862286

22872287
assert(opts->revs);
22882288
if (read_and_refresh_cache(opts))
22892289
return -1;
22902290

22912291
for (i = 0; i < opts->revs->pending.nr; i++) {
2292-
unsigned char sha1[20];
2292+
struct object_id oid;
22932293
const char *name = opts->revs->pending.objects[i].name;
22942294

22952295
/* This happens when using --stdin. */
22962296
if (!strlen(name))
22972297
continue;
22982298

2299-
if (!get_sha1(name, sha1)) {
2300-
if (!lookup_commit_reference_gently(sha1, 1)) {
2301-
enum object_type type = sha1_object_info(sha1, NULL);
2299+
if (!get_oid(name, &oid)) {
2300+
if (!lookup_commit_reference_gently(oid.hash, 1)) {
2301+
enum object_type type = sha1_object_info(oid.hash, NULL);
23022302
return error(_("%s: can't cherry-pick a %s"),
23032303
name, typename(type));
23042304
}
@@ -2335,9 +2335,9 @@ int sequencer_pick_revisions(struct replay_opts *opts)
23352335
if (walk_revs_populate_todo(&todo_list, opts) ||
23362336
create_seq_dir() < 0)
23372337
return -1;
2338-
if (get_sha1("HEAD", sha1) && (opts->action == REPLAY_REVERT))
2338+
if (get_oid("HEAD", &oid) && (opts->action == REPLAY_REVERT))
23392339
return error(_("can't revert as initial commit"));
2340-
if (save_head(sha1_to_hex(sha1)))
2340+
if (save_head(oid_to_hex(&oid)))
23412341
return -1;
23422342
if (save_opts(opts))
23432343
return -1;

sha1_name.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -722,14 +722,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
722722
static int get_parent(const char *name, int len,
723723
unsigned char *result, int idx)
724724
{
725-
unsigned char sha1[20];
726-
int ret = get_sha1_1(name, len, sha1, GET_SHA1_COMMITTISH);
725+
struct object_id oid;
726+
int ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
727727
struct commit *commit;
728728
struct commit_list *p;
729729

730730
if (ret)
731731
return ret;
732-
commit = lookup_commit_reference(sha1);
732+
commit = lookup_commit_reference(oid.hash);
733733
if (parse_commit(commit))
734734
return -1;
735735
if (!idx) {
@@ -750,14 +750,14 @@ static int get_parent(const char *name, int len,
750750
static int get_nth_ancestor(const char *name, int len,
751751
unsigned char *result, int generation)
752752
{
753-
unsigned char sha1[20];
753+
struct object_id oid;
754754
struct commit *commit;
755755
int ret;
756756

757-
ret = get_sha1_1(name, len, sha1, GET_SHA1_COMMITTISH);
757+
ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
758758
if (ret)
759759
return ret;
760-
commit = lookup_commit_reference(sha1);
760+
commit = lookup_commit_reference(oid.hash);
761761
if (!commit)
762762
return -1;
763763

shallow.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ static uint32_t *paint_alloc(struct paint_info *info)
466466
* UNINTERESTING or BOTTOM is hit. Set the id-th bit in ref_bitmap for
467467
* all walked commits.
468468
*/
469-
static void paint_down(struct paint_info *info, const unsigned char *sha1,
469+
static void paint_down(struct paint_info *info, const struct object_id *oid,
470470
unsigned int id)
471471
{
472472
unsigned int i, nr;
@@ -475,7 +475,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
475475
size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
476476
uint32_t *tmp = xmalloc(bitmap_size); /* to be freed before return */
477477
uint32_t *bitmap = paint_alloc(info);
478-
struct commit *c = lookup_commit_reference_gently(sha1, 1);
478+
struct commit *c = lookup_commit_reference_gently(oid->hash, 1);
479479
if (!c)
480480
return;
481481
memset(bitmap, 0, bitmap_size);
@@ -604,7 +604,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
604604
}
605605

606606
for (i = 0; i < ref->nr; i++)
607-
paint_down(&pi, ref->oid[i].hash, i);
607+
paint_down(&pi, ref->oid + i, i);
608608

609609
if (used) {
610610
int bitmap_size = ((pi.nr_bits + 31) / 32) * sizeof(uint32_t);

submodule.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -896,17 +896,17 @@ int push_unpushed_submodules(struct oid_array *commits,
896896
return ret;
897897
}
898898

899-
static int is_submodule_commit_present(const char *path, unsigned char sha1[20])
899+
static int is_submodule_commit_present(const char *path, struct object_id *oid)
900900
{
901901
int is_present = 0;
902-
if (!add_submodule_odb(path) && lookup_commit_reference(sha1)) {
902+
if (!add_submodule_odb(path) && lookup_commit_reference(oid->hash)) {
903903
/* Even if the submodule is checked out and the commit is
904904
* present, make sure it is reachable from a ref. */
905905
struct child_process cp = CHILD_PROCESS_INIT;
906906
const char *argv[] = {"rev-list", "-n", "1", NULL, "--not", "--all", NULL};
907907
struct strbuf buf = STRBUF_INIT;
908908

909-
argv[3] = sha1_to_hex(sha1);
909+
argv[3] = oid_to_hex(oid);
910910
cp.argv = argv;
911911
prepare_submodule_repo_env(&cp.env_array);
912912
cp.git_cmd = 1;
@@ -937,7 +937,7 @@ static void submodule_collect_changed_cb(struct diff_queue_struct *q,
937937
* being moved around. */
938938
struct string_list_item *path;
939939
path = unsorted_string_list_lookup(&changed_submodule_paths, p->two->path);
940-
if (!path && !is_submodule_commit_present(p->two->path, p->two->oid.hash))
940+
if (!path && !is_submodule_commit_present(p->two->path, &p->two->oid))
941941
string_list_append(&changed_submodule_paths, xstrdup(p->two->path));
942942
} else {
943943
/* Submodule is new or was moved here */

0 commit comments

Comments
 (0)