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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)