Skip to content

Commit c1ea625

Browse files
carenasgitster
authored andcommitted
commit-reach: avoid is_descendant_of() shim
d91d6fb (commit-reach: create repo_is_descendant_of(), 2020-06-17) adds a repository aware version of is_descendant_of() and a backward compatibility shim that is barely used. Update all callers to directly use the new repo_is_descendant_of() function instead; making the codebase simpler and pushing more the_repository references higher up the stack. Helped-by: Derrick Stolee <[email protected]> Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80b8ada commit c1ea625

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

builtin/pull.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10251025
commit_list_insert(head, &list);
10261026
merge_head = lookup_commit_reference(the_repository,
10271027
&merge_heads.oid[0]);
1028-
if (is_descendant_of(merge_head, list)) {
1028+
if (repo_is_descendant_of(the_repository,
1029+
merge_head, list)) {
10291030
/* we can fast-forward this without invoking rebase */
10301031
opt_ff = "--ff-only";
10311032
ran_ff = 1;

commit-reach.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ struct commit_list *repo_get_merge_bases(struct repository *r,
283283
/*
284284
* Is "commit" a descendant of one of the elements on the "with_commit" list?
285285
*/
286-
static int repo_is_descendant_of(struct repository *r,
287-
struct commit *commit,
288-
struct commit_list *with_commit)
286+
int repo_is_descendant_of(struct repository *r,
287+
struct commit *commit,
288+
struct commit_list *with_commit)
289289
{
290290
if (!with_commit)
291291
return 1;
@@ -310,11 +310,6 @@ static int repo_is_descendant_of(struct repository *r,
310310
}
311311
}
312312

313-
int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
314-
{
315-
return repo_is_descendant_of(the_repository, commit, with_commit);
316-
}
317-
318313
/*
319314
* Is "commit" an ancestor of one of the "references"?
320315
*/
@@ -432,7 +427,8 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
432427
return 0;
433428

434429
commit_list_insert(old_commit, &old_commit_list);
435-
return is_descendant_of(new_commit, old_commit_list);
430+
return repo_is_descendant_of(the_repository,
431+
new_commit, old_commit_list);
436432
}
437433

438434
/*
@@ -551,7 +547,7 @@ int commit_contains(struct ref_filter *filter, struct commit *commit,
551547
{
552548
if (filter->with_commit_tag_algo)
553549
return contains_tag_algo(commit, list, cache) == CONTAINS_YES;
554-
return is_descendant_of(commit, list);
550+
return repo_is_descendant_of(the_repository, commit, list);
555551
}
556552

557553
static int compare_commits_by_gen(const void *_a, const void *_b)

commit-reach.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
2727

2828
struct commit_list *get_octopus_merge_bases(struct commit_list *in);
2929

30-
int is_descendant_of(struct commit *commit, struct commit_list *with_commit);
30+
int repo_is_descendant_of(struct repository *r,
31+
struct commit *commit,
32+
struct commit_list *with_commit);
3133
int repo_in_merge_bases(struct repository *r,
3234
struct commit *commit,
3335
struct commit *reference);

t/helper/test-reach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int cmd__reach(int ac, const char **av)
108108
else if (!strcmp(av[1], "in_merge_bases"))
109109
printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B));
110110
else if (!strcmp(av[1], "is_descendant_of"))
111-
printf("%s(A,X):%d\n", av[1], is_descendant_of(A, X));
111+
printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X));
112112
else if (!strcmp(av[1], "get_merge_bases_many")) {
113113
struct commit_list *list = get_merge_bases_many(A, X_nr, X_array);
114114
printf("%s(A,X):\n", av[1]);

0 commit comments

Comments
 (0)