Skip to content

Commit

Permalink
templater: fix id of brackets-prefix format to respect total length
Browse files Browse the repository at this point in the history
I think the intent of '- 1' here is the separator length, which was
originally ':'. Alternatively, we can ensure that prefix + remainder is
always 12 chars.
  • Loading branch information
yuja committed Jan 19, 2023
1 parent d6c6cdb commit 139fe08
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,11 @@ impl CommitOrChangeId {

fn highlight_shortest_prefix(mut hex: String, total_len: usize, repo: RepoRef) -> String {
let prefix_len = repo.base_repo().shortest_unique_prefix_length(&hex);
if prefix_len < total_len - 1 {
if prefix_len < total_len - 2 {
format!(
"{}[{}]",
&hex[0..prefix_len],
&hex[prefix_len..total_len - 1]
&hex[prefix_len..total_len - 2]
)
} else {
hex.truncate(total_len);
Expand Down
26 changes: 13 additions & 13 deletions tests/test_commit_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ fn test_log_default() {

// Test default log output format
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["log"]), @r###"
@ f[fdaa62087a] test.user@example.com 2001-02-03 04:05:09.000 +07:00 my-branch 9d[e54178d59]
@ f[fdaa62087] test.user@example.com 2001-02-03 04:05:09.000 +07:00 my-branch 9d[e54178d5]
| (empty) description 1
o 9a[45c67d3e9] test.user@example.com 2001-02-03 04:05:08.000 +07:00 4[291e264ae9]
o 9a[45c67d3e] test.user@example.com 2001-02-03 04:05:08.000 +07:00 4[291e264ae]
| add a file
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
(empty) (no description set)
"###);

// Test default log output format with bracket prefixes
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["log", "--config-toml", "ui.unique-prefixes='brackets'"]), @r###"
@ f[fdaa62087a] test.user@example.com 2001-02-03 04:05:09.000 +07:00 my-branch 9d[e54178d59]
@ f[fdaa62087] test.user@example.com 2001-02-03 04:05:09.000 +07:00 my-branch 9d[e54178d5]
| (empty) description 1
o 9a[45c67d3e9] test.user@example.com 2001-02-03 04:05:08.000 +07:00 4[291e264ae9]
o 9a[45c67d3e] test.user@example.com 2001-02-03 04:05:08.000 +07:00 4[291e264ae]
| add a file
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
(empty) (no description set)
Expand All @@ -95,9 +95,9 @@ fn test_log_default() {
// Color
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always"]);
insta::assert_snapshot!(stdout, @r###"
@ [1m[38;5;13mf[fdaa62087a][39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:09.000 +07:00[39m [38;5;13mmy-branch[39m [38;5;12m9d[e54178d59][39m[0m
@ [1m[38;5;13mf[fdaa62087][39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:09.000 +07:00[39m [38;5;13mmy-branch[39m [38;5;12m9d[e54178d5][39m[0m
| (empty) description 1
o [38;5;5m9a[45c67d3e9][39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4[291e264ae9][39m
o [38;5;5m9a[45c67d3e][39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4[291e264ae][39m
| add a file
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
(empty) (no description set)
Expand All @@ -106,9 +106,9 @@ fn test_log_default() {
// Color without graph
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always", "--no-graph"]);
insta::assert_snapshot!(stdout, @r###"
[1m[38;5;13mf[fdaa62087a][39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:09.000 +07:00[39m [38;5;13mmy-branch[39m [38;5;12m9d[e54178d59][39m[0m
[1m[38;5;13mf[fdaa62087][39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:09.000 +07:00[39m [38;5;13mmy-branch[39m [38;5;12m9d[e54178d5][39m[0m
(empty) description 1
[38;5;5m9a[45c67d3e9][39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4[291e264ae9][39m
[38;5;5m9a[45c67d3e][39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4[291e264ae][39m
add a file
000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
(empty) (no description set)
Expand All @@ -126,7 +126,7 @@ fn test_log_default_divergence() {
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
// No divergence
insta::assert_snapshot!(stdout, @r###"
@ 9[a45c67d3e9] test.user@example.com 2001-02-03 04:05:08.000 +07:00 7[a17d52e633]
@ 9[a45c67d3e] test.user@example.com 2001-02-03 04:05:08.000 +07:00 7[a17d52e63]
| description 1
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
(empty) (no description set)
Expand All @@ -140,9 +140,9 @@ fn test_log_default_divergence() {
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
Concurrent modification detected, resolving automatically.
o 9[a45c67d3e9]?? test.user@example.com 2001-02-03 04:05:10.000 +07:00 8[979953d4c6]
o 9[a45c67d3e]?? test.user@example.com 2001-02-03 04:05:10.000 +07:00 8[979953d4c]
| description 2
| @ 9[a45c67d3e9]?? test.user@example.com 2001-02-03 04:05:08.000 +07:00 7[a17d52e633]
| @ 9[a45c67d3e]?? test.user@example.com 2001-02-03 04:05:08.000 +07:00 7[a17d52e63]
|/ description 1
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
(empty) (no description set)
Expand All @@ -151,9 +151,9 @@ fn test_log_default_divergence() {
// Color
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always"]);
insta::assert_snapshot!(stdout, @r###"
o [38;5;1m9[a45c67d3e9]??[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:10.000 +07:00[39m [38;5;4m8[979953d4c6][39m
o [38;5;1m9[a45c67d3e]??[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:10.000 +07:00[39m [38;5;4m8[979953d4c][39m
| description 2
| @ [1m[38;5;9m9[a45c67d3e9]??[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:08.000 +07:00[39m [38;5;12m7[a17d52e633][39m[0m
| @ [1m[38;5;9m9[a45c67d3e]??[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:08.000 +07:00[39m [38;5;12m7[a17d52e63][39m[0m
|/ description 1
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
(empty) (no description set)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_init_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn test_init_git_external() {
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
o d[3866db7e30] git.user@example.com 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8[d698d4a8ee]
o d[3866db7e3] git.user@example.com 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8[d698d4a8e]
~ My commit message
"###);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ fn test_init_git_colocated() {
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
o d[3866db7e30] git.user@example.com 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8[d698d4a8ee]
o d[3866db7e3] git.user@example.com 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8[d698d4a8e]
~ My commit message
"###);
}
Expand Down
34 changes: 17 additions & 17 deletions tests/test_log_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn test_log_prefix_highlight() {
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", prefix_format]),
@r###"
@ Change 9[a45c67d3e9] initial b[a1a30916d2] original
@ Change 9[a45c67d3e] initial b[a1a30916d] original
~
"###
);
Expand All @@ -315,24 +315,24 @@ fn test_log_prefix_highlight() {
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", prefix_format]),
@r###"
o Change 9a4[5c67d3e9] initial ba1[a30916d2] original
o Change 9a4[5c67d3e] initial ba1[a30916d] original
~
"###
);
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-----------..@", "-T", prefix_format]),
@r###"
@ Change 4c9[32da8013] commit49 d8[3437a2cef]
o Change 0d[58f15eaba] commit48 f3[abb4ea0ac]
o Change fc[e6c2c5912] commit47 38e[891bea27]
o Change d5[1defcac30] commit46 1c[04d947707]
o Change 4f[13b1391d6] commit45 747[24ae22b1]
o Change 6a[de2950a04] commit44 c7a[a67cf7bb]
o Change 06c[482e452d] commit43 8e[c99dfcb6c]
o Change 392[beeb018e] commit42 8f0[e60411b7]
o Change a1[b73d3ff91] commit41 71[d6937a66c]
o Change 708[8f461291] commit40 db[572049026]
o Change c49[f7f006c7] commit39 d94[54fec8a6]
@ Change 4c9[32da801] commit49 d8[3437a2ce]
o Change 0d[58f15eab] commit48 f3[abb4ea0a]
o Change fc[e6c2c591] commit47 38e[891bea2]
o Change d5[1defcac3] commit46 1c[04d94770]
o Change 4f[13b1391d] commit45 747[24ae22b]
o Change 6a[de2950a0] commit44 c7a[a67cf7b]
o Change 06c[482e452] commit43 8e[c99dfcb6]
o Change 392[beeb018] commit42 8f0[e60411b]
o Change a1[b73d3ff9] commit41 71[d6937a66]
o Change 708[8f46129] commit40 db[57204902]
o Change c49[f7f006c] commit39 d94[54fec8a]
~
"###
);
Expand All @@ -355,7 +355,7 @@ fn test_log_prefix_highlight_counts_hidden_commits() {
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", prefix_format]),
@r###"
@ Change 9[a45c67d3e9] initial b[a1a30916d2] original
@ Change 9[a45c67d3e] initial b[a1a30916d] original
o Change 000000000000 (no description set) 000000000000
"###
);
Expand All @@ -367,15 +367,15 @@ fn test_log_prefix_highlight_counts_hidden_commits() {
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-r", "ba1", "-T", prefix_format]),
@r###"
o Change 9a4[5c67d3e9] initial ba1[a30916d2]
o Change 9a4[5c67d3e] initial ba1[a30916d]
~
"###
);
// The first commit is no longer visible
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", prefix_format]),
@r###"
@ Change 9a4[5c67d3e9] commit99 de[3177d2acf] original
@ Change 9a4[5c67d3e] commit99 de[3177d2ac] original
o Change 000000000000 (no description set) 000000000000
"###
);
Expand All @@ -388,7 +388,7 @@ fn test_log_prefix_highlight_counts_hidden_commits() {
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-r", "de", "-T", prefix_format]),
@r###"
@ Change 9a4[5c67d3e9] commit99 de[3177d2acf] original
@ Change 9a4[5c67d3e] commit99 de[3177d2ac] original
~
"###
);
Expand Down
44 changes: 22 additions & 22 deletions tests/test_obslog_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,57 @@ fn test_obslog_with_or_without_diff() {

let stdout = get_log_output(&test_env, &repo_path, &["obslog"]);
insta::assert_snapshot!(stdout, @r###"
@ 8[e4fac809cb] test.user@example.com 2001-02-03 04:05:10.000 +07:00 66[b42ad3607]
@ 8[e4fac809c] test.user@example.com 2001-02-03 04:05:10.000 +07:00 66[b42ad360]
| my description
o 8[e4fac809cb] test.user@example.com 2001-02-03 04:05:09.000 +07:00 af[536e5af67] conflict
o 8[e4fac809c] test.user@example.com 2001-02-03 04:05:09.000 +07:00 af[536e5af6] conflict
| my description
o 8[e4fac809cb] test.user@example.com 2001-02-03 04:05:09.000 +07:00 6f[bba7bcb59]
o 8[e4fac809c] test.user@example.com 2001-02-03 04:05:09.000 +07:00 6f[bba7bcb5]
| my description
o 8[e4fac809cb] test.user@example.com 2001-02-03 04:05:08.000 +07:00 e[ac0d0dae08]
o 8[e4fac809c] test.user@example.com 2001-02-03 04:05:08.000 +07:00 e[ac0d0dae0]
(empty) my description
"###);

// There should be no diff caused by the rebase because it was a pure rebase
// (even even though it resulted in a conflict).
let stdout = get_log_output(&test_env, &repo_path, &["obslog", "-p"]);
insta::assert_snapshot!(stdout, @r###"
@ 8[e4fac809cb] test.user@example.com 2001-02-03 04:05:10.000 +07:00 66[b42ad3607]
@ 8[e4fac809c] test.user@example.com 2001-02-03 04:05:10.000 +07:00 66[b42ad360]
| my description
| Resolved conflict in file1:
| 1 1: <<<<<<<resolved
| 2 : %%%%%%%
| 3 : +bar
| 4 : >>>>>>>
o 8[e4fac809cb] test.user@example.com 2001-02-03 04:05:09.000 +07:00 af[536e5af67] conflict
o 8[e4fac809c] test.user@example.com 2001-02-03 04:05:09.000 +07:00 af[536e5af6] conflict
| my description
o 8[e4fac809cb] test.user@example.com 2001-02-03 04:05:09.000 +07:00 6f[bba7bcb59]
o 8[e4fac809c] test.user@example.com 2001-02-03 04:05:09.000 +07:00 6f[bba7bcb5]
| my description
| Modified regular file file1:
| 1 1: foo
| 2: bar
| Added regular file file2:
| 1: foo
o 8[e4fac809cb] test.user@example.com 2001-02-03 04:05:08.000 +07:00 e[ac0d0dae08]
o 8[e4fac809c] test.user@example.com 2001-02-03 04:05:08.000 +07:00 e[ac0d0dae0]
(empty) my description
"###);

// Test `--no-graph`
let stdout = get_log_output(&test_env, &repo_path, &["obslog", "--no-graph"]);
insta::assert_snapshot!(stdout, @r###"
8[e4fac809cb] test.user@example.com 2001-02-03 04:05:10.000 +07:00 66[b42ad3607]
8[e4fac809c] test.user@example.com 2001-02-03 04:05:10.000 +07:00 66[b42ad360]
my description
8[e4fac809cb] test.user@example.com 2001-02-03 04:05:09.000 +07:00 af[536e5af67] conflict
8[e4fac809c] test.user@example.com 2001-02-03 04:05:09.000 +07:00 af[536e5af6] conflict
my description
8[e4fac809cb] test.user@example.com 2001-02-03 04:05:09.000 +07:00 6f[bba7bcb59]
8[e4fac809c] test.user@example.com 2001-02-03 04:05:09.000 +07:00 6f[bba7bcb5]
my description
8[e4fac809cb] test.user@example.com 2001-02-03 04:05:08.000 +07:00 e[ac0d0dae08]
8[e4fac809c] test.user@example.com 2001-02-03 04:05:08.000 +07:00 e[ac0d0dae0]
(empty) my description
"###);

// Test `--git` format, and that it implies `-p`
let stdout = get_log_output(&test_env, &repo_path, &["obslog", "--no-graph", "--git"]);
insta::assert_snapshot!(stdout, @r###"
8[e4fac809cb] test.user@example.com 2001-02-03 04:05:10.000 +07:00 66[b42ad3607]
8[e4fac809c] test.user@example.com 2001-02-03 04:05:10.000 +07:00 66[b42ad360]
my description
diff --git a/file1 b/file1
index e155302a24...2ab19ae607 100644
Expand All @@ -96,9 +96,9 @@ fn test_obslog_with_or_without_diff() {
-+bar
->>>>>>>
+resolved
8[e4fac809cb] test.user@example.com 2001-02-03 04:05:09.000 +07:00 af[536e5af67] conflict
8[e4fac809c] test.user@example.com 2001-02-03 04:05:09.000 +07:00 af[536e5af6] conflict
my description
8[e4fac809cb] test.user@example.com 2001-02-03 04:05:09.000 +07:00 6f[bba7bcb59]
8[e4fac809c] test.user@example.com 2001-02-03 04:05:09.000 +07:00 6f[bba7bcb5]
my description
diff --git a/file1 b/file1
index 257cc5642c...3bd1f0e297 100644
Expand All @@ -114,7 +114,7 @@ fn test_obslog_with_or_without_diff() {
+++ b/file2
@@ -1,0 +1,1 @@
+foo
8[e4fac809cb] test.user@example.com 2001-02-03 04:05:08.000 +07:00 e[ac0d0dae08]
8[e4fac809c] test.user@example.com 2001-02-03 04:05:08.000 +07:00 e[ac0d0dae0]
(empty) my description
"###);
}
Expand All @@ -136,25 +136,25 @@ fn test_obslog_squash() {

let stdout = get_log_output(&test_env, &repo_path, &["obslog", "-p", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
o 9a[45c67d3e9] test.user@example.com 2001-02-03 04:05:10.000 +07:00 27[e721a5ba7]
o 9a[45c67d3e] test.user@example.com 2001-02-03 04:05:10.000 +07:00 27[e721a5ba]
|\ squashed
| | Modified regular file file1:
| | 1 1: foo
| | 2: bar
o | 9a[45c67d3e9] test.user@example.com 2001-02-03 04:05:09.000 +07:00 97[64e503e1a]
o | 9a[45c67d3e] test.user@example.com 2001-02-03 04:05:09.000 +07:00 97[64e503e1]
| | first
| | Added regular file file1:
| | 1: foo
o | 9a[45c67d3e9] test.user@example.com 2001-02-03 04:05:08.000 +07:00 6[9542c1984c]
o | 9a[45c67d3e] test.user@example.com 2001-02-03 04:05:08.000 +07:00 6[9542c1984]
| | (empty) first
o | 9a[45c67d3e9] test.user@example.com 2001-02-03 04:05:07.000 +07:00 23[0dd059e1b]
o | 9a[45c67d3e] test.user@example.com 2001-02-03 04:05:07.000 +07:00 23[0dd059e1]
/ (empty) (no description set)
o ff[daa62087a] test.user@example.com 2001-02-03 04:05:10.000 +07:00 f[09a38899f2]
o ff[daa62087] test.user@example.com 2001-02-03 04:05:10.000 +07:00 f[09a38899f]
| second
| Modified regular file file1:
| 1 1: foo
| 2: bar
o ff[daa62087a] test.user@example.com 2001-02-03 04:05:09.000 +07:00 5[7996536970]
o ff[daa62087] test.user@example.com 2001-02-03 04:05:09.000 +07:00 5[799653697]
(empty) second
"###);
}
Expand Down

0 comments on commit 139fe08

Please sign in to comment.