From f1898a31b50878294d7c070c5314c8b983af88b9 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 3 Nov 2023 16:20:39 +0900 Subject: [PATCH] merge: simply print interleaved conflict values in debug output We could apply that for the resolved case, but Resolved/Conflicted label seems more useful than just printing Merge([value]). --- cli/tests/test_chmod_command.rs | 14 +++++------ lib/src/merge.rs | 6 +---- lib/tests/test_conflicts.rs | 42 +++++++++++++-------------------- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/cli/tests/test_chmod_command.rs b/cli/tests/test_chmod_command.rs index 21d39a578..2d523142a 100644 --- a/cli/tests/test_chmod_command.rs +++ b/cli/tests/test_chmod_command.rs @@ -68,7 +68,7 @@ fn test_chmod_regular_conflict() { let stdout = test_env.jj_cmd_success(&repo_path, &["debug", "tree"]); insta::assert_snapshot!(stdout, @r###" - file: Conflicted { removes: [Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false })], adds: [Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: true }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: false })] } + file: Conflicted([Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: true }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: false })]) "###); let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file"]); insta::assert_snapshot!(stdout, @@ -87,7 +87,7 @@ fn test_chmod_regular_conflict() { let stdout = test_env.jj_cmd_success(&repo_path, &["debug", "tree"]); insta::assert_snapshot!(stdout, @r###" - file: Conflicted { removes: [Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: true })], adds: [Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: true }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: true })] } + file: Conflicted([Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: true }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: true }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: true })]) "###); let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file"]); insta::assert_snapshot!(stdout, @@ -104,7 +104,7 @@ fn test_chmod_regular_conflict() { let stdout = test_env.jj_cmd_success(&repo_path, &["debug", "tree"]); insta::assert_snapshot!(stdout, @r###" - file: Conflicted { removes: [Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false })], adds: [Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: false }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: false })] } + file: Conflicted([Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: false })]) "###); let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file"]); insta::assert_snapshot!(stdout, @@ -127,7 +127,7 @@ fn test_chmod_regular_conflict() { let stdout = test_env.jj_cmd_success(&repo_path, &["debug", "tree"]); insta::assert_snapshot!(stdout, @r###" - file: Conflicted { removes: [Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false })], adds: [Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: false }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: false })] } + file: Conflicted([Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: false })]) "###); let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file"]); insta::assert_snapshot!(stdout, @@ -190,7 +190,7 @@ fn test_chmod_file_dir_deletion_conflicts() { let stdout = test_env.jj_cmd_success(&repo_path, &["debug", "tree", "-r=file_dir"]); insta::assert_snapshot!(stdout, @r###" - file: Conflicted { removes: [Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false })], adds: [Some(File { id: FileId("78981922613b2afb6025042ff6bd878ac1994e85"), executable: false }), Some(Tree(TreeId("133bb38fc4e4bf6b551f1f04db7e48f04cac2877")))] } + file: Conflicted([Some(File { id: FileId("78981922613b2afb6025042ff6bd878ac1994e85"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(Tree(TreeId("133bb38fc4e4bf6b551f1f04db7e48f04cac2877")))]) "###); let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "-r=file_dir", "file"]); insta::assert_snapshot!(stdout, @@ -209,7 +209,7 @@ fn test_chmod_file_dir_deletion_conflicts() { let stdout = test_env.jj_cmd_success(&repo_path, &["debug", "tree", "-r=file_deletion"]); insta::assert_snapshot!(stdout, @r###" - file: Conflicted { removes: [Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false })], adds: [Some(File { id: FileId("78981922613b2afb6025042ff6bd878ac1994e85"), executable: false }), None] } + file: Conflicted([Some(File { id: FileId("78981922613b2afb6025042ff6bd878ac1994e85"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), None]) "###); let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "-r=file_deletion", "file"]); insta::assert_snapshot!(stdout, @@ -233,7 +233,7 @@ fn test_chmod_file_dir_deletion_conflicts() { let stdout = test_env.jj_cmd_success(&repo_path, &["debug", "tree", "-r=file_deletion"]); insta::assert_snapshot!(stdout, @r###" - file: Conflicted { removes: [Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: true })], adds: [Some(File { id: FileId("78981922613b2afb6025042ff6bd878ac1994e85"), executable: true }), None] } + file: Conflicted([Some(File { id: FileId("78981922613b2afb6025042ff6bd878ac1994e85"), executable: true }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: true }), None]) "###); let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "-r=file_deletion", "file"]); insta::assert_snapshot!(stdout, diff --git a/lib/src/merge.rs b/lib/src/merge.rs index dde8be11b..b4702d260 100644 --- a/lib/src/merge.rs +++ b/lib/src/merge.rs @@ -125,11 +125,7 @@ impl Debug for Merge { if let Some(value) = self.as_resolved() { f.debug_tuple("Resolved").field(value).finish() } else { - // TODO: just print values? - f.debug_struct("Conflicted") - .field("removes", &self.removes().collect_vec()) - .field("adds", &self.adds().collect_vec()) - .finish() + f.debug_tuple("Conflicted").field(&self.values).finish() } } } diff --git a/lib/tests/test_conflicts.rs b/lib/tests/test_conflicts.rs index b39acb2f5..0837d63a6 100644 --- a/lib/tests/test_conflicts.rs +++ b/lib/tests/test_conflicts.rs @@ -304,27 +304,23 @@ line 5 right @r###" Some( [ - Conflicted { - removes: [ - "line 1\nline 2\n", - ], - adds: [ + Conflicted( + [ "line 1 left\nline 2 left\n", + "line 1\nline 2\n", "line 1 right\nline 2\n", ], - }, + ), Resolved( "line 3\n", ), - Conflicted { - removes: [ - "line 4\nline 5\n", - ], - adds: [ + Conflicted( + [ "line 4\nline 5 left\n", + "line 4\nline 5\n", "line 4 right\nline 5 right\n", ], - }, + ), ], ) "###); @@ -464,15 +460,13 @@ line 5 Resolved( "line 1\n", ), - Conflicted { - removes: [ - "line 2\nline 3\nline 4\n", - ], - adds: [ + Conflicted( + [ "line 2\nleft\nline 4\n", + "line 2\nline 3\nline 4\n", "right\n", ], - }, + ), Resolved( "line 5\n", ), @@ -511,17 +505,15 @@ line 5 Resolved( "line 1\n", ), - Conflicted { - removes: [ - "line 2\nline 3\nline 4\n", - "line 2\nline 3\nline 4\n", - ], - adds: [ + Conflicted( + [ "line 2\nleft\nline 4\n", + "line 2\nline 3\nline 4\n", "right\n", + "line 2\nline 3\nline 4\n", "line 2\nforward\nline 3\nline 4\n", ], - }, + ), Resolved( "line 5\n", ),