commit: add repository argument to lookup_commit_reference_gently
Add a repository argument to allow callers of lookup_commit_reference_gently 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
21e1ee8f4f4b7767d506b02504e97f6bcaef13a0
20 files changed
+59
-38
archive.c
+1
-1
@@ -380,7 +380,7 @@ static void parse_treeish_arg(const char **argv,
380
if (get_oid(name, &oid))
381
die("Not a valid object name");
382
383
- commit = lookup_commit_reference_gently(&oid, 1);
383
+ commit = lookup_commit_reference_gently(the_repository, &oid, 1);
384
if (commit) {
385
commit_sha1 = commit->object.oid.hash;
386
archive_time = commit->date;
blame.c
+2
-1
@@ -1712,7 +1712,8 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
1712
/* Do we have HEAD? */
1713
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
1714
return NULL;
1715
- head_commit = lookup_commit_reference_gently(&head_oid, 1);
1715
+ head_commit = lookup_commit_reference_gently(the_repository,
1716
+ &head_oid, 1);
1717
if (!head_commit)
1718
return NULL;
1719
builtin/checkout.c
+3
-3
@@ -379,7 +379,7 @@ static int checkout_paths(const struct checkout_opts *opts,
379
die(_("unable to write new index file"));
380
381
read_ref_full("HEAD", 0, &rev, NULL);
382
- head = lookup_commit_reference_gently(&rev, 1);
382
+ head = lookup_commit_reference_gently(the_repository, &rev, 1);
383
384
errs |= post_checkout_hook(head, head, 0);
385
return errs;
@@ -830,7 +830,7 @@ static int switch_branches(const struct checkout_opts *opts,
830
memset(&old_branch_info, 0, sizeof(old_branch_info));
831
old_branch_info.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag);
832
if (old_branch_info.path)
833
- old_branch_info.commit = lookup_commit_reference_gently(&rev, 1);
833
+ old_branch_info.commit = lookup_commit_reference_gently(the_repository, &rev, 1);
834
if (!(flag & REF_ISSYMREF))
835
old_branch_info.path = NULL;
836
@@ -1004,7 +1004,7 @@ static int parse_branchname_arg(int argc, const char **argv,
1004
else
1005
new_branch_info->path = NULL; /* not an existing branch */
1006
1007
- new_branch_info->commit = lookup_commit_reference_gently(rev, 1);
1007
+ new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1);
1008
if (!new_branch_info->commit) {
1009
/* not a commit */
1010
*source_tree = parse_tree_indirect(rev);
builtin/describe.c
+3
-2
@@ -331,7 +331,8 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
331
init_commit_names(&commit_names);
332
n = hashmap_iter_first(&names, &iter);
333
for (; n; n = hashmap_iter_next(&iter)) {
334
- c = lookup_commit_reference_gently(&n->peeled, 1);
334
+ c = lookup_commit_reference_gently(the_repository,
335
+ &n->peeled, 1);
336
if (c)
337
*commit_names_at(&commit_names, c) = n;
338
}
@@ -509,7 +510,7 @@ static void describe(const char *arg, int last_one)
510
511
if (get_oid(arg, &oid))
512
die(_("Not a valid object name %s"), arg);
512
- cmit = lookup_commit_reference_gently(&oid, 1);
513
+ cmit = lookup_commit_reference_gently(the_repository, &oid, 1);
514
515
if (cmit)
516
describe_commit(&oid, &sb);
builtin/fetch.c
+6
-3
@@ -684,8 +684,10 @@ static int update_local_ref(struct ref *ref,
684
return r;
685
}
686
687
- current = lookup_commit_reference_gently(&ref->old_oid, 1);
688
- updated = lookup_commit_reference_gently(&ref->new_oid, 1);
687
+ current = lookup_commit_reference_gently(the_repository,
688
+ &ref->old_oid, 1);
689
+ updated = lookup_commit_reference_gently(the_repository,
690
+ &ref->new_oid, 1);
691
if (!current || !updated) {
692
const char *msg;
693
const char *what;
@@ -818,7 +820,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
820
continue;
821
}
822
821
- commit = lookup_commit_reference_gently(&rm->old_oid,
823
+ commit = lookup_commit_reference_gently(the_repository,
824
+ &rm->old_oid,
825
1);
826
if (!commit)
827
rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;
builtin/reflog.c
+6
-4
@@ -196,7 +196,7 @@ static int keep_entry(struct commit **it, struct object_id *oid)
196
197
if (is_null_oid(oid))
198
return 1;
199
- commit = lookup_commit_reference_gently(oid, 1);
199
+ commit = lookup_commit_reference_gently(the_repository, oid, 1);
200
if (!commit)
201
return 0;
202
@@ -265,7 +265,8 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit
265
if (is_null_oid(oid))
266
return 0;
267
268
- commit = lookup_commit_reference_gently(oid, 1);
268
+ commit = lookup_commit_reference_gently(the_repository, oid,
269
+ 1);
270
271
/* Not a commit -- keep it */
272
if (!commit)
@@ -322,7 +323,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid,
323
struct commit *tip_commit;
324
if (flags & REF_ISSYMREF)
325
return 0;
325
- tip_commit = lookup_commit_reference_gently(oid, 1);
326
+ tip_commit = lookup_commit_reference_gently(the_repository, oid, 1);
327
if (!tip_commit)
328
return 0;
329
commit_list_insert(tip_commit, list);
@@ -339,7 +340,8 @@ static void reflog_expiry_prepare(const char *refname,
340
cb->tip_commit = NULL;
341
cb->unreachable_expire_kind = UE_HEAD;
342
} else {
342
- cb->tip_commit = lookup_commit_reference_gently(oid, 1);
343
+ cb->tip_commit = lookup_commit_reference_gently(the_repository,
344
+ oid, 1);
345
if (!cb->tip_commit)
346
cb->unreachable_expire_kind = UE_ALWAYS;
347
else
builtin/show-branch.c
+2
-1
@@ -378,7 +378,8 @@ static void sort_ref_range(int bottom, int top)
378
static int append_ref(const char *refname, const struct object_id *oid,
379
int allow_dups)
380
{
381
- struct commit *commit = lookup_commit_reference_gently(oid, 1);
381
+ struct commit *commit = lookup_commit_reference_gently(the_repository,
382
+ oid, 1);
383
int i;
384
385
if (!commit)
bundle.c
+1
-1
@@ -180,7 +180,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
180
/* Clean up objects used, as they will be reused. */
181
for (i = 0; i < p->nr; i++) {
182
struct ref_list_entry *e = p->list + i;
183
- commit = lookup_commit_reference_gently(&e->oid, 1);
183
+ commit = lookup_commit_reference_gently(the_repository, &e->oid, 1);
184
if (commit)
185
clear_commit_marks(commit, ALL_REV_FLAGS);
186
}
commit-graph.c
+1
-1
@@ -701,7 +701,7 @@ void write_commit_graph(const char *obj_dir,
701
if (commit_hex[i] && parse_oid_hex(commit_hex[i], &oid, &end))
702
continue;
703
704
- result = lookup_commit_reference_gently(&oid, 1);
704
+ result = lookup_commit_reference_gently(the_repository, &oid, 1);
705
706
if (result) {
707
ALLOC_GROW(oids.list, oids.nr + 1, oids.alloc);
commit.c
+3
-3
@@ -24,8 +24,8 @@ int save_commit_buffer = 1;
24
25
const char *commit_type = "commit";
26
27
-struct commit *lookup_commit_reference_gently(const struct object_id *oid,
28
- int quiet)
27
+struct commit *lookup_commit_reference_gently_the_repository(
28
+ const struct object_id *oid, int quiet)
29
{
30
struct object *obj = deref_tag(parse_object(the_repository, oid),
31
NULL, 0);
@@ -37,7 +37,7 @@ struct commit *lookup_commit_reference_gently(const struct object_id *oid,
37
38
struct commit *lookup_commit_reference(const struct object_id *oid)
39
{
40
- return lookup_commit_reference_gently(oid, 0);
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)
commit.h
+4
-1
@@ -65,7 +65,10 @@ 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);
68
-struct commit *lookup_commit_reference_gently(const struct object_id *oid,
68
+#define lookup_commit_reference_gently(r, o, q) \
69
+ lookup_commit_reference_gently_##r(o, q)
70
+struct commit *lookup_commit_reference_gently_the_repository(
71
+ const struct object_id *oid,
72
int quiet);
73
struct commit *lookup_commit_reference_by_name(const char *name);
74
fast-import.c
+4
-2
@@ -1724,8 +1724,10 @@ static int update_branch(struct branch *b)
1724
if (!force_update && !is_null_oid(&old_oid)) {
1725
struct commit *old_cmit, *new_cmit;
1726
1727
- old_cmit = lookup_commit_reference_gently(&old_oid, 0);
1728
- new_cmit = lookup_commit_reference_gently(&b->oid, 0);
1727
+ old_cmit = lookup_commit_reference_gently(the_repository,
1728
+ &old_oid, 0);
1729
+ new_cmit = lookup_commit_reference_gently(the_repository,
1730
+ &b->oid, 0);
1731
if (!old_cmit || !new_cmit)
1732
return error("Branch %s is missing commits.", b->name);
1733
notes-cache.c
+2
-1
@@ -1,6 +1,7 @@
1
#include "cache.h"
2
#include "notes-cache.h"
3
#include "object-store.h"
4
+#include "repository.h"
5
#include "commit.h"
6
#include "refs.h"
7
@@ -15,7 +16,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
16
if (read_ref(ref, &oid) < 0)
17
return 0;
18
18
- commit = lookup_commit_reference_gently(&oid, 1);
19
+ commit = lookup_commit_reference_gently(the_repository, &oid, 1);
20
if (!commit)
21
return 0;
22
ref-filter.c
+4
-2
@@ -2026,7 +2026,8 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
2026
* non-commits early. The actual filtering is done later.
2027
*/
2028
if (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) {
2029
- commit = lookup_commit_reference_gently(oid, 1);
2029
+ commit = lookup_commit_reference_gently(the_repository, oid,
2030
+ 1);
2031
if (!commit)
2032
return 0;
2033
/* We perform the filtering for the '--contains' option... */
@@ -2383,7 +2384,8 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
2384
if (get_oid(arg, &oid))
2385
die(_("malformed object name %s"), arg);
2386
2386
- rf->merge_commit = lookup_commit_reference_gently(&oid, 0);
2387
+ rf->merge_commit = lookup_commit_reference_gently(the_repository,
2388
+ &oid, 0);
2389
if (!rf->merge_commit)
2390
return opterror(opt, "must point to a commit", 0);
2391
remote.c
+5
-4
@@ -1149,7 +1149,7 @@ static void add_to_tips(struct tips *tips, const struct object_id *oid)
1149
1150
if (is_null_oid(oid))
1151
return;
1152
- commit = lookup_commit_reference_gently(oid, 1);
1152
+ commit = lookup_commit_reference_gently(the_repository, oid, 1);
1153
if (!commit || (commit->object.flags & TMP_MARK))
1154
return;
1155
commit->object.flags |= TMP_MARK;
@@ -1211,7 +1211,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
1211
1212
if (is_null_oid(&ref->new_oid))
1213
continue;
1214
- commit = lookup_commit_reference_gently(&ref->new_oid,
1214
+ commit = lookup_commit_reference_gently(the_repository,
1215
+ &ref->new_oid,
1216
1);
1217
if (!commit)
1218
/* not pushing a commit, which is not an error */
@@ -1435,8 +1436,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
1436
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
1437
else if (!has_object_file(&ref->old_oid))
1438
reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
1438
- else if (!lookup_commit_reference_gently(&ref->old_oid, 1) ||
1439
- !lookup_commit_reference_gently(&ref->new_oid, 1))
1439
+ else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
1440
+ !lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
1441
reject_reason = REF_STATUS_REJECT_NEEDS_FORCE;
1442
else if (!ref_newer(&ref->new_oid, &ref->old_oid))
1443
reject_reason = REF_STATUS_REJECT_NONFASTFORWARD;
sequencer.c
+1
-1
@@ -3610,7 +3610,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
3610
continue;
3611
3612
if (!get_oid(name, &oid)) {
3613
- if (!lookup_commit_reference_gently(&oid, 1)) {
3613
+ if (!lookup_commit_reference_gently(the_repository, &oid, 1)) {
3614
enum object_type type = oid_object_info(the_repository,
3615
&oid,
3616
NULL);
sha1-name.c
+2
-2
@@ -1251,13 +1251,13 @@ int get_oid_mb(const char *name, struct object_id *oid)
1251
}
1252
if (st)
1253
return st;
1254
- one = lookup_commit_reference_gently(&oid_tmp, 0);
1254
+ one = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
1255
if (!one)
1256
return -1;
1257
1258
if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
1259
return -1;
1260
- two = lookup_commit_reference_gently(&oid_tmp, 0);
1260
+ two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
1261
if (!two)
1262
return -1;
1263
mbs = get_merge_bases(one, two);
shallow.c
+6
-3
@@ -492,7 +492,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
492
struct commit_list *head = NULL;
493
int bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32);
494
size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
495
- struct commit *c = lookup_commit_reference_gently(oid, 1);
495
+ struct commit *c = lookup_commit_reference_gently(the_repository, oid,
496
+ 1);
497
uint32_t *tmp; /* to be freed before return */
498
uint32_t *bitmap;
499
@@ -554,7 +555,8 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
555
static int mark_uninteresting(const char *refname, const struct object_id *oid,
556
int flags, void *cb_data)
557
{
557
- struct commit *commit = lookup_commit_reference_gently(oid, 1);
558
+ struct commit *commit = lookup_commit_reference_gently(the_repository,
559
+ oid, 1);
560
if (!commit)
561
return 0;
562
commit->object.flags |= UNINTERESTING;
@@ -664,7 +666,8 @@ static int add_ref(const char *refname, const struct object_id *oid,
666
{
667
struct commit_array *ca = cb_data;
668
ALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc);
667
- ca->commits[ca->nr] = lookup_commit_reference_gently(oid, 1);
669
+ ca->commits[ca->nr] = lookup_commit_reference_gently(the_repository,
670
+ oid, 1);
671
if (ca->commits[ca->nr])
672
ca->nr++;
673
return 0;
walker.c
+2
-1
@@ -207,7 +207,8 @@ static int interpret_target(struct walker *walker, char *target, struct object_i
207
static int mark_complete(const char *path, const struct object_id *oid,
208
int flag, void *cb_data)
209
{
210
- struct commit *commit = lookup_commit_reference_gently(oid, 1);
210
+ struct commit *commit = lookup_commit_reference_gently(the_repository,
211
+ oid, 1);
212
213
if (commit) {
214
commit->object.flags |= COMPLETE;
wt-status.c
+1
-1
@@ -1489,7 +1489,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1489
/* sha1 is a commit? match without further lookup */
1490
(!oidcmp(&cb.noid, &oid) ||
1491
/* perhaps sha1 is a tag, try to dereference to a commit */
1492
- ((commit = lookup_commit_reference_gently(&oid, 1)) != NULL &&
1492
+ ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&
1493
!oidcmp(&cb.noid, &commit->object.oid)))) {
1494
const char *from = ref;
1495
if (!skip_prefix(from, "refs/tags/", &from))