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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 6, 2017 at 22:10 UTC
1e43ed986775d8e8ecaef4dac8b98dcbae6298c1
6 files changed
+39
-39
notes-merge.c
+13
-13
@@ -535,7 +535,7 @@ int notes_merge(struct notes_merge_options *o,
535
struct notes_tree *local_tree,
536
unsigned char *result_sha1)
537
{
538
- unsigned char local_sha1[20], remote_sha1[20];
538
+ struct object_id local_oid, remote_oid;
539
struct commit *local, *remote;
540
struct commit_list *bases = NULL;
541
const unsigned char *base_sha1, *base_tree_sha1;
@@ -549,46 +549,46 @@ int notes_merge(struct notes_merge_options *o,
549
o->local_ref, o->remote_ref);
550
551
/* 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))
553
die("Failed to resolve local notes ref '%s'", o->local_ref);
554
else if (!check_refname_format(o->local_ref, 0) &&
555
- is_null_sha1(local_sha1))
555
+ is_null_oid(&local_oid))
556
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)))
558
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));
561
562
/* 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)) {
564
/*
565
* Failed to get remote_sha1. If o->remote_ref looks like an
566
* unborn ref, perform the merge using an empty notes tree.
567
*/
568
if (!check_refname_format(o->remote_ref, 0)) {
569
- hashclr(remote_sha1);
569
+ oidclr(&remote_oid);
570
remote = NULL;
571
} else {
572
die("Failed to resolve remote notes ref '%s'",
573
o->remote_ref);
574
}
575
- } else if (!(remote = lookup_commit_reference(remote_sha1))) {
575
+ } else if (!(remote = lookup_commit_reference(remote_oid.hash))) {
576
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);
578
}
579
- trace_printf("\tremote commit: %.7s\n", sha1_to_hex(remote_sha1));
579
+ trace_printf("\tremote commit: %.7s\n", oid_to_hex(&remote_oid));
580
581
if (!local && !remote)
582
die("Cannot merge empty notes ref (%s) into empty notes ref "
583
"(%s)", o->remote_ref, o->local_ref);
584
if (!local) {
585
/* result == remote commit */
586
- hashcpy(result_sha1, remote_sha1);
586
+ hashcpy(result_sha1, remote_oid.hash);
587
goto found_result;
588
}
589
if (!remote) {
590
/* result == local commit */
591
- hashcpy(result_sha1, local_sha1);
591
+ hashcpy(result_sha1, local_oid.hash);
592
goto found_result;
593
}
594
assert(local && remote);
ref-filter.c
+3
-3
@@ -2090,7 +2090,7 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
2090
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
2091
{
2092
struct ref_filter *rf = opt->value;
2093
- unsigned char sha1[20];
2093
+ struct object_id oid;
2094
int no_merged = starts_with(opt->long_name, "no");
2095
2096
if (rf->merge) {
@@ -2105,10 +2105,10 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
2105
? REF_FILTER_MERGED_OMIT
2106
: REF_FILTER_MERGED_INCLUDE;
2107
2108
- if (get_sha1(arg, sha1))
2108
+ if (get_oid(arg, &oid))
2109
die(_("malformed object name %s"), arg);
2110
2111
- rf->merge_commit = lookup_commit_reference_gently(sha1, 0);
2111
+ rf->merge_commit = lookup_commit_reference_gently(oid.hash, 0);
2112
if (!rf->merge_commit)
2113
return opterror(opt, "must point to a commit", 0);
2114
sequencer.c
+10
-10
@@ -1222,7 +1222,7 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list)
1222
1223
static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
1224
{
1225
- unsigned char commit_sha1[20];
1225
+ struct object_id commit_oid;
1226
char *end_of_object_name;
1227
int i, saved, status, padding;
1228
@@ -1271,7 +1271,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
1271
end_of_object_name = (char *) bol + strcspn(bol, " \t\n");
1272
saved = *end_of_object_name;
1273
*end_of_object_name = '\0';
1274
- status = get_sha1(bol, commit_sha1);
1274
+ status = get_oid(bol, &commit_oid);
1275
*end_of_object_name = saved;
1276
1277
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)
1280
if (status < 0)
1281
return -1;
1282
1283
- item->commit = lookup_commit_reference(commit_sha1);
1283
+ item->commit = lookup_commit_reference(commit_oid.hash);
1284
return !item->commit;
1285
}
1286
@@ -2281,7 +2281,7 @@ static int single_pick(struct commit *cmit, struct replay_opts *opts)
2281
int sequencer_pick_revisions(struct replay_opts *opts)
2282
{
2283
struct todo_list todo_list = TODO_LIST_INIT;
2284
- unsigned char sha1[20];
2284
+ struct object_id oid;
2285
int i, res;
2286
2287
assert(opts->revs);
@@ -2289,16 +2289,16 @@ int sequencer_pick_revisions(struct replay_opts *opts)
2289
return -1;
2290
2291
for (i = 0; i < opts->revs->pending.nr; i++) {
2292
- unsigned char sha1[20];
2292
+ struct object_id oid;
2293
const char *name = opts->revs->pending.objects[i].name;
2294
2295
/* This happens when using --stdin. */
2296
if (!strlen(name))
2297
continue;
2298
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);
2302
return error(_("%s: can't cherry-pick a %s"),
2303
name, typename(type));
2304
}
@@ -2335,9 +2335,9 @@ int sequencer_pick_revisions(struct replay_opts *opts)
2335
if (walk_revs_populate_todo(&todo_list, opts) ||
2336
create_seq_dir() < 0)
2337
return -1;
2338
- if (get_sha1("HEAD", sha1) && (opts->action == REPLAY_REVERT))
2338
+ if (get_oid("HEAD", &oid) && (opts->action == REPLAY_REVERT))
2339
return error(_("can't revert as initial commit"));
2340
- if (save_head(sha1_to_hex(sha1)))
2340
+ if (save_head(oid_to_hex(&oid)))
2341
return -1;
2342
if (save_opts(opts))
2343
return -1;
sha1_name.c
+6
-6
@@ -722,14 +722,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
722
static int get_parent(const char *name, int len,
723
unsigned char *result, int idx)
724
{
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);
727
struct commit *commit;
728
struct commit_list *p;
729
730
if (ret)
731
return ret;
732
- commit = lookup_commit_reference(sha1);
732
+ commit = lookup_commit_reference(oid.hash);
733
if (parse_commit(commit))
734
return -1;
735
if (!idx) {
@@ -750,14 +750,14 @@ static int get_parent(const char *name, int len,
750
static int get_nth_ancestor(const char *name, int len,
751
unsigned char *result, int generation)
752
{
753
- unsigned char sha1[20];
753
+ struct object_id oid;
754
struct commit *commit;
755
int ret;
756
757
- ret = get_sha1_1(name, len, sha1, GET_SHA1_COMMITTISH);
757
+ ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
758
if (ret)
759
return ret;
760
- commit = lookup_commit_reference(sha1);
760
+ commit = lookup_commit_reference(oid.hash);
761
if (!commit)
762
return -1;
763
shallow.c
+3
-3
@@ -466,7 +466,7 @@ static uint32_t *paint_alloc(struct paint_info *info)
466
* UNINTERESTING or BOTTOM is hit. Set the id-th bit in ref_bitmap for
467
* all walked commits.
468
*/
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,
470
unsigned int id)
471
{
472
unsigned int i, nr;
@@ -475,7 +475,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
475
size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
476
uint32_t *tmp = xmalloc(bitmap_size); /* to be freed before return */
477
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);
479
if (!c)
480
return;
481
memset(bitmap, 0, bitmap_size);
@@ -604,7 +604,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
604
}
605
606
for (i = 0; i < ref->nr; i++)
607
- paint_down(&pi, ref->oid[i].hash, i);
607
+ paint_down(&pi, ref->oid + i, i);
608
609
if (used) {
610
int bitmap_size = ((pi.nr_bits + 31) / 32) * sizeof(uint32_t);
submodule.c
+4
-4
@@ -896,17 +896,17 @@ int push_unpushed_submodules(struct oid_array *commits,
896
return ret;
897
}
898
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)
900
{
901
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)) {
903
/* Even if the submodule is checked out and the commit is
904
* present, make sure it is reachable from a ref. */
905
struct child_process cp = CHILD_PROCESS_INIT;
906
const char *argv[] = {"rev-list", "-n", "1", NULL, "--not", "--all", NULL};
907
struct strbuf buf = STRBUF_INIT;
908
909
- argv[3] = sha1_to_hex(sha1);
909
+ argv[3] = oid_to_hex(oid);
910
cp.argv = argv;
911
prepare_submodule_repo_env(&cp.env_array);
912
cp.git_cmd = 1;
@@ -937,7 +937,7 @@ static void submodule_collect_changed_cb(struct diff_queue_struct *q,
937
* being moved around. */
938
struct string_list_item *path;
939
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))
941
string_list_append(&changed_submodule_paths, xstrdup(p->two->path));
942
} else {
943
/* Submodule is new or was moved here */