Skip to content

Commit

Permalink
log: encode elided commit as None (PoC)
Browse files Browse the repository at this point in the history
Note that "if(self && root, ..)" doesn't work because the templater doesn't
support short-circuiting as of now. "if(self, if(root, ..))" works.
  • Loading branch information
yuja committed Mar 18, 2024
1 parent 6d8420e commit 1f3d5f3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 52 deletions.
15 changes: 9 additions & 6 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ pub(crate) fn cmd_log(
.settings()
.config()
.get_bool("ui.log-synthetic-elided-nodes")?;
let template = workspace_command.parse_commit_template(&template_string)?;
let template = {
let language = workspace_command.commit_template_language()?;
workspace_command.parse_template(&language, &template_string)?
};
let with_content_format = LogContentFormat::new(ui, command.settings())?;

{
Expand Down Expand Up @@ -159,7 +162,7 @@ pub(crate) fn cmd_log(
}
let mut buffer = vec![];
let key = (commit_id, false);
let commit = store.get_commit(&key.0)?;
let commit = Some(store.get_commit(&key.0)?);
with_content_format.write_graph_text(
ui.new_formatter(&mut buffer).as_mut(),
|formatter| template.format(&commit, formatter),
Expand All @@ -174,7 +177,7 @@ pub(crate) fn cmd_log(
ui,
formatter.as_mut(),
&workspace_command,
&commit,
commit.as_ref().unwrap(),
matcher.as_ref(),
&diff_formats,
)?;
Expand All @@ -198,7 +201,7 @@ pub(crate) fn cmd_log(
let mut buffer = vec![];
with_content_format.write_graph_text(
ui.new_formatter(&mut buffer).as_mut(),
|formatter| writeln!(formatter.labeled("elided"), "(elided revisions)"),
|formatter| template.format(&None, formatter),
|| graph.width(&elided_key, &edges),
)?;
graph.add_node(
Expand All @@ -216,15 +219,15 @@ pub(crate) fn cmd_log(
Box::new(revset.iter())
};
for commit_or_error in iter.commits(store).take(args.limit.unwrap_or(usize::MAX)) {
let commit = commit_or_error?;
let commit = Some(commit_or_error?);
with_content_format
.write(formatter, |formatter| template.format(&commit, formatter))?;
if !diff_formats.is_empty() {
diff_util::show_patch(
ui,
formatter,
&workspace_command,
&commit,
commit.as_ref().unwrap(),
matcher.as_ref(),
&diff_formats,
)?;
Expand Down
84 changes: 46 additions & 38 deletions cli/src/config/templates.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,52 +41,59 @@ show = 'builtin_log_detailed'

[template-aliases]
builtin_log_oneline = '''
if(root,
builtin_log_root(change_id, commit_id),
label(if(current_working_copy, "working_copy"),
concat(
separate(" ",
builtin_change_id_with_hidden_and_divergent_info,
if(author.email(), author.username(), email_placeholder),
format_timestamp(committer.timestamp()),
branches,
tags,
working_copies,
git_head,
format_short_commit_id(commit_id),
if(conflict, label("conflict", "conflict")),
if(empty, label("empty", "(empty)")),
if(description, description.first_line(), description_placeholder),
) ++ "\n",
if(self,
if(root,
builtin_log_root(change_id, commit_id),
label(if(current_working_copy, "working_copy"),
concat(
separate(" ",
builtin_change_id_with_hidden_and_divergent_info,
if(author.email(), author.username(), email_placeholder),
format_timestamp(committer.timestamp()),
branches,
tags,
working_copies,
git_head,
format_short_commit_id(commit_id),
if(conflict, label("conflict", "conflict")),
if(empty, label("empty", "(empty)")),
if(description, description.first_line(), description_placeholder),
) ++ "\n",
),
),
)
),
elided_revisions_placeholder ++ "\n",
)
'''
builtin_log_compact = '''
if(root,
builtin_log_root(change_id, commit_id),
label(if(current_working_copy, "working_copy"),
concat(
separate(" ",
builtin_change_id_with_hidden_and_divergent_info,
format_short_signature(author),
format_timestamp(committer.timestamp()),
branches,
tags,
working_copies,
git_head,
format_short_commit_id(commit_id),
if(conflict, label("conflict", "conflict")),
) ++ "\n",
separate(" ",
if(empty, label("empty", "(empty)")),
if(description, description.first_line(), description_placeholder),
) ++ "\n",
if(self,
if(root,
builtin_log_root(change_id, commit_id),
label(if(current_working_copy, "working_copy"),
concat(
separate(" ",
builtin_change_id_with_hidden_and_divergent_info,
format_short_signature(author),
format_timestamp(committer.timestamp()),
branches,
tags,
working_copies,
git_head,
format_short_commit_id(commit_id),
if(conflict, label("conflict", "conflict")),
) ++ "\n",
separate(" ",
if(empty, label("empty", "(empty)")),
if(description, description.first_line(), description_placeholder),
) ++ "\n",
),
),
)
),
elided_revisions_placeholder ++ "\n",
)
'''
builtin_log_comfortable = 'builtin_log_compact ++ "\n"'
# TODO: should the detailed (or show) template support elided nodes?
'builtin_log_detailed' = '''
concat(
"Commit ID: " ++ commit_id ++ "\n",
Expand Down Expand Up @@ -138,6 +145,7 @@ separate(" ",

description_placeholder = '''
label(if(empty, "empty ") ++ "description placeholder", "(no description set)")'''
elided_revisions_placeholder = 'label("elided", "(elided revisions)")'
email_placeholder = 'label("email placeholder", "(no email set)")'
name_placeholder = 'label("name placeholder", "(no name set)")'
commit_summary_separator = 'label("separator", " | ")'
Expand Down
17 changes: 9 additions & 8 deletions cli/tests/test_log_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn test_log_with_no_template() {
- builtin_op_log_compact
- commit_summary_separator
- description_placeholder
- elided_revisions_placeholder
- email_placeholder
- name_placeholder
"###);
Expand Down Expand Up @@ -1388,10 +1389,10 @@ fn test_elided() {
├─╮
│ ◉ side branch 2
│ │
│ ◌ (elided revisions)
│ ◌ <Error: No commit available>
◉ │ main branch 2
│ │
◌ │ (elided revisions)
◌ │ <Error: No commit available>
├─╯
◉ initial
Expand All @@ -1403,10 +1404,10 @@ fn test_elided() {
insta::assert_snapshot!(get_log("@-- | root()"), @r###"
◉ side branch 1
(elided revisions)
<Error: No commit available>
│ ◉ main branch 1
│ │
│ ◌ (elided revisions)
│ ◌ <Error: No commit available>
├─╯
"###);
Expand Down Expand Up @@ -1447,10 +1448,10 @@ fn test_custom_symbols() {
├─╮
│ ┝ side branch 2
│ │
│ 🮀 (elided revisions)
│ 🮀 <Error: No commit available>
┝ │ main branch 2
│ │
🮀 │ (elided revisions)
🮀 │ <Error: No commit available>
├─╯
┝ initial
Expand All @@ -1469,10 +1470,10 @@ fn test_custom_symbols() {
|\
| * side branch 2
| |
| : (elided revisions)
| : <Error: No commit available>
* | main branch 2
| |
: | (elided revisions)
: | <Error: No commit available>
|/
* initial
|
Expand Down
1 change: 1 addition & 0 deletions cli/tests/test_obslog_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ fn test_obslog_with_no_template() {
- builtin_op_log_compact
- commit_summary_separator
- description_placeholder
- elided_revisions_placeholder
- email_placeholder
- name_placeholder
"###);
Expand Down
1 change: 1 addition & 0 deletions cli/tests/test_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fn test_op_log_with_no_template() {
- builtin_op_log_compact
- commit_summary_separator
- description_placeholder
- elided_revisions_placeholder
- email_placeholder
- name_placeholder
"###);
Expand Down
1 change: 1 addition & 0 deletions cli/tests/test_show_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fn test_show_with_no_template() {
- builtin_op_log_compact
- commit_summary_separator
- description_placeholder
- elided_revisions_placeholder
- email_placeholder
- name_placeholder
"###);
Expand Down

0 comments on commit 1f3d5f3

Please sign in to comment.