From 0f2573abaeed2c007a63de197e50c1940409af2b Mon Sep 17 00:00:00 2001 From: Anton Bulakh Date: Fri, 5 Apr 2024 14:35:29 +0300 Subject: [PATCH] templates: Split oplog template into hookable functions This is to allow modifying default templates without completely overriding them, for example to change the oplog snapshots but keep other defaults --- CHANGELOG.md | 2 ++ cli/src/config/templates.toml | 36 ++++++++++++++++------------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dffe00f6b..4e0708403 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking changes +* The default template alias `builtin_op_log_root(op_id: OperationId)` was replaced by `format_root_operation(root: Operation)`. + ### New features * The list of conflicted paths is printed whenever the working copy changes. diff --git a/cli/src/config/templates.toml b/cli/src/config/templates.toml index 80b0f9aa6..d1e4e2d4f 100644 --- a/cli/src/config/templates.toml +++ b/cli/src/config/templates.toml @@ -102,18 +102,11 @@ concat( ''' builtin_op_log_compact = ''' -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"), - ), +label(if(current_operation, "current_operation"), + coalesce( + if(snapshot, format_snapshot_operation(self)), + if(root, format_root_operation(self)), + format_operation(self), ) ) ''' @@ -128,13 +121,6 @@ separate(" ", ) ++ "\n" ''' -'builtin_op_log_root(op_id)' = ''' -separate(" ", - op_id.short(), - label("root", "root()"), -) ++ "\n" -''' - description_placeholder = ''' label(if(empty, "empty ") ++ "description placeholder", "(no description set)")''' @@ -156,12 +142,22 @@ commit_summary_separator = 'label("separator", " | ")' time_range.start().ago() ++ label("time", ", lasted ") ++ time_range.duration()''' 'format_timestamp(timestamp)' = 'timestamp.local().format("%Y-%m-%d %H:%M:%S")' +'format_operation(op)' = ''' + concat( + separate(" ", op.id().short(), op.user(), format_time_range(op.time())), "\n", + op.description().first_line(), "\n", + if(op.tags(), op.tags() ++ "\n"), + ) +''' +'format_snapshot_operation(op)' = 'format_operation(op)' +'format_root_operation(root)' = 'separate(" ", root.id().short(), label("root", "root()")) ++ "\n"' + # We have "hidden" override "divergent", since a hidden revision does not cause # change id conflicts and is not affected by such conflicts; you have to use the # commit id to refer to a hidden revision regardless. builtin_change_id_with_hidden_and_divergent_info = ''' if(hidden, - label("hidden", + label("hidden", format_short_change_id(change_id) ++ " hidden" ), label(if(divergent, "divergent"),