ok/jj
1
0
Fork 0
forked from mirrors/jj

index: squash an index segment into its parent more aggressively

Before this change, you could end up with an index segment with 10
commits, then a child segment with 9 commits, then another child with
8 commits, and so on. That's not what I had intended. This changes
makes it so we squash if a segment has more than half as many commits
as its parent instead.
This commit is contained in:
Martin von Zweigbergk 2021-09-11 21:59:42 -07:00
parent 2a23ee3f15
commit 11c0130303
2 changed files with 17 additions and 11 deletions

View file

@ -563,9 +563,9 @@ impl MutableIndex {
buf
}
/// If the MutableIndex has more commits than its parent ReadonlyIndex,
/// return MutableIndex with the commits from both. This is done
/// recursively, so the stack of index files has O(log n) files.
/// If the MutableIndex has more than half the commits of its parent
/// ReadonlyIndex, return MutableIndex with the commits from both. This
/// is done recursively, so the stack of index files has O(log n) files.
fn maybe_squash_with_ancestors(self) -> MutableIndex {
let mut num_new_commits = self.segment_num_commits();
let mut files_to_squash = vec![];
@ -576,7 +576,7 @@ impl MutableIndex {
Some(parent_file) => {
// TODO: We should probably also squash if the parent file has less than N
// commits, regardless of how many (few) are in `self`.
if num_new_commits < parent_file.segment_num_commits() {
if 2 * num_new_commits < parent_file.segment_num_commits() {
squashed = MutableIndex::incremental(parent_file);
break;
}

View file

@ -368,10 +368,8 @@ fn test_index_commits_incremental_empty_transaction(use_git: bool) {
assert_eq!(stats.num_commits, 2 + 1);
assert_eq!(stats.num_merges, 0);
assert_eq!(stats.max_generation_number, 1);
assert_eq!(stats.levels.len(), 2);
assert_eq!(stats.levels[0].num_commits, 2);
assert_eq!(stats.levels[1].num_commits, 1);
assert_ne!(stats.levels[1].name, stats.levels[0].name);
assert_eq!(stats.levels.len(), 1);
assert_eq!(stats.levels[0].num_commits, 3);
assert_eq!(generation_number(index.as_ref(), root_commit.id()), 0);
assert_eq!(generation_number(index.as_ref(), commit_a.id()), 1);
@ -433,9 +431,9 @@ fn test_index_commits_incremental_squashed(use_git: bool) {
let (_temp_dir, mut repo) = testutils::init_repo(&settings, use_git);
repo = create_n_commits(&settings, &repo, 1);
assert_eq!(commits_by_level(&repo), vec![2, 1]);
assert_eq!(commits_by_level(&repo), vec![3]);
repo = create_n_commits(&settings, &repo, 1);
assert_eq!(commits_by_level(&repo), vec![4]);
assert_eq!(commits_by_level(&repo), vec![3, 1]);
let (_temp_dir, mut repo) = testutils::init_repo(&settings, use_git);
repo = create_n_commits(&settings, &repo, 2);
@ -459,7 +457,15 @@ fn test_index_commits_incremental_squashed(use_git: bool) {
repo = create_n_commits(&settings, &repo, 8);
repo = create_n_commits(&settings, &repo, 4);
repo = create_n_commits(&settings, &repo, 2);
assert_eq!(commits_by_level(&repo), vec![34, 16, 8, 4, 2]);
assert_eq!(commits_by_level(&repo), vec![58, 6]);
let (_temp_dir, mut repo) = testutils::init_repo(&settings, use_git);
repo = create_n_commits(&settings, &repo, 29);
repo = create_n_commits(&settings, &repo, 15);
repo = create_n_commits(&settings, &repo, 7);
repo = create_n_commits(&settings, &repo, 3);
repo = create_n_commits(&settings, &repo, 1);
assert_eq!(commits_by_level(&repo), vec![31, 15, 7, 3, 1]);
let (_temp_dir, mut repo) = testutils::init_repo(&settings, use_git);
repo = create_n_commits(&settings, &repo, 10);