Skip to content

Commit bc83266

Browse files
bk2204gitster
authored andcommitted
Convert lookup_commit* to struct object_id
Convert lookup_commit, lookup_commit_or_die, lookup_commit_reference, and lookup_commit_reference_gently to take struct object_id arguments. Introduce a temporary in parse_object buffer in order to convert this function. This is required since in order to convert parse_object and parse_object_buffer, lookup_commit_reference_gently and lookup_commit_or_die would need to be converted. Not introducing a temporary would therefore require that lookup_commit_or_die take a struct object_id *, but lookup_commit would take unsigned char *, leaving a confusing and hard-to-use interface. parse_object_buffer will lose this temporary in a later patch. This commit was created with manual changes to commit.c, commit.h, and object.c, plus the following semantic patch: @@ expression E1, E2; @@ - lookup_commit_reference_gently(E1.hash, E2) + lookup_commit_reference_gently(&E1, E2) @@ expression E1, E2; @@ - lookup_commit_reference_gently(E1->hash, E2) + lookup_commit_reference_gently(E1, E2) @@ expression E1; @@ - lookup_commit_reference(E1.hash) + lookup_commit_reference(&E1) @@ expression E1; @@ - lookup_commit_reference(E1->hash) + lookup_commit_reference(E1) @@ expression E1; @@ - lookup_commit(E1.hash) + lookup_commit(&E1) @@ expression E1; @@ - lookup_commit(E1->hash) + lookup_commit(E1) @@ expression E1, E2; @@ - lookup_commit_or_die(E1.hash, E2) + lookup_commit_or_die(&E1, E2) @@ expression E1, E2; @@ - lookup_commit_or_die(E1->hash, E2) + lookup_commit_or_die(E1, E2) Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1e43ed9 commit bc83266

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+138
-132
lines changed

