Skip to content

Commit

Permalink
templates: make op_summary more readable
Browse files Browse the repository at this point in the history
Added colons to make it seem less like an English sentence, see
#4602 (comment)

I believe printing both the start and end times is excessive for a
summary. For now, I have it print just the start time for consistency.
I intend to change it to print the ending time later.

I was a bit torn on whether to use `format_timestamp(self.time().start())`
or `self.time().start().ago()`. The latter looks better, but is less
configurable and worse for dates long ago. In the future, we could add a
`format_op_summary_timestamp` function and/or a template function that
uses `.ago()` for recent dates and absolute dates for old dates.
  • Loading branch information
ilyagr committed Oct 14, 2024
1 parent 7051eff commit e761844
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 69 deletions.
4 changes: 2 additions & 2 deletions cli/src/commands/operation/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ pub fn cmd_op_diff(
let op_summary_template = workspace_command.operation_summary_template();
ui.request_pager();
let mut formatter = ui.stdout_formatter();
write!(formatter, "From operation ")?;
write!(formatter, "From operation: ")?;
op_summary_template.format(&from_op, &mut *formatter)?;
writeln!(formatter)?;
write!(formatter, " To operation ")?;
write!(formatter, " To operation: ")?;
op_summary_template.format(&to_op, &mut *formatter)?;
writeln!(formatter)?;

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/operation/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn cmd_op_restore(
);
tx.repo_mut().set_view(new_view);
if let Some(mut formatter) = ui.status_formatter() {
write!(formatter, "Restored to operation ")?;
write!(formatter, "Restored to operation: ")?;
let template = tx.base_workspace_helper().operation_summary_template();
template.format(&target_op, formatter.as_mut())?;
writeln!(formatter)?;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/operation/undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn cmd_op_undo(
);
tx.repo_mut().set_view(new_view);
if let Some(mut formatter) = ui.status_formatter() {
write!(formatter, "Undid operation ")?;
write!(formatter, "Undid operation: ")?;
let template = tx.base_workspace_helper().operation_summary_template();
template.format(&bad_op, formatter.as_mut())?;
writeln!(formatter)?;
Expand Down
16 changes: 13 additions & 3 deletions cli/src/config/templates.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@ tag_list = '''
label("tag", name) ++ format_ref_targets(self) ++ "\n"
'''

# TODO: Here and elsewhere, the end time for operations is more meaningful than
# the start time. https://github.com/martinvonz/jj/pull/4602#discussion_r1791207491
op_summary = '''
if(root,
separate(" ", self.id().short(), label("root", "root()")),
separate(" ", self.id().short(), format_time_range(self.time()), self.description().first_line())
separate(" ",
self.id().short(),
if(root,
label("root", "root()"),
surround(
"(",
")",
format_timestamp(self.time().start())
)
),
self.description().first_line()
)
'''

Expand Down
4 changes: 2 additions & 2 deletions cli/tests/test_duplicate_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn test_duplicate() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation b5bdbb51ab28 2001-02-03 04:05:17.000 +07:00 - 2001-02-03 04:05:17.000 +07:00 duplicate 1 commit(s)
Undid operation: b5bdbb51ab28 (2001-02-03 08:05:17) duplicate 1 commit(s)
"#);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate" /* duplicates `c` */]);
insta::assert_snapshot!(stdout, @"");
Expand Down Expand Up @@ -280,7 +280,7 @@ fn test_undo_after_duplicate() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation e3dbefa46ed5 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00 duplicate 1 commit(s)
Undid operation: e3dbefa46ed5 (2001-02-03 08:05:11) duplicate 1 commit(s)
"#);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 2443ea76b0b1 a
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_git_colocated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ fn test_git_colocated_undo_head_move() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation b50ec983d1c1 2001-02-03 04:05:13.000 +07:00 - 2001-02-03 04:05:13.000 +07:00 new empty commit
Undid operation: b50ec983d1c1 (2001-02-03 08:05:13) new empty commit
Working copy now at: royxmykx eb08b363 (empty) (no description set)
Parent commit : qpvuntsm 230dd059 (empty) (no description set)
"#);
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_git_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ fn test_git_fetch_undo() {
let (stdout, stderr) = test_env.jj_cmd_ok(&target_jj_repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation eb2029853b02 2001-02-03 04:05:18.000 +07:00 - 2001-02-03 04:05:18.000 +07:00 fetch from git remote(s) origin
Undid operation: eb2029853b02 (2001-02-03 08:05:18) fetch from git remote(s) origin
"#);
// The undo works as expected
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
Expand Down Expand Up @@ -1018,7 +1018,7 @@ fn test_fetch_undo_what() {
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation eac759b9ab75 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Restored to operation: eac759b9ab75 (2001-02-03 08:05:07) add workspace 'default'
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
b (deleted)
Expand Down Expand Up @@ -1047,7 +1047,7 @@ fn test_fetch_undo_what() {
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation eac759b9ab75 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Restored to operation: eac759b9ab75 (2001-02-03 08:05:07) add workspace 'default'
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
newbookmark: qpvuntsm 230dd059 (empty) (no description set)
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_git_import_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn test_git_export_undo() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation b27a68390bea 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00 export git refs
Undid operation: b27a68390bea (2001-02-03 08:05:10) export git refs
"#);
insta::assert_debug_snapshot!(get_git_repo_refs(&git_repo), @r###"
[
Expand Down Expand Up @@ -162,7 +162,7 @@ fn test_git_import_undo() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation eac759b9ab75 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Restored to operation: eac759b9ab75 (2001-02-03 08:05:07) add workspace 'default'
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
// Try "git import" again, which should re-import the bookmark "a".
Expand Down Expand Up @@ -228,7 +228,7 @@ fn test_git_import_move_export_with_default_undo() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation eac759b9ab75 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Restored to operation: eac759b9ab75 (2001-02-03 08:05:07) add workspace 'default'
Working copy now at: qpvuntsm 230dd059 (empty) (no description set)
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"#);
Expand Down
Loading

0 comments on commit e761844

Please sign in to comment.