templater: Add operation.snapshot() boolean

Expose the information we now record, to allow changing the default "snapshot
working copy" message or to make snapshots more compact/less distracting in
the log
This commit is contained in:
Anton Bulakh 2024-04-05 14:21:36 +03:00
parent f4fb8f18a7
commit 29729e844d
3 changed files with 21 additions and 8 deletions

View file

@ -30,6 +30,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* File path arguments now support [file pattern
syntax](docs/filesets.md#file-patterns).
* Operation objects in templates now have a `snapshot() -> Boolean` method that
evaluates to true if the operation was a snapshot created by a non-mutating
command (e.g. `jj log`).
### Fixed bugs
* Revsets now support `\`-escapes in string literal.
@ -231,7 +235,7 @@ No code changes (fixing Rust `Cargo.toml` stuff).
When symlink support is unavailable, they will be materialized as regular files in the
working copy (instead of resulting in a crash).
[#2](https://github.com/martinvonz/jj/issues/2)
* On Windows, the `:builtin` pager is now used by default, rather than being
disabled entirely.
@ -278,7 +282,7 @@ Thanks to the people who made this release happen!
copy commit on top of a single specified revision, i.e. with one parent.
`merge` creates a new working copy commit on top of *at least* two specified
revisions, i.e. with two or more parents.
The only difference between these commands and `jj new`, which *also* creates
a new working copy commit, is that `new` can create a working copy commit on
top of any arbitrary number of revisions, so it can handle both the previous
@ -435,7 +439,7 @@ Thanks to the people who made this release happen!
* `jj branch set` no longer creates a new branch. Use `jj branch create`
instead.
* `jj init --git` in an existing Git repository now errors and exits rather than
creating a second Git store.
@ -599,8 +603,8 @@ Thanks to the people who made this release happen!
### New features
* The `ancestors()` revset function now takes an optional `depth` argument
to limit the depth of the ancestor set. For example, use `jj log -r
* The `ancestors()` revset function now takes an optional `depth` argument
to limit the depth of the ancestor set. For example, use `jj log -r
'ancestors(@, 5)` to view the last 5 commits.
* Support for the Watchman filesystem monitor is now bundled by default. Set
@ -765,13 +769,13 @@ Thanks to the people who made this release happen!
respectively.
* `jj log` timestamp format now accepts `.utc()` to convert a timestamp to UTC.
* templates now support additional string methods `.starts_with(x)`, `.ends_with(x)`
`.remove_prefix(x)`, `.remove_suffix(x)`, and `.substr(start, end)`.
* `jj next` and `jj prev` are added, these allow you to traverse the history
in a linear style. For people coming from Sapling and `git-branchles`
see [#2126](https://github.com/martinvonz/jj/issues/2126) for
see [#2126](https://github.com/martinvonz/jj/issues/2126) for
further pending improvements.
* `jj diff --stat` has been implemented. It shows a histogram of the changes,

View file

@ -249,6 +249,14 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap<Operation> {
});
Ok(L::wrap_string(out_property))
});
map.insert(
"snapshot",
|_language, _build_ctx, self_property, function| {
template_parser::expect_no_arguments(function)?;
let out_property = self_property.map(|op| op.metadata().is_snapshot);
Ok(L::wrap_boolean(out_property))
},
);
map.insert("time", |_language, _build_ctx, self_property, function| {
template_parser::expect_no_arguments(function)?;
let out_property = self_property.map(|op| TimestampRange {

View file

@ -133,7 +133,8 @@ This type cannot be printed. The following methods are defined.
* `tags() -> String`
* `time() -> TimestampRange`
* `user() -> String`
* `root() -> Boolean`: True if the commit is the root commit.
* `snapshot() -> Boolean`: True if the operation is a snapshot operation.
* `root() -> Boolean`: True if the operation is the root operation.
### OperationId type