Skip to content

Commit 4d5430f

Browse files
stefanbellergitster
authored andcommitted
commit-reach: prepare in_merge_bases[_many] to handle any repo
Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 21a9651 commit 4d5430f

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

commit-reach.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,17 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
312312
/*
313313
* Is "commit" an ancestor of one of the "references"?
314314
*/
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)
316317
{
317318
struct commit_list *bases;
318319
int ret = 0, i;
319320
uint32_t min_generation = GENERATION_NUMBER_INFINITY;
320321

321-
if (parse_commit(commit))
322+
if (repo_parse_commit(r, commit))
322323
return ret;
323324
for (i = 0; i < nr_reference; i++) {
324-
if (parse_commit(reference[i]))
325+
if (repo_parse_commit(r, reference[i]))
325326
return ret;
326327
if (reference[i]->generation < min_generation)
327328
min_generation = reference[i]->generation;
@@ -330,7 +331,7 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
330331
if (commit->generation > min_generation)
331332
return ret;
332333

333-
bases = paint_down_to_common(the_repository, commit,
334+
bases = paint_down_to_common(r, commit,
334335
nr_reference, reference,
335336
commit->generation);
336337
if (commit->object.flags & PARENT2)
@@ -344,9 +345,11 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
344345
/*
345346
* Is "commit" an ancestor of (i.e. reachable from) the "reference"?
346347
*/
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)
348351
{
349-
return in_merge_bases_many(commit, 1, &reference);
352+
return repo_in_merge_bases_many(r, commit, 1, &reference);
350353
}
351354

352355
struct commit_list *reduce_heads(struct commit_list *heads)

commit-reach.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
2727
struct commit_list *get_octopus_merge_bases(struct commit_list *in);
2828

2929
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
3240

3341
/*
3442
* Takes a list of commits and returns a new list where those

contrib/coccinelle/the_repository.pending.cocci

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,20 @@ expression G;
9090
- get_merge_bases_many_dirty(
9191
+ repo_get_merge_bases_many_dirty(the_repository,
9292
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);

0 commit comments

Comments
 (0)