ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

33 commits

Author SHA1 Message Date
Yuya Nishihara
2bd6983003 templates: reimplement builtin_change_id_with_hidden_and_divergent_info alias
This helps extract commit_summary template as an alias function.
2024-04-26 16:56:35 +09:00
Yuya Nishihara
a63dbcc329 templater: include actual type name in error messages 2024-04-26 00:57:26 +09:00
Yuya Nishihara
1b3bcedd53 cli: label log/obslog template as "log"
It was removed at 522025e091 "log: remove unused and inconsistent `log`
label", but obslog had the same inconsistency. Since it's now easy to label
the template output, let's re-add the "log" label.

The change in test_templater_upper_lower() is noop. Formatter no longer
emits reset sequence in the middle because the template is still labeled.
2024-04-18 11:14:28 +09:00
Anton Älgmyr
2af590eb54 Add template aliases with node symbol configs. 2024-04-15 22:21:31 +02:00
Yuya Nishihara
074e6e12bc revset, templater: include short parse error description in summary line
This makes the summary line more informative. Even though it just duplicates
the message printed later, I think it's easier to follow.

This patch also adjusts some RevsetParseError messages because it seemed
redundant to repeat "revset function", "argument", etc.
2024-03-28 10:53:06 +09:00
Yuya Nishihara
2cd70bdf14 revset, templater: render parse error as usual error chain
Because the CLI error handler now prints error sources in multi-line format,
it doesn't make much sense to render Revset/TemplateParseError differently.

This patch also fixes the source() of the SyntaxError kind. It should be
self.pest_error.source() (= None), not self.pest_error.
2024-03-28 10:53:06 +09:00
Yuya Nishihara
31525705db cli: add "Hint: " or "Warning: " heading to almost all messages
It's inconsistent that some warnings have headings and some don't, and it seems
the choice is arbitrary. Let's unify the style. There are two exceptions:
1. continued line following labeled message,
2. "unrecognized response" followed by prompt.
2024-03-26 11:23:13 +09:00
Yuya Nishihara
82b6d073f1 templater: migrate global functions to table-based lookup
The original plan was to extend the globals table to implement "revset(expr)".
I'm not sure if that's more discoverable than "self.contained_in(revset_expr)"
method, but we can decide that later. Anyways, this patch adds typo suggestion
for global functions.
2024-03-16 10:28:19 +09:00
Yuya Nishihara
7bc4521862 templater: expand similarity hint with aliases
-Tbuiltin now shows the list of the builtin templates, which seems useful.
2024-02-28 09:03:04 +09:00
Yuya Nishihara
71a9dc8304 templater: add similarity hint to no such method/keyword errors
The translation from method error to keyword error can go wrong if the context
object had n-ary methods (n > 0), which isn't the case as of now. For
simplicity, arguments error is mapped to "self.<name>(..)" suggestion.

Local variables and "self" could be merged without using extra method, but
we'll need extend_*_candidates() to merge in symbol/function aliases anyway.
2024-02-28 09:03:04 +09:00
Yuya Nishihara
406f2b6147 templater: retain "++" in parsed tree to provide better error indication 2024-02-09 07:42:54 +09:00
Yuya Nishihara
fd4c5a601c templater: translate symbol rules in error message
This is simplified version of the revset change c4769e0b7c.
2024-02-09 07:42:54 +09:00
Yuya Nishihara
88a1729f8b templater: parse logical operators (||, &&, and !)
These operator symbols are different from the ones in the revset language. I
have no idea if we need bitwise operators, but we'll probably add comparison
operators. It would look weird if 'x == y & z' were parsed as '(x == y) & z'.
2024-02-09 07:42:54 +09:00
jyn
d66fcf2ca0 compile integration tests as a single binary
this greatly speeds up the time to run all tests, at the cost of slightly larger recompile times for individual tests.

this unfortunately adds the requirement that all tests are listed in `runner.rs` for the crate.
to avoid forgetting, i've added a new test that ensures the directory is in sync with the file.

 ## benchmarks

before this change, recompiling all tests took 32-50 seconds and running a single test took 3.5 seconds:

```
; hyperfine 'touch lib/src/lib.rs && cargo t --test test_working_copy'
  Time (mean ± σ):      3.543 s ±  0.168 s    [User: 2.597 s, System: 1.262 s]
  Range (min … max):    3.400 s …  3.847 s    10 runs
```

after this change, recompiling all tests take 4 seconds:
```
;  hyperfine 'touch lib/src/lib.rs ; cargo t --test runner --no-run'
  Time (mean ± σ):      4.055 s ±  0.123 s    [User: 3.591 s, System: 1.593 s]
  Range (min … max):    3.804 s …  4.159 s    10 runs
```
and running a single test takes about the same:
```
; hyperfine 'touch lib/src/lib.rs && cargo t --test runner -- test_working_copy'
  Time (mean ± σ):      4.129 s ±  0.120 s    [User: 3.636 s, System: 1.593 s]
  Range (min … max):    3.933 s …  4.346 s    10 runs
```

