From de163216c0e1ef6f8a25ecc76350950072e157c1 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Sun, 5 Feb 2023 21:38:54 -0800 Subject: [PATCH] Templater: make `shortest` id functions default to 0 length This makes them print the shortest unique prefix only. --- src/template_parser.rs | 4 ++-- tests/test_log_command.rs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/template_parser.rs b/src/template_parser.rs index b25afc215..dcac75a1d 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -498,7 +498,7 @@ fn parse_commit_or_change_id_method<'a, I: 'a>( Property::String(chain_properties( (self_property, len_property), TemplatePropertyFn(|(id, len): &(CommitOrChangeId, Option)| { - id.shortest_prefix_and_brackets(len.unwrap_or(12)) + id.shortest_prefix_and_brackets(len.unwrap_or(0)) }), )) } @@ -507,7 +507,7 @@ fn parse_commit_or_change_id_method<'a, I: 'a>( Property::IdWithHighlightedPrefix(chain_properties( (self_property, len_property), TemplatePropertyFn(|(id, len): &(CommitOrChangeId, Option)| { - id.shortest_styled_prefix(len.unwrap_or(12)) + id.shortest_styled_prefix(len.unwrap_or(0)) }), )) } diff --git a/tests/test_log_command.rs b/tests/test_log_command.rs index db617a690..1a8c9be8c 100644 --- a/tests/test_log_command.rs +++ b/tests/test_log_command.rs @@ -303,7 +303,7 @@ fn test_log_prefix_highlight_brackets() { test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]); test_env.jj_cmd_success(&repo_path, &["branch", "c", "original"]); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", &prefix_format(None)]), + test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", &prefix_format(Some(12))]), @r###" @ Change 9[a45c67d3e96] initial b[a1a30916d29] original ~ @@ -314,14 +314,14 @@ fn test_log_prefix_highlight_brackets() { std::fs::write(repo_path.join("file"), format!("file {i}\n")).unwrap(); } insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", &prefix_format(None)]), + test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", &prefix_format(Some(12))]), @r###" o Change 9a4[5c67d3e96] initial ba1[a30916d29] original ~ "### ); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-----------..@", "-T", &prefix_format(None)]), + test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-----------..@", "-T", &prefix_format(Some(12))]), @r###" @ Change 4c9[32da80131] commit49 d8[3437a2ceff] o Change 0d[58f15eaba6] commit48 f3[abb4ea0ac3] @@ -355,7 +355,7 @@ fn test_log_prefix_highlight_brackets() { "### ); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-----------..@", "-T", &prefix_format(Some(0))]), + test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-----------..@", "-T", &prefix_format(None)]), @r###" @ Change 4c9 commit49 d8 o Change 0d commit48 f3 @@ -393,7 +393,7 @@ fn test_log_prefix_highlight_styled() { test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]); test_env.jj_cmd_success(&repo_path, &["branch", "c", "original"]); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", &prefix_format(None)]), + test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", &prefix_format(Some(12))]), @r###" @ Change 9a45c67d3e96 initial ba1a30916d29 original ~ @@ -404,7 +404,7 @@ fn test_log_prefix_highlight_styled() { std::fs::write(repo_path.join("file"), format!("file {i}\n")).unwrap(); } insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", &prefix_format(None)]), + test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", &prefix_format(Some(12))]), @r###" o Change 9a45c67d3e96 initial ba1a30916d29 original ~ @@ -418,7 +418,7 @@ fn test_log_prefix_highlight_styled() { "-r", "@-----------..@", "-T", - &prefix_format(None), + &prefix_format(Some(12)), ], ); insta::assert_snapshot!(stdout, @@ -472,7 +472,7 @@ fn test_log_prefix_highlight_styled() { "-r", "@-----------..@", "-T", - &prefix_format(Some(0)), + &prefix_format(None), ], ); insta::assert_snapshot!(stdout, @@ -500,8 +500,8 @@ fn test_log_prefix_highlight_counts_hidden_commits() { let repo_path = test_env.env_root().join("repo"); let prefix_format = r#" - "Change " change_id.shortest_prefix_and_brackets() " " description.first_line() - " " commit_id.shortest_prefix_and_brackets() " " branches + "Change " change_id.shortest_prefix_and_brackets(12) " " description.first_line() + " " commit_id.shortest_prefix_and_brackets(12) " " branches "#; std::fs::write(repo_path.join("file"), "original file\n").unwrap();