ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: hide irrelevant information about root commit in default log templates

I've extracted the `builtin_log_root` template for users to customize the
default templates without fully overriding them, for example I would remove
the change_id/commit_id for myself - and we discussed in Discord that leaving
those makes sense for the user to be reminded/teached that the root commit has
a change id made from z's.
This commit is contained in:
Anton Bulakh 2023-08-15 16:18:56 +03:00 committed by Anton Bulakh
parent 82923afcc5
commit dc6e1d7dee
9 changed files with 83 additions and 82 deletions

View file

@ -31,6 +31,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### New features ### New features
* Default template for `jj log` now does not show irrelevant information
(timestamp, empty, message placeholder etc.) about the root commit.
* Commit templates now support the `root` keyword, which is `true` for the root * Commit templates now support the `root` keyword, which is `true` for the root
commit and `false` for every other commit. commit and `false` for every other commit.

View file

@ -33,6 +33,7 @@
"conflict" = "red" "conflict" = "red"
"empty" = "green" "empty" = "green"
"separator" = "bright black" "separator" = "bright black"
"root" = {fg = "bright green", bold = true}
"working_copy" = { bold = true } "working_copy" = { bold = true }
"working_copy commit_id" = "bright blue" "working_copy commit_id" = "bright blue"

View file

@ -29,50 +29,58 @@ op_log = 'builtin_op_log_compact'
show = 'builtin_log_detailed' show = 'builtin_log_detailed'
[template-aliases] [template-aliases]
'builtin_log_oneline' = '''label(if(current_working_copy, "working_copy"), 'builtin_log_oneline' = '''
concat( if(root,
separate(" ", builtin_log_root(change_id, commit_id),
label( label(if(current_working_copy, "working_copy"),
separate(" ", if(divergent, "divergent"), if(hidden, "hidden")), concat(
separate(" ", separate(" ",
format_short_change_id(change_id) ++ if(divergent, "??"), label(
if(hidden, "hidden"))), separate(" ", if(divergent, "divergent"), if(hidden, "hidden")),
author.username(), separate(" ",
format_timestamp(committer.timestamp()), format_short_change_id(change_id) ++ if(divergent, "??"),
branches, if(hidden, "hidden"))),
tags, author.username(),
working_copies, format_timestamp(committer.timestamp()),
git_head, branches,
format_short_commit_id(commit_id), tags,
if(conflict, label("conflict", "conflict")), working_copies,
if(empty, label("empty", "(empty)")), git_head,
if(description, description.first_line(), description_placeholder), format_short_commit_id(commit_id),
) ++ "\n", if(conflict, label("conflict", "conflict")),
), if(empty, label("empty", "(empty)")),
if(description, description.first_line(), description_placeholder),
) ++ "\n",
),
)
) )
''' '''
'builtin_log_compact' = '''label(if(current_working_copy, "working_copy"), 'builtin_log_compact' = '''
concat( if(root,
separate(" ", builtin_log_root(change_id, commit_id),
label( label(if(current_working_copy, "working_copy"),
separate(" ", if(divergent, "divergent"), if(hidden, "hidden")), concat(
separate(" ", separate(" ",
format_short_change_id(change_id) ++ if(divergent, "??"), label(
if(hidden, "hidden"))), separate(" ", if(divergent, "divergent"), if(hidden, "hidden")),
format_short_signature(author), separate(" ",
format_timestamp(committer.timestamp()), format_short_change_id(change_id) ++ if(divergent, "??"),
branches, if(hidden, "hidden"))),
tags, format_short_signature(author),
working_copies, format_timestamp(committer.timestamp()),
git_head, branches,
format_short_commit_id(commit_id), tags,
if(conflict, label("conflict", "conflict")), working_copies,
) ++ "\n", git_head,
separate(" ", format_short_commit_id(commit_id),
if(empty, label("empty", "(empty)")), if(conflict, label("conflict", "conflict")),
if(description, description.first_line(), description_placeholder), ) ++ "\n",
) ++ "\n", separate(" ",
), if(empty, label("empty", "(empty)")),
if(description, description.first_line(), description_placeholder),
) ++ "\n",
),
)
) )
''' '''
builtin_log_comfortable = 'builtin_log_compact ++ "\n"' builtin_log_comfortable = 'builtin_log_compact ++ "\n"'
@ -104,6 +112,15 @@ label(if(current_operation, "current_operation"),
''' '''
builtin_op_log_comfortable = 'builtin_op_log_compact ++ "\n"' builtin_op_log_comfortable = 'builtin_op_log_compact ++ "\n"'
'builtin_log_root(change_id, commit_id)' = '''
separate(" ",
format_short_change_id(change_id),
label("root", "root"),
format_short_commit_id(commit_id),
branches
)
'''
'description_placeholder' = 'label("description", "(no description set)")' 'description_placeholder' = 'label("description", "(no description set)")'
'commit_summary_separator' = 'label("separator", " | ")' 'commit_summary_separator' = 'label("separator", " | ")'

View file

@ -137,8 +137,7 @@ fn test_alias_cannot_override_builtin() {
// Alias should be ignored // Alias should be ignored
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "root"]); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "root"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
} }

View file

@ -128,8 +128,7 @@ fn test_log_default() {
(empty) description 1 (empty) description 1
qpvuntsm test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264 qpvuntsm test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264
add a file add a file
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
// Color // Color
@ -139,8 +138,7 @@ fn test_log_default() {
(empty) description 1 (empty) description 1
qpvuntsm test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264 qpvuntsm test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264
add a file add a file
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
// Color without graph // Color without graph
@ -150,8 +148,7 @@ fn test_log_default() {
(empty) description 1 (empty) description 1
qpvuntsm test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264 qpvuntsm test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264
add a file add a file
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
} }
@ -164,23 +161,20 @@ fn test_log_builtin_templates() {
insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @r###" insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @r###"
@ qpvuntsm test.user 2001-02-03 04:05:07.000 +07:00 230dd059 (empty) (no description set) @ qpvuntsm test.user 2001-02-03 04:05:07.000 +07:00 230dd059 (empty) (no description set)
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 (empty) (no description set) zzzzzzzz root 00000000
"###); "###);
insta::assert_snapshot!(render(r#"builtin_log_compact"#), @r###" insta::assert_snapshot!(render(r#"builtin_log_compact"#), @r###"
@ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059
(empty) (no description set) (empty) (no description set)
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @r###" insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @r###"
@ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059
(empty) (no description set) (empty) (no description set)
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @r###" insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @r###"
@ -214,8 +208,7 @@ fn test_log_obslog_divergence() {
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ qpvuntsm test.user@example.com 2001-02-03 04:05:08.000 +07:00 7a17d52e @ qpvuntsm test.user@example.com 2001-02-03 04:05:08.000 +07:00 7a17d52e
description 1 description 1
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
// Create divergence // Create divergence
@ -230,8 +223,7 @@ fn test_log_obslog_divergence() {
description 2 description 2
@ qpvuntsm?? test.user@example.com 2001-02-03 04:05:08.000 +07:00 7a17d52e @ qpvuntsm?? test.user@example.com 2001-02-03 04:05:08.000 +07:00 7a17d52e
description 1 description 1
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
// Color // Color
@ -241,8 +233,7 @@ fn test_log_obslog_divergence() {
description 2 description 2
@ qpvuntsm?? test.user@example.com 2001-02-03 04:05:08.000 +07:00 7a17d52e @ qpvuntsm?? test.user@example.com 2001-02-03 04:05:08.000 +07:00 7a17d52e
description 1 description 1
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
// Obslog and hidden divergent // Obslog and hidden divergent
@ -283,8 +274,7 @@ fn test_log_git_head() {
initial initial
qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 master HEAD@git 230dd059 qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 master HEAD@git 230dd059
(empty) (no description set) (empty) (no description set)
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
} }
@ -309,8 +299,7 @@ fn test_log_customize_short_id() {
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ Q_pvun test.user@example.com 2001-02-03 04:05:08.000 +07:00 6_9542 @ Q_pvun test.user@example.com 2001-02-03 04:05:08.000 +07:00 6_9542
(empty) first (empty) first
Z_zzzz 1970-01-01 00:00:00.000 +00:00 0_0000 Z_zzzz root 0_0000
(empty) (no description set)
"###); "###);
// Customize only the change id // Customize only the change id
@ -328,7 +317,6 @@ fn test_log_customize_short_id() {
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ QPVUNTSM test.user@example.com 2001-02-03 04:05:08.000 +07:00 69542c19 @ QPVUNTSM test.user@example.com 2001-02-03 04:05:08.000 +07:00 69542c19
(empty) first (empty) first
ZZZZZZZZ 1970-01-01 00:00:00.000 +00:00 00000000 ZZZZZZZZ root 00000000
(empty) (no description set)
"###); "###);
} }

View file

@ -649,8 +649,7 @@ fn test_diff_external_tool() {
-- --
file1 file1
file2 file2
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
-- --
"###); "###);

View file

@ -321,8 +321,7 @@ fn test_init_git_external_but_git_dir_exists() {
// The local ".git" repository is unrelated, so no commits should be imported // The local ".git" repository is unrelated, so no commits should be imported
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]); let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
// Check that Git HEAD is not set because this isn't a colocated repo // Check that Git HEAD is not set because this isn't a colocated repo

View file

@ -49,8 +49,7 @@ fn test_log_legacy_range_operator() {
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059
(empty) (no description set) (empty) (no description set)
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
insta::assert_snapshot!(stderr, @r###" insta::assert_snapshot!(stderr, @r###"
The `:` revset operator is deprecated. Please switch to `::`. The `:` revset operator is deprecated. Please switch to `::`.
@ -59,8 +58,7 @@ fn test_log_legacy_range_operator() {
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059
(empty) (no description set) (empty) (no description set)
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
insta::assert_snapshot!(stderr, @r###" insta::assert_snapshot!(stderr, @r###"
The `:` revset operator is deprecated. Please switch to `::`. The `:` revset operator is deprecated. Please switch to `::`.

View file

@ -256,14 +256,12 @@ fn test_alias() {
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "my-root"]); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "my-root"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "identity(my-root)"]); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "identity(my-root)"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "root & syntax-error"]); let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "root & syntax-error"]);
@ -385,8 +383,7 @@ fn test_bad_alias_decl() {
// Invalid declaration should be warned and ignored. // Invalid declaration should be warned and ignored.
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r", "my-root"]); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r", "my-root"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
zzzzzzzz 1970-01-01 00:00:00.000 +00:00 00000000 zzzzzzzz root 00000000
(empty) (no description set)
"###); "###);
insta::assert_snapshot!(stderr, @r###" insta::assert_snapshot!(stderr, @r###"
Failed to load "revset-aliases."bad"": --> 1:1 Failed to load "revset-aliases."bad"": --> 1:1