archive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static void parse_treeish_arg(const char **argv,
360360
if (get_sha1(name, oid.hash))
361361
die("Not a valid object name");
362362

363-
commit = lookup_commit_reference_gently(oid.hash, 1);
363+
commit = lookup_commit_reference_gently(&oid, 1);
364364
if (commit) {
365365
commit_sha1 = commit->object.oid.hash;
366366
archive_time = commit->date;

bisect.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
705705

706706
static struct commit *get_commit_reference(const struct object_id *oid)
707707
{
708-
struct commit *r = lookup_commit_reference(oid->hash);
708+
struct commit *r = lookup_commit_reference(oid);
709709
if (!r)
710710
die(_("Not a valid commit name %s"), oid_to_hex(oid));
711711
return r;

branch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void create_branch(const char *name, const char *start_name,
286286
break;
287287
}
288288

289-
if ((commit = lookup_commit_reference(oid.hash)) == NULL)
289+
if ((commit = lookup_commit_reference(&oid)) == NULL)
290290
die(_("Not a valid branch point: '%s'."), start_name);
291291
oidcpy(&oid, &commit->object.oid);
292292

builtin/am.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ static int parse_mail_rebase(struct am_state *state, const char *mail)
14881488
if (get_mail_commit_oid(&commit_oid, mail) < 0)
14891489
die(_("could not parse %s"), mail);
14901490

1491-
commit = lookup_commit_or_die(commit_oid.hash, mail);
1491+
commit = lookup_commit_or_die(&commit_oid, mail);
14921492

14931493
get_commit_info(state, commit);
14941494

@@ -1683,7 +1683,7 @@ static void do_commit(const struct am_state *state)
16831683

16841684
if (!get_sha1_commit("HEAD", parent.hash)) {
16851685
old_oid = &parent;
1686-
commit_list_insert(lookup_commit(parent.hash), &parents);
1686+
commit_list_insert(lookup_commit(&parent), &parents);
16871687
} else {
16881688
old_oid = NULL;
16891689
say(state, stderr, _("applying to an empty history"));

builtin/blame.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc
22532253
{
22542254
struct commit *parent;
22552255

2256-
parent = lookup_commit_reference(oid->hash);
2256+
parent = lookup_commit_reference(oid);
22572257
if (!parent)
22582258
die("no such commit %s", oid_to_hex(oid));
22592259
return &commit_list_insert(parent, tail)->next;
@@ -2475,7 +2475,7 @@ static const char *dwim_reverse_initial(struct scoreboard *sb)
24752475
/* Do we have HEAD? */
24762476
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
24772477
return NULL;
2478-
head_commit = lookup_commit_reference_gently(head_oid.hash, 1);
2478+
head_commit = lookup_commit_reference_gently(&head_oid, 1);
24792479
if (!head_commit)
24802480
return NULL;
24812481

builtin/branch.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int branch_merged(int kind, const char *name,
124124
(reference_name = reference_name_to_free =
125125
resolve_refdup(upstream, RESOLVE_REF_READING,
126126
oid.hash, NULL)) != NULL)
127-
reference_rev = lookup_commit_reference(oid.hash);
127+
reference_rev = lookup_commit_reference(&oid);
128128
}
129129
if (!reference_rev)
130130
reference_rev = head_rev;
@@ -157,7 +157,7 @@ static int check_branch_commit(const char *branchname, const char *refname,
157157
const struct object_id *oid, struct commit *head_rev,
158158
int kinds, int force)
159159
{
160-
struct commit *rev = lookup_commit_reference(oid->hash);
160+
struct commit *rev = lookup_commit_reference(oid);
161161
if (!rev) {
162162
error(_("Couldn't look up commit object for '%s'"), refname);
163163
return -1;
@@ -211,7 +211,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
211211
}
212212

213213
if (!force) {
214-
head_rev = lookup_commit_reference(head_oid.hash);
214+
head_rev = lookup_commit_reference(&head_oid);
215215
if (!head_rev)
216216
die(_("Couldn't look up commit object for HEAD"));
217217
}

builtin/checkout.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static int checkout_paths(const struct checkout_opts *opts,
393393
die(_("unable to write new index file"));
394394

395395
read_ref_full("HEAD", 0, rev.hash, NULL);
396-
head = lookup_commit_reference_gently(rev.hash, 1);
396+
head = lookup_commit_reference_gently(&rev, 1);
397397

398398
errs |= post_checkout_hook(head, head, 0);
399399
return errs;
@@ -833,7 +833,7 @@ static int switch_branches(const struct checkout_opts *opts,
833833
int flag, writeout_error = 0;
834834
memset(&old, 0, sizeof(old));
835835
old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag);
836-
old.commit = lookup_commit_reference_gently(rev.hash, 1);
836+
old.commit = lookup_commit_reference_gently(&rev, 1);
837837
if (!(flag & REF_ISSYMREF))
838838
old.path = NULL;
839839

@@ -1047,7 +1047,7 @@ static int parse_branchname_arg(int argc, const char **argv,
10471047
else
10481048
new->path = NULL; /* not an existing branch */
10491049

1050-
new->commit = lookup_commit_reference_gently(rev->hash, 1);
1050+
new->commit = lookup_commit_reference_gently(rev, 1);
10511051
if (!new->commit) {
10521052
/* not a commit */
10531053
*source_tree = parse_tree_indirect(rev->hash);

builtin/clone.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
682682
install_branch_config(0, head, option_origin, our->name);
683683
}
684684
} else if (our) {
685-
struct commit *c = lookup_commit_reference(our->old_oid.hash);
685+
struct commit *c = lookup_commit_reference(&our->old_oid);
686686
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
687687
update_ref(msg, "HEAD", c->object.oid.hash,
688688
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);

builtin/commit-tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
5858
if (get_sha1_commit(argv[i], oid.hash))
5959
die("Not a valid object name %s", argv[i]);
6060
assert_sha1_type(oid.hash, OBJ_COMMIT);
61-
new_parent(lookup_commit(oid.hash), &parents);
61+
new_parent(lookup_commit(&oid), &parents);
6262
continue;
6363
}
6464

builtin/commit.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,
14301430
struct strbuf author_ident = STRBUF_INIT;
14311431
struct strbuf committer_ident = STRBUF_INIT;
14321432

1433-
commit = lookup_commit(oid->hash);
1433+
commit = lookup_commit(oid);
14341434
if (!commit)
14351435
die(_("couldn't look up newly created commit"));
14361436
if (parse_commit(commit))
@@ -1654,7 +1654,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16541654
if (get_sha1("HEAD", oid.hash))
16551655
current_head = NULL;
16561656
else {
1657-
current_head = lookup_commit_or_die(oid.hash, "HEAD");
1657+
current_head = lookup_commit_or_die(&oid, "HEAD");
16581658
if (parse_commit(current_head))
16591659
die(_("could not parse HEAD commit"));
16601660
}

builtin/describe.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static void describe(const char *arg, int last_one)
281281

282282
if (get_oid(arg, &oid))
283283
die(_("Not a valid object name %s"), arg);
284-
cmit = lookup_commit_reference(oid.hash);
284+
cmit = lookup_commit_reference(&oid);
285285
if (!cmit)
286286
die(_("%s is not a valid '%s' object"), arg, commit_type);
287287

@@ -309,7 +309,7 @@ static void describe(const char *arg, int last_one)
309309
struct commit *c;
310310
struct commit_name *n = hashmap_iter_first(&names, &iter);
311311
for (; n; n = hashmap_iter_next(&iter)) {
312-
c = lookup_commit_reference_gently(n->peeled.hash, 1);
312+
c = lookup_commit_reference_gently(&n->peeled, 1);
313313
if (c)
314314
c->util = n;
315315
}

builtin/diff-tree.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static struct rev_info log_tree_opt;
99

1010
static int diff_tree_commit_sha1(const struct object_id *oid)
1111
{
12-
struct commit *commit = lookup_commit_reference(oid->hash);
12+
struct commit *commit = lookup_commit_reference(oid);
1313
if (!commit)
1414
return -1;
1515
return log_tree_commit(&log_tree_opt, commit);
@@ -23,7 +23,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p)
2323

2424
/* Graft the fake parents locally to the commit */
2525
while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) {
26-
struct commit *parent = lookup_commit(oid.hash);
26+
struct commit *parent = lookup_commit(&oid);
2727
if (!pptr) {
2828
/* Free the real parent list */
2929
free_commit_list(commit->parents);

builtin/fast-export.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ static void import_marks(char *input_file)
938938
/* only commits */
939939
continue;
940940

941-
commit = lookup_commit(oid.hash);
941+
commit = lookup_commit(&oid);
942942
if (!commit)
943943
die("not a commit? can't happen: %s", oid_to_hex(&oid));
944944

builtin/fetch.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ static int update_local_ref(struct ref *ref,
636636
return r;
637637
}
638638

639-
current = lookup_commit_reference_gently(ref->old_oid.hash, 1);
640-
updated = lookup_commit_reference_gently(ref->new_oid.hash, 1);
639+
current = lookup_commit_reference_gently(&ref->old_oid, 1);
640+
updated = lookup_commit_reference_gently(&ref->new_oid, 1);
641641
if (!current || !updated) {
642642
const char *msg;
643643
const char *what;
@@ -770,7 +770,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
770770
continue;
771771
}
772772

773-
commit = lookup_commit_reference_gently(rm->old_oid.hash, 1);
773+
commit = lookup_commit_reference_gently(&rm->old_oid,
774+
1);
774775
if (!commit)
775776
rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;
776777

builtin/fmt-merge-msg.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ static void find_merge_parents(struct merge_parents *result,
566566
commit_list_insert(parent, &parents);
567567
add_merge_parent(result, &obj->oid, &parent->object.oid);
568568
}
569-
head_commit = lookup_commit(head->hash);
569+
head_commit = lookup_commit(head);
570570
if (head_commit)
571571
commit_list_insert(head_commit, &parents);
572572
parents = reduce_heads(parents);
@@ -633,7 +633,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
633633
struct commit *head;
634634
struct rev_info rev;
635635

636-
head = lookup_commit_or_die(head_oid.hash, "HEAD");
636+
head = lookup_commit_or_die(&head_oid, "HEAD");
637637
init_revisions(&rev, NULL);
638638
rev.commit_format = CMIT_FMT_ONELINE;
639639
rev.ignore_merges = 1;

builtin/log.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
878878
o2 = rev->pending.objects[1].item;
879879
flags1 = o1->flags;
880880
flags2 = o2->flags;
881-
c1 = lookup_commit_reference(o1->oid.hash);
882-
c2 = lookup_commit_reference(o2->oid.hash);
881+
c1 = lookup_commit_reference(&o1->oid);
882+
c2 = lookup_commit_reference(&o2->oid);
883883

884884
if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
885885
die(_("Not a range."));
@@ -1263,7 +1263,7 @@ static struct commit *get_base_commit(const char *base_commit,
12631263

12641264
if (get_oid(upstream, &oid))
12651265
die(_("Failed to resolve '%s' as a valid ref."), upstream);
1266-
commit = lookup_commit_or_die(oid.hash, "upstream base");
1266+
commit = lookup_commit_or_die(&oid, "upstream base");
12671267
base_list = get_merge_bases_many(commit, total, list);
12681268
/* There should be one and only one merge base. */
12691269
if (!base_list || base_list->next)
@@ -1819,7 +1819,7 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
18191819
{
18201820
struct object_id oid;
18211821
if (get_oid(arg, &oid) == 0) {
1822-
struct commit *commit = lookup_commit_reference(oid.hash);
1822+
struct commit *commit = lookup_commit_reference(&oid);
18231823
if (commit) {
18241824
commit->object.flags |= flags;
18251825
add_pending_object(revs, &commit->object, arg);

builtin/merge-base.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static struct commit *get_commit_reference(const char *arg)
4141

4242
if (get_oid(arg, &revkey))
4343
die("Not a valid object name %s", arg);
44-
r = lookup_commit_reference(revkey.hash);
44+
r = lookup_commit_reference(&revkey);
4545
if (!r)
4646
die("Not a valid commit name %s", arg);
4747

@@ -120,7 +120,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
120120
if (is_null_oid(oid))
121121
return;
122122

123-
commit = lookup_commit(oid->hash);
123+
commit = lookup_commit(oid);
124124
if (!commit ||
125125
(commit->object.flags & TMP_MARK) ||
126126
parse_commit(commit))
@@ -168,7 +168,7 @@ static int handle_fork_point(int argc, const char **argv)
168168
if (get_oid(commitname, &oid))
169169
die("Not a valid object name: '%s'", commitname);
170170

171-
derived = lookup_commit_reference(oid.hash);
171+
derived = lookup_commit_reference(&oid);
172172
memset(&revs, 0, sizeof(revs));
173173
revs.initial = 1;
174174
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);

builtin/merge.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11231123
if (!branch || is_null_oid(&head_oid))
11241124
head_commit = NULL;
11251125
else
1126-
head_commit = lookup_commit_or_die(head_oid.hash, "HEAD");
1126+
head_commit = lookup_commit_or_die(&head_oid, "HEAD");
11271127

11281128
init_diff_ui_defaults();
11291129
git_config(git_merge_config, NULL);

builtin/notes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ static int merge_commit(struct notes_merge_options *o)
706706

707707
if (get_oid("NOTES_MERGE_PARTIAL", &oid))
708708
die(_("failed to read ref NOTES_MERGE_PARTIAL"));
709-
else if (!(partial = lookup_commit_reference(oid.hash)))
709+
else if (!(partial = lookup_commit_reference(&oid)))
710710
die(_("could not find commit from NOTES_MERGE_PARTIAL."));
711711
else if (parse_commit(partial))
712712
die(_("could not parse commit from NOTES_MERGE_PARTIAL."));

builtin/pull.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,10 @@ static int get_octopus_merge_base(struct object_id *merge_base,
698698
{
699699
struct commit_list *revs = NULL, *result;
700700

701-
commit_list_insert(lookup_commit_reference(curr_head->hash), &revs);
702-
commit_list_insert(lookup_commit_reference(merge_head->hash), &revs);
701+
commit_list_insert(lookup_commit_reference(curr_head), &revs);
702+
commit_list_insert(lookup_commit_reference(merge_head), &revs);
703703
if (!is_null_oid(fork_point))
704-
commit_list_insert(lookup_commit_reference(fork_point->hash), &revs);
704+
commit_list_insert(lookup_commit_reference(fork_point), &revs);
705705

706706
result = reduce_heads(get_octopus_merge_bases(revs));
707707
free_commit_list(revs);
@@ -865,9 +865,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
865865
struct commit_list *list = NULL;
866866
struct commit *merge_head, *head;
867867

868-
head = lookup_commit_reference(orig_head.hash);
868+
head = lookup_commit_reference(&orig_head);
869869
commit_list_insert(head, &list);
870-
merge_head = lookup_commit_reference(merge_heads.oid[0].hash);
870+
merge_head = lookup_commit_reference(&merge_heads.oid[0]);
871871
if (is_descendant_of(merge_head, list)) {
872872
/* we can fast-forward this without invoking rebase */
873873
opt_ff = "--ff-only";

builtin/reflog.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static int keep_entry(struct commit **it, struct object_id *oid)
192192

193193
if (is_null_oid(oid))
194194
return 1;
195-
commit = lookup_commit_reference_gently(oid->hash, 1);
195+
commit = lookup_commit_reference_gently(oid, 1);
196196
if (!commit)
197197
return 0;
198198

@@ -261,7 +261,7 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit
261261
if (is_null_oid(oid))
262262
return 0;
263263

264-
commit = lookup_commit_reference_gently(oid->hash, 1);
264+
commit = lookup_commit_reference_gently(oid, 1);
265265

266266
/* Not a commit -- keep it */
267267
if (!commit)
@@ -318,7 +318,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid,
318318
struct commit *tip_commit;
319319
if (flags & REF_ISSYMREF)
320320
return 0;
321-
tip_commit = lookup_commit_reference_gently(oid->hash, 1);
321+
tip_commit = lookup_commit_reference_gently(oid, 1);
322322
if (!tip_commit)
323323
return 0;
324324
commit_list_insert(tip_commit, list);
@@ -335,7 +335,7 @@ static void reflog_expiry_prepare(const char *refname,
335335
cb->tip_commit = NULL;
336336
cb->unreachable_expire_kind = UE_HEAD;
337337
} else {
338-
cb->tip_commit = lookup_commit_reference_gently(oid->hash, 1);
338+
cb->tip_commit = lookup_commit_reference_gently(oid, 1);
339339
if (!cb->tip_commit)
340340
cb->unreachable_expire_kind = UE_ALWAYS;
341341
else

builtin/replace.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static void replace_parents(struct strbuf *buf, int argc, const char **argv)
328328
struct object_id oid;
329329
if (get_oid(argv[i], &oid) < 0)
330330
die(_("Not a valid object name: '%s'"), argv[i]);
331-
lookup_commit_or_die(oid.hash, argv[i]);
331+
lookup_commit_or_die(&oid, argv[i]);
332332
strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&oid));
333333
}
334334

@@ -394,7 +394,7 @@ static int create_graft(int argc, const char **argv, int force)
394394

395395
if (get_oid(old_ref, &old) < 0)
396396
die(_("Not a valid object name: '%s'"), old_ref);
397-
commit = lookup_commit_or_die(old.hash, old_ref);
397+
commit = lookup_commit_or_die(&old, old_ref);
398398

399399
buffer = get_commit_buffer(commit, &size);
400400
strbuf_add(&buf, buffer, size);

0 commit comments

Comments
 (0)