commit-reach: avoid is_descendant_of() shim
d91d6fbf26 (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 <dstolee@microsoft.com> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Carlo Marcelo Arenas Belón committed
Jun 23, 2020 at 11:42 UTC
c1ea625f72110fda87fd225d7dff002befb82d9f
4 files changed
+12
-13
builtin/pull.c
+2
-1
@@ -1025,7 +1025,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1025
commit_list_insert(head, &list);
1026
merge_head = lookup_commit_reference(the_repository,
1027
&merge_heads.oid[0]);
1028
- if (is_descendant_of(merge_head, list)) {
1028
+ if (repo_is_descendant_of(the_repository,
1029
+ merge_head, list)) {
1030
/* we can fast-forward this without invoking rebase */
1031
opt_ff = "--ff-only";
1032
ran_ff = 1;
commit-reach.c
+6
-10
@@ -283,9 +283,9 @@ struct commit_list *repo_get_merge_bases(struct repository *r,
283
/*
284
* Is "commit" a descendant of one of the elements on the "with_commit" list?
285
*/
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)
289
{
290
if (!with_commit)
291
return 1;
@@ -310,11 +310,6 @@ static int repo_is_descendant_of(struct repository *r,
310
}
311
}
312
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
-
313
/*
314
* Is "commit" an ancestor of one of the "references"?
315
*/
@@ -432,7 +427,8 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
427
return 0;
428
429
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);
432
}
433
434
/*
@@ -551,7 +547,7 @@ int commit_contains(struct ref_filter *filter, struct commit *commit,
547
{
548
if (filter->with_commit_tag_algo)
549
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);
551
}
552
553
static int compare_commits_by_gen(const void *_a, const void *_b)
commit-reach.h
+3
-1
@@ -27,7 +27,9 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
27
28
struct commit_list *get_octopus_merge_bases(struct commit_list *in);
29
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);
33
int repo_in_merge_bases(struct repository *r,
34
struct commit *commit,
35
struct commit *reference);
t/helper/test-reach.c
+1
-1
@@ -108,7 +108,7 @@ int cmd__reach(int ac, const char **av)
108
else if (!strcmp(av[1], "in_merge_bases"))
109
printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B));
110
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));
112
else if (!strcmp(av[1], "get_merge_bases_many")) {
113
struct commit_list *list = get_merge_bases_many(A, X_nr, X_array);
114
printf("%s(A,X):\n", av[1]);