Skip to content

Commit

Permalink
config: Add commit_timestamp(commit) template alias
Browse files Browse the repository at this point in the history
Adds an extension point for changing which date is displayed in log
formats. The function should return a timestamp, not a formatted string.
  • Loading branch information
jennings committed Dec 18, 2024
1 parent 822f016 commit 598627a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* A new Email template type is added. `Signature.email()` now returns an Email
template type instead of a String.

* Adds a new template alias `commit_timestamp(commit)` which defaults to the
committer date.

### Fixed bugs

* The `$NO_COLOR` environment variable must now be non-empty to be respected.
Expand Down
7 changes: 4 additions & 3 deletions cli/src/config/templates.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ annotate_commit_summary = '''
separate(" ",
change_id.shortest(8),
pad_end(8, truncate_end(8, author.email().local())),
committer.timestamp().local().format('%Y-%m-%d %H:%M:%S'),
commit_timestamp(self).local().format('%Y-%m-%d %H:%M:%S'),
)
'''

Expand Down Expand Up @@ -73,7 +73,7 @@ if(root,
separate(" ",
format_short_change_id_with_hidden_and_divergent_info(self),
if(author.email(), author.email().local(), email_placeholder),
format_timestamp(committer.timestamp()),
format_timestamp(commit_timestamp(self)),
bookmarks,
tags,
working_copies,
Expand Down Expand Up @@ -160,6 +160,7 @@ name_placeholder = 'label("name placeholder", "(no name set)")'
commit_summary_separator = 'label("separator", " | ")'

# Hook points for users to customize the default templates:
'commit_timestamp(commit)' = 'commit.committer.timestamp()'
'format_short_id(id)' = 'id.shortest(8)'
'format_short_change_id(id)' = 'format_short_id(id)'
'format_short_commit_id(id)' = 'format_short_id(id)'
Expand Down Expand Up @@ -256,7 +257,7 @@ if(commit.hidden(),
separate(" ",
format_short_change_id_with_hidden_and_divergent_info(commit),
format_short_signature(commit.author()),
format_timestamp(commit.committer().timestamp()),
format_timestamp(commit_timestamp(commit)),
commit.bookmarks(),
commit.tags(),
commit.working_copies(),
Expand Down
12 changes: 12 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,18 @@ Can be customized by the `format_short_signature()` template alias.
'format_short_signature(signature)' = 'signature.username()'
```

### Commit timestamp

Determines the date shown in log formats. By default, shows the committer
timestamp, but can be changed to show the author timestamp instead. The function
must return a timestamp because the result will likely be formatted with
`format_timestamp()`.

```toml
[template-aliases]
'commit_timestamp(commit)' = 'commit.author.timestamp()'
```

### Allow "large" revsets by default

Certain commands (such as `jj rebase`) can take multiple revset arguments, but
Expand Down

0 comments on commit 598627a

Please sign in to comment.