From 3e7c56820702b65943cb4984aba172263580d7ba Mon Sep 17 00:00:00 2001 From: Aleksey Kuznetsov Date: Fri, 16 Feb 2024 20:40:05 +0500 Subject: [PATCH] graph: sort parents from farthest to closest --- cli/tests/test_chmod_command.rs | 4 +- cli/tests/test_commit_template.rs | 2 +- cli/tests/test_duplicate_command.rs | 8 +-- cli/tests/test_log_command.rs | 64 +++++++++++++++++-- cli/tests/test_new_command.rs | 24 +++---- cli/tests/test_rebase_command.rs | 14 ++-- cli/tests/test_workspaces.rs | 8 +-- .../default_index/revset_graph_iterator.rs | 4 +- 8 files changed, 93 insertions(+), 35 deletions(-) diff --git a/cli/tests/test_chmod_command.rs b/cli/tests/test_chmod_command.rs index ac4fbeb266..f104a3e399 100644 --- a/cli/tests/test_chmod_command.rs +++ b/cli/tests/test_chmod_command.rs @@ -57,8 +57,8 @@ fn test_chmod_regular_conflict() { insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ conflict ├─╮ - │ ◉ n - ◉ │ x + │ ◉ x + ◉ │ n ├─╯ ◉ base ◉ diff --git a/cli/tests/test_commit_template.rs b/cli/tests/test_commit_template.rs index 13eda0c4fa..aed60e39e9 100644 --- a/cli/tests/test_commit_template.rs +++ b/cli/tests/test_commit_template.rs @@ -31,7 +31,7 @@ fn test_log_parents() { insta::assert_snapshot!(stdout, @r###" @ c067170d4ca1bc6162b64f7550617ec809647f84 ├─╮ P: 4db490c88528133d579540b6900b8098f0c17701 230dd059e1b059aefc0da06a2e5a7dbf22362f22 - ◉ │ 4db490c88528133d579540b6900b8098f0c17701 + │ ◉ 4db490c88528133d579540b6900b8098f0c17701 ├─╯ P: 230dd059e1b059aefc0da06a2e5a7dbf22362f22 ◉ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 │ P: 0000000000000000000000000000000000000000 diff --git a/cli/tests/test_duplicate_command.rs b/cli/tests/test_duplicate_command.rs index efce45ed55..32fa140de1 100644 --- a/cli/tests/test_duplicate_command.rs +++ b/cli/tests/test_duplicate_command.rs @@ -120,11 +120,11 @@ fn test_duplicate_many() { insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" ◉ 8348ddcec733 e ├─╮ - ◉ │ 3b74d9691015 b + │ ◉ 3b74d9691015 b │ │ @ 921dde6e55c0 e - │ ╭─┤ - │ ◉ │ ebd06dba20ec d - │ ◉ │ c0cb3a0b73e7 c + ╭───┤ + ◉ │ │ ebd06dba20ec d + ◉ │ │ c0cb3a0b73e7 c ├─╯ │ │ ◉ 1394f625cbbd b ├───╯ diff --git a/cli/tests/test_log_command.rs b/cli/tests/test_log_command.rs index 6721d29efb..43057b3933 100644 --- a/cli/tests/test_log_command.rs +++ b/cli/tests/test_log_command.rs @@ -835,8 +835,8 @@ fn test_log_limit() { insta::assert_snapshot!(stdout, @r###" @ d ├─╮ - │ ◉ b - ◉ │ c + │ ◉ c + ◉ │ b ├─╯ "###); @@ -845,7 +845,7 @@ fn test_log_limit() { insta::assert_snapshot!(stdout, @r###" @ d ├─╮ - │ ◉ b + │ ◉ c "###); let stdout = test_env.jj_cmd_success( @@ -866,7 +866,7 @@ fn test_log_limit() { ◉ ◉ a ├─╮ - │ ◉ c + │ ◉ b "###); let stdout = test_env.jj_cmd_success( &repo_path, @@ -1287,6 +1287,62 @@ fn test_log_word_wrap() { "###); } +#[test] +fn test_merge_fix_and_initial() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); + let repo_path = test_env.env_root().join("repo"); + + test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]); + test_env.jj_cmd_ok(&repo_path, &["new", "-m", "fix"]); + test_env.jj_cmd_ok(&repo_path, &["new", "-m", "merge", "@", "@-"]); + + let get_log = |revs: &str| -> String { + test_env.jj_cmd_success( + &repo_path, + &["log", "-T", r#"description ++ "\n""#, "-r", revs], + ) + }; + + insta::assert_snapshot!(get_log("::"), @r###" + @ merge + ├─╮ + │ ◉ fix + ├─╯ + ◉ initial + │ + ◉ + "###); +} + +#[test] +fn test_merge_initial_and_fix() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); + let repo_path = test_env.env_root().join("repo"); + + test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]); + test_env.jj_cmd_ok(&repo_path, &["new", "-m", "fix"]); + test_env.jj_cmd_ok(&repo_path, &["new", "-m", "merge", "@-", "@"]); + + let get_log = |revs: &str| -> String { + test_env.jj_cmd_success( + &repo_path, + &["log", "-T", r#"description ++ "\n""#, "-r", revs], + ) + }; + + insta::assert_snapshot!(get_log("::"), @r###" + @ merge + ├─╮ + │ ◉ fix + ├─╯ + ◉ initial + │ + ◉ + "###); +} + #[test] fn test_elided() { // Test that elided commits are shown as synthetic nodes. diff --git a/cli/tests/test_new_command.rs b/cli/tests/test_new_command.rs index 635ed6ff88..740e4d33b9 100644 --- a/cli/tests/test_new_command.rs +++ b/cli/tests/test_new_command.rs @@ -318,11 +318,11 @@ fn test_new_insert_before() { ├─╯ @ G ├─┬─╮ - │ │ ◉ B - │ │ ◉ A + │ │ ◉ E │ ◉ │ D │ ├─╯ - ◉ │ E + ◉ │ B + ◉ │ A ├─╯ ◉ root "###); @@ -358,13 +358,13 @@ fn test_new_insert_before_root_successors() { insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###" ◉ F ├─╮ - │ ◉ E - ◉ │ D + │ ◉ D + ◉ │ E │ │ ◉ C │ │ ◉ B │ │ ◉ A - ├───╯ - @ │ G + │ ├─╯ + │ @ G ├─╯ ◉ root "###); @@ -428,13 +428,13 @@ fn test_new_insert_before_no_root_merge() { insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###" ◉ F ├─╮ - │ ◉ E - ◉ │ D + │ ◉ D + ◉ │ E │ │ ◉ C │ │ ◉ B - ├───╯ - @ │ G - ◉ │ A + │ ├─╯ + │ @ G + │ ◉ A ├─╯ ◉ root "###); diff --git a/cli/tests/test_rebase_command.rs b/cli/tests/test_rebase_command.rs index bab0095137..599220b499 100644 --- a/cli/tests/test_rebase_command.rs +++ b/cli/tests/test_rebase_command.rs @@ -311,9 +311,9 @@ fn test_rebase_single_revision() { ◉ c │ @ d │ ├─╮ - │ │ ◉ a + │ │ ◉ b ├───╯ - │ ◉ b + │ ◉ a ├─╯ ◉ "###); @@ -355,8 +355,8 @@ fn test_rebase_single_revision_merge_parent() { ◉ c │ @ d ╭─┤ - ◉ │ a │ ◉ b + ◉ │ a ├─╯ ◉ "###); @@ -376,8 +376,8 @@ fn test_rebase_revision_onto_descendant() { insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ merge ├─╮ - │ ◉ a - ◉ │ b + │ ◉ b + ◉ │ a ├─╯ ◉ base ◉ @@ -482,8 +482,8 @@ fn test_rebase_multiple_destinations() { insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" ◉ a ├─╮ - │ ◉ b - @ │ c + │ @ c + ◉ │ b ├─╯ ◉ "###); diff --git a/cli/tests/test_workspaces.rs b/cli/tests/test_workspaces.rs index 8e3047df9b..7f1695fcac 100644 --- a/cli/tests/test_workspaces.rs +++ b/cli/tests/test_workspaces.rs @@ -97,8 +97,8 @@ fn test_workspaces_add_second_workspace_on_merge() { ├─╮ │ │ @ 21a0ea6d1c86c413cb30d7f7d216a74754b148c4 default@ ╭─┬─╯ - │ ◉ 09ba8d9dfa21b8572c2361e6947ca024d8f0a198 - ◉ │ 1694f2ddf8ecf9e55ca3cd9554bc0654186b07e0 + │ ◉ 1694f2ddf8ecf9e55ca3cd9554bc0654186b07e0 + ◉ │ 09ba8d9dfa21b8572c2361e6947ca024d8f0a198 ├─╯ ◉ 0000000000000000000000000000000000000000 "###); @@ -217,10 +217,10 @@ fn test_workspaces_add_workspace_multiple_revisions() { insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###" ◉ fa8fdc28af12d3c96b1e0ed062f5a8f9a99818f0 merge@ ├─┬─╮ - │ │ ◉ e7d7dbb91c5a543ea680711093e689916d5f31df + │ │ ◉ 23881f07b53ce1ea936ca8842e344dea9c3356e5 │ ◉ │ 1f6a15f0af2a985703864347f5fdf27a82fc3d73 │ ├─╯ - ◉ │ 23881f07b53ce1ea936ca8842e344dea9c3356e5 + ◉ │ e7d7dbb91c5a543ea680711093e689916d5f31df ├─╯ │ @ 5b36783cd11c4607a329c5e8c2fd9097c9ce2add default@ ├─╯ diff --git a/lib/src/default_index/revset_graph_iterator.rs b/lib/src/default_index/revset_graph_iterator.rs index 7d02bc58ab..bed2c6bef5 100644 --- a/lib/src/default_index/revset_graph_iterator.rs +++ b/lib/src/default_index/revset_graph_iterator.rs @@ -196,7 +196,9 @@ impl<'revset, 'index> RevsetGraphIterator<'revset, 'index> { ) -> Vec { let mut edges = Vec::new(); let mut known_ancestors = HashSet::new(); - for parent in index_entry.parents() { + let mut parents: Vec<_> = index_entry.parents().collect(); + parents.sort_by(|a, b| a.position().cmp(&b.position())); + for parent in parents { let parent_position = parent.position(); self.consume_to(parent_position); if self.look_ahead.contains_key(&parent_position) {