Commit bc83266a authored by brian m. carlson's avatar brian m. carlson Committed by Junio C Hamano

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's avatarbrian m. carlson <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 1e43ed98
......@@ -360,7 +360,7 @@ static void parse_treeish_arg(const char **argv,
if (get_sha1(name, oid.hash))
die("Not a valid object name");
commit = lookup_commit_reference_gently(oid.hash, 1);
commit = lookup_commit_reference_gently(&oid, 1);
if (commit) {
commit_sha1 = commit->object.oid.hash;
archive_time = commit->date;
......
......@@ -705,7 +705,7 @@ static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
static struct commit *get_commit_reference(const struct object_id *oid)
{
struct commit *r = lookup_commit_reference(oid->hash);
struct commit *r = lookup_commit_reference(oid);
if (!r)
die(_("Not a valid commit name %s"), oid_to_hex(oid));
return r;
......
......@@ -286,7 +286,7 @@ void create_branch(const char *name, const char *start_name,
break;
}
if ((commit = lookup_commit_reference(oid.hash)) == NULL)
if ((commit = lookup_commit_reference(&oid)) == NULL)
die(_("Not a valid branch point: '%s'."), start_name);
oidcpy(&oid, &commit->object.oid);
......
......@@ -1488,7 +1488,7 @@ static int parse_mail_rebase(struct am_state *state, const char *mail)
if (get_mail_commit_oid(&commit_oid, mail) < 0)
die(_("could not parse %s"), mail);
commit = lookup_commit_or_die(commit_oid.hash, mail);
commit = lookup_commit_or_die(&commit_oid, mail);
get_commit_info(state, commit);
......@@ -1683,7 +1683,7 @@ static void do_commit(const struct am_state *state)
if (!get_sha1_commit("HEAD", parent.hash)) {
old_oid = &parent;
commit_list_insert(lookup_commit(parent.hash), &parents);
commit_list_insert(lookup_commit(&parent), &parents);
} else {
old_oid = NULL;
say(state, stderr, _("applying to an empty history"));
......
......@@ -2253,7 +2253,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc
{
struct commit *parent;
parent = lookup_commit_reference(oid->hash);
parent = lookup_commit_reference(oid);
if (!parent)
die("no such commit %s", oid_to_hex(oid));
return &commit_list_insert(parent, tail)->next;
......@@ -2475,7 +2475,7 @@ static const char *dwim_reverse_initial(struct scoreboard *sb)
/* Do we have HEAD? */
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
return NULL;
head_commit = lookup_commit_reference_gently(head_oid.hash, 1);
head_commit = lookup_commit_reference_gently(&head_oid, 1);
if (!head_commit)
return NULL;
......
......@@ -124,7 +124,7 @@ static int branch_merged(int kind, const char *name,
(reference_name = reference_name_to_free =
resolve_refdup(upstream, RESOLVE_REF_READING,
oid.hash, NULL)) != NULL)
reference_rev = lookup_commit_reference(oid.hash);
reference_rev = lookup_commit_reference(&oid);
}
if (!reference_rev)
reference_rev = head_rev;
......@@ -157,7 +157,7 @@ static int check_branch_commit(const char *branchname, const char *refname,
const struct object_id *oid, struct commit *head_rev,
int kinds, int force)
{
struct commit *rev = lookup_commit_reference(oid->hash);
struct commit *rev = lookup_commit_reference(oid);
if (!rev) {
error(_("Couldn't look up commit object for '%s'"), refname);
return -1;
......@@ -211,7 +211,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
}
if (!force) {
head_rev = lookup_commit_reference(head_oid.hash);
head_rev = lookup_commit_reference(&head_oid);
if (!head_rev)
die(_("Couldn't look up commit object for HEAD"));
}
......
......@@ -393,7 +393,7 @@ static int checkout_paths(const struct checkout_opts *opts,
die(_("unable to write new index file"));
read_ref_full("HEAD", 0, rev.hash, NULL);
head = lookup_commit_reference_gently(rev.hash, 1);
head = lookup_commit_reference_gently(&rev, 1);
errs |= post_checkout_hook(head, head, 0);
return errs;
......@@ -833,7 +833,7 @@ static int switch_branches(const struct checkout_opts *opts,
int flag, writeout_error = 0;
memset(&old, 0, sizeof(old));
old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag);
old.commit = lookup_commit_reference_gently(rev.hash, 1);
old.commit = lookup_commit_reference_gently(&rev, 1);
if (!(flag & REF_ISSYMREF))
old.path = NULL;
......@@ -1047,7 +1047,7 @@ static int parse_branchname_arg(int argc, const char **argv,
else
new->path = NULL; /* not an existing branch */
new->commit = lookup_commit_reference_gently(rev->hash, 1);
new->commit = lookup_commit_reference_gently(rev, 1);
if (!new->commit) {
/* not a commit */
*source_tree = parse_tree_indirect(rev->hash);
......
......@@ -682,7 +682,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
install_branch_config(0, head, option_origin, our->name);
}
} else if (our) {
struct commit *c = lookup_commit_reference(our->old_oid.hash);
struct commit *c = lookup_commit_reference(&our->old_oid);
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
update_ref(msg, "HEAD", c->object.oid.hash,
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
......
......@@ -58,7 +58,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
if (get_sha1_commit(argv[i], oid.hash))
die("Not a valid object name %s", argv[i]);
assert_sha1_type(oid.hash, OBJ_COMMIT);
new_parent(lookup_commit(oid.hash), &parents);
new_parent(lookup_commit(&oid), &parents);
continue;
}
......
......@@ -1430,7 +1430,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,
struct strbuf author_ident = STRBUF_INIT;
struct strbuf committer_ident = STRBUF_INIT;
commit = lookup_commit(oid->hash);
commit = lookup_commit(oid);
if (!commit)
die(_("couldn't look up newly created commit"));
if (parse_commit(commit))
......@@ -1654,7 +1654,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
if (get_sha1("HEAD", oid.hash))
current_head = NULL;
else {
current_head = lookup_commit_or_die(oid.hash, "HEAD");
current_head = lookup_commit_or_die(&oid, "HEAD");
if (parse_commit(current_head))
die(_("could not parse HEAD commit"));
}
......
......@@ -281,7 +281,7 @@ static void describe(const char *arg, int last_one)
if (get_oid(arg, &oid))
die(_("Not a valid object name %s"), arg);
cmit = lookup_commit_reference(oid.hash);
cmit = lookup_commit_reference(&oid);
if (!cmit)
die(_("%s is not a valid '%s' object"), arg, commit_type);
......@@ -309,7 +309,7 @@ static void describe(const char *arg, int last_one)
struct commit *c;
struct commit_name *n = hashmap_iter_first(&names, &iter);
for (; n; n = hashmap_iter_next(&iter)) {
c = lookup_commit_reference_gently(n->peeled.hash, 1);
c = lookup_commit_reference_gently(&n->peeled, 1);
if (c)
c->util = n;
}
......
......@@ -9,7 +9,7 @@ static struct rev_info log_tree_opt;
static int diff_tree_commit_sha1(const struct object_id *oid)
{
struct commit *commit = lookup_commit_reference(oid->hash);
struct commit *commit = lookup_commit_reference(oid);
if (!commit)
return -1;
return log_tree_commit(&log_tree_opt, commit);
......@@ -23,7 +23,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p)
/* Graft the fake parents locally to the commit */
while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) {
struct commit *parent = lookup_commit(oid.hash);
struct commit *parent = lookup_commit(&oid);
if (!pptr) {
/* Free the real parent list */
free_commit_list(commit->parents);
......
......@@ -938,7 +938,7 @@ static void import_marks(char *input_file)
/* only commits */
continue;
commit = lookup_commit(oid.hash);
commit = lookup_commit(&oid);
if (!commit)
die("not a commit? can't happen: %s", oid_to_hex(&oid));
......
......@@ -636,8 +636,8 @@ static int update_local_ref(struct ref *ref,
return r;
}
current = lookup_commit_reference_gently(ref->old_oid.hash, 1);
updated = lookup_commit_reference_gently(ref->new_oid.hash, 1);
current = lookup_commit_reference_gently(&ref->old_oid, 1);
updated = lookup_commit_reference_gently(&ref->new_oid, 1);
if (!current || !updated) {
const char *msg;
const char *what;
......@@ -770,7 +770,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
continue;
}
commit = lookup_commit_reference_gently(rm->old_oid.hash, 1);
commit = lookup_commit_reference_gently(&rm->old_oid,
1);
if (!commit)
rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;
......
......@@ -566,7 +566,7 @@ static void find_merge_parents(struct merge_parents *result,
commit_list_insert(parent, &parents);
add_merge_parent(result, &obj->oid, &parent->object.oid);
}
head_commit = lookup_commit(head->hash);
head_commit = lookup_commit(head);
if (head_commit)
commit_list_insert(head_commit, &parents);
parents = reduce_heads(parents);
......@@ -633,7 +633,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
struct commit *head;
struct rev_info rev;
head = lookup_commit_or_die(head_oid.hash, "HEAD");
head = lookup_commit_or_die(&head_oid, "HEAD");
init_revisions(&rev, NULL);
rev.commit_format = CMIT_FMT_ONELINE;
rev.ignore_merges = 1;
......
......@@ -878,8 +878,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
o2 = rev->pending.objects[1].item;
flags1 = o1->flags;
flags2 = o2->flags;
c1 = lookup_commit_reference(o1->oid.hash);
c2 = lookup_commit_reference(o2->oid.hash);
c1 = lookup_commit_reference(&o1->oid);
c2 = lookup_commit_reference(&o2->oid);
if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
die(_("Not a range."));
......@@ -1263,7 +1263,7 @@ static struct commit *get_base_commit(const char *base_commit,
if (get_oid(upstream, &oid))
die(_("Failed to resolve '%s' as a valid ref."), upstream);
commit = lookup_commit_or_die(oid.hash, "upstream base");
commit = lookup_commit_or_die(&oid, "upstream base");
base_list = get_merge_bases_many(commit, total, list);
/* There should be one and only one merge base. */
if (!base_list || base_list->next)
......@@ -1819,7 +1819,7 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
{
struct object_id oid;
if (get_oid(arg, &oid) == 0) {
struct commit *commit = lookup_commit_reference(oid.hash);
struct commit *commit = lookup_commit_reference(&oid);
if (commit) {
commit->object.flags |= flags;
add_pending_object(revs, &commit->object, arg);
......
......@@ -41,7 +41,7 @@ static struct commit *get_commit_reference(const char *arg)
if (get_oid(arg, &revkey))
die("Not a valid object name %s", arg);
r = lookup_commit_reference(revkey.hash);
r = lookup_commit_reference(&revkey);
if (!r)
die("Not a valid commit name %s", arg);
......@@ -120,7 +120,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
if (is_null_oid(oid))
return;
commit = lookup_commit(oid->hash);
commit = lookup_commit(oid);
if (!commit ||
(commit->object.flags & TMP_MARK) ||
parse_commit(commit))
......@@ -168,7 +168,7 @@ static int handle_fork_point(int argc, const char **argv)
if (get_oid(commitname, &oid))
die("Not a valid object name: '%s'", commitname);
derived = lookup_commit_reference(oid.hash);
derived = lookup_commit_reference(&oid);
memset(&revs, 0, sizeof(revs));
revs.initial = 1;
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
......
......@@ -1123,7 +1123,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (!branch || is_null_oid(&head_oid))
head_commit = NULL;
else
head_commit = lookup_commit_or_die(head_oid.hash, "HEAD");
head_commit = lookup_commit_or_die(&head_oid, "HEAD");
init_diff_ui_defaults();
git_config(git_merge_config, NULL);
......
......@@ -706,7 +706,7 @@ static int merge_commit(struct notes_merge_options *o)
if (get_oid("NOTES_MERGE_PARTIAL", &oid))
die(_("failed to read ref NOTES_MERGE_PARTIAL"));
else if (!(partial = lookup_commit_reference(oid.hash)))
else if (!(partial = lookup_commit_reference(&oid)))
die(_("could not find commit from NOTES_MERGE_PARTIAL."));
else if (parse_commit(partial))
die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
......
......@@ -698,10 +698,10 @@ static int get_octopus_merge_base(struct object_id *merge_base,
{
struct commit_list *revs = NULL, *result;
commit_list_insert(lookup_commit_reference(curr_head->hash), &revs);
commit_list_insert(lookup_commit_reference(merge_head->hash), &revs);
commit_list_insert(lookup_commit_reference(curr_head), &revs);
commit_list_insert(lookup_commit_reference(merge_head), &revs);
if (!is_null_oid(fork_point))
commit_list_insert(lookup_commit_reference(fork_point->hash), &revs);
commit_list_insert(lookup_commit_reference(fork_point), &revs);
result = reduce_heads(get_octopus_merge_bases(revs));
free_commit_list(revs);
......@@ -865,9 +865,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
struct commit_list *list = NULL;
struct commit *merge_head, *head;
head = lookup_commit_reference(orig_head.hash);
head = lookup_commit_reference(&orig_head);
commit_list_insert(head, &list);
merge_head = lookup_commit_reference(merge_heads.oid[0].hash);
merge_head = lookup_commit_reference(&merge_heads.oid[0]);
if (is_descendant_of(merge_head, list)) {
/* we can fast-forward this without invoking rebase */
opt_ff = "--ff-only";
......
......@@ -192,7 +192,7 @@ static int keep_entry(struct commit **it, struct object_id *oid)
if (is_null_oid(oid))
return 1;
commit = lookup_commit_reference_gently(oid->hash, 1);
commit = lookup_commit_reference_gently(oid, 1);
if (!commit)
return 0;
......@@ -261,7 +261,7 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit
if (is_null_oid(oid))
return 0;
commit = lookup_commit_reference_gently(oid->hash, 1);
commit = lookup_commit_reference_gently(oid, 1);
/* Not a commit -- keep it */
if (!commit)
......@@ -318,7 +318,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid,
struct commit *tip_commit;
if (flags & REF_ISSYMREF)
return 0;
tip_commit = lookup_commit_reference_gently(oid->hash, 1);
tip_commit = lookup_commit_reference_gently(oid, 1);
if (!tip_commit)
return 0;
commit_list_insert(tip_commit, list);
......@@ -335,7 +335,7 @@ static void reflog_expiry_prepare(const char *refname,
cb->tip_commit = NULL;
cb->unreachable_expire_kind = UE_HEAD;
} else {
cb->tip_commit = lookup_commit_reference_gently(oid->hash, 1);
cb->tip_commit = lookup_commit_reference_gently(oid, 1);
if (!cb->tip_commit)
cb->unreachable_expire_kind = UE_ALWAYS;
else
......
......@@ -328,7 +328,7 @@ static void replace_parents(struct strbuf *buf, int argc, const char **argv)
struct object_id oid;
if (get_oid(argv[i], &oid) < 0)
die(_("Not a valid object name: '%s'"), argv[i]);
lookup_commit_or_die(oid.hash, argv[i]);
lookup_commit_or_die(&oid, argv[i]);
strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&oid));
}
......@@ -394,7 +394,7 @@ static int create_graft(int argc, const char **argv, int force)
if (get_oid(old_ref, &old) < 0)
die(_("Not a valid object name: '%s'"), old_ref);
commit = lookup_commit_or_die(old.hash, old_ref);
commit = lookup_commit_or_die(&old, old_ref);
buffer = get_commit_buffer(commit, &size);
strbuf_add(&buf, buffer, size);
......
......@@ -303,7 +303,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
struct commit *commit;
if (get_sha1_committish(rev, oid.hash))
die(_("Failed to resolve '%s' as a valid revision."), rev);
commit = lookup_commit_reference(oid.hash);
commit = lookup_commit_reference(&oid);
if (!commit)
die(_("Could not parse object '%s'."), rev);
oidcpy(&oid, &commit->object.oid);
......@@ -380,7 +380,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
update_ref_status = reset_refs(rev, &oid);
if (reset_type == HARD && !update_ref_status && !quiet)
print_new_head_line(lookup_commit_reference(oid.hash));
print_new_head_line(lookup_commit_reference(&oid));
}
if (!pathspec.nr)
remove_branch_state();
......
......@@ -279,8 +279,8 @@ static int try_difference(const char *arg)
if (symmetric) {
struct commit_list *exclude;
struct commit *a, *b;
a = lookup_commit_reference(oid.hash);
b = lookup_commit_reference(end.hash);
a = lookup_commit_reference(&oid);
b = lookup_commit_reference(&end);
exclude = get_merge_bases(a, b);
while (exclude) {
struct commit *commit = pop_commit(&exclude);
......@@ -332,7 +332,7 @@ static int try_parent_shorthands(const char *arg)
return 0;
}
commit = lookup_commit_reference(oid.hash);
commit = lookup_commit_reference(&oid);
if (exclude_parent &&
exclude_parent > commit_list_count(commit->parents)) {
*dotdot = '^';
......
......@@ -358,7 +358,7 @@ static void sort_ref_range(int bottom, int top)
static int append_ref(const char *refname, const struct object_id *oid,
int allow_dups)
{
struct commit *commit = lookup_commit_reference_gently(oid->hash, 1);
struct commit *commit = lookup_commit_reference_gently(oid, 1);
int i;
if (!commit)
......@@ -816,7 +816,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
MAX_REVS), MAX_REVS);
if (get_sha1(ref_name[num_rev], revkey.hash))
die(_("'%s' is not a valid ref."), ref_name[num_rev]);
commit = lookup_commit_reference(revkey.hash);
commit = lookup_commit_reference(&revkey);
if (!commit)
die(_("cannot find commit %s (%s)"),
ref_name[num_rev], oid_to_hex(&revkey));
......
......@@ -328,7 +328,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
}
free(buf);
if ((c = lookup_commit_reference(oid->hash)) != NULL)
if ((c = lookup_commit_reference(oid)) != NULL)
strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
break;
case OBJ_TREE:
......
......@@ -25,7 +25,7 @@ static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned
memset(&signature_check, 0, sizeof(signature_check));
ret = check_commit_signature(lookup_commit(oid->hash), &signature_check);
ret = check_commit_signature(lookup_commit(oid), &signature_check);
print_signature_buffer(&signature_check, flags);
signature_check_clear(&signature_check);
......
......@@ -367,7 +367,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
* in terms of a tag (e.g. v2.0 from the range
* "v1.0..v2.0")?
*/
struct commit *one = lookup_commit_reference(oid.hash);
struct commit *one = lookup_commit_reference(&oid);
struct object *obj;
if (e->item == &(one->object)) {
......
......@@ -18,38 +18,38 @@ int save_commit_buffer = 1;
const char *commit_type = "commit";
struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
struct commit *lookup_commit_reference_gently(const struct object_id *oid,
int quiet)
{
struct object *obj = deref_tag(parse_object(sha1), NULL, 0);
struct object *obj = deref_tag(parse_object(oid->hash), NULL, 0);
if (!obj)
return NULL;
return object_as_type(obj, OBJ_COMMIT, quiet);
}
struct commit *lookup_commit_reference(const unsigned char *sha1)
struct commit *lookup_commit_reference(const struct object_id *oid)
{
return lookup_commit_reference_gently(sha1, 0);
return lookup_commit_reference_gently(oid, 0);
}
struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name)
struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)
{
struct commit *c = lookup_commit_reference(sha1);
struct commit *c = lookup_commit_reference(oid);
if (!c)
die(_("could not parse %s"), ref_name);
if (hashcmp(sha1, c->object.oid.hash)) {
if (oidcmp(oid, &c->object.oid)) {
warning(_("%s %s is not a commit!"),
ref_name, sha1_to_hex(sha1));
ref_name, oid_to_hex(oid));
}
return c;
}
struct commit *lookup_commit(const unsigned char *sha1)
struct commit *lookup_commit(const struct object_id *oid)
{
struct object *obj = lookup_object(sha1);
struct object *obj = lookup_object(oid->hash);
if (!obj)
return create_object(sha1, alloc_commit_node());
return create_object(oid->hash, alloc_commit_node());
return object_as_type(obj, OBJ_COMMIT, 0);
}
......@@ -60,7 +60,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
if (get_sha1_committish(name, oid.hash))
return NULL;
commit = lookup_commit_reference(oid.hash);
commit = lookup_commit_reference(&oid);
if (parse_commit(commit))
return NULL;
return commit;
......@@ -350,7 +350,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
*/
if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
continue;
new_parent = lookup_commit(parent.hash);
new_parent = lookup_commit(&parent);
if (new_parent)
pptr = &commit_list_insert(new_parent, pptr)->next;
}
......@@ -358,7 +358,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
int i;
struct commit *new_parent;
for (i = 0; i < graft->nr_parent; i++) {
new_parent = lookup_commit(graft->parent[i].hash);
new_parent = lookup_commit(&graft->parent[i]);
if (!new_parent)
continue;
pptr = &commit_list_insert(new_parent, pptr)->next;
......@@ -562,7 +562,7 @@ void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark)
for (i = 0; i < a->nr; i++) {
object = a->objects[i].item;
commit = lookup_commit_reference_gently(object->oid.hash, 1);
commit = lookup_commit_reference_gently(&object->oid, 1);
if (commit)
clear_commit_marks(commit, mark);
}
......
......@@ -45,18 +45,18 @@ enum decoration_type {
void add_name_decoration(enum decoration_type type, const char *name, struct object *obj);
const struct name_decoration *get_name_decoration(const struct object *obj);
struct commit *lookup_commit(const unsigned char *sha1);
struct commit *lookup_commit_reference(const unsigned char *sha1);
struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
struct commit *lookup_commit(const struct object_id *oid);
struct commit *lookup_commit_reference(const struct object_id *oid);
struct commit *lookup_commit_reference_gently(const struct object_id *oid,
int quiet);
struct commit *lookup_commit_reference_by_name(const char *name);
/*
* Look up object named by "sha1", dereference tag as necessary,
* get a commit and return it. If "sha1" does not dereference to
* Look up object named by "oid", dereference tag as necessary,
* get a commit and return it. If "oid" does not dereference to
* a commit, use ref_name to report an error and die.
*/
struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name);
struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name);
int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size);
int parse_commit_gently(struct commit *item, int quiet_on_missing);
......
......@@ -1763,8 +1763,8 @@ static int update_branch(struct branch *b)
if (!force_update && !is_null_oid(&old_oid)) {
struct commit *old_cmit, *new_cmit;
old_cmit = lookup_commit_reference_gently(old_oid.hash, 0);
new_cmit = lookup_commit_reference_gently(b->oid.hash, 0);
old_cmit = lookup_commit_reference_gently(&old_oid, 0);
new_cmit = lookup_commit_reference_gently(&b->oid, 0);
if (!old_cmit || !new_cmit)
return error("Branch %s is missing commits.", b->name);
......
......@@ -483,7 +483,7 @@ static int find_common(struct fetch_pack_args *args,
case ACK_ready:
case ACK_continue: {
struct commit *commit =
lookup_commit(result_oid->hash);
lookup_commit(result_oid);
if (!commit)
die(_("invalid commit %s"), oid_to_hex(result_oid));
if (args->stateless_rpc
......
......@@ -1569,8 +1569,9 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
static int verify_merge_base(struct object_id *head_oid, struct ref *remote)
{
struct commit *head = lookup_commit_or_die(head_oid->hash, "HEAD");
struct commit *branch = lookup_commit_or_die(remote->old_oid.hash, remote->name);
struct commit *head = lookup_commit_or_die(head_oid, "HEAD");
struct commit *branch = lookup_commit_or_die(&remote->old_oid,
remote->name);
return in_merge_bases(branch, head);
}
......
......@@ -140,7 +140,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
{
struct commit *commit = lookup_commit(graft->oid.hash);
struct commit *commit = lookup_commit(&graft->oid);
if (!commit)
return 0;
add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
......
......@@ -14,7 +14,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
if (read_ref(ref, oid.hash) < 0)
return 0;
commit = lookup_commit_reference_gently(oid.hash, 1);
commit = lookup_commit_reference_gently(&oid, 1);
if (!commit)
return 0;
......
......@@ -554,7 +554,7 @@ int notes_merge(struct notes_merge_options *o,
else if (!check_refname_format(o->local_ref, 0) &&
is_null_oid(&local_oid))
local = NULL; /* local_sha1 == null_sha1 indicates unborn ref */
else if (!(local = lookup_commit_reference(local_oid.hash)))
else if (!(local = lookup_commit_reference(&local_oid)))
die("Could not parse local commit %s (%s)",
oid_to_hex(&local_oid), o->local_ref);
trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid));
......@@ -572,7 +572,7 @@ int notes_merge(struct notes_merge_options *o,
die("Failed to resolve remote notes ref '%s'",
o->remote_ref);
}
} else if (!(remote = lookup_commit_reference(remote_oid.hash))) {
} else if (!(remote = lookup_commit_reference(&remote_oid))) {
die("Could not parse remote commit %s (%s)",
oid_to_hex(&remote_oid), o->remote_ref);
}
......
......@@ -18,7 +18,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
/* Deduce parent commit from t->ref */
struct object_id parent_oid;
if (!read_ref(t->ref, parent_oid.hash)) {
struct commit *parent = lookup_commit(parent_oid.hash);
struct commit *parent = lookup_commit(&parent_oid);
if (parse_commit(parent))
die("Failed to find/parse commit %s", t->ref);
commit_list_insert(parent, &parents);
......
......@@ -182,9 +182,12 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
{
struct object_id oid;
struct object *obj;
*eaten_p = 0;
hashcpy(oid.hash, sha1);
obj = NULL;
if (type == OBJ_BLOB) {
struct blob *blob = lookup_blob(sha1);
......@@ -206,7 +209,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
}
}
} else if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(sha1);
struct commit *commit = lookup_commit(&oid);
if (commit) {
if (parse_commit_buffer(commit, buffer