diff --git a/cli/src/commands/log.rs b/cli/src/commands/log.rs index 0b59bbb6e3..2fc257a247 100644 --- a/cli/src/commands/log.rs +++ b/cli/src/commands/log.rs @@ -110,7 +110,10 @@ pub(crate) fn cmd_log( .settings() .config() .get_bool("ui.log-synthetic-elided-nodes")?; - let template = workspace_command.parse_commit_template(&template_string)?; + let template = { + let language = workspace_command.commit_template_language()?; + workspace_command.parse_template(&language, &template_string)? + }; let with_content_format = LogContentFormat::new(ui, command.settings())?; { @@ -159,7 +162,7 @@ pub(crate) fn cmd_log( } let mut buffer = vec![]; let key = (commit_id, false); - let commit = store.get_commit(&key.0)?; + let commit = Some(store.get_commit(&key.0)?); with_content_format.write_graph_text( ui.new_formatter(&mut buffer).as_mut(), |formatter| template.format(&commit, formatter), @@ -174,7 +177,7 @@ pub(crate) fn cmd_log( ui, formatter.as_mut(), &workspace_command, - &commit, + commit.as_ref().unwrap(), matcher.as_ref(), &diff_formats, )?; @@ -198,7 +201,7 @@ pub(crate) fn cmd_log( let mut buffer = vec![]; with_content_format.write_graph_text( ui.new_formatter(&mut buffer).as_mut(), - |formatter| writeln!(formatter.labeled("elided"), "(elided revisions)"), + |formatter| template.format(&None, formatter), || graph.width(&elided_key, &edges), )?; graph.add_node( @@ -216,7 +219,7 @@ pub(crate) fn cmd_log( Box::new(revset.iter()) }; for commit_or_error in iter.commits(store).take(args.limit.unwrap_or(usize::MAX)) { - let commit = commit_or_error?; + let commit = Some(commit_or_error?); with_content_format .write(formatter, |formatter| template.format(&commit, formatter))?; if !diff_formats.is_empty() { @@ -224,7 +227,7 @@ pub(crate) fn cmd_log( ui, formatter, &workspace_command, - &commit, + commit.as_ref().unwrap(), matcher.as_ref(), &diff_formats, )?; diff --git a/cli/src/config/templates.toml b/cli/src/config/templates.toml index faea7d626e..c42c630390 100644 --- a/cli/src/config/templates.toml +++ b/cli/src/config/templates.toml @@ -41,52 +41,59 @@ show = 'builtin_log_detailed' [template-aliases] builtin_log_oneline = ''' -if(root, - builtin_log_root(change_id, commit_id), - label(if(current_working_copy, "working_copy"), - concat( - separate(" ", - builtin_change_id_with_hidden_and_divergent_info, - if(author.email(), author.username(), email_placeholder), - format_timestamp(committer.timestamp()), - branches, - tags, - working_copies, - git_head, - format_short_commit_id(commit_id), - if(conflict, label("conflict", "conflict")), - if(empty, label("empty", "(empty)")), - if(description, description.first_line(), description_placeholder), - ) ++ "\n", +if(self, + if(root, + builtin_log_root(change_id, commit_id), + label(if(current_working_copy, "working_copy"), + concat( + separate(" ", + builtin_change_id_with_hidden_and_divergent_info, + if(author.email(), author.username(), email_placeholder), + format_timestamp(committer.timestamp()), + branches, + tags, + working_copies, + git_head, + format_short_commit_id(commit_id), + if(conflict, label("conflict", "conflict")), + if(empty, label("empty", "(empty)")), + if(description, description.first_line(), description_placeholder), + ) ++ "\n", + ), ), - ) + ), + elided_revisions_placeholder ++ "\n", ) ''' builtin_log_compact = ''' -if(root, - builtin_log_root(change_id, commit_id), - label(if(current_working_copy, "working_copy"), - concat( - separate(" ", - builtin_change_id_with_hidden_and_divergent_info, - format_short_signature(author), - format_timestamp(committer.timestamp()), - branches, - tags, - working_copies, - git_head, - format_short_commit_id(commit_id), - if(conflict, label("conflict", "conflict")), - ) ++ "\n", - separate(" ", - if(empty, label("empty", "(empty)")), - if(description, description.first_line(), description_placeholder), - ) ++ "\n", +if(self, + if(root, + builtin_log_root(change_id, commit_id), + label(if(current_working_copy, "working_copy"), + concat( + separate(" ", + builtin_change_id_with_hidden_and_divergent_info, + format_short_signature(author), + format_timestamp(committer.timestamp()), + branches, + tags, + working_copies, + git_head, + format_short_commit_id(commit_id), + if(conflict, label("conflict", "conflict")), + ) ++ "\n", + separate(" ", + if(empty, label("empty", "(empty)")), + if(description, description.first_line(), description_placeholder), + ) ++ "\n", + ), ), - ) + ), + elided_revisions_placeholder ++ "\n", ) ''' builtin_log_comfortable = 'builtin_log_compact ++ "\n"' +# TODO: should the detailed (or show) template support elided nodes? 'builtin_log_detailed' = ''' concat( "Commit ID: " ++ commit_id ++ "\n", @@ -138,6 +145,7 @@ separate(" ", description_placeholder = ''' label(if(empty, "empty ") ++ "description placeholder", "(no description set)")''' +elided_revisions_placeholder = 'label("elided", "(elided revisions)")' email_placeholder = 'label("email placeholder", "(no email set)")' name_placeholder = 'label("name placeholder", "(no name set)")' commit_summary_separator = 'label("separator", " | ")' diff --git a/cli/tests/test_log_command.rs b/cli/tests/test_log_command.rs index 5601b53610..2f691f317e 100644 --- a/cli/tests/test_log_command.rs +++ b/cli/tests/test_log_command.rs @@ -49,6 +49,7 @@ fn test_log_with_no_template() { - builtin_op_log_compact - commit_summary_separator - description_placeholder + - elided_revisions_placeholder - email_placeholder - name_placeholder "###); @@ -1388,10 +1389,10 @@ fn test_elided() { ├─╮ │ ◉ side branch 2 │ │ - │ ◌ (elided revisions) + │ ◌ ◉ │ main branch 2 │ │ - ◌ │ (elided revisions) + ◌ │ ├─╯ ◉ initial │ @@ -1403,10 +1404,10 @@ fn test_elided() { insta::assert_snapshot!(get_log("@-- | root()"), @r###" ◉ side branch 1 │ - ◌ (elided revisions) + ◌ │ ◉ main branch 1 │ │ - │ ◌ (elided revisions) + │ ◌ ├─╯ ◉ "###); @@ -1447,10 +1448,10 @@ fn test_custom_symbols() { ├─╮ │ ┝ side branch 2 │ │ - │ 🮀 (elided revisions) + │ 🮀 ┝ │ main branch 2 │ │ - 🮀 │ (elided revisions) + 🮀 │ ├─╯ ┝ initial │ @@ -1469,10 +1470,10 @@ fn test_custom_symbols() { |\ | * side branch 2 | | - | : (elided revisions) + | : * | main branch 2 | | - : | (elided revisions) + : | |/ * initial | diff --git a/cli/tests/test_obslog_command.rs b/cli/tests/test_obslog_command.rs index af20ec0572..c80351d79d 100644 --- a/cli/tests/test_obslog_command.rs +++ b/cli/tests/test_obslog_command.rs @@ -257,6 +257,7 @@ fn test_obslog_with_no_template() { - builtin_op_log_compact - commit_summary_separator - description_placeholder + - elided_revisions_placeholder - email_placeholder - name_placeholder "###); diff --git a/cli/tests/test_operations.rs b/cli/tests/test_operations.rs index ff00f1089b..d2a93100f7 100644 --- a/cli/tests/test_operations.rs +++ b/cli/tests/test_operations.rs @@ -114,6 +114,7 @@ fn test_op_log_with_no_template() { - builtin_op_log_compact - commit_summary_separator - description_placeholder + - elided_revisions_placeholder - email_placeholder - name_placeholder "###); diff --git a/cli/tests/test_show_command.rs b/cli/tests/test_show_command.rs index baa681ffc7..3adba087cf 100644 --- a/cli/tests/test_show_command.rs +++ b/cli/tests/test_show_command.rs @@ -69,6 +69,7 @@ fn test_show_with_no_template() { - builtin_op_log_compact - commit_summary_separator - description_placeholder + - elided_revisions_placeholder - email_placeholder - name_placeholder "###);