From 3c61e9239c63ac94f671ad7030cbeb6a0ab6dcfd Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 15 Feb 2023 19:58:18 +0900 Subject: [PATCH] config: remove ui.log-author-format in favor of template alias --- CHANGELOG.md | 5 ++- lib/src/settings.rs | 6 --- src/cli_util.rs | 15 ------- src/config-schema.json | 11 ------ src/config/templates.toml | 1 + tests/test_log_command.rs | 82 +++------------------------------------ 6 files changed, 9 insertions(+), 111 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e808d1733..96549ebb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -155,8 +155,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `author`/`committer` templates now support `.username()`, which leaves out the domain information of `.email()`. -* It is now possible to change the author format of `jj log` with the new - `ui.log-author-format` option. +* It is now possible to change the author format of `jj log` with the + `format_short_signature()` template alias. For details, see + [the documentation](docs/config.md). * Added support for template aliases. New symbols and functions can be configured by `template-aliases. = `. Be aware that diff --git a/lib/src/settings.rs b/lib/src/settings.rs index 934bf5eac..89b189e26 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -164,12 +164,6 @@ impl UserSettings { .unwrap_or(false) } - pub fn log_author_format(&self) -> String { - self.config - .get_string("ui.log-author-format") - .unwrap_or_else(|_| "email".to_owned()) - } - pub fn config(&self) -> &config::Config { &self.config } diff --git a/src/cli_util.rs b/src/cli_util.rs index 04ee8370e..6bf651b4b 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -1544,21 +1544,6 @@ fn load_template_aliases( ) -> Result { const TABLE_KEY: &str = "template-aliases"; let mut aliases_map = TemplateAliasesMap::new(); - - // 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? - let signature_template = match settings.log_author_format().as_str() { - "none" => r#""""#, - "full" => "signature", - "name" => "signature.name()", - "username" => "signature.username()", - _ => "signature.email()", - }; - aliases_map - .insert("format_short_signature(signature)", signature_template) - .unwrap(); - let table = settings.config().get_table(TABLE_KEY)?; for (decl, value) in table.into_iter().sorted_by(|a, b| a.0.cmp(&b.0)) { let r = value diff --git a/src/config-schema.json b/src/config-schema.json index 42490bbbc..aade1fac6 100644 --- a/src/config-schema.json +++ b/src/config-schema.json @@ -107,17 +107,6 @@ } } }, - "log-author-format": { - "enum": [ - "none", - "full", - "name", - "username", - "email" - ], - "default": "email", - "description": "Determines how author information is displayed in `jj log`" - }, "editor": { "type": "string", "description": "Editor to use for commands that involve editing text" diff --git a/src/config/templates.toml b/src/config/templates.toml index be7a26bc7..59b64bffb 100644 --- a/src/config/templates.toml +++ b/src/config/templates.toml @@ -34,6 +34,7 @@ show = 'show' # Hook points for users to customize the default templates: 'format_short_id(id)' = 'id.shortest(12)' +'format_short_signature(signature)' = 'signature.email()' 'format_timestamp(timestamp)' = 'timestamp' # TODO: Add branches, tags, etc diff --git a/tests/test_log_command.rs b/tests/test_log_command.rs index bd998fb54..f47eefc09 100644 --- a/tests/test_log_command.rs +++ b/tests/test_log_command.rs @@ -561,7 +561,7 @@ fn test_log_shortest_length_parameter() { } #[test] -fn test_log_author_format_in_default_template() { +fn test_log_author_format() { let test_env = TestEnvironment::default(); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); @@ -574,91 +574,19 @@ fn test_log_author_format_in_default_template() { ~ "### ); + + let decl = "template-aliases.'format_short_signature(signature)'"; insta::assert_snapshot!( test_env.jj_cmd_success( &repo_path, &[ - "--config-toml=ui.log-author-format=''", + "--config-toml", + &format!("{decl}='signature.username()'"), "log", "--revisions=@", ], ), @r###" - @ qpvuntsmwlqt test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059e1b0 - │ (empty) (no description set) - ~ - "### - ); - insta::assert_snapshot!( - test_env.jj_cmd_success( - &repo_path, - &[ - "--config-toml=ui.log-author-format='gibberish'", - "log", - "--revisions=@", - ], - ), - @r###" - @ qpvuntsmwlqt test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059e1b0 - │ (empty) (no description set) - ~ - "### - ); - insta::assert_snapshot!( - test_env.jj_cmd_success( - &repo_path, - &[ - "--config-toml=ui.log-author-format='email'", - "log", - "--revisions=@", - ], - ), - @r###" - @ qpvuntsmwlqt test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059e1b0 - │ (empty) (no description set) - ~ - "### - ); - insta::assert_snapshot!( - test_env.jj_cmd_success( - &repo_path, - &[ - "--config-toml=ui.log-author-format='none'", - "log", - "--revisions=@", - ], - ), - @r###" - @ qpvuntsmwlqt 2001-02-03 04:05:07.000 +07:00 230dd059e1b0 - │ (empty) (no description set) - ~ - "### - ); - insta::assert_snapshot!( - test_env.jj_cmd_success( - &repo_path, - &[ - "--config-toml=ui.log-author-format='name'", - "log", - "--revisions=@" - ], - ), - @r###" - @ qpvuntsmwlqt Test User 2001-02-03 04:05:07.000 +07:00 230dd059e1b0 - │ (empty) (no description set) - ~ - "### - ); - insta::assert_snapshot!( - test_env.jj_cmd_success( - &repo_path, - &[ - "--config-toml=ui.log-author-format='username'", - "log", - "--revisions=@" - ], - ), - @r###" @ qpvuntsmwlqt test.user 2001-02-03 04:05:07.000 +07:00 230dd059e1b0 │ (empty) (no description set) ~