about 1.4 seconds of that is the time for the runner, of which .4 is the time for the linker. so
there may be room for further improving the times.
2024-02-06 18:19:41 -08:00
Yuya Nishihara
2874a69faf tests: migrate most tests from test_templater.rs
test_templater_alias(), test_templater_alias_override(), and
test_templater_bad_alias_decl() aren't moved since they also test config loading
and error formatting. The first test in test_templater_parse_error() is left for
the same reason. test_templater_upper_lower() depends on the commit templater.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
957360dc83 tests: use color formatter in core template tests
test_templater_label_function() is migrated as example.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
96f8ca5d54 tests: add minimal template language and test helpers
I don't think many of the tests in test_templater.rs should use "jj log" command
as they check very specific template syntax and function behaviors. Let's move
them to in-module tests. We could add a separate test file, but we would have
to export a couple of templater macros.

test_templater_timestamp_method() is migrated as example.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
b455335983 tests: move test_templater_branches() to test_commit_template.rs
It's not testing the core templater functionality.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
58acc1d111 tests: replace jj_cmd_success() involving mutation to allow stderr output 2023-10-11 19:24:01 +09:00
Martin von Zweigbergk
58de7c292b cli: redefine default log revset using immutable_heads()
I think most users who change the set of immutable heads away from
`trunk() | tags()` are going to also want to change the default log
revset to include the newly mutable commit and to exclude the newly
immutable commits. So let's update the default log revset to use
`immutable_heads()` instead.

`test_templater` changed because we have overridden the set of
immutable commits there so `jj log` now includes the remote branch.
2023-10-01 11:15:30 -07:00
Martin von Zweigbergk
a6ef3f0b6c cli: make set of immutable commits configurable
This adds a new `revset-aliases.immutable_heads()s` config for
defining the set of immutable commits. The set is defined as the
configured revset, as well as its ancestors, and the root commit
commit (even if the configured set is empty).

This patch also adds enforcement of the config where we already had
checks preventing rewrite of the root commit. The working-copy commit
is implicitly assumed to be writable in most cases. Specifically, we
won't prevent amending the working copy even if the user includes it
in the config but we do prevent `jj edit @` in that case. That seems
good enough to me. Maybe we should emit a warning when the working
copy is in the set of immutable commits.

Maybe we should add support for something more like [Mercurial's
phases](https://wiki.mercurial-scm.org/Phases), which is propagated on
push and pull. There's already some affordance for that in the view
object's `public_heads` field. However, this is simpler, especially
since we can't propagate the phase to Git remotes, and seems like a
good start. Also, it lets you say that commits authored by other users
are immutable, for example.

For now, the functionality is in the CLI library. I'm not sure if we
want to move it into the library crate. I'm leaning towards letting
library users do whatever they want without being restricted by
immutable commits. I do think we should move the functionality into a
future `ui-lib` or `ui-util` crate. That crate would have most of the
functionality in the current `cli_util` module (but in a
non-CLI-specific form).
2023-09-25 15:41:45 -07:00
Zachary Dremann
2177dc0657 Allow \0 escape for nulls
This allows safely getting e.g. multiple descriptions, and knowing where the
boundaries are
2023-09-14 17:11:05 -04:00
Yuya Nishihara
e3c85d6ecc revset: convert root symbol to function
The idea is that we can fully eliminate special symbols that would otherwise
shadow user branches, tags, or change ID prefixes.

Closes #2095
2023-09-04 10:36:30 +09:00
Yuya Nishihara
4394bf8de8 templater: add boolean literals
They are implemented as literal expressions so that user cannot override
them by false and true aliases.
2023-09-03 07:01:40 +09:00
Yuya Nishihara
f422f1300c templater: move empty signature placeholder to user template
This patch also extracts format_detailed_signature() function to deduplicate
the "show" template bits.

The added placeholder templates aren't labeled as "empty". If needed, I think
the whole template can be labeled as "empty" (or "empty_commit") just like
"working_copy".

Closes #2112
2023-08-27 09:38:36 +09:00
Yuya Nishihara
b45da80c12 tests: add more tests for empty signature
As I'm going to change the Signature type to not fill out a placeholder
message, we need to test the builtin templates as well.
2023-08-27 09:38:36 +09:00
Yuya Nishihara
88b509f857 tests: do not use "author" template keyword to test string functions
I'm going to change the default formatting of empty Signature type, and
these tests should use a non-empty keyword.
2023-08-27 09:38:36 +09:00
Yuya Nishihara
3f7d884d00 templater: fix offset of negative substr() index to be char-based 2023-08-25 22:59:31 +09:00
Zachary Dremann
ac448202da templates: Add more string methods
Add starts_with/ends_with/remove_prefix/remove_suffix/substr methods to string when templating.
2023-08-24 11:24:07 -04:00
Zachary Dremann
9702a425e5 Allow negative numbers in the template grammar
This allows negative numbers, which also means functions which took numbers can now take negative numbers

Luckily, they all already handled this exactly as expected.
2023-08-24 11:24:07 -04:00
Emily Fox
2062abdc9d templates: replace empty name and email strings with placeholders
New placeholders say "(no name availalbe)" and "(no email available)",
because empty strings aren't _necessarily_ a configuration issue.
2023-08-18 17:22:59 -05:00
Martin von Zweigbergk
f1b817e8ca cleanup: fix warnings from nightly clippy 2023-08-14 22:11:56 -07:00
Martin von Zweigbergk
0075174308 tests: move tests/ under cli/ so they're run again
Thanks to @ilyagr for noticing that they should be moved.
2023-08-05 06:18:59 +00:00
Renamed from tests/test_templater.rs (Browse further)