Skip to content

Commit 1fd45ef

Browse files
committed
commit-reach: replace ref_newer logic
The ref_newer method is used by 'git push' to check if a force-push is required. This method does not use any kind of cutoff when walking, so in the case of a force-push will walk all reachable commits. The is_descendant_of method already uses paint_down_to_common along with cutoffs. By translating the ref_newer arguments into the commit and commit_list required by is_descendant_of, we can have one fewer commit walk and also improve our performance! For a copy of the Linux repository, 'test-tool reach ref_newer' presents the following improvements with the specified input. In the case that ref_newer returns 1, there is no improvement. The improvement is in the second case where ref_newer returns 0. Input ----- A:v4.9 B:v3.19 Before: 0.09 s After: 0.09 s To test the negative case, add a new commit with parent v3.19, regenerate the commit-graph, and then run with B pointing at that commit. Before: 0.43 s After: 0.09 s Signed-off-by: Derrick Stolee <[email protected]>
1 parent 95b11ce commit 1fd45ef

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

commit-reach.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -365,20 +365,11 @@ void reduce_heads_replace(struct commit_list **heads)
365365
*heads = result;
366366
}
367367

368-
static void unmark_and_free(struct commit_list *list, unsigned int mark)
369-
{
370-
while (list) {
371-
struct commit *commit = pop_commit(&list);
372-
commit->object.flags &= ~mark;
373-
}
374-
}
375-
376368
int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
377369
{
378370
struct object *o;
379371
struct commit *old_commit, *new_commit;
380-
struct commit_list *list, *used;
381-
int found = 0;
372+
struct commit_list *old_commit_list = NULL;
382373

383374
/*
384375
* Both new_commit and old_commit must be commit-ish and new_commit is descendant of
@@ -399,19 +390,8 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
399390
if (parse_commit(new_commit) < 0)
400391
return 0;
401392

402-
used = list = NULL;
403-
commit_list_insert(new_commit, &list);
404-
while (list) {
405-
new_commit = pop_most_recent_commit(&list, TMP_MARK);
406-
commit_list_insert(new_commit, &used);
407-
if (new_commit == old_commit) {
408-
found = 1;
409-
break;
410-
}
411-
}
412-
unmark_and_free(list, TMP_MARK);
413-
unmark_and_free(used, TMP_MARK);
414-
return found;
393+
commit_list_insert(old_commit, &old_commit_list);
394+
return is_descendant_of(new_commit, old_commit_list);
415395
}
416396

417397
/*

0 commit comments

Comments
 (0)