From 88fef10eac8d34f8cc698f473dbce5d9e2f3c1f8 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 28 Aug 2021 22:03:49 -0700 Subject: [PATCH] cleanup: use literal newlines in string literals I'm about to enable `rustfmt`'s formatting of string literals, and that makes these string literals with escaped newlines harder to read. --- lib/tests/test_revset.rs | 11 +---- src/commands.rs | 99 +++++++++++++++++++++++----------------- tests/smoke_test.rs | 22 ++++----- 3 files changed, 69 insertions(+), 63 deletions(-) diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index 8f9b2fa64..c916a74a1 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -769,16 +769,9 @@ fn test_evaluate_expression_descendants(use_git: bool) { ] ); - // Can find ancestors of a specific commit + // Can find descendants of a specific commit assert_eq!( - resolve_commit_ids( - mut_repo.as_repo_ref(), - &format!( - "{},,\ - ", - commit3.id().hex() - ) - ), + resolve_commit_ids(mut_repo.as_repo_ref(), &format!("{},,", commit3.id().hex())), vec![ commit6.id().clone(), commit4.id().clone(), diff --git a/src/commands.rs b/src/commands.rs index bae21803f..57056ac14 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -148,8 +148,12 @@ fn get_repo(ui: &Ui, matches: &ArgMatches) -> Result, CommandE .to_str() .unwrap() .to_owned(); - message += &format!("\nIt looks like this is a git repo. You can create a jj repo backed by it by running this:\n\ - jj init --git-store={} ", git_dir_str); + message += &format!( + " +It looks like this is a git repo. You can create a jj repo backed by it by running this: +jj init --git-store={} ", + git_dir_str + ); } return Err(CommandError::UserError(message)); } @@ -1922,16 +1926,18 @@ fn cmd_squash( let new_parent_tree_id; if sub_matches.is_present("interactive") { let instructions = format!( - "You are moving changes from: {}\n\ - into its parent: {}\n\ - \n\ - The left side of the diff shows the contents of the parent commit. The\n\ - right side initially shows the contents of the commit you're moving\n\ - changes from.\n\ - \n\ - Adjust the right side until the diff shows the changes you want to move\n\ - to the destination. If you don't make any changes, then all the changes\n\ - from the source will be moved into the parent.\n", + "\ +You are moving changes from: {} +into its parent: {} + +The left side of the diff shows the contents of the parent commit. The +right side initially shows the contents of the commit you're moving +changes from. + +Adjust the right side until the diff shows the changes you want to move +to the destination. If you don't make any changes, then all the changes +from the source will be moved into the parent. +", short_commit_description(&commit), short_commit_description(parent) ); @@ -1982,15 +1988,17 @@ fn cmd_unsquash( let new_parent_tree_id; if sub_matches.is_present("interactive") { let instructions = format!( - "You are moving changes from: {}\n\ - into its child: {}\n\ - \n\ - The diff initially shows the parent commit's changes.\n\ - \n\ - Adjust the right side until it shows the contents you want to keep in\n\ - the parent commit. The changes you edited out will be moved into the\n\ - child commit. If you don't make any changes, then the operation will be\n\ - aborted.\n", + "\ +You are moving changes from: {} +into its child: {} + +The diff initially shows the parent commit's changes. + +Adjust the right side until it shows the contents you want to keep in +the parent commit. The changes you edited out will be moved into the +child commit. If you don't make any changes, then the operation will be +aborted. +", short_commit_description(parent), short_commit_description(&commit) ); @@ -2055,15 +2063,17 @@ fn cmd_restore( )); } let instructions = format!( - "You are restoring state from: {}\n\ - into: {}\n\ - \n\ - The left side of the diff shows the contents of the commit you're\n\ - restoring from. The right side initially shows the contents of the\n\ - commit you're restoring into.\n\ - \n\ - Adjust the right side until it has the changes you wanted from the left\n\ - side. If you don't make any changes, then the operation will be aborted.\n", + "\ +You are restoring state from: {} +into: {} + +The left side of the diff shows the contents of the commit you're +restoring from. The right side initially shows the contents of the +commit you're restoring into. + +Adjust the right side until it has the changes you wanted from the left +side. If you don't make any changes, then the operation will be aborted. +", short_commit_description(&from_commit), short_commit_description(&to_commit) ); @@ -2115,12 +2125,13 @@ fn cmd_edit( let repo = repo_command.repo(); let base_tree = merge_commit_trees(repo.as_repo_ref(), &commit.parents()); let instructions = format!( - "You are editing changes in: {}\n\ - \n\ - The diff initially shows the commit's changes.\n\ - \n\ - Adjust the right side until it shows the contents you want. If you\n\ - don't make any changes, then the operation will be aborted.\n", + "\ +You are editing changes in: {} + +The diff initially shows the commit's changes. + +Adjust the right side until it shows the contents you want. If you +don't make any changes, then the operation will be aborted.", short_commit_description(&commit) ); let tree_id = crate::diff_edit::edit_diff(ui, &base_tree, &commit.tree(), &instructions)?; @@ -2151,13 +2162,15 @@ fn cmd_split( let repo = repo_command.repo(); let base_tree = merge_commit_trees(repo.as_repo_ref(), &commit.parents()); let instructions = format!( - "You are splitting a commit in two: {}\n\ - \n\ - The diff initially shows the changes in the commit you're splitting.\n\ - \n\ - Adjust the right side until it shows the contents you want for the first\n\ - commit. The remainder will be in the second commit. If you don't make\n\ - any changes, then the operation will be aborted.\n", + "\ +You are splitting a commit in two: {} + +The diff initially shows the changes in the commit you're splitting. + +Adjust the right side until it shows the contents you want for the first +commit. The remainder will be in the second commit. If you don't make +any changes, then the operation will be aborted. +", short_commit_description(&commit) ); let tree_id = crate::diff_edit::edit_diff(ui, &base_tree, &commit.tree(), &instructions)?; diff --git a/tests/smoke_test.rs b/tests/smoke_test.rs index 78578a68f..099c77961 100644 --- a/tests/smoke_test.rs +++ b/tests/smoke_test.rs @@ -28,10 +28,10 @@ fn smoke_test() { assert_eq!(output.status, 0); let stdout_string = output.stdout_string(); let output_regex = Regex::new( - "^Parent commit: 000000000000 \n\ - Working copy : ([[:xdigit:]]+) \n\ - The working copy is clean\n\ - $", + "^Parent commit: 000000000000 +Working copy : ([[:xdigit:]]+) +The working copy is clean +$", ) .unwrap(); assert!( @@ -56,13 +56,13 @@ fn smoke_test() { assert_eq!(output.status, 0); let stdout_string = output.stdout_string(); let output_regex = Regex::new( - "^Parent commit: 000000000000 \n\ - Working copy : ([[:xdigit:]]+) \n\ - Working copy changes:\n\ - A file1\n\ - A file2\n\ - A file3\n\ - $", + "^Parent commit: 000000000000 +Working copy : ([[:xdigit:]]+) +Working copy changes: +A file1 +A file2 +A file3 +$", ) .unwrap(); assert!(