Skip to content

Commit dc4b3cf

Browse files
committed
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()
2 parents 7b2685e + 80b8ada commit dc4b3cf

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

commit-reach.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +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-
int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
286+
static int repo_is_descendant_of(struct repository *r,
287+
struct commit *commit,
288+
struct commit_list *with_commit)
287289
{
288290
if (!with_commit)
289291
return 1;
@@ -301,13 +303,18 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
301303

302304
other = with_commit->item;
303305
with_commit = with_commit->next;
304-
if (in_merge_bases(other, commit))
306+
if (repo_in_merge_bases_many(r, other, 1, &commit))
305307
return 1;
306308
}
307309
return 0;
308310
}
309311
}
310312

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+
311318
/*
312319
* Is "commit" an ancestor of one of the "references"?
313320
*/
@@ -348,7 +355,15 @@ int repo_in_merge_bases(struct repository *r,
348355
struct commit *commit,
349356
struct commit *reference)
350357
{
351-
return repo_in_merge_bases_many(r, commit, 1, &reference);
358+
int res;
359+
struct commit_list *list = NULL;
360+
struct commit_list **next = &list;
361+
362+
next = commit_list_append(commit, next);
363+
res = repo_is_descendant_of(r, reference, list);
364+
free_commit_list(list);
365+
366+
return res;
352367
}
353368

354369
struct commit_list *reduce_heads(struct commit_list *heads)

0 commit comments

Comments
 (0)