]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-reach: avoid is_descendant_of() shim
authorCarlo Marcelo Arenas Belón <carenas@gmail.com>
Tue, 23 Jun 2020 18:42:22 +0000 (11:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Jun 2020 23:36:53 +0000 (16:36 -0700)
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>
builtin/pull.c
commit-reach.c
commit-reach.h
t/helper/test-reach.c

index 00e5857a8d18da3394d6e5a3316e8f56bb98fdb5..fe5f33557f8f76dcf33599c689efce70a073d874 100644 (file)
@@ -1025,7 +1025,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                        commit_list_insert(head, &list);
                        merge_head = lookup_commit_reference(the_repository,
                                                             &merge_heads.oid[0]);
-                       if (is_descendant_of(merge_head, list)) {
+                       if (repo_is_descendant_of(the_repository,
+                                                 merge_head, list)) {
                                /* we can fast-forward this without invoking rebase */
                                opt_ff = "--ff-only";
                                ran_ff = 1;
index 43e303d5f25b8dc51bee95ebceb52d0818fa858f..2d85265a35061745cb59c6f2d2991f8ae41bd0a7 100644 (file)
@@ -283,9 +283,9 @@ struct commit_list *repo_get_merge_bases(struct repository *r,
 /*
  * Is "commit" a descendant of one of the elements on the "with_commit" list?
  */
-static int repo_is_descendant_of(struct repository *r,
-                                struct commit *commit,
-                                struct commit_list *with_commit)
+int repo_is_descendant_of(struct repository *r,
+                         struct commit *commit,
+                         struct commit_list *with_commit)
 {
        if (!with_commit)
                return 1;
@@ -310,11 +310,6 @@ static int repo_is_descendant_of(struct repository *r,
        }
 }
 
-int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
-{
-       return repo_is_descendant_of(the_repository, commit, with_commit);
-}
-
 /*
  * Is "commit" an ancestor of one of the "references"?
  */
@@ -432,7 +427,8 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
                return 0;
 
        commit_list_insert(old_commit, &old_commit_list);
-       return is_descendant_of(new_commit, old_commit_list);
+       return repo_is_descendant_of(the_repository,
+                                   new_commit, old_commit_list);
 }
 
 /*
@@ -551,7 +547,7 @@ int commit_contains(struct ref_filter *filter, struct commit *commit,
 {
        if (filter->with_commit_tag_algo)
                return contains_tag_algo(commit, list, cache) == CONTAINS_YES;
-       return is_descendant_of(commit, list);
+       return repo_is_descendant_of(the_repository, commit, list);
 }
 
 static int compare_commits_by_gen(const void *_a, const void *_b)
index 99a43e8b64fc803d7b7f4d09d11c2ec31fdb0a76..b49ad71a3177f7dfb670fedd272e68cc89a03e77 100644 (file)
@@ -27,7 +27,9 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
 
 struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
-int is_descendant_of(struct commit *commit, struct commit_list *with_commit);
+int repo_is_descendant_of(struct repository *r,
+                         struct commit *commit,
+                         struct commit_list *with_commit);
 int repo_in_merge_bases(struct repository *r,
                        struct commit *commit,
                        struct commit *reference);
index a0272178b7791d4146cd196d402e666809753da1..1d640f4757161efe53fb1be973b711a18b7a99bf 100644 (file)
@@ -108,7 +108,7 @@ int cmd__reach(int ac, const char **av)
        else if (!strcmp(av[1], "in_merge_bases"))
                printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B));
        else if (!strcmp(av[1], "is_descendant_of"))
-               printf("%s(A,X):%d\n", av[1], is_descendant_of(A, X));
+               printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X));
        else if (!strcmp(av[1], "get_merge_bases_many")) {
                struct commit_list *list = get_merge_bases_many(A, X_nr, X_array);
                printf("%s(A,X):\n", av[1]);