commit-reach: prepare in_merge_bases[_many] to handle any repo
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
4d5430f7479d45c3fca088984a08ec093f870b5b
3 files changed
+36
-8
commit-reach.c
+9
-6
@@ -312,16 +312,17 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
312
/*
313
* Is "commit" an ancestor of one of the "references"?
314
*/
315
-int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference)
315
+int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
316
+ int nr_reference, struct commit **reference)
317
{
318
struct commit_list *bases;
319
int ret = 0, i;
320
uint32_t min_generation = GENERATION_NUMBER_INFINITY;
321
321
- if (parse_commit(commit))
322
+ if (repo_parse_commit(r, commit))
323
return ret;
324
for (i = 0; i < nr_reference; i++) {
324
- if (parse_commit(reference[i]))
325
+ if (repo_parse_commit(r, reference[i]))
326
return ret;
327
if (reference[i]->generation < min_generation)
328
min_generation = reference[i]->generation;
@@ -330,7 +331,7 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
331
if (commit->generation > min_generation)
332
return ret;
333
333
- bases = paint_down_to_common(the_repository, commit,
334
+ bases = paint_down_to_common(r, commit,
335
nr_reference, reference,
336
commit->generation);
337
if (commit->object.flags & PARENT2)
@@ -344,9 +345,11 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
345
/*
346
* Is "commit" an ancestor of (i.e. reachable from) the "reference"?
347
*/
347
-int in_merge_bases(struct commit *commit, struct commit *reference)
348
+int repo_in_merge_bases(struct repository *r,
349
+ struct commit *commit,
350
+ struct commit *reference)
351
{
349
- return in_merge_bases_many(commit, 1, &reference);
352
+ return repo_in_merge_bases_many(r, commit, 1, &reference);
353
}
354
355
struct commit_list *reduce_heads(struct commit_list *heads)
commit-reach.h
+10
-2
@@ -27,8 +27,16 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
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);
31
-int in_merge_bases(struct commit *commit, struct commit *reference);
30
+int repo_in_merge_bases(struct repository *r,
31
+ struct commit *commit,
32
+ struct commit *reference);
33
+int repo_in_merge_bases_many(struct repository *r,
34
+ struct commit *commit,
35
+ int nr_reference, struct commit **reference);
36
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
37
+#define in_merge_bases(c1, c2) repo_in_merge_bases(the_repository, c1, c2)
38
+#define in_merge_bases_many(c1, n, cs) repo_in_merge_bases_many(the_repository, c1, n, cs)
39
+#endif
40
41
/*
42
* Takes a list of commits and returns a new list where those
contrib/coccinelle/the_repository.pending.cocci
+17
@@ -90,3 +90,20 @@ expression G;
90
- get_merge_bases_many_dirty(
91
+ repo_get_merge_bases_many_dirty(the_repository,
92
E, F, G);
93
+
94
+@@
95
+expression E;
96
+expression F;
97
+@@
98
+- in_merge_bases(
99
++ repo_in_merge_bases(the_repository,
100
+ E, F);
101
+
102
+@@
103
+expression E;
104
+expression F;
105
+expression G;
106
+@@
107
+- in_merge_bases_many(
108
++ repo_in_merge_bases_many(the_repository,
109
+ E, F, G);