mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-28 15:34:22 +00:00
config: extract default log template to config/templates.toml
This commit is contained in:
parent
a2bc826cf4
commit
a5a49c8c12
5 changed files with 36 additions and 38 deletions
|
@ -1527,9 +1527,6 @@ pub fn update_working_copy(
|
|||
Ok(stats)
|
||||
}
|
||||
|
||||
pub const DESCRIPTION_PLACEHOLDER_TEMPLATE: &str =
|
||||
r#"label("description", "(no description set)")"#;
|
||||
|
||||
fn load_template_aliases(
|
||||
ui: &mut Ui,
|
||||
settings: &UserSettings,
|
||||
|
@ -1540,9 +1537,6 @@ fn load_template_aliases(
|
|||
// TODO: Reorganize default template aliases and config knobs:
|
||||
// - remove these configs and let user override aliases?
|
||||
// - separate namespace or config section for these "default" aliases? but how?
|
||||
aliases_map
|
||||
.insert("description_placeholder", DESCRIPTION_PLACEHOLDER_TEMPLATE)
|
||||
.unwrap();
|
||||
let timestamp_template = if settings.relative_timestamps() {
|
||||
"timestamp.ago()"
|
||||
} else {
|
||||
|
|
|
@ -1405,33 +1405,6 @@ fn cmd_status(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn log_template(settings: &UserSettings) -> String {
|
||||
let default_template = r#"
|
||||
label(if(current_working_copy, "working_copy"),
|
||||
separate(" ",
|
||||
if(divergent,
|
||||
label("divergent", format_short_id(change_id) "??"),
|
||||
format_short_id(change_id)),
|
||||
format_short_signature(author),
|
||||
format_timestamp(committer.timestamp()),
|
||||
branches,
|
||||
tags,
|
||||
working_copies,
|
||||
git_head,
|
||||
format_short_id(commit_id),
|
||||
if(conflict, label("conflict", "conflict")),
|
||||
)
|
||||
"\n"
|
||||
if(empty, label("empty", "(empty)") " ")
|
||||
if(description, description.first_line(), description_placeholder)
|
||||
"\n"
|
||||
)"#;
|
||||
settings
|
||||
.config()
|
||||
.get_string("template.log.graph")
|
||||
.unwrap_or(default_template.to_owned())
|
||||
}
|
||||
|
||||
fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), CommandError> {
|
||||
let workspace_command = command.workspace_helper(ui)?;
|
||||
|
||||
|
@ -1455,7 +1428,10 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
|
|||
|
||||
let template_string = match &args.template {
|
||||
Some(value) => value.to_string(),
|
||||
None => log_template(command.settings()),
|
||||
None => command
|
||||
.settings()
|
||||
.config()
|
||||
.get_string("template.log.graph")?,
|
||||
};
|
||||
let template = workspace_command.parse_commit_template(&template_string)?;
|
||||
|
||||
|
@ -1588,7 +1564,10 @@ fn cmd_obslog(ui: &mut Ui, command: &CommandHelper, args: &ObslogArgs) -> Result
|
|||
|
||||
let template_string = match &args.template {
|
||||
Some(value) => value.to_string(),
|
||||
None => log_template(command.settings()),
|
||||
None => command
|
||||
.settings()
|
||||
.config()
|
||||
.get_string("template.log.graph")?,
|
||||
};
|
||||
let template = workspace_command.parse_commit_template(&template_string)?;
|
||||
|
||||
|
|
|
@ -242,6 +242,7 @@ pub fn default_config() -> config::Config {
|
|||
.add_source(from_toml!("config/colors.toml"))
|
||||
.add_source(from_toml!("config/merge_tools.toml"))
|
||||
.add_source(from_toml!("config/misc.toml"))
|
||||
.add_source(from_toml!("config/templates.toml"))
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
@ -7,6 +7,3 @@ fetch = "origin"
|
|||
|
||||
[revset-aliases]
|
||||
# Placeholder: added by user
|
||||
|
||||
[template-aliases]
|
||||
# Placeholder: added by user
|
||||
|
|
27
src/config/templates.toml
Normal file
27
src/config/templates.toml
Normal file
|
@ -0,0 +1,27 @@
|
|||
# TODO: rename section to [templates]?
|
||||
[template]
|
||||
# TODO: drop '.graph'?
|
||||
log.graph = '''
|
||||
label(if(current_working_copy, "working_copy"),
|
||||
separate(" ",
|
||||
if(divergent,
|
||||
label("divergent", format_short_id(change_id) "??"),
|
||||
format_short_id(change_id)),
|
||||
format_short_signature(author),
|
||||
format_timestamp(committer.timestamp()),
|
||||
branches,
|
||||
tags,
|
||||
working_copies,
|
||||
git_head,
|
||||
format_short_id(commit_id),
|
||||
if(conflict, label("conflict", "conflict")),
|
||||
)
|
||||
"\n"
|
||||
if(empty, label("empty", "(empty)") " ")
|
||||
if(description, description.first_line(), description_placeholder)
|
||||
"\n"
|
||||
)
|
||||
'''
|
||||
|
||||
[template-aliases]
|
||||
'description_placeholder' = 'label("description", "(no description set)")'
|
Loading…
Reference in a new issue