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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Jun 28, 2018 at 18:21 UTC
2122f6754c93be8f02bfb5704ed96c88fc9837a8
27 files changed
+65
-51
bisect.c
+1
-1
@@ -724,7 +724,7 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
724
725
static struct commit *get_commit_reference(const struct object_id *oid)
726
{
727
- struct commit *r = lookup_commit_reference(oid);
727
+ struct commit *r = lookup_commit_reference(the_repository, oid);
728
if (!r)
729
die(_("Not a valid commit name %s"), oid_to_hex(oid));
730
return r;
blame.c
+1
-1
@@ -119,7 +119,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc
119
{
120
struct commit *parent;
121
122
- parent = lookup_commit_reference(oid);
122
+ parent = lookup_commit_reference(the_repository, oid);
123
if (!parent)
124
die("no such commit %s", oid_to_hex(oid));
125
return &commit_list_insert(parent, tail)->next;
branch.c
+1
-1
@@ -302,7 +302,7 @@ void create_branch(const char *name, const char *start_name,
302
break;
303
}
304
305
- if ((commit = lookup_commit_reference(&oid)) == NULL)
305
+ if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
306
die(_("Not a valid branch point: '%s'."), start_name);
307
oidcpy(&oid, &commit->object.oid);
308
builtin/branch.c
+4
-3
@@ -121,7 +121,8 @@ static int branch_merged(int kind, const char *name,
121
(reference_name = reference_name_to_free =
122
resolve_refdup(upstream, RESOLVE_REF_READING,
123
&oid, NULL)) != NULL)
124
- reference_rev = lookup_commit_reference(&oid);
124
+ reference_rev = lookup_commit_reference(the_repository,
125
+ &oid);
126
}
127
if (!reference_rev)
128
reference_rev = head_rev;
@@ -154,7 +155,7 @@ static int check_branch_commit(const char *branchname, const char *refname,
155
const struct object_id *oid, struct commit *head_rev,
156
int kinds, int force)
157
{
157
- struct commit *rev = lookup_commit_reference(oid);
158
+ struct commit *rev = lookup_commit_reference(the_repository, oid);
159
if (!rev) {
160
error(_("Couldn't look up commit object for '%s'"), refname);
161
return -1;
@@ -208,7 +209,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
209
}
210
211
if (!force) {
211
- head_rev = lookup_commit_reference(&head_oid);
212
+ head_rev = lookup_commit_reference(the_repository, &head_oid);
213
if (!head_rev)
214
die(_("Couldn't look up commit object for HEAD"));
215
}
builtin/clone.c
+2
-1
@@ -696,7 +696,8 @@ static void update_head(const struct ref *our, const struct ref *remote,
696
install_branch_config(0, head, option_origin, our->name);
697
}
698
} else if (our) {
699
- struct commit *c = lookup_commit_reference(&our->old_oid);
699
+ struct commit *c = lookup_commit_reference(the_repository,
700
+ &our->old_oid);
701
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
702
update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF,
703
UPDATE_REFS_DIE_ON_ERR);
builtin/describe.c
+1
-1
@@ -303,7 +303,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
303
unsigned long seen_commits = 0;
304
unsigned int unannotated_cnt = 0;
305
306
- cmit = lookup_commit_reference(oid);
306
+ cmit = lookup_commit_reference(the_repository, oid);
307
308
n = find_commit_name(&cmit->object.oid);
309
if (n && (tags || all || n->prio == 2)) {
builtin/diff-tree.c
+1
-1
@@ -11,7 +11,7 @@ static struct rev_info log_tree_opt;
11
12
static int diff_tree_commit_oid(const struct object_id *oid)
13
{
14
- struct commit *commit = lookup_commit_reference(oid);
14
+ struct commit *commit = lookup_commit_reference(the_repository, oid);
15
if (!commit)
16
return -1;
17
return log_tree_commit(&log_tree_opt, commit);
builtin/log.c
+4
-3
@@ -907,8 +907,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
907
o2 = rev->pending.objects[1].item;
908
flags1 = o1->flags;
909
flags2 = o2->flags;
910
- c1 = lookup_commit_reference(&o1->oid);
911
- c2 = lookup_commit_reference(&o2->oid);
910
+ c1 = lookup_commit_reference(the_repository, &o1->oid);
911
+ c2 = lookup_commit_reference(the_repository, &o2->oid);
912
913
if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
914
die(_("Not a range."));
@@ -1864,7 +1864,8 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
1864
{
1865
struct object_id oid;
1866
if (get_oid(arg, &oid) == 0) {
1867
- struct commit *commit = lookup_commit_reference(&oid);
1867
+ struct commit *commit = lookup_commit_reference(the_repository,
1868
+ &oid);
1869
if (commit) {
1870
commit->object.flags |= flags;
1871
add_pending_object(revs, &commit->object, arg);
builtin/merge-base.c
+3
-2
@@ -6,6 +6,7 @@
6
#include "diff.h"
7
#include "revision.h"
8
#include "parse-options.h"
9
+#include "repository.h"
10
11
static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
12
{
@@ -42,7 +43,7 @@ static struct commit *get_commit_reference(const char *arg)
43
44
if (get_oid(arg, &revkey))
45
die("Not a valid object name %s", arg);
45
- r = lookup_commit_reference(&revkey);
46
+ r = lookup_commit_reference(the_repository, &revkey);
47
if (!r)
48
die("Not a valid commit name %s", arg);
49
@@ -171,7 +172,7 @@ static int handle_fork_point(int argc, const char **argv)
172
if (get_oid(commitname, &oid))
173
die("Not a valid object name: '%s'", commitname);
174
174
- derived = lookup_commit_reference(&oid);
175
+ derived = lookup_commit_reference(the_repository, &oid);
176
memset(&revs, 0, sizeof(revs));
177
revs.initial = 1;
178
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
builtin/notes.c
+2
-1
@@ -12,6 +12,7 @@
12
#include "builtin.h"
13
#include "notes.h"
14
#include "object-store.h"
15
+#include "repository.h"
16
#include "blob.h"
17
#include "pretty.h"
18
#include "refs.h"
@@ -711,7 +712,7 @@ static int merge_commit(struct notes_merge_options *o)
712
713
if (get_oid("NOTES_MERGE_PARTIAL", &oid))
714
die(_("failed to read ref NOTES_MERGE_PARTIAL"));
714
- else if (!(partial = lookup_commit_reference(&oid)))
715
+ else if (!(partial = lookup_commit_reference(the_repository, &oid)))
716
die(_("could not find commit from NOTES_MERGE_PARTIAL."));
717
else if (parse_commit(partial))
718
die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
builtin/pull.c
+10
-5
@@ -765,10 +765,13 @@ static int get_octopus_merge_base(struct object_id *merge_base,
765
{
766
struct commit_list *revs = NULL, *result;
767
768
- commit_list_insert(lookup_commit_reference(curr_head), &revs);
769
- commit_list_insert(lookup_commit_reference(merge_head), &revs);
768
+ commit_list_insert(lookup_commit_reference(the_repository, curr_head),
769
+ &revs);
770
+ commit_list_insert(lookup_commit_reference(the_repository, merge_head),
771
+ &revs);
772
if (!is_null_oid(fork_point))
771
- commit_list_insert(lookup_commit_reference(fork_point), &revs);
773
+ commit_list_insert(lookup_commit_reference(the_repository, fork_point),
774
+ &revs);
775
776
result = get_octopus_merge_bases(revs);
777
free_commit_list(revs);
@@ -944,9 +947,11 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
947
struct commit_list *list = NULL;
948
struct commit *merge_head, *head;
949
947
- head = lookup_commit_reference(&orig_head);
950
+ head = lookup_commit_reference(the_repository,
951
+ &orig_head);
952
commit_list_insert(head, &list);
949
- merge_head = lookup_commit_reference(&merge_heads.oid[0]);
953
+ merge_head = lookup_commit_reference(the_repository,
954
+ &merge_heads.oid[0]);
955
if (is_descendant_of(merge_head, list)) {
956
/* we can fast-forward this without invoking rebase */
957
opt_ff = "--ff-only";
builtin/replace.c
+2
-2
@@ -371,7 +371,7 @@ static int replace_parents(struct strbuf *buf, int argc, const char **argv)
371
return error(_("Not a valid object name: '%s'"),
372
argv[i]);
373
}
374
- if (!lookup_commit_reference(&oid)) {
374
+ if (!lookup_commit_reference(the_repository, &oid)) {
375
strbuf_release(&new_parents);
376
return error(_("could not parse %s"), argv[i]);
377
}
@@ -443,7 +443,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
443
444
if (get_oid(old_ref, &old_oid) < 0)
445
return error(_("Not a valid object name: '%s'"), old_ref);
446
- commit = lookup_commit_reference(&old_oid);
446
+ commit = lookup_commit_reference(the_repository, &old_oid);
447
if (!commit)
448
return error(_("could not parse %s"), old_ref);
449
builtin/reset.c
+2
-2
@@ -319,7 +319,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
319
struct commit *commit;
320
if (get_oid_committish(rev, &oid))
321
die(_("Failed to resolve '%s' as a valid revision."), rev);
322
- commit = lookup_commit_reference(&oid);
322
+ commit = lookup_commit_reference(the_repository, &oid);
323
if (!commit)
324
die(_("Could not parse object '%s'."), rev);
325
oidcpy(&oid, &commit->object.oid);
@@ -396,7 +396,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
396
update_ref_status = reset_refs(rev, &oid);
397
398
if (reset_type == HARD && !update_ref_status && !quiet)
399
- print_new_head_line(lookup_commit_reference(&oid));
399
+ print_new_head_line(lookup_commit_reference(the_repository, &oid));
400
}
401
if (!pathspec.nr)
402
remove_branch_state();
builtin/rev-parse.c
+3
-3
@@ -280,8 +280,8 @@ static int try_difference(const char *arg)
280
if (symmetric) {
281
struct commit_list *exclude;
282
struct commit *a, *b;
283
- a = lookup_commit_reference(&start_oid);
284
- b = lookup_commit_reference(&end_oid);
283
+ a = lookup_commit_reference(the_repository, &start_oid);
284
+ b = lookup_commit_reference(the_repository, &end_oid);
285
if (!a || !b) {
286
*dotdot = '.';
287
return 0;
@@ -333,7 +333,7 @@ static int try_parent_shorthands(const char *arg)
333
334
*dotdot = 0;
335
if (get_oid_committish(arg, &oid) ||
336
- !(commit = lookup_commit_reference(&oid))) {
336
+ !(commit = lookup_commit_reference(the_repository, &oid))) {
337
*dotdot = '^';
338
return 0;
339
}
builtin/show-branch.c
+1
-1
@@ -831,7 +831,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
831
MAX_REVS), MAX_REVS);
832
if (get_oid(ref_name[num_rev], &revkey))
833
die(_("'%s' is not a valid ref."), ref_name[num_rev]);
834
- commit = lookup_commit_reference(&revkey);
834
+ commit = lookup_commit_reference(the_repository, &revkey);
835
if (!commit)
836
die(_("cannot find commit %s (%s)"),
837
ref_name[num_rev], oid_to_hex(&revkey));
builtin/tag.c
+1
-1
@@ -313,7 +313,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
313
}
314
free(buf);
315
316
- if ((c = lookup_commit_reference(oid)) != NULL)
316
+ if ((c = lookup_commit_reference(the_repository, oid)) != NULL)
317
strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
318
break;
319
case OBJ_TREE:
bundle.c
+2
-1
@@ -375,7 +375,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
375
* in terms of a tag (e.g. v2.0 from the range
376
* "v1.0..v2.0")?
377
*/
378
- struct commit *one = lookup_commit_reference(&oid);
378
+ struct commit *one = lookup_commit_reference(the_repository,
379
+ &oid);
380
struct object *obj;
381
382
if (e->item == &(one->object)) {
commit.c
+3
-3
@@ -35,14 +35,14 @@ struct commit *lookup_commit_reference_gently_the_repository(
35
return object_as_type(the_repository, obj, OBJ_COMMIT, quiet);
36
}
37
38
-struct commit *lookup_commit_reference(const struct object_id *oid)
38
+struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)
39
{
40
return lookup_commit_reference_gently(the_repository, oid, 0);
41
}
42
43
struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)
44
{
45
- struct commit *c = lookup_commit_reference(oid);
45
+ struct commit *c = lookup_commit_reference(the_repository, oid);
46
if (!c)
47
die(_("could not parse %s"), ref_name);
48
if (oidcmp(oid, &c->object.oid)) {
@@ -68,7 +68,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
68
69
if (get_oid_committish(name, &oid))
70
return NULL;
71
- commit = lookup_commit_reference(&oid);
71
+ commit = lookup_commit_reference(the_repository, &oid);
72
if (parse_commit(commit))
73
return NULL;
74
return commit;
commit.h
+3
-1
@@ -64,7 +64,9 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj
64
const struct name_decoration *get_name_decoration(const struct object *obj);
65
66
struct commit *lookup_commit(const struct object_id *oid);
67
-struct commit *lookup_commit_reference(const struct object_id *oid);
67
+#define lookup_commit_reference(r, o) \
68
+ lookup_commit_reference_##r(o)
69
+struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);
70
#define lookup_commit_reference_gently(r, o, q) \
71
lookup_commit_reference_gently_##r(o, q)
72
struct commit *lookup_commit_reference_gently_the_repository(
merge-recursive.c
+3
-3
@@ -1192,9 +1192,9 @@ static int merge_submodule(struct merge_options *o,
1192
return 0;
1193
}
1194
1195
- if (!(commit_base = lookup_commit_reference(base)) ||
1196
- !(commit_a = lookup_commit_reference(a)) ||
1197
- !(commit_b = lookup_commit_reference(b))) {
1195
+ if (!(commit_base = lookup_commit_reference(the_repository, base)) ||
1196
+ !(commit_a = lookup_commit_reference(the_repository, a)) ||
1197
+ !(commit_b = lookup_commit_reference(the_repository, b))) {
1198
output(o, 1, _("Failed to merge submodule %s (commits not present)"), path);
1199
return 0;
1200
}
notes-merge.c
+3
-2
@@ -2,6 +2,7 @@
2
#include "commit.h"
3
#include "refs.h"
4
#include "object-store.h"
5
+#include "repository.h"
6
#include "diff.h"
7
#include "diffcore.h"
8
#include "xdiff-interface.h"
@@ -553,7 +554,7 @@ int notes_merge(struct notes_merge_options *o,
554
else if (!check_refname_format(o->local_ref, 0) &&
555
is_null_oid(&local_oid))
556
local = NULL; /* local_oid == null_oid indicates unborn ref */
556
- else if (!(local = lookup_commit_reference(&local_oid)))
557
+ else if (!(local = lookup_commit_reference(the_repository, &local_oid)))
558
die("Could not parse local commit %s (%s)",
559
oid_to_hex(&local_oid), o->local_ref);
560
trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid));
@@ -571,7 +572,7 @@ int notes_merge(struct notes_merge_options *o,
572
die("Failed to resolve remote notes ref '%s'",
573
o->remote_ref);
574
}
574
- } else if (!(remote = lookup_commit_reference(&remote_oid))) {
575
+ } else if (!(remote = lookup_commit_reference(the_repository, &remote_oid))) {
576
die("Could not parse remote commit %s (%s)",
577
oid_to_hex(&remote_oid), o->remote_ref);
578
}
parse-options-cb.c
+1
-1
@@ -91,7 +91,7 @@ int parse_opt_commits(const struct option *opt, const char *arg, int unset)
91
return -1;
92
if (get_oid(arg, &oid))
93
return error("malformed object name %s", arg);
94
- commit = lookup_commit_reference(&oid);
94
+ commit = lookup_commit_reference(the_repository, &oid);
95
if (!commit)
96
return error("no such commit %s", arg);
97
commit_list_insert(commit, opt->value);
remote.c
+2
-2
@@ -1865,13 +1865,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
1865
/* Cannot stat if what we used to build on no longer exists */
1866
if (read_ref(base, &oid))
1867
return -1;
1868
- theirs = lookup_commit_reference(&oid);
1868
+ theirs = lookup_commit_reference(the_repository, &oid);
1869
if (!theirs)
1870
return -1;
1871
1872
if (read_ref(branch->refname, &oid))
1873
return -1;
1874
- ours = lookup_commit_reference(&oid);
1874
+ ours = lookup_commit_reference(the_repository, &oid);
1875
if (!ours)
1876
return -1;
1877
revision.c
+2
-2
@@ -1591,8 +1591,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
1591
struct commit *a, *b;
1592
struct commit_list *exclude;
1593
1594
- a = lookup_commit_reference(&a_obj->oid);
1595
- b = lookup_commit_reference(&b_obj->oid);
1594
+ a = lookup_commit_reference(the_repository, &a_obj->oid);
1595
+ b = lookup_commit_reference(the_repository, &b_obj->oid);
1596
if (!a || !b)
1597
return dotdot_missing(arg, dotdot, revs, symmetric);
1598
sequencer.c
+3
-3
@@ -1176,7 +1176,7 @@ static int parse_head(struct commit **head)
1176
if (get_oid("HEAD", &oid)) {
1177
current_head = NULL;
1178
} else {
1179
- current_head = lookup_commit_reference(&oid);
1179
+ current_head = lookup_commit_reference(the_repository, &oid);
1180
if (!current_head)
1181
return error(_("could not parse HEAD"));
1182
if (oidcmp(&oid, ¤t_head->object.oid)) {
@@ -1511,7 +1511,7 @@ static int update_squash_messages(enum todo_command command,
1511
1512
if (get_oid("HEAD", &head))
1513
return error(_("need a HEAD to fixup"));
1514
- if (!(head_commit = lookup_commit_reference(&head)))
1514
+ if (!(head_commit = lookup_commit_reference(the_repository, &head)))
1515
return error(_("could not read HEAD"));
1516
if (!(head_message = get_commit_buffer(head_commit, NULL)))
1517
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)
2009
if (status < 0)
2010
return -1;
2011
2012
- item->commit = lookup_commit_reference(&commit_oid);
2012
+ item->commit = lookup_commit_reference(the_repository, &commit_oid);
2013
return !item->commit;
2014
}
2015
sha1-name.c
+2
-2
@@ -844,7 +844,7 @@ static int get_parent(const char *name, int len,
844
845
if (ret)
846
return ret;
847
- commit = lookup_commit_reference(&oid);
847
+ commit = lookup_commit_reference(the_repository, &oid);
848
if (parse_commit(commit))
849
return -1;
850
if (!idx) {
@@ -872,7 +872,7 @@ static int get_nth_ancestor(const char *name, int len,
872
ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
873
if (ret)
874
return ret;
875
- commit = lookup_commit_reference(&oid);
875
+ commit = lookup_commit_reference(the_repository, &oid);
876
if (!commit)
877
return -1;
878
submodule.c
+2
-2
@@ -517,8 +517,8 @@ static void show_submodule_header(struct diff_options *o, const char *path,
517
* Attempt to lookup the commit references, and determine if this is
518
* a fast forward or fast backwards update.
519
*/
520
- *left = lookup_commit_reference(one);
521
- *right = lookup_commit_reference(two);
520
+ *left = lookup_commit_reference(the_repository, one);
521
+ *right = lookup_commit_reference(the_repository, two);
522
523
/*
524
* Warn about missing commits in the submodule project, but only if