Skip to content

Commit fa3254b

Browse files
committed
templates: add hook points for users to customize the default operation id
Same as `format_short_change_id`. We can't use `format_short_id` because `operation.id()` does not have `shortest()` method.
1 parent 3bfbec1 commit fa3254b

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7070
Provides `self.commit()`, `.content()`, `.line_number()`, and
7171
`.first_line_in_hunk()`.
7272

73+
* Templates now have `format_short_operation_id(id)` function for users to
74+
customize the default operation id representation.
75+
7376
### Fixed bugs
7477

7578
* `jj status` now shows untracked files under untracked directories.

cli/src/config/templates.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ commit_summary_separator = 'label("separator", " | ")'
184184
'format_short_id(id)' = 'id.shortest(8)'
185185
'format_short_change_id(id)' = 'format_short_id(id)'
186186
'format_short_commit_id(id)' = 'format_short_id(id)'
187+
'format_short_operation_id(id)' = 'id.short()'
187188
'format_short_signature(signature)' = '''
188189
coalesce(signature.email(), email_placeholder)'''
189190
'format_detailed_signature(signature)' = '''
@@ -251,7 +252,7 @@ if(ref.tracking_present(), surround("(", ")", separate(", ",
251252

252253
'format_operation(op)' = '''
253254
concat(
254-
separate(" ", op.id().short(), op.user(), format_time_range(op.time())), "\n",
255+
separate(" ", format_short_operation_id(op.id()), op.user(), format_time_range(op.time())), "\n",
255256
op.description().first_line(), "\n",
256257
if(op.tags(), op.tags() ++ "\n"),
257258
)
@@ -262,7 +263,7 @@ concat(
262263

263264
'format_operation_oneline(op)' = '''
264265
separate(" ",
265-
op.id().short(), op.user(), format_time_range(op.time()),
266+
format_short_operation_id(op.id()), op.user(), format_time_range(op.time()),
266267
op.description().first_line(),
267268
if(op.tags(), op.tags()),
268269
) ++ "\n"

docs/config.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,14 @@ To customize these separately, use the `format_short_commit_id()` and
465465
'format_short_change_id(id)' = 'format_short_id(id).upper()'
466466
```
467467

468+
Operation ids can be customized by the `format_short_operation_id()` alias:
469+
470+
```toml
471+
[template-aliases]
472+
# Always show 12 characters
473+
'format_short_operation_id(id)' = 'id.short(12)'
474+
```
475+
468476
To get shorter prefixes for certain revisions, set `revsets.short-prefixes`:
469477

470478
```toml

0 commit comments

Comments
 (0)