Commit Graph

130 Commits

Author SHA1 Message Date
Velociraptor115
c1b7a6ea52 template: Add support for per-file diff stats
The primary benefit of this change is that it splits
"lines_added()" and "lines_removed()" into separate fields,
which will be useful for tools.

Many tools use "status()", "lines_added()", "lines_removed()",
"source()" and "target()" to show useful information about
every file modified in a commit.

The existing diff stats summary shows only the combined 
number of lines modified, along with a "percentage" representation
of line additions vs. deletions. This is lossy and not
useful for tools, since it is impossible to arrive at
the exact number of lines added and deleted.
2025-12-02 12:59:00 +00:00
Joseph Lou
0b8ecd5c63 template: Add join() function
Sometimes it's useful to add a separator between every argument, even if
it's empty.
2025-11-24 15:47:24 +00:00
Joseph Lou
3f486f3f82 template: Add RepoPath.absolute() method 2025-11-11 03:55:51 +00:00
Björn Kautler
f0b52724f1 docs: clarify substr index meaning 2025-11-11 01:01:18 +00:00
Ilya Grigoriev
9da52f5251 docs templates: document the label function and color labels better
I originally meant to make a smaller change, but I ended up reordering the
discussion of different topics, resulting in a large diff.

Fixes #7778
2025-10-25 05:30:45 +00:00
Yuya Nishihara
ba48317236 templater: add commit.local/remote_tags() methods for completeness 2025-10-16 15:44:50 +00:00
Yuya Nishihara
0fb99c12cc templater: include remote tags in "tags" output
Since we can now update tags internally, local and remote tags may be out of
sync in non-colocated Git repositories. "tags" template should indicate that.
2025-10-16 15:44:50 +00:00
Joseph Lou
c7630f4a3d docs: Add DatePattern type in templating
Functionality remains the same; this only affects the docs. This change
points users to supported formats for the `Timestamp.after()` and
`Timestamp.before()` methods, which can already be found in the revset
"Date pattern" type.
2025-10-14 04:05:09 +00:00
Michael Chirico
20a7faaac9 docs: Add an example with 'description' & coalesce() 2025-10-13 17:23:55 +00:00
Joseph Lou
76fc4a939c docs: Add description to Commit.trailers() 2025-10-12 05:46:54 +00:00
Defelo
b38dcbb919 ssh-signing: include key in verification result 2025-10-08 13:02:43 +00:00
Bryce Berger
b9ad82b97a templates: add remote and * to bookmarks in builtin_log_redacted
Remote names are potentially sensitive? Unsure, so better to redact them.

For getting the "*": This could have been done without modifying the
Rust side, with e.g. `stringify(bookmark).ends_with("*")`. However, this
feels brittle.

With adding `.synced()` to the template language, bookmark formatting
_could_ be done entirely in templates now. I don't know if that's
desired, so leaving for a potential future commmit.
2025-10-08 12:48:27 +00:00
George Christou
9856b38026 template: add string split method 2025-10-07 10:24:28 +00:00
George Christou
1a0e868e5c template: add string replace method 2025-09-19 09:01:07 +00:00
Austin Seipp
8e2820f130 templates: add hyperlink alias 2025-09-09 09:18:12 +00:00
Jade Lovelace
735a27d4ef templates: add string.match function
This allows for any matcher type and allows extracting a capture group
by number.
2025-09-02 02:19:54 +00:00
Jade Lovelace
30bb37967d templates: support string patterns in template language
This is a basic implementation of the same string pattern system as in
the revset language. It's currently only used for `string.matches`, so
you can now do:

```
"foo".matches(regex:'[a-f]o+')
```

In the future this could be added to more string functions (and e.g.
the ability to parse things out of strings could be added).

CC: https://github.com/jj-vcs/jj/issues/6893
2025-09-02 02:19:54 +00:00
Yuya Nishihara
535d8d48dd templater: serialize ConfigValue through toml::Value
We could instead implement serde::Serialize wrapper manually, but it would be
tedious to process recursive data structure. Let's just rely on the toml crate.
The cost of conversion wouldn't matter.
2025-08-25 05:52:46 +00:00
Yuya Nishihara
a4cf4f2ae8 cli: evolog: migrate to evolution template type
This patch doesn't add builtin_evolog_redacted template because I'm not sure if
we want to collect evolution log for debugging purpose. The redacted template
can be added later if needed.
2025-08-21 13:35:21 +00:00
Yuya Nishihara
425b719045 templater: add CommitEvolutionEntry type
I don't have a strong feeling whether we should add "entry.commit() -> Commit"
method or forward method calls to the Commit object, but this patch implements
the former because:

 a. evolution_entry.diff() should return inter diff, whereas commit.diff()
    doesn't.
 b. auto-labeling works if self.commit() is an explicit method call.
 c. the implementation and documentation can be simple.

