Skip to content

Commit 4f69b8c

Browse files
abhishekkumar2718gitster
authored andcommitted
commit-reach: use corrected commit dates in paint_down_to_common()
With corrected commit dates implemented, we no longer have to rely on commit date as a heuristic in paint_down_to_common(). While using corrected commit dates Git walks nearly the same number of commits as commit date, the process is slower as for each comparision we have to access a commit-slab (for corrected committer date) instead of accessing struct member (for committer date). For example, the command `git merge-base v4.8 v4.9` on the linux repository walks 167468 commits, taking 0.135s for committer date and 167496 commits, taking 0.157s for corrected committer date respectively. t6404-recursive-merge setups a unique repository where all commits have the same committer date without well-defined merge-base. While running tests with GIT_TEST_COMMIT_GRAPH unset, we use committer date as a heuristic in paint_down_to_common(). 6404.1 'combined merge conflicts' merges commits in the order: - Merge C with B to form a intermediate commit. - Merge the intermediate commit with A. With GIT_TEST_COMMIT_GRAPH=1, we write a commit-graph and subsequently use the corrected committer date, which changes the order in which commits are merged: - Merge A with B to form a intermediate commit. - Merge the intermediate commit with C. While resulting repositories are equivalent, 6404.4 'virtual trees were processed' fails with GIT_TEST_COMMIT_GRAPH=1 as we are selecting different merge-bases and thus have different object ids for the intermediate commits. As this has already causes problems (as noted in 859fdc0 (commit-graph: define GIT_TEST_COMMIT_GRAPH, 2018-08-29)), we disable commit graph within t6404-recursive-merge. Signed-off-by: Abhishek Kumar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d5b67a2 commit 4f69b8c

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

commit-graph.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,20 @@ int generation_numbers_enabled(struct repository *r)
705705
return !!first_generation;
706706
}
707707

708+
int corrected_commit_dates_enabled(struct repository *r)
709+
{
710+
struct commit_graph *g;
711+
if (!prepare_commit_graph(r))
712+
return 0;
713+
714+
g = r->objects->commit_graph;
715+
716+
if (!g->num_commits)
717+
return 0;
718+
719+
return g->read_generation_data;
720+
}
721+
708722
struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
709723
{
710724
struct commit_graph *g = r->objects->commit_graph;

commit-graph.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,19 @@ struct commit_graph *read_commit_graph_one(struct repository *r,
8989
struct commit_graph *parse_commit_graph(struct repository *r,
9090
void *graph_map, size_t graph_size);
9191

92+
struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r);
93+
9294
/*
9395
* Return 1 if and only if the repository has a commit-graph
9496
* file and generation numbers are computed in that file.
9597
*/
9698
int generation_numbers_enabled(struct repository *r);
9799

98-
struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r);
100+
/*
101+
* Return 1 if and only if the repository has a commit-graph
102+
* file and generation data chunk has been written for the file.
103+
*/
104+
int corrected_commit_dates_enabled(struct repository *r);
99105

100106
enum commit_graph_write_flags {
101107
COMMIT_GRAPH_WRITE_APPEND = (1 << 0),

commit-reach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static struct commit_list *paint_down_to_common(struct repository *r,
3939
int i;
4040
timestamp_t last_gen = GENERATION_NUMBER_INFINITY;
4141

42-
if (!min_generation)
42+
if (!min_generation && !corrected_commit_dates_enabled(r))
4343
queue.compare = compare_commits_by_commit_date;
4444

4545
one->object.flags |= PARENT1;

t/t6404-recursive-merge.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ GIT_COMMITTER_DATE="2006-12-12 23:28:00 +0100"
1515
export GIT_COMMITTER_DATE
1616

1717
test_expect_success 'setup tests' '
18+
GIT_TEST_COMMIT_GRAPH=0 &&
19+
export GIT_TEST_COMMIT_GRAPH &&
1820
echo 1 >a1 &&
1921
git add a1 &&
2022
GIT_AUTHOR_DATE="2006-12-12 23:00:00" git commit -m 1 a1 &&
@@ -66,7 +68,7 @@ test_expect_success 'setup tests' '
6668
'
6769

6870
test_expect_success 'combined merge conflicts' '
69-
test_must_fail env GIT_TEST_COMMIT_GRAPH=0 git merge -m final G
71+
test_must_fail git merge -m final G
7072
'
7173

7274
test_expect_success 'result contains a conflict' '
@@ -82,6 +84,7 @@ test_expect_success 'result contains a conflict' '
8284
'
8385

8486
test_expect_success 'virtual trees were processed' '
87+
# TODO: fragile test, relies on ambigious merge-base resolution
8588
git ls-files --stage >out &&
8689
8790
cat >expect <<-EOF &&

0 commit comments

Comments
 (0)