Commit 2122f675 authored by Stefan Beller's avatar Stefan Beller Committed by Junio C Hamano

commit: add repository argument to lookup_commit_reference

Add a repository argument to allow callers of lookup_commit_reference
to be more specific about which repository to handle. This is a small
mechanical change; it doesn't change the implementation to handle
repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a
repository other than the_repository at compile time.
Signed-off-by: Stefan Beller's avatarStefan Beller <sbeller@google.com>
Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
parent 21e1ee8f
......@@ -724,7 +724,7 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
static struct commit *get_commit_reference(const struct object_id *oid)
{
struct commit *r = lookup_commit_reference(oid);
struct commit *r = lookup_commit_reference(the_repository, oid);
if (!r)
die(_("Not a valid commit name %s"), oid_to_hex(oid));
return r;
......
......@@ -119,7 +119,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc
{
struct commit *parent;
parent = lookup_commit_reference(oid);
parent = lookup_commit_reference(the_repository, oid);
if (!parent)
die("no such commit %s", oid_to_hex(oid));
return &commit_list_insert(parent, tail)->next;
......
......@@ -302,7 +302,7 @@ void create_branch(const char *name, const char *start_name,
break;
}
if ((commit = lookup_commit_reference(&oid)) == NULL)
if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
die(_("Not a valid branch point: '%s'."), start_name);
oidcpy(&oid, &commit->object.oid);
......
......@@ -121,7 +121,8 @@ static int branch_merged(int kind, const char *name,
(reference_name = reference_name_to_free =
resolve_refdup(upstream, RESOLVE_REF_READING,
&oid, NULL)) != NULL)
reference_rev = lookup_commit_reference(&oid);
reference_rev = lookup_commit_reference(the_repository,
&oid);
}
if (!reference_rev)
reference_rev = head_rev;
......@@ -154,7 +155,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);
struct commit *rev = lookup_commit_reference(the_repository, oid);
if (!rev) {
error(_("Couldn't look up commit object for '%s'"), refname);
return -1;
......@@ -208,7 +209,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
}
if (!force) {
head_rev = lookup_commit_reference(&head_oid);
head_rev = lookup_commit_reference(the_repository, &head_oid);
if (!head_rev)
die(_("Couldn't look up commit object for HEAD"));
}
......
......@@ -696,7 +696,8 @@ 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);
struct commit *c = lookup_commit_reference(the_repository,
&our->old_oid);
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF,
UPDATE_REFS_DIE_ON_ERR);
......
......@@ -303,7 +303,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
unsigned long seen_commits = 0;
unsigned int unannotated_cnt = 0;
cmit = lookup_commit_reference(oid);
cmit = lookup_commit_reference(the_repository, oid);
n = find_commit_name(&cmit->object.oid);
if (n && (tags || all || n->prio == 2)) {
......
......@@ -11,7 +11,7 @@ static struct rev_info log_tree_opt;
static int diff_tree_commit_oid(const struct object_id *oid)
{
struct commit *commit = lookup_commit_reference(oid);
struct commit *commit = lookup_commit_reference(the_repository, oid);
if (!commit)
return -1;
return log_tree_commit(&log_tree_opt, commit);
......
......@@ -907,8 +907,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);
c2 = lookup_commit_reference(&o2->oid);
c1 = lookup_commit_reference(the_repository, &o1->oid);
c2 = lookup_commit_reference(the_repository, &o2->oid);
if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
die(_("Not a range."));
......@@ -1864,7 +1864,8 @@ 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);
struct commit *commit = lookup_commit_reference(the_repository,
&oid);
if (commit) {
commit->object.flags |= flags;
add_pending_object(revs, &commit->object, arg);
......
......@@ -6,6 +6,7 @@
#include "diff.h"
#include "revision.h"
#include "parse-options.h"
#include "repository.h"
static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
{
......@@ -42,7 +43,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);
r = lookup_commit_reference(the_repository, &revkey);
if (!r)
die("Not a valid commit name %s", arg);
......@@ -171,7 +172,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);
derived = lookup_commit_reference(the_repository, &oid);
memset(&revs, 0, sizeof(revs));
revs.initial = 1;
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
......
......@@ -12,6 +12,7 @@
#include "builtin.h"
#include "notes.h"
#include "object-store.h"
#include "repository.h"
#include "blob.h"
#include "pretty.h"
#include "refs.h"
......@@ -711,7 +712,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)))
else if (!(partial = lookup_commit_reference(the_repository, &oid)))
die(_("could not find commit from NOTES_MERGE_PARTIAL."));
else if (parse_commit(partial))
die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
......
......@@ -765,10 +765,13 @@ 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), &revs);
commit_list_insert(lookup_commit_reference(merge_head), &revs);
commit_list_insert(lookup_commit_reference(the_repository, curr_head),
&revs);
commit_list_insert(lookup_commit_reference(the_repository, merge_head),
&revs);
if (!is_null_oid(fork_point))
commit_list_insert(lookup_commit_reference(fork_point), &revs);
commit_list_insert(lookup_commit_reference(the_repository, fork_point),
&revs);
result = get_octopus_merge_bases(revs);
free_commit_list(revs);
......@@ -944,9 +947,11 @@ 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);
head = lookup_commit_reference(the_repository,
&orig_head);
commit_list_insert(head, &list);
merge_head = lookup_commit_reference(&merge_heads.oid[0]);
merge_head = lookup_commit_reference(the_repository,
&merge_heads.oid[0]);
if (is_descendant_of(merge_head, list)) {
/* we can fast-forward this without invoking rebase */
opt_ff = "--ff-only";
......
......@@ -371,7 +371,7 @@ static int replace_parents(struct strbuf *buf, int argc, const char **argv)
return error(_("Not a valid object name: '%s'"),
argv[i]);
}
if (!lookup_commit_reference(&oid)) {
if (!lookup_commit_reference(the_repository, &oid)) {
strbuf_release(&new_parents);
return error(_("could not parse %s"), argv[i]);
}
......@@ -443,7 +443,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
if (get_oid(old_ref, &old_oid) < 0)
return error(_("Not a valid object name: '%s'"), old_ref);
commit = lookup_commit_reference(&old_oid);
commit = lookup_commit_reference(the_repository, &old_oid);
if (!commit)
return error(_("could not parse %s"), old_ref);
......
......@@ -319,7 +319,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
struct commit *commit;
if (get_oid_committish(rev, &oid))
die(_("Failed to resolve '%s' as a valid revision."), rev);
commit = lookup_commit_reference(&oid);
commit = lookup_commit_reference(the_repository, &oid);
if (!commit)
die(_("Could not parse object '%s'."), rev);
oidcpy(&oid, &commit->object.oid);
......@@ -396,7 +396,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));
print_new_head_line(lookup_commit_reference(the_repository, &oid));
}
if (!pathspec.nr)
remove_branch_state();
......
......@@ -280,8 +280,8 @@ static int try_difference(const char *arg)
if (symmetric) {
struct commit_list *exclude;
struct commit *a, *b;
a = lookup_commit_reference(&start_oid);
b = lookup_commit_reference(&end_oid);
a = lookup_commit_reference(the_repository, &start_oid);
b = lookup_commit_reference(the_repository, &end_oid);
if (!a || !b) {
*dotdot = '.';
return 0;
......@@ -333,7 +333,7 @@ static int try_parent_shorthands(const char *arg)
*dotdot = 0;
if (get_oid_committish(arg, &oid) ||
!(commit = lookup_commit_reference(&oid))) {
!(commit = lookup_commit_reference(the_repository, &oid))) {
*dotdot = '^';
return 0;
}
......
......@@ -831,7 +831,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
MAX_REVS), MAX_REVS);
if (get_oid(ref_name[num_rev], &revkey))
die(_("'%s' is not a valid ref."), ref_name[num_rev]);
commit = lookup_commit_reference(&revkey);
commit = lookup_commit_reference(the_repository, &revkey);
if (!commit)
die(_("cannot find commit %s (%s)"),
ref_name[num_rev], oid_to_hex(&revkey));
......
......@@ -313,7 +313,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
}
free(buf);
if ((c = lookup_commit_reference(oid)) != NULL)
if ((c = lookup_commit_reference(the_repository, oid)) != NULL)
strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
break;
case OBJ_TREE:
......
......@@ -375,7 +375,8 @@ 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);
struct commit *one = lookup_commit_reference(the_repository,
&oid);
struct object *obj;
if (e->item == &(one->object)) {
......
......@@ -35,14 +35,14 @@ struct commit *lookup_commit_reference_gently_the_repository(
return object_as_type(the_repository, obj, OBJ_COMMIT, quiet);
}
struct commit *lookup_commit_reference(const struct object_id *oid)
struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)
{
return lookup_commit_reference_gently(the_repository, oid, 0);
}
struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)
{
struct commit *c = lookup_commit_reference(oid);
struct commit *c = lookup_commit_reference(the_repository, oid);
if (!c)
die(_("could not parse %s"), ref_name);
if (oidcmp(oid, &c->object.oid)) {
......@@ -68,7 +68,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
if (get_oid_committish(name, &oid))
return NULL;
commit = lookup_commit_reference(&oid);
commit = lookup_commit_reference(the_repository, &oid);
if (parse_commit(commit))
return NULL;
return commit;
......
......@@ -64,7 +64,9 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj
const struct name_decoration *get_name_decoration(const struct object *obj);
struct commit *lookup_commit(const struct object_id *oid);
struct commit *lookup_commit_reference(const struct object_id *oid);
#define lookup_commit_reference(r, o) \
lookup_commit_reference_##r(o)
struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);
#define lookup_commit_reference_gently(r, o, q) \
lookup_commit_reference_gently_##r(o, q)
struct commit *lookup_commit_reference_gently_the_repository(
......
......@@ -1192,9 +1192,9 @@ static int merge_submodule(struct merge_options *o,
return 0;
}
if (!(commit_base = lookup_commit_reference(base)) ||
!(commit_a = lookup_commit_reference(a)) ||
!(commit_b = lookup_commit_reference(b))) {
if (!(commit_base = lookup_commit_reference(the_repository, base)) ||
!(commit_a = lookup_commit_reference(the_repository, a)) ||
!(commit_b = lookup_commit_reference(the_repository, b))) {
output(o, 1, _("Failed to merge submodule %s (commits not present)"), path);
return 0;
}
......
......@@ -2,6 +2,7 @@
#include "commit.h"
#include "refs.h"
#include "object-store.h"
#include "repository.h"
#include "diff.h"
#include "diffcore.h"
#include "xdiff-interface.h"
......@@ -553,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_oid == null_oid indicates unborn ref */
else if (!(local = lookup_commit_reference(&local_oid)))
else if (!(local = lookup_commit_reference(the_repository, &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));
......@@ -571,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))) {
} else if (!(remote = lookup_commit_reference(the_repository, &remote_oid))) {
die("Could not parse remote commit %s (%s)",
oid_to_hex(&remote_oid), o->remote_ref);
}
......
......@@ -91,7 +91,7 @@ int parse_opt_commits(const struct option *opt, const char *arg, int unset)
return -1;
if (get_oid(arg, &oid))
return error("malformed object name %s", arg);
commit = lookup_commit_reference(&oid);
commit = lookup_commit_reference(the_repository, &oid);
if (!commit)
return error("no such commit %s", arg);
commit_list_insert(commit, opt->value);
......
......@@ -1865,13 +1865,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
/* Cannot stat if what we used to build on no longer exists */
if (read_ref(base, &oid))
return -1;
theirs = lookup_commit_reference(&oid);
theirs = lookup_commit_reference(the_repository, &oid);
if (!theirs)
return -1;
if (read_ref(branch->refname, &oid))
return -1;
ours = lookup_commit_reference(&oid);
ours = lookup_commit_reference(the_repository, &oid);
if (!ours)
return -1;
......
......@@ -1591,8 +1591,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
struct commit *a, *b;
struct commit_list *exclude;
a = lookup_commit_reference(&a_obj->oid);
b = lookup_commit_reference(&b_obj->oid);
a = lookup_commit_reference(the_repository, &a_obj->oid);
b = lookup_commit_reference(the_repository, &b_obj->oid);
if (!a || !b)
return dotdot_missing(arg, dotdot, revs, symmetric);
......
......@@ -1176,7 +1176,7 @@ static int parse_head(struct commit **head)
if (get_oid("HEAD", &oid)) {
current_head = NULL;
} else {
current_head = lookup_commit_reference(&oid);
current_head = lookup_commit_reference(the_repository, &oid);
if (!current_head)
return error(_("could not parse HEAD"));
if (oidcmp(&oid, &current_head->object.oid)) {
......@@ -1511,7 +1511,7 @@ static int update_squash_messages(enum todo_command command,
if (get_oid("HEAD", &head))
return error(_("need a HEAD to fixup"));
if (!(head_commit = lookup_commit_reference(&head)))
if (!(head_commit = lookup_commit_reference(the_repository, &head)))
return error(_("could not read HEAD"));
if (!(head_message = get_commit_buffer(head_commit, NULL)))
return error(_("could not read HEAD's commit message"));
......@@ -2009,7 +2009,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
if (status < 0)
return -1;
item->commit = lookup_commit_reference(&commit_oid);
item->commit = lookup_commit_reference(the_repository, &commit_oid);
return !item->commit;
}
......
......@@ -844,7 +844,7 @@ static int get_parent(const char *name, int len,
if (ret)
return ret;
commit = lookup_commit_reference(&oid);
commit = lookup_commit_reference(the_repository, &oid);
if (parse_commit(commit))
return -1;
if (!idx) {
......@@ -872,7 +872,7 @@ static int get_nth_ancestor(const char *name, int len,
ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
if (ret)
return ret;
commit = lookup_commit_reference(&oid);
commit = lookup_commit_reference(the_repository, &oid);
if (!commit)
return -1;
......
......@@ -517,8 +517,8 @@ static void show_submodule_header(struct diff_options *o, const char *path,
* Attempt to lookup the commit references, and determine if this is
* a fast forward or fast backwards update.
*/
*left = lookup_commit_reference(one);
*right = lookup_commit_reference(two);
*left = lookup_commit_reference(the_repository, one);
*right = lookup_commit_reference(the_repository, two);
/*
* Warn about missing commits in the submodule project, but only if
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment