diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-06-25 22:27:47 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-06-25 22:27:47 +0300 |
commit | dc4b3cfb92c82d5516955d8db642ec4e6bc4671b (patch) | |
tree | 73030a4d78788de46b914a1070c0a487b43b48e8 | |
parent | 7b2685ef2d637de333765f5406d36799894c9a38 (diff) | |
parent | 80b8ada54756e972b01d20b98a388fbbc3a2fe58 (diff) |
Merge branch 'ds/merge-base-is-ancestor-optim'
"git merge-base --is-ancestor" is taught to take advantage of the
commit graph.
* ds/merge-base-is-ancestor-optim:
commit-reach: use fast logic in repo_in_merge_base
commit-reach: create repo_is_descendant_of()
-rw-r--r-- | commit-reach.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/commit-reach.c b/commit-reach.c index 4ca7e706a1..43e303d5f2 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -283,7 +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? */ -int is_descendant_of(struct commit *commit, struct commit_list *with_commit) +static int repo_is_descendant_of(struct repository *r, + struct commit *commit, + struct commit_list *with_commit) { if (!with_commit) return 1; @@ -301,13 +303,18 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit) other = with_commit->item; with_commit = with_commit->next; - if (in_merge_bases(other, commit)) + if (repo_in_merge_bases_many(r, other, 1, &commit)) return 1; } return 0; } } +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"? */ @@ -348,7 +355,15 @@ int repo_in_merge_bases(struct repository *r, struct commit *commit, struct commit *reference) { - return repo_in_merge_bases_many(r, commit, 1, &reference); + int res; + struct commit_list *list = NULL; + struct commit_list **next = &list; + + next = commit_list_append(commit, next); + res = repo_is_descendant_of(r, reference, list); + free_commit_list(list); + + return res; } struct commit_list *reduce_heads(struct commit_list *heads) |