Skip to content

Commit 04bc8d1

Browse files
derrickstoleegitster
authored andcommitted
commit: use generation number in remove_redundant()
The static remove_redundant() method is used to filter a list of commits by removing those that are reachable from another commit in the list. This is used to remove all possible merge- bases except a maximal, mutually independent set. To determine these commits are independent, we use a number of paint_down_to_common() walks and use the PARENT1, PARENT2 flags to determine reachability. Since we only care about reachability and not the full set of merge-bases between 'one' and 'twos', we can use the 'min_generation' parameter to short-circuit the walk. When no commit-graph exists, there is no change in behavior. For a copy of the Linux repository, we measured the following performance improvements: git merge-base v3.3 v4.5 Before: 234 ms After: 208 ms Rel %: -11% git merge-base v4.3 v4.5 Before: 102 ms After: 83 ms Rel %: -19% The experiments above were chosen to demonstrate that we are improving the filtering of the merge-base set. In the first example, more time is spent walking the history to find the set of merge bases before the remove_redundant() call. The starting commits are closer together in the second example, therefore more time is spent in remove_redundant(). The relative change in performance differs as expected. Reported-by: Jakub Narebski <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7c1ec3 commit 04bc8d1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

commit.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ static int remove_redundant(struct commit **array, int cnt)
949949
parse_commit(array[i]);
950950
for (i = 0; i < cnt; i++) {
951951
struct commit_list *common;
952+
uint32_t min_generation = array[i]->generation;
952953

953954
if (redundant[i])
954955
continue;
@@ -957,8 +958,12 @@ static int remove_redundant(struct commit **array, int cnt)
957958
continue;
958959
filled_index[filled] = j;
959960
work[filled++] = array[j];
961+
962+
if (array[j]->generation < min_generation)
963+
min_generation = array[j]->generation;
960964
}
961-
common = paint_down_to_common(array[i], filled, work, 0);
965+
common = paint_down_to_common(array[i], filled, work,
966+
min_generation);
962967
if (array[i]->object.flags & PARENT2)
963968
redundant[i] = 1;
964969
for (j = 0; j < filled; j++)

0 commit comments

Comments
 (0)