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

cli: use label() to highlight "working_copy" commit in log template

I think this is a proper way to label the working-copy commit. This also
fixes "jj obslog" output, but I don't think anyone would care.
This commit is contained in:
Yuya Nishihara 2023-02-03 12:49:40 +09:00
parent e2eda9f72f
commit e2a5a14463
4 changed files with 30 additions and 31 deletions

View file

@ -34,6 +34,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Use `if(description, description, "(no description set)\n")` to get back
the previous behavior.
* If a custom `template.log.graph` template is set, working-copy commit will
no longer be highlighted automatically. Wrap your template with
`label(if(current_working_copy, "working_copy"), ...)` to label the
working-copy entry.
* The global `--no-commit-working-copy` is now called `--ignore-working-copy`.
### New features

View file

@ -1407,21 +1407,23 @@ fn log_template(settings: &UserSettings) -> String {
};
let default_template = format!(
r#"
if(divergent,
label("divergent", change_id.{prefix_format} "??"),
change_id.{prefix_format})
" " author.email()
" " {committer_timestamp}
if(branches, " " branches)
if(tags, " " tags)
if(working_copies, " " working_copies)
if(git_head, " " git_head)
" " commit_id.{prefix_format}
if(conflict, label("conflict", " conflict"))
"\n"
if(empty, label("empty", "(empty) "))
if(description, description.first_line(), {DESCRIPTION_PLACEHOLDER_TEMPLATE})
"\n""#,
label(if(current_working_copy, "working_copy"),
if(divergent,
label("divergent", change_id.{prefix_format} "??"),
change_id.{prefix_format})
" " author.email()
" " {committer_timestamp}
if(branches, " " branches)
if(tags, " " tags)
if(working_copies, " " working_copies)
if(git_head, " " git_head)
" " commit_id.{prefix_format}
if(conflict, label("conflict", " conflict"))
"\n"
if(empty, label("empty", "(empty) "))
if(description, description.first_line(), {DESCRIPTION_PLACEHOLDER_TEMPLATE})
"\n"
)"#,
);
settings
.config()
@ -1459,15 +1461,6 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
workspace_id,
&template_string,
)?;
let format_commit_template = |commit: &Commit, formatter: &mut dyn Formatter| {
if Some(commit.id()) == wc_commit_id {
formatter.with_label("working_copy", |formatter| {
template.format(commit, formatter)
})
} else {
template.format(commit, formatter)
}
};
{
ui.request_pager();
@ -1509,7 +1502,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
let mut buffer = vec![];
let commit_id = index_entry.commit_id();
let commit = store.get_commit(&commit_id)?;
format_commit_template(&commit, ui.new_formatter(&mut buffer).as_mut())?;
template.format(&commit, ui.new_formatter(&mut buffer).as_mut())?;
if !buffer.ends_with(b"\n") {
buffer.push(b'\n');
}
@ -1544,7 +1537,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
};
for index_entry in iter {
let commit = store.get_commit(&index_entry.commit_id())?;
format_commit_template(&commit, formatter)?;
template.format(&commit, formatter)?;
if !diff_formats.is_empty() {
diff_util::show_patch(
formatter,

View file

@ -182,7 +182,7 @@ fn test_color_config() {
// Test that --color=always is respected.
let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T", "commit_id"]);
insta::assert_snapshot!(stdout, @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
o 0000000000000000000000000000000000000000
"###);
@ -190,7 +190,7 @@ fn test_color_config() {
test_env.add_config(r#"ui.color="always""#);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
insta::assert_snapshot!(stdout, @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
o 0000000000000000000000000000000000000000
"###);
@ -246,7 +246,7 @@ fn test_color_config() {
test_env.add_env_var("NO_COLOR", "");
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
insta::assert_snapshot!(stdout, @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
o 0000000000000000000000000000000000000000
"###);

View file

@ -659,7 +659,8 @@ fn test_graph_template_color() {
);
// First test without color for comparison
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T=description"]);
let template = r#"label(if(current_working_copy, "working_copy"), description)"#;
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]);
insta::assert_snapshot!(stdout, @r###"
@ single line
o first line
@ -667,7 +668,7 @@ fn test_graph_template_color() {
| third line
o
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T=description"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T", template]);
insta::assert_snapshot!(stdout, @r###"
@ single line
o first line