commit-reach: prepare get_merge_bases to handle any repo

Similarly to previous patches, the get_merge_base functions are used often in the code base, which makes migrating them hard. Implement the new functions, prefixed with 'repo_' and hide the old functions behind a wrapper macro. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Nov 13, 2018 at 16:12 UTC 21a9651ba3fb350f48a53bf885a225bf6b71cac3
3 files changed +56 -20
commit-reach.c
+14 -10
@@ -258,23 +258,27 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r,
258 return result;
259 }
260
261 -struct commit_list *get_merge_bases_many(struct commit *one,
262 - int n,
263 - struct commit **twos)
261 +struct commit_list *repo_get_merge_bases_many(struct repository *r,
262 + struct commit *one,
263 + int n,
264 + struct commit **twos)
265 {
265 - return get_merge_bases_many_0(the_repository, one, n, twos, 1);
266 + return get_merge_bases_many_0(r, one, n, twos, 1);
267 }
268
268 -struct commit_list *get_merge_bases_many_dirty(struct commit *one,
269 - int n,
270 - struct commit **twos)
269 +struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
270 + struct commit *one,
271 + int n,
272 + struct commit **twos)
273 {
272 - return get_merge_bases_many_0(the_repository, one, n, twos, 0);
274 + return get_merge_bases_many_0(r, one, n, twos, 0);
275 }
276
275 -struct commit_list *get_merge_bases(struct commit *one, struct commit *two)
277 +struct commit_list *repo_get_merge_bases(struct repository *r,
278 + struct commit *one,
279 + struct commit *two)
280 {
277 - return get_merge_bases_many_0(the_repository, one, 1, &two, 1);
281 + return get_merge_bases_many_0(r, one, 1, &two, 1);
282 }
283
284 /*
commit-reach.h
+16 -10
@@ -8,17 +8,23 @@ struct commit_list;
8 struct contains_cache;
9 struct ref_filter;
10
11 -struct commit_list *get_merge_bases_many(struct commit *one,
12 - int n,
13 - struct commit **twos);
14 -struct commit_list *get_merge_bases_many_dirty(struct commit *one,
15 - int n,
16 - struct commit **twos);
17 -struct commit_list *get_merge_bases(struct commit *one, struct commit *two);
18 -struct commit_list *get_octopus_merge_bases(struct commit_list *in);
19 -
11 +struct commit_list *repo_get_merge_bases(struct repository *r,
12 + struct commit *rev1,
13 + struct commit *rev2);
14 +struct commit_list *repo_get_merge_bases_many(struct repository *r,
15 + struct commit *one, int n,
16 + struct commit **twos);
17 /* To be used only when object flags after this call no longer matter */
21 -struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n, struct commit **twos);
18 +struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
19 + struct commit *one, int n,
20 + struct commit **twos);
21 +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
22 +#define get_merge_bases(r1, r2) repo_get_merge_bases(the_repository, r1, r2)
23 +#define get_merge_bases_many(one, n, two) repo_get_merge_bases_many(the_repository, one, n, two)
24 +#define get_merge_bases_many_dirty(one, n, twos) repo_get_merge_bases_many_dirty(the_repository, one, n, twos)
25 +#endif
26 +
27 +struct commit_list *get_octopus_merge_bases(struct commit_list *in);
28
29 int is_descendant_of(struct commit *commit, struct commit_list *with_commit);
30 int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference);
contrib/coccinelle/the_repository.pending.cocci
+26
@@ -64,3 +64,29 @@ expression E;
64 - parse_commit(
65 + repo_parse_commit(the_repository,
66 E)
67 +
68 +@@
69 +expression E;
70 +expression F;
71 +@@
72 +- get_merge_bases(
73 ++ repo_get_merge_bases(the_repository,
74 + E, F);
75 +
76 +@@
77 +expression E;
78 +expression F;
79 +expression G;
80 +@@
81 +- get_merge_bases_many(
82 ++ repo_get_merge_bases_many(the_repository,
83 + E, F, G);
84 +
85 +@@
86 +expression E;
87 +expression F;
88 +expression G;
89 +@@
90 +- get_merge_bases_many_dirty(
91 ++ repo_get_merge_bases_many_dirty(the_repository,
92 + E, F, G);