Skip to content

Commit

Permalink
cli: don't use format_*() in annotate template, truncate author, omit…
Browse files Browse the repository at this point in the history
… commit id

The problem is that author names are variable-length by nature, and format_*()
can be customized in that way. Commit ids are redundant in most cases where
commits aren't diverged.

We could add some format_short_fixed_length_*() hook points, but it would
probably be easier to just customize the annotation template at all.
  • Loading branch information
yuja committed Nov 5, 2024
1 parent f568bac commit be9df56
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
7 changes: 3 additions & 4 deletions cli/src/config/templates.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ commit_summary = 'format_commit_summary_with_refs(self, bookmarks)'

annotate_commit_summary = '''
separate(" ",
format_short_id(change_id),
format_short_id(commit_id),
format_short_signature(author),
format_timestamp(committer.timestamp()),
change_id.shortest(8),
pad_end(8, truncate_end(8, author.username())),
committer.timestamp().local().format('%Y-%m-%d %H:%M:%S'),
)
'''

Expand Down
49 changes: 26 additions & 23 deletions cli/tests/test_file_annotate_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ fn test_annotate_linear() {
let repo_path = test_env.env_root().join("repo");

std::fs::write(repo_path.join("file.txt"), "line1\n").unwrap();
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=initial"]);
test_env.jj_cmd_ok(
&repo_path,
&["describe", "-m=initial", "--author=Foo <[email protected]>"],
);

test_env.jj_cmd_ok(&repo_path, &["new", "-m=next"]);
append_to_file(&repo_path.join("file.txt"), "new text from new commit");

let stdout = test_env.jj_cmd_success(&repo_path, &["file", "annotate", "file.txt"]);
insta::assert_snapshot!(stdout, @r###"
qpvuntsm 8934c772 [email protected] 2001-02-03 08:05:08 1: line1
kkmpptxz 41ae16e6 test.[email protected] 2001-02-03 08:05:10 2: new text from new commit
"###);
insta::assert_snapshot!(stdout, @r"
qpvuntsm foo 2001-02-03 08:05:08 1: line1
kkmpptxz test.use 2001-02-03 08:05:10 2: new text from new commit
");
}

#[test]
Expand Down Expand Up @@ -72,11 +75,11 @@ fn test_annotate_merge() {
.unwrap();

let stdout = test_env.jj_cmd_success(&repo_path, &["file", "annotate", "file.txt"]);
insta::assert_snapshot!(stdout, @r###"
qpvuntsm 8934c772 test.[email protected] 2001-02-03 08:05:08 1: line1
zsuskuln 712ba14a test.[email protected] 2001-02-03 08:05:11 2: new text from new commit 1
royxmykx b0571bd9 test.[email protected] 2001-02-03 08:05:13 3: new text from new commit 2
"###);
insta::assert_snapshot!(stdout, @r"
qpvuntsm test.use 2001-02-03 08:05:08 1: line1
zsuskuln test.use 2001-02-03 08:05:11 2: new text from new commit 1
royxmykx test.use 2001-02-03 08:05:13 3: new text from new commit 2
");
}

#[test]
Expand All @@ -102,15 +105,15 @@ fn test_annotate_conflicted() {
test_env.jj_cmd_ok(&repo_path, &["new"]);

let stdout = test_env.jj_cmd_success(&repo_path, &["file", "annotate", "file.txt"]);
insta::assert_snapshot!(stdout, @r###"
qpvuntsm 8934c772 test.[email protected] 2001-02-03 08:05:08 1: line1
yostqsxw 7b90c9f6 test.[email protected] 2001-02-03 08:05:15 2: <<<<<<< Conflict 1 of 1
yostqsxw 7b90c9f6 test.[email protected] 2001-02-03 08:05:15 3: %%%%%%% Changes from base to side #1
yostqsxw 7b90c9f6 test.[email protected] 2001-02-03 08:05:15 4: +new text from new commit 1
yostqsxw 7b90c9f6 test.[email protected] 2001-02-03 08:05:15 5: +++++++ Contents of side #2
royxmykx b0571bd9 test.[email protected] 2001-02-03 08:05:13 6: new text from new commit 2
yostqsxw 7b90c9f6 test.[email protected] 2001-02-03 08:05:15 7: >>>>>>> Conflict 1 of 1 ends
"###);
insta::assert_snapshot!(stdout, @r"
qpvuntsm test.use 2001-02-03 08:05:08 1: line1
yostqsxw test.use 2001-02-03 08:05:15 2: <<<<<<< Conflict 1 of 1
yostqsxw test.use 2001-02-03 08:05:15 3: %%%%%%% Changes from base to side #1
yostqsxw test.use 2001-02-03 08:05:15 4: +new text from new commit 1
yostqsxw test.use 2001-02-03 08:05:15 5: +++++++ Contents of side #2
royxmykx test.use 2001-02-03 08:05:13 6: new text from new commit 2
yostqsxw test.use 2001-02-03 08:05:15 7: >>>>>>> Conflict 1 of 1 ends
");
}

#[test]
Expand Down Expand Up @@ -141,8 +144,8 @@ fn test_annotate_merge_one_sided_conflict_resolution() {
.unwrap();

let stdout = test_env.jj_cmd_success(&repo_path, &["file", "annotate", "file.txt"]);
insta::assert_snapshot!(stdout, @r###"
qpvuntsm 8934c772 test.[email protected] 2001-02-03 08:05:08 1: line1
zsuskuln 712ba14a test.[email protected] 2001-02-03 08:05:11 2: new text from new commit 1
"###);
insta::assert_snapshot!(stdout, @r"
qpvuntsm test.use 2001-02-03 08:05:08 1: line1
zsuskuln test.use 2001-02-03 08:05:11 2: new text from new commit 1
");
}

0 comments on commit be9df56

Please sign in to comment.