mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 06:27:43 +00:00
cli: give root operation special treatment in template (like root commit)
This commit is contained in:
parent
6e302bb3a2
commit
41db64e63c
6 changed files with 51 additions and 41 deletions
|
@ -164,7 +164,12 @@ fn cmd_op_log(
|
|||
None => command.settings().config().get_string("templates.op_log")?,
|
||||
};
|
||||
let template_aliases = command.load_template_aliases(ui)?;
|
||||
let template = operation_templater::parse(current_op_id, &template_string, &template_aliases)?;
|
||||
let template = operation_templater::parse(
|
||||
repo_loader.op_store().root_operation_id(),
|
||||
current_op_id,
|
||||
&template_string,
|
||||
&template_aliases,
|
||||
)?;
|
||||
let with_content_format = LogContentFormat::new(ui, command.settings())?;
|
||||
|
||||
ui.request_pager();
|
||||
|
|
|
@ -91,16 +91,19 @@ concat(
|
|||
'''
|
||||
|
||||
builtin_op_log_compact = '''
|
||||
label(if(current_operation, "current_operation"),
|
||||
concat(
|
||||
separate(" ",
|
||||
id.short(),
|
||||
user,
|
||||
format_time_range(time),
|
||||
) ++ "\n",
|
||||
description.first_line() ++ "\n",
|
||||
if(tags, tags ++ "\n"),
|
||||
),
|
||||
if(root,
|
||||
builtin_op_log_root(id),
|
||||
label(if(current_operation, "current_operation"),
|
||||
concat(
|
||||
separate(" ",
|
||||
id.short(),
|
||||
user,
|
||||
format_time_range(time),
|
||||
) ++ "\n",
|
||||
description.first_line() ++ "\n",
|
||||
if(tags, tags ++ "\n"),
|
||||
),
|
||||
)
|
||||
)
|
||||
'''
|
||||
builtin_op_log_comfortable = 'builtin_op_log_compact ++ "\n"'
|
||||
|
@ -114,6 +117,14 @@ separate(" ",
|
|||
)
|
||||
'''
|
||||
|
||||
'builtin_op_log_root(op_id)' = '''
|
||||
separate(" ",
|
||||
op_id.short(),
|
||||
label("root", "root()"),
|
||||
)
|
||||
'''
|
||||
|
||||
|
||||
description_placeholder = '''
|
||||
label(if(empty, "empty ") ++ "description placeholder", "(no description set)")'''
|
||||
email_placeholder = 'label("email placeholder", "(no email set)")'
|
||||
|
|
|
@ -32,6 +32,7 @@ use crate::templater::{
|
|||
};
|
||||
|
||||
struct OperationTemplateLanguage<'b> {
|
||||
root_op_id: &'b OperationId,
|
||||
current_op_id: Option<&'b OperationId>,
|
||||
}
|
||||
|
||||
|
@ -148,6 +149,10 @@ fn build_operation_keyword(
|
|||
// TODO: introduce dedicated type and provide accessors?
|
||||
format!("{}@{}", metadata.username, metadata.hostname)
|
||||
})),
|
||||
"root" => {
|
||||
let root_op_id = language.root_op_id.clone();
|
||||
language.wrap_boolean(wrap_fn(move |op| op.id() == &root_op_id))
|
||||
}
|
||||
_ => return Err(TemplateParseError::no_such_keyword(name, span)),
|
||||
};
|
||||
Ok(property)
|
||||
|
@ -186,11 +191,15 @@ fn build_operation_id_method(
|
|||
}
|
||||
|
||||
pub fn parse(
|
||||
root_op_id: &OperationId,
|
||||
current_op_id: Option<&OperationId>,
|
||||
template_text: &str,
|
||||
aliases_map: &TemplateAliasesMap,
|
||||
) -> TemplateParseResult<Box<dyn Template<Operation>>> {
|
||||
let language = OperationTemplateLanguage { current_op_id };
|
||||
let language = OperationTemplateLanguage {
|
||||
root_op_id,
|
||||
current_op_id,
|
||||
};
|
||||
let node = template_parser::parse(template_text, aliases_map)?;
|
||||
template_builder::build(&language, &node)
|
||||
}
|
||||
|
|
|
@ -45,8 +45,7 @@ fn test_concurrent_operation_divergence() {
|
|||
│ add workspace 'default'
|
||||
◉ 0e8aee02e242 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
|
||||
// We should be informed about the concurrent modification
|
||||
|
@ -82,8 +81,7 @@ fn test_concurrent_operations_auto_rebase() {
|
|||
│ add workspace 'default'
|
||||
◉ 0e8aee02e242 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
let op_id_hex = stdout[3..15].to_string();
|
||||
|
||||
|
|
|
@ -45,8 +45,7 @@ fn test_op_log() {
|
|||
│ add workspace 'default'
|
||||
◉ 0e8aee02e242 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
let op_log_lines = stdout.lines().collect_vec();
|
||||
let add_workspace_id = op_log_lines[3].split(' ').nth(2).unwrap();
|
||||
|
@ -121,8 +120,7 @@ fn test_op_log_no_graph() {
|
|||
[1madd workspace 'default'[0m
|
||||
[38;5;4m0e8aee02e242[39m [38;5;3mtest-username@host.example.com[39m [38;5;6m2001-02-03 04:05:07.000 +07:00[39m - [38;5;6m2001-02-03 04:05:07.000 +07:00[39m
|
||||
initialize repo
|
||||
[38;5;4m000000000000[39m [38;5;3m@[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m - [38;5;6m1970-01-01 00:00:00.000 +00:00[39m
|
||||
|
||||
[38;5;4m000000000000[39m [38;5;2mroot()[39m
|
||||
"###);
|
||||
}
|
||||
|
||||
|
@ -191,8 +189,7 @@ fn test_op_log_template() {
|
|||
│ add workspace 'default'
|
||||
◉ 0e8aee02e242 test-username@host.example.com NN years ago, lasted less than a microsecond
|
||||
│ initialize repo
|
||||
◉ 000000000000 @ NN years ago, lasted less than a microsecond
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
}
|
||||
|
||||
|
@ -212,8 +209,7 @@ fn test_op_log_builtin_templates() {
|
|||
│ add workspace 'default'
|
||||
◉ 0e8aee02e242 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
|
||||
insta::assert_snapshot!(render(r#"builtin_op_log_comfortable"#), @r###"
|
||||
|
@ -227,9 +223,7 @@ fn test_op_log_builtin_templates() {
|
|||
◉ 0e8aee02e242 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
│
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
}
|
||||
|
||||
|
@ -258,8 +252,7 @@ fn test_op_log_word_wrap() {
|
|||
│ add workspace 'default'
|
||||
◉ 0e8aee02e242 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
insta::assert_snapshot!(render(&["op", "log"], 40, true), @r###"
|
||||
@ 27143b59c690
|
||||
|
@ -272,10 +265,7 @@ fn test_op_log_word_wrap() {
|
|||
│ 2001-02-03 04:05:07.000 +07:00 -
|
||||
│ 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
◉ 000000000000 @ 1970-01-01
|
||||
00:00:00.000 +00:00 - 1970-01-01
|
||||
00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
}
|
||||
|
||||
|
@ -318,8 +308,7 @@ fn test_op_abandon_ancestors() {
|
|||
│ add workspace 'default'
|
||||
◉ 0e8aee02e242 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
|
||||
// Abandon old operations. The working-copy operation id should be updated.
|
||||
|
@ -336,8 +325,7 @@ fn test_op_abandon_ancestors() {
|
|||
@ 1c88fada5b95 test-username@host.example.com 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00
|
||||
│ commit a8ac27b29a157ae7dabc0deb524df68823505730
|
||||
│ args: jj commit -m 'commit 2'
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
|
||||
// Abandon operation range.
|
||||
|
@ -355,8 +343,7 @@ fn test_op_abandon_ancestors() {
|
|||
◉ 1c88fada5b95 test-username@host.example.com 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00
|
||||
│ commit a8ac27b29a157ae7dabc0deb524df68823505730
|
||||
│ args: jj commit -m 'commit 2'
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
|
||||
// Can't abandon the current operation.
|
||||
|
@ -390,8 +377,7 @@ fn test_op_abandon_ancestors() {
|
|||
◉ 1c88fada5b95 test-username@host.example.com 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00
|
||||
│ commit a8ac27b29a157ae7dabc0deb524df68823505730
|
||||
│ args: jj commit -m 'commit 2'
|
||||
◉ 000000000000 @ 1970-01-01 00:00:00.000 +00:00 - 1970-01-01 00:00:00.000 +00:00
|
||||
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
|
||||
// Abandon empty range.
|
||||
|
|
|
@ -50,6 +50,7 @@ The following keywords can be used in `jj op log` templates.
|
|||
* `tags: String`
|
||||
* `time: TimestampRange`
|
||||
* `user: String`
|
||||
* `root: Boolean`: True if the commit is the root commit.
|
||||
|
||||
## Operators
|
||||
|
||||
|
|
Loading…
Reference in a new issue