Skip to content

Commit 00b20e2

Browse files
committed
cli: use same per-commit labels for node and non-node templates
The top-level `immutable` and `conflict` labels we add to commits in the node templates are also useful in the text part. For example, we may want to color change ids for immutable commits differently (we do that at Google). I also added a `mutable` label, to make it easier to define colors for mutable commits without having to define the color for all commits and then overriding it for immutable commits.
1 parent 439536c commit 00b20e2

File tree

4 files changed

+56
-34
lines changed

4 files changed

+56
-34
lines changed

cli/src/config/templates.toml

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ builtin_log_oneline = 'builtin_log_oneline(self)'
145145
'builtin_log_oneline(commit)' = '''
146146
if(commit.root(),
147147
format_root_commit(commit),
148-
label(if(commit.current_working_copy(), "working_copy"),
148+
label(
149+
separate(" ",
150+
if(commit.current_working_copy(), "working_copy"),
151+
if(commit.immutable(), "immutable", "mutable"),
152+
if(commit.conflict(), "conflicted"),
153+
),
149154
concat(
150155
separate(" ",
151156
format_short_change_id_with_hidden_and_divergent_info(commit),
@@ -174,7 +179,12 @@ builtin_log_compact = 'builtin_log_compact(self)'
174179
'builtin_log_compact(commit)' = '''
175180
if(commit.root(),
176181
format_root_commit(commit),
177-
label(if(commit.current_working_copy(), "working_copy"),
182+
label(
183+
separate(" ",
184+
if(commit.current_working_copy(), "working_copy"),
185+
if(commit.immutable(), "immutable", "mutable"),
186+
if(commit.conflict(), "conflicted"),
187+
),
178188
concat(
179189
format_short_commit_header(commit) ++ "\n",
180190
separate(" ",
@@ -193,7 +203,12 @@ builtin_log_redacted = 'builtin_log_redacted(self)'
193203
'builtin_log_redacted(commit)' = '''
194204
if(commit.root(),
195205
format_root_commit(commit),
196-
label(if(commit.current_working_copy(), "working_copy"),
206+
label(
207+
separate(" ",
208+
if(commit.current_working_copy(), "working_copy"),
209+
if(commit.immutable(), "immutable", "mutable"),
210+
if(commit.conflict(), "conflicted"),
211+
),
197212
concat(
198213
format_short_commit_header_redacted(commit) ++ "\n",
199214
separate(" ",
@@ -209,7 +224,12 @@ builtin_log_compact_full_description = 'builtin_log_compact_full_description(sel
209224
'builtin_log_compact_full_description(commit)' = '''
210225
if(commit.root(),
211226
format_root_commit(commit),
212-
label(if(commit.current_working_copy(), "working_copy"),
227+
label(
228+
separate(" ",
229+
if(commit.current_working_copy(), "working_copy"),
230+
if(commit.immutable(), "immutable", "mutable"),
231+
if(commit.conflict(), "conflicted"),
232+
),
213233
concat(
214234
format_short_commit_header(commit) ++ "\n",
215235
separate(" ",
@@ -328,12 +348,14 @@ label(if(commit.current_working_copy(), "working_copy"),
328348
'''
329349

330350
'format_root_commit(root)' = '''
331-
separate(" ",
332-
format_short_change_id(root.change_id()),
333-
label("root", "root()"),
334-
format_short_commit_id(root.commit_id()),
335-
root.bookmarks(),
336-
) ++ "\n"
351+
label("immutable",
352+
separate(" ",
353+
format_short_change_id(root.change_id()),
354+
label("root", "root()"),
355+
format_short_commit_id(root.commit_id()),
356+
root.bookmarks(),
357+
) ++ "\n"
358+
)
337359
'''
338360

339361
'format_ref_targets(ref)' = '''
@@ -467,7 +489,7 @@ coalesce(
467489
label(
468490
separate(" ",
469491
if(current_working_copy, "working_copy"),
470-
if(immutable, "immutable"),
492+
if(immutable, "immutable", "mutable"),
471493
if(conflict, "conflicted"),
472494
),
473495
coalesce(
@@ -486,7 +508,7 @@ coalesce(
486508
label(
487509
separate(" ",
488510
if(current_working_copy, "working_copy"),
489-
if(immutable, "immutable"),
511+
if(immutable, "immutable", "mutable"),
490512
if(conflict, "conflicted"),
491513
),
492514
coalesce(

cli/tests/test_commit_template.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -475,43 +475,43 @@ fn test_log_builtin_templates_colored_debug() {
475475
.success();
476476

477477
insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @r"
478-
<<log commit node working_copy::@>> <<log commit working_copy change_id shortest prefix::r>><<log commit working_copy change_id shortest rest::lvkpnrz>><<log commit working_copy:: >><<log commit working_copy email placeholder::(no email set)>><<log commit working_copy:: >><<log commit working_copy committer timestamp local format::2001-02-03 08:05:08>><<log commit working_copy:: >><<log commit working_copy bookmarks name::my-bookmark>><<log commit working_copy:: >><<log commit working_copy commit_id shortest prefix::a>><<log commit working_copy commit_id shortest rest::ec3ec96>><<log commit working_copy:: >><<log commit working_copy empty::(empty)>><<log commit working_copy:: >><<log commit working_copy empty description placeholder::(no description set)>><<log commit working_copy::>>
479-
<<log commit node::○>> [1m[38;5;5m<<log commit change_id shortest prefix::q>>[0m[38;5;8m<<log commit change_id shortest rest::pvuntsm>>[39m<<log commit:: >>[38;5;3m<<log commit author email local::test.user>>[39m<<log commit:: >>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::e>>[0m[38;5;8m<<log commit commit_id shortest rest::8849ae1>>[39m<<log commit:: >>[38;5;2m<<log commit empty::(empty)>>[39m<<log commit:: >>[38;5;2m<<log commit empty description placeholder::(no description set)>>[39m<<log commit::>>
480-
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit change_id shortest prefix::z>>[0m[38;5;8m<<log commit change_id shortest rest::zzzzzzz>>[39m<<log commit:: >>[38;5;2m<<log commit root::root()>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::0>>[0m[38;5;8m<<log commit commit_id shortest rest::0000000>>[39m<<log commit::>>
478+
<<log commit node working_copy mutable::@>> <<log commit working_copy mutable change_id shortest prefix::r>><<log commit working_copy mutable change_id shortest rest::lvkpnrz>><<log commit working_copy mutable:: >><<log commit working_copy mutable email placeholder::(no email set)>><<log commit working_copy mutable:: >><<log commit working_copy mutable committer timestamp local format::2001-02-03 08:05:08>><<log commit working_copy mutable:: >><<log commit working_copy mutable bookmarks name::my-bookmark>><<log commit working_copy mutable:: >><<log commit working_copy mutable commit_id shortest prefix::a>><<log commit working_copy mutable commit_id shortest rest::ec3ec96>><<log commit working_copy mutable:: >><<log commit working_copy mutable empty::(empty)>><<log commit working_copy mutable:: >><<log commit working_copy mutable empty description placeholder::(no description set)>><<log commit working_copy mutable::>>
479+
<<log commit node mutable::○>> [1m[38;5;5m<<log commit mutable change_id shortest prefix::q>>[0m[38;5;8m<<log commit mutable change_id shortest rest::pvuntsm>>[39m<<log commit mutable:: >>[38;5;3m<<log commit mutable author email local::test.user>>[39m<<log commit mutable:: >>[38;5;6m<<log commit mutable committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit mutable:: >>[1m[38;5;4m<<log commit mutable commit_id shortest prefix::e>>[0m[38;5;8m<<log commit mutable commit_id shortest rest::8849ae1>>[39m<<log commit mutable:: >>[38;5;2m<<log commit mutable empty::(empty)>>[39m<<log commit mutable:: >>[38;5;2m<<log commit mutable empty description placeholder::(no description set)>>[39m<<log commit mutable::>>
480+
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit immutable change_id shortest prefix::z>>[0m[38;5;8m<<log commit immutable change_id shortest rest::zzzzzzz>>[39m<<log commit immutable:: >>[38;5;2m<<log commit immutable root::root()>>[39m<<log commit immutable:: >>[1m[38;5;4m<<log commit immutable commit_id shortest prefix::0>>[0m[38;5;8m<<log commit immutable commit_id shortest rest::0000000>>[39m<<log commit immutable::>>
481481
[EOF]
482482
");
483483

484484
insta::assert_snapshot!(render(r#"builtin_log_compact"#), @r"
485-
[1m[38;5;2m<<log commit node working_copy::@>>[0m [1m[38;5;13m<<log commit working_copy change_id shortest prefix::r>>[38;5;8m<<log commit working_copy change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy:: >>[38;5;9m<<log commit working_copy email placeholder::(no email set)>>[39m<<log commit working_copy:: >>[38;5;14m<<log commit working_copy committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy:: >>[38;5;13m<<log commit working_copy bookmarks name::my-bookmark>>[39m<<log commit working_copy:: >>[38;5;12m<<log commit working_copy commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy::>>[0m
486-
│ [1m[38;5;10m<<log commit working_copy empty::(empty)>>[39m<<log commit working_copy:: >>[38;5;10m<<log commit working_copy empty description placeholder::(no description set)>>[39m<<log commit working_copy::>>[0m
487-
<<log commit node::○>> [1m[38;5;5m<<log commit change_id shortest prefix::q>>[0m[38;5;8m<<log commit change_id shortest rest::pvuntsm>>[39m<<log commit:: >>[38;5;3m<<log commit author email local::test.user>><<log commit author email::@>><<log commit author email domain::example.com>>[39m<<log commit:: >>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::e>>[0m[38;5;8m<<log commit commit_id shortest rest::8849ae1>>[39m<<log commit::>>
488-
│ [38;5;2m<<log commit empty::(empty)>>[39m<<log commit:: >>[38;5;2m<<log commit empty description placeholder::(no description set)>>[39m<<log commit::>>
489-
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit change_id shortest prefix::z>>[0m[38;5;8m<<log commit change_id shortest rest::zzzzzzz>>[39m<<log commit:: >>[38;5;2m<<log commit root::root()>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::0>>[0m[38;5;8m<<log commit commit_id shortest rest::0000000>>[39m<<log commit::>>
485+
[1m[38;5;2m<<log commit node working_copy mutable::@>>[0m [1m[38;5;13m<<log commit working_copy mutable change_id shortest prefix::r>>[38;5;8m<<log commit working_copy mutable change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy mutable:: >>[38;5;9m<<log commit working_copy mutable email placeholder::(no email set)>>[39m<<log commit working_copy mutable:: >>[38;5;14m<<log commit working_copy mutable committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy mutable:: >>[38;5;13m<<log commit working_copy mutable bookmarks name::my-bookmark>>[39m<<log commit working_copy mutable:: >>[38;5;12m<<log commit working_copy mutable commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy mutable commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy mutable::>>[0m
486+
│ [1m[38;5;10m<<log commit working_copy mutable empty::(empty)>>[39m<<log commit working_copy mutable:: >>[38;5;10m<<log commit working_copy mutable empty description placeholder::(no description set)>>[39m<<log commit working_copy mutable::>>[0m
487+
<<log commit node mutable::○>> [1m[38;5;5m<<log commit mutable change_id shortest prefix::q>>[0m[38;5;8m<<log commit mutable change_id shortest rest::pvuntsm>>[39m<<log commit mutable:: >>[38;5;3m<<log commit mutable author email local::test.user>><<log commit mutable author email::@>><<log commit mutable author email domain::example.com>>[39m<<log commit mutable:: >>[38;5;6m<<log commit mutable committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit mutable:: >>[1m[38;5;4m<<log commit mutable commit_id shortest prefix::e>>[0m[38;5;8m<<log commit mutable commit_id shortest rest::8849ae1>>[39m<<log commit mutable::>>
488+
│ [38;5;2m<<log commit mutable empty::(empty)>>[39m<<log commit mutable:: >>[38;5;2m<<log commit mutable empty description placeholder::(no description set)>>[39m<<log commit mutable::>>
489+
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit immutable change_id shortest prefix::z>>[0m[38;5;8m<<log commit immutable change_id shortest rest::zzzzzzz>>[39m<<log commit immutable:: >>[38;5;2m<<log commit immutable root::root()>>[39m<<log commit immutable:: >>[1m[38;5;4m<<log commit immutable commit_id shortest prefix::0>>[0m[38;5;8m<<log commit immutable commit_id shortest rest::0000000>>[39m<<log commit immutable::>>
490490
[EOF]
491491
");
492492

493493
insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @r"
494-
[1m[38;5;2m<<log commit node working_copy::@>>[0m [1m[38;5;13m<<log commit working_copy change_id shortest prefix::r>>[38;5;8m<<log commit working_copy change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy:: >>[38;5;9m<<log commit working_copy email placeholder::(no email set)>>[39m<<log commit working_copy:: >>[38;5;14m<<log commit working_copy committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy:: >>[38;5;13m<<log commit working_copy bookmarks name::my-bookmark>>[39m<<log commit working_copy:: >>[38;5;12m<<log commit working_copy commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy::>>[0m
495-
│ [1m[38;5;10m<<log commit working_copy empty::(empty)>>[39m<<log commit working_copy:: >>[38;5;10m<<log commit working_copy empty description placeholder::(no description set)>>[39m<<log commit working_copy::>>[0m
494+
[1m[38;5;2m<<log commit node working_copy mutable::@>>[0m [1m[38;5;13m<<log commit working_copy mutable change_id shortest prefix::r>>[38;5;8m<<log commit working_copy mutable change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy mutable:: >>[38;5;9m<<log commit working_copy mutable email placeholder::(no email set)>>[39m<<log commit working_copy mutable:: >>[38;5;14m<<log commit working_copy mutable committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy mutable:: >>[38;5;13m<<log commit working_copy mutable bookmarks name::my-bookmark>>[39m<<log commit working_copy mutable:: >>[38;5;12m<<log commit working_copy mutable commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy mutable commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy mutable::>>[0m
495+
│ [1m[38;5;10m<<log commit working_copy mutable empty::(empty)>>[39m<<log commit working_copy mutable:: >>[38;5;10m<<log commit working_copy mutable empty description placeholder::(no description set)>>[39m<<log commit working_copy mutable::>>[0m
496496
│ <<log commit::>>
497-
<<log commit node::○>> [1m[38;5;5m<<log commit change_id shortest prefix::q>>[0m[38;5;8m<<log commit change_id shortest rest::pvuntsm>>[39m<<log commit:: >>[38;5;3m<<log commit author email local::test.user>><<log commit author email::@>><<log commit author email domain::example.com>>[39m<<log commit:: >>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::e>>[0m[38;5;8m<<log commit commit_id shortest rest::8849ae1>>[39m<<log commit::>>
498-
│ [38;5;2m<<log commit empty::(empty)>>[39m<<log commit:: >>[38;5;2m<<log commit empty description placeholder::(no description set)>>[39m<<log commit::>>
497+
<<log commit node mutable::○>> [1m[38;5;5m<<log commit mutable change_id shortest prefix::q>>[0m[38;5;8m<<log commit mutable change_id shortest rest::pvuntsm>>[39m<<log commit mutable:: >>[38;5;3m<<log commit mutable author email local::test.user>><<log commit mutable author email::@>><<log commit mutable author email domain::example.com>>[39m<<log commit mutable:: >>[38;5;6m<<log commit mutable committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit mutable:: >>[1m[38;5;4m<<log commit mutable commit_id shortest prefix::e>>[0m[38;5;8m<<log commit mutable commit_id shortest rest::8849ae1>>[39m<<log commit mutable::>>
498+
│ [38;5;2m<<log commit mutable empty::(empty)>>[39m<<log commit mutable:: >>[38;5;2m<<log commit mutable empty description placeholder::(no description set)>>[39m<<log commit mutable::>>
499499
│ <<log commit::>>
500-
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit change_id shortest prefix::z>>[0m[38;5;8m<<log commit change_id shortest rest::zzzzzzz>>[39m<<log commit:: >>[38;5;2m<<log commit root::root()>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::0>>[0m[38;5;8m<<log commit commit_id shortest rest::0000000>>[39m<<log commit::>>
500+
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit immutable change_id shortest prefix::z>>[0m[38;5;8m<<log commit immutable change_id shortest rest::zzzzzzz>>[39m<<log commit immutable:: >>[38;5;2m<<log commit immutable root::root()>>[39m<<log commit immutable:: >>[1m[38;5;4m<<log commit immutable commit_id shortest prefix::0>>[0m[38;5;8m<<log commit immutable commit_id shortest rest::0000000>>[39m<<log commit immutable::>>
501501
<<log commit::>>
502502
[EOF]
503503
");
504504

505505
insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @r"
506-
[1m[38;5;2m<<log commit node working_copy::@>>[0m <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::aec3ec964d0771edea9da48a2a170bc6ffa1c725>>[39m<<log commit::>>
506+
[1m[38;5;2m<<log commit node working_copy mutable::@>>[0m <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::aec3ec964d0771edea9da48a2a170bc6ffa1c725>>[39m<<log commit::>>
507507
│ <<log commit::Change ID: >><<log commit change_id::rlvkpnrzqnoowoytxnquwvuryrwnrmlp>><<log commit::>>
508508
│ <<log commit::Bookmarks: >><<log commit local_bookmarks name::my-bookmark>><<log commit::>>
509509
│ <<log commit::Author : >><<log commit name placeholder::(no name set)>><<log commit:: <>><<log commit email placeholder::(no email set)>><<log commit::> (>><<log commit author timestamp local format::2001-02-03 08:05:08>><<log commit::)>>
510510
│ <<log commit::Committer: >><<log commit name placeholder::(no name set)>><<log commit:: <>><<log commit email placeholder::(no email set)>><<log commit::> (>><<log commit committer timestamp local format::2001-02-03 08:05:08>><<log commit::)>>
511511
│ <<log commit::>>
512512
│ <<log commit empty description placeholder:: (no description set)>><<log commit::>>
513513
│ <<log commit::>>
514-
<<log commit node::○>> <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::e8849ae12c709f2321908879bc724fdb2ab8a781>>[39m<<log commit::>>
514+
<<log commit node mutable::○>> <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::e8849ae12c709f2321908879bc724fdb2ab8a781>>[39m<<log commit::>>
515515
│ <<log commit::Change ID: >><<log commit change_id::qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu>><<log commit::>>
516516
│ <<log commit::Author : >><<log commit author name::Test User>><<log commit:: <>><<log commit author email local::test.user>><<log commit author email::@>><<log commit author email domain::example.com>><<log commit::> (>><<log commit author timestamp local format::2001-02-03 08:05:07>><<log commit::)>>
517517
│ <<log commit::Committer: >><<log commit committer name::Test User>><<log commit:: <>><<log commit committer email local::test.user>><<log commit committer email::@>><<log commit committer email domain::example.com>><<log commit::> (>><<log commit committer timestamp local format::2001-02-03 08:05:07>><<log commit::)>>

0 commit comments

Comments
 (0)