Tests will be added by the next patch.
2025-08-21 13:35:21 +00:00
George Christou
b89cce9162 template: add any and all methods to lists
This allows checking whether "any" or "all" elements in a list satisfy a given
predicate, similar to Python's native `any()` and `all()` functions, but
instead as list methods that take lambda predicates.

These new methods follow the same pattern as existing `filter` and `map`
operations, i.e. taking a lambda that receives each item and must return a
boolean.
2025-08-16 11:28:35 +00:00
Gaëtan Lehmann
d526a6f0fd template: add a hash function 2025-08-10 19:24:36 +00:00
Scott Taylor
9d8f351a09 docs: display optional arguments more simply
I was initially planning to try adding an `nth` keyword argument to
`parents()` instead of adding `first_parent()`, and I noticed that based
on the current style, it would have been shown as one of the following
in the revset documentation:

* `parents(x[, depth[, [nth=]index]])`
* `parents(x[, depth][, [nth=]index])`

These both seem difficult to read to me, so I'm proposing changing the
style to something more like this:

* `parents(x, [depth], [[nth=]index])`

I also added a brief section explaining the syntax in case it isn't
immediately obvious what the square brackets mean.
2025-08-04 23:56:38 +00:00
Yuya Nishihara
abd7f43507 templater: add commit.files() function to list existing files
I think this can be useful in CLI tests. I noticed there are lots of "jj file
list" calls in https://github.com/jj-vcs/jj/pull/6141 which could be combined
with "jj log" outputs.
2025-08-02 01:30:29 +00:00
Daniel Luz
2c0a1331be annotate: add original line number to template
Fixes #6103.
2025-07-22 20:29:05 +00:00
Josh Steadmon
d7fa04f510 templater: add parents() method for Operation
Add a parents() method for `Operation` template objects, copied from the
implementation for `Commit`s.

The test case added in test_operations.rs was heavily inspired by
test_commit_templates.rs:test_log_parents().

Fixes #6979
2025-07-18 17:16:09 +00:00
Alexander Kobjolke
d858d8cb41 docs: document Commit.signature() 2025-07-08 00:47:52 +00:00
Pavan Kumar Sunkara
c038ef4bc3 workspaces: Add templating support to workspace list 2025-07-07 19:14:07 +00:00
Yuya Nishihara
49fc8abe69 docs: document the purpose of Stringify template type 2025-07-01 00:30:22 +00:00
Yuya Nishihara
e3b6599424 templater: rename PlainText pseudo type to Stringify
Since the goal of this pseudo type is to get a String value, it can be called a
ToString or Stringify. I chose the latter because Stringify sounds similar to
Serialize (verb), and I don't want to rename the internal functions to
.try_into_to_string().

https://github.com/jj-vcs/jj/pull/6840#discussion_r2173076763
2025-07-01 00:30:22 +00:00
Yuya Nishihara
4d3fa2b5d4 docs: show which template types support implicit conversions 2025-06-28 00:40:14 +00:00
Yuya Nishihara
a561fab59c templater: add PlainText/Serialize pseudo types for documentation purpose 2025-06-28 00:40:14 +00:00
Yuya Nishihara
0a60e85525 templater: add json() function
This was discussed in #3219 and #3262, and apparently, people don't agree
whether we should implement machine-readable formatting by using templater.
However, there are recurring requests about JSON output, and "jj api" is still
vaporware. So I think it's good to add some support for JSON output.

I'm not going to add syntax to build custom JSON object/list for now. Instead,
property types such as Commit will implement fixed serialization output. The
user might have to write ad-hoc JSON constructs to concatenate the default JSON
output and their custom JSON fields.

We'll need a documentation about which types are serializable. I think this can
be added later when more types get serialization support.
2025-06-18 18:34:37 +00:00
Yuya Nishihara
1e4c636a02 docs: add section about naming convention of template labels 2025-05-19 01:41:15 +00:00
T6
13c6257aac templater: add arithmetic operators 2025-05-16 12:45:09 +00:00
Yuya Nishihara
a9bae8bc91 templater: deprecate CommitId::normal_hex()
If CommitId and ChangeId were separate types in templates, we wouldn't add
CommitId::normal_hex().
2025-05-16 11:12:33 +00:00
Yuya Nishihara
2d79c6431d templater: introduce newtype to format ref/remote name in revset syntax
This is the last part of the series 02722eae54 "view: port bookmark/tag name
types to RefName/RemoteName." Templater doesn't use these name types internally
because we wouldn't gain much type safety in template language.

