Skip to content

Commit 21a9651

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f28e87f commit 21a9651

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

commit-reach.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,23 +258,27 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r,
258258
return result;
259259
}
260260

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)
264265
{
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);
266267
}
267268

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)
271273
{
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);
273275
}
274276

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)
276280
{
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);
278282
}
279283

280284
/*

commit-reach.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ struct commit_list;
88
struct contains_cache;
99
struct ref_filter;
1010

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);
2017
/* 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);
2228

2329
int is_descendant_of(struct commit *commit, struct commit_list *with_commit);
2430
int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference);

contrib/coccinelle/the_repository.pending.cocci

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,29 @@ expression E;
6464
- parse_commit(
6565
+ repo_parse_commit(the_repository,
6666
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);

0 commit comments

Comments
 (0)