templater: Allow separate styling for change and commit ids

This commit is contained in:
Ilya Grigoriev 2023-02-20 20:38:52 -08:00
parent 00b18bcd18
commit 49fd177c47
3 changed files with 42 additions and 7 deletions

View file

@ -152,6 +152,15 @@ Can be customized by the `format_short_id()` template alias.
'format_short_id(id)' = 'id.short(12)'
```
To customize these separately, use the `format_short_commit_id()` and
`format_short_change_id()` aliases:
```toml
[template-aliases]
# Uppercase change ids. `jj` treats change and commit ids as case-insensitive.
'format_short_change_id(id)' = 'format_short_id(id).upper()'
```
### Relative timestamps
Can be customized by the `format_timestamp()` template alias.

View file

@ -1,6 +1,6 @@
[templates]
commit_summary = '''
format_short_id(commit_id) " "
format_short_commit_id(commit_id) " "
if(description, description.first_line(), description_placeholder)
'''
@ -8,15 +8,15 @@ log = '''
label(if(current_working_copy, "working_copy"),
separate(" ",
if(divergent,
label("divergent", format_short_id(change_id) "??"),
format_short_id(change_id)),
label("divergent", format_short_change_id(change_id) "??"),
format_short_change_id(change_id)),
format_short_signature(author),
format_timestamp(committer.timestamp()),
branches,
tags,
working_copies,
git_head,
format_short_id(commit_id),
format_short_commit_id(commit_id),
if(conflict, label("conflict", "conflict")),
)
"\n"
@ -47,6 +47,8 @@ show = 'show'
# Hook points for users to customize the default templates:
'format_short_id(id)' = 'id.shortest(12)'
'format_short_change_id(id)' = 'format_short_id(id)'
'format_short_commit_id(id)' = 'format_short_id(id)'
'format_short_signature(signature)' = 'signature.email()'
'format_time_range(time_range)' = '''
time_range.start().ago() label("time", ", lasted ") time_range.duration()'''

View file

@ -177,15 +177,39 @@ fn test_log_customize_short_id() {
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "first"]);
// Customize both the commit and the change id
let decl = "template-aliases.'format_short_id(id)'";
let stdout = test_env.jj_cmd_success(
&repo_path,
&["log", "--config-toml", &format!("{decl}='id.shortest()'")],
&[
"log",
"--config-toml",
&format!("{decl}='id.shortest(5).prefix().upper() \"_\" id.shortest(5).rest()'"),
],
);
insta::assert_snapshot!(stdout, @r###"
@ q test.user@example.com 2001-02-03 04:05:08.000 +07:00 6
@ Q_pvun test.user@example.com 2001-02-03 04:05:08.000 +07:00 6_9542
(empty) first
o z 1970-01-01 00:00:00.000 +00:00 0
o Z_zzzz 1970-01-01 00:00:00.000 +00:00 0_0000
(empty) (no description set)
"###);
// Customize only the change id
let stdout = test_env.jj_cmd_success(
&repo_path,
&[
"log",
"--config-toml",
r#"
[template-aliases]
'format_short_change_id(id)'='format_short_id(id).upper()'
"#,
],
);
insta::assert_snapshot!(stdout, @r###"
@ QPVUNTSMWLQT test.user@example.com 2001-02-03 04:05:08.000 +07:00 69542c1984c1
(empty) first
o ZZZZZZZZZZZZ 1970-01-01 00:00:00.000 +00:00 000000000000
(empty) (no description set)
"###);
}