The return type of .remote() is changed to Option<RefSymbol>. An empty symbol is
rendered with quotes, so it would be weird if local_bookmark.remote() returned
an empty RefSymbol.
2025-05-13 23:54:47 +00:00
Yuya Nishihara
cb877a94c1 templater: allow comparison between optional and non-optional values
I'm going to add RefSymbol(String) type to format bookmark/remote name in revset
syntax. Since an empty symbol will be rendered differently from an empty string,
bookmark.remote() -> String will be changed to -> Option<RefSymbol>. Then, we'll
need to add support for comparison between optional and non-optional values.

In template language, method call on None produces an error. If we followed this
rule, comparison would have to be expressed as `opt && opt == lit`. I feel this
would be too verbose, and wouldn't help eliminate user error caused by
unintended comparison between Option<T> and T anyway. So this patch implements
comparison by lifting T to Option<T> implicitly.
2025-05-13 00:18:02 +00:00
Vincent Ging Ho Yim
8c4840135f docs/templates: surround type names with backticks in section headings
In particular, this fixes the section heading for the `List<Trailer>` type. Before this
commit, that heading was rendered incorrectly as 'List type'.
2025-05-11 13:14:36 +00:00
Gaëtan Lehmann
2c4a0328f9 templates: add self.trailers().contains_key(key)
as a simpler and more readable alternative to

    self.trailers().filter(|t| t.key() == "Change-Id")
2025-04-29 06:36:12 +00:00
Mateus Auler
968806bc64 templates: implement Commit.trailers() 2025-04-27 18:29:25 +00:00
Nicole Patricia Mazzuca
02687ac7e5 docs: standardize on .method() syntax
In docs/templates.md, the Commit type and Operation type looked like:

`method() -> ReturnType`

rather than everything else, which looks like:

`.method() -> ReturnType`

This commit changes the Commit and Operation types to look more like the
rest of the documentation.
2025-04-04 13:58:33 +00:00
Yuya Nishihara
896424db76 templater: rename RefName type to CommitRef
I'm thinking of adding RefName(str) and RemoteName(str) newtypes, and the
templater type name would conflict with that. Since the templater RefName type
is basically a (name, target) pair, I think it should be called a "Ref", and I
added "Commit" prefix for disambiguation.

This isn't a breaking change since template type names only appear in docs and
error messages.
2025-03-14 14:58:29 +00:00
George Christou
e1abaca21c templater: add trim methods to String type 2025-02-21 21:23:11 +00:00
Andrew Gilbert
5dac0ef4d1 docs templates: add link to templates toml file 2025-02-17 21:02:23 +00:00
Yuya Nishihara
4ec22dde38 templater: port annotation line content to template
I originally thought we would have to add BString template type first, but we
can use opaque Template type instead.
2025-02-15 11:07:17 +00:00
Bryce Berger
3bc111e60e annotate: make AnnotationLine template type
Allows:
* self.commit()
* self.line_number()
* self.first_line_in_hunk()

Certain pagers (like `delta`), when used for `git blame`, only show the
commit information for the first line in a hunk. This would be a nice
addition to `jj file annotate`.

`jj file annotate` already uses a template to control the rendering of
commit information --- `templates.annotate_commit_summary`. Instead of
a custom CLI flag, the tools necessary to do this should be available in
the template language.

If `1 % 2` or `1.is_even()` was available in the template language, this
would also allow alternating colors (using `raw_escape_sequence`).

Example:

```toml
[templates]
# only show commit info for the first line of each hunk
annotate_commit_summary = '''
if(first_line_in_hunk,
  show_commit_info(commit),
  pad_end(20, " "),
)
'''
```
2025-02-15 02:34:38 +00:00
Yuya Nishihara
0d2becbac3 templater: add stringify(x) function to call string methods on template
It's also useful to remove color labels from the inner template.
2025-02-14 00:54:03 +00:00
Yuya Nishihara
78f08d9e6c docs: use single-quoted template string in JSON example
It's easier to parse than \".
2025-02-14 00:54:03 +00:00
hkalbasi
272955f4fe templater: add .escape_json method to string 2025-02-12 22:17:30 +00:00