Commit graph

841 commits

Author SHA1 Message Date
Martin von Zweigbergk
e51878f4fd cli: show timestamp in local timezone and without millis and offset
As discussed in #2900, the milliseconds are rarely useful, and it can
be confusing with different timezones because it makes harder to
compare timestamps.

I added an environment variable to control the timestamp in a
cross-platform way. I didn't document because it exists only for tests
(like `JJ_RANDOMNESS_SEED`).

Closes #2900
2024-03-20 07:54:08 -07:00
Ilya Grigoriev
4fbe6aecc9 clippy: remove some unused code beta clippy/rustc compain about
There are still some warnings from (seemingly) clippy bugs. Quoting
myself from Discord:

> PSA: the latest beta cargo clippy (from Rust 1.78) has some problems
> that affect jj: https://github.com/rust-lang/rust-clippy/issues/12467
> and https://github.com/rust-lang/rust-clippy/issues/12377.  You could
> disable clippy::assigning_clones and clippy::empty_docs as a workaround.
> VS Code can disable them in rust-analyzer, you can also use
> https://github.com/ericseppanen/cargo-cranky (you can put Cranky.toml in
> the per-user gitignore).
2024-03-19 18:33:29 -07:00
Yuya Nishihara
54bb3b4114 cli: remove last use of resolve_multiple_nonempty_revsets() from cmd_run() 2024-03-18 18:23:03 +09:00
Tom Ward
933150d819 cli: allow colors in form #rrggbb
Changes the formatter to accept not only existing color names (such as "red" or
"green") but also those in the form #rrggbb, where rr, gg, and bb are two-digit
hexadecimal numbers. This allows much finer control over colors used.
2024-03-18 08:03:31 +00:00
Yuya Nishihara
3ffe3d9ed8 git-push: warn unmatched revision set per "-rREVISIONS" argument
If -rREVISIONS is specified, the user would probably expect the set contains
at least one local branch.
2024-03-18 09:32:43 +09:00
Yuya Nishihara
8de3932bda git-push: narrow search space of -rREVISIONS 2024-03-18 09:32:43 +09:00
Yuya Nishihara
bc7a42a00e git-push: do not error out on empty revision set
"-r REVISIONS" here specifies the search space of the branches to push, and
warned if no branches are found in that space. I don't think an empty set
should be an error, but a warning for consistency. The warning message will be
improved by the subsequent patches.
2024-03-18 09:32:43 +09:00
Yuya Nishihara
02c0927734 git-push: extract function that looks up branches by revisions
cmd_git_push() is large. Let's split it up.
2024-03-18 09:32:43 +09:00
Yuya Nishihara
4e9d35d049 cli: make "abandon" not fail with empty revset
This command belongs to the same category as "duplicate".

We might want a plural version of resolve_revset(), but I'm not sure whether
it should return Vec<Commit> or Revset. Let's revisit it later when we get
more callers.
2024-03-18 09:32:35 +09:00
Yuya Nishihara
f678ba08cf cli: make "duplicate none()" exit successfully
Per discussion in
https://github.com/martinvonz/jj/pull/3311#discussion_r1527171058

We can also rely on the default "Nothing changed." handling, but it seems
better to state the input set is empty.
2024-03-18 09:32:35 +09:00
Yuya Nishihara
f46b738f6e cli: include root() in the heads node of the immutable set expression
It helps to optimize '~immutable()' to '(immutable_heads() | root())..'.
2024-03-17 14:50:48 +09:00
Yuya Nishihara
50363419fb revset: substitute '~(::x)' to 'x..'
Suppose we have an alias 'immutable()' = '::immutable_heads()', user can
express (visible) mutable set as '~immutable()'. 'immutable_heads()..' can
terminate early, but a generic difference 'all() & ~immutable()' can't.
2024-03-17 14:50:48 +09:00
Yuya Nishihara
9207314173 revset: add substitution rule for "::x & ~(::y-)"
Suppose the generation value is usually small, it should be faster to do
bounded range look up first 'y-', then walk ancestors with the unwanted set
'y-..x'.
2024-03-17 14:50:48 +09:00
Yuya Nishihara
b2194d7d2b cli: use present tense "duplicate" in transaction description 2024-03-17 11:44:41 +09:00
Yuya Nishihara
dc7d1beff3 cli: remove .unwrap() from cmd_duplicate() and simplify new commits mapping 2024-03-17 11:44:41 +09:00
Yuya Nishihara
4e3c772428 cli: make "duplicate" evaluate source revisions all at once
There's a subtle behavior change that an empty revset is no longer rejected
individually, but I think that's good for "jj duplicate".

cmd_duplicate() was the last caller of index.topo_order().
2024-03-17 11:44:41 +09:00
Yuya Nishihara
a1b3b3c547 cli: extract helper that concatenates multiple revision args
I'm going to add one more callers.
2024-03-17 11:44:41 +09:00
dploch
d832b4488c operation_templater: support extensions of the template language 2024-03-16 10:32:53 -04:00
Martin von Zweigbergk
c55e08023e workspace: don't lose sparsed-away paths when recovering workspace
When an operation is missing and we recover the workspace, we create a
new working-copy commit on top of the desired working-copy commit (per
the available head operation). We then reset the working copy to an
empty tree because it shouldn't really matter much which commit we
reset to. However, when the workspace is sparse, it does matter, as
the test case from the previous patch shows. This patch fixes it by
replacing the `reset_to_empty()` method by a new `recover(&Commit)`,
which effectively resets to the empty tree and then resets to the
commit. That way, any subsequent snapshotting will result keep the
paths from that tree for paths outside the sparse patterns.
2024-03-16 07:30:36 -07:00
Martin von Zweigbergk
ffb12680a6 tests: demonstrate sparsed-away paths lost on stale-workspace recovery
As shown by the updated test case, when we recover from a working copy
pointing to a lost operation, the new working-copy commit after
snapshotting will have lost any files outside the sparse patterns.
2024-03-16 07:30:36 -07:00
Martin von Zweigbergk
0d197791a0 tests: add unsnapshotted changes in secondary workspace in recovery test
This adds modifed, removed, and added files in the secondary working
copy.
2024-03-16 07:30:36 -07:00
Martin von Zweigbergk
df9434bd4b tests: use short commit ids in workspace tests
It doesn't look like we need the full ids for anything and the full
ids are especially distracting in the test that uses the native
backend.
2024-03-16 07:30:36 -07:00
Alexis (Poliorcetics) Bourget
93c707a469 lib: improve error message for invalid string pattern, suggesting to use one of the known one 2024-03-16 14:22:16 +01:00
Ilya Grigoriev
8600750fce merge tools: split DiffEditWorkingCopies from DiffWorkingCopies
As suggested by @yuja in https://github.com/martinvonz/jj/pull/3296#discussion_r1525829712
2024-03-15 21:35:57 -07:00
Ilya Grigoriev
6a63c705aa merge tools: rename variable to make diff for the next commit simpler 2024-03-15 21:35:57 -07:00
Yuya Nishihara
429cdb38d7 cli: don't bury GitImportError sources
#3301
2024-03-16 12:51:18 +09:00
Yuya Nishihara
a6ee51a998 cli: move revset::optimize() invocation from parse() to evaluate()
AST substitution is technically closer to parsing, but the parsed expression
can be modified further by caller. So I think it's better to do optimize() in
later pass.

revset_util::parse() is inlined.
2024-03-16 10:28:27 +09:00
Yuya Nishihara
70a2a44f42 cli: ensure revset bench does not include cost of short-prefixes computation
Spotted while moving revset::optimize() around. Since we don't include the
parsing cost of the target expression, we shouldn't include parsing/evaluation
cost of the short-prefixes either. The IdPrefixContext is currently populated
by WorkspaceCommandHelper::new(), but it's hard to tell.
2024-03-16 10:28:27 +09:00
Yuya Nishihara
97cf16c77d cli: use unresolved root() when constructing immutable set expression
The immutable set expression has to be resolved anyway, so it's simpler to
use RevsetExpression::root().
2024-03-16 10:28:27 +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
85f2f3a439 templater: generalize merge_fn_map() helper
The global function type is slightly different from method calls.
2024-03-16 10:28:19 +09:00
Yuya Nishihara
fa9cb72445 templater: dispatch global functions through TemplateLanguage trait
Prepares for migrating to table-based lookup. It's unlikely that the
implementor handles global function calls differently, but the core doesn't
have an access to the customized symbol table.
2024-03-16 10:28:19 +09:00
Yuya Nishihara
1e8bf8426c templater: consolidate auto labeling into build_expression()
Now almost all build_*() functions return L::Property, so it seems more
consistent to do labeling in one place.
2024-03-16 10:28:19 +09:00
Yuya Nishihara
5ec56fb3e9 templater: inline build_method_call()
I don't think this function will grow to unmaintainable size, and I'm going
to add global function dispatcher there.
2024-03-16 10:28:19 +09:00
Ilya Grigoriev
0120cf994b external diff editor: move utility functions to a new file
This is preparation for #3292, which will use these functions. The main
goal is to merge the parts of #3292 that are likely to cause merge
conflicts with other PRs while I polish it up.
2024-03-15 12:30:37 -07:00
Ilya Grigoriev
d5a4891b49 external diff editor: extract functions to populate and delete JJ_INSTRUCTIONS
This will be reused for integration with the new `:builtin-web` diff editor in #3292.

`instructions-path_to_cleanup` is moved into DiffWorkingCopies.

DiffWorkingCopies: add instructions_path_to_cleanup
2024-03-15 12:30:37 -07:00
Martin von Zweigbergk
3bb9fd412a debug-tree: allow looking up tree by path and id, not just revision
Sometimes only a tree has been created, so we shouldn't require a
commit for `jj debug tree`.
2024-03-14 23:28:59 -07:00
Khionu Sybiern
3bbc3e5715 docs: add FAQ for why to use new-then-amend over edit 2024-03-14 11:32:53 -07:00
Khionu Sybiern
289b9bc71f cli: update help message for jj edit
This change updates the language of `jj edit`'s help message to be
more clear as to the nature of the command. It also adds a 
recommendation for a more idiomatic/safer workflow.
2024-03-14 11:32:53 -07:00
Yuya Nishihara
e3303efcf3 cli_util: inline WorkspaceCommandHelper::check_non_empty()
It's simple, and has no data dependency.
2024-03-14 23:51:21 +09:00
Yuya Nishihara
218b1c6c16 commit_templater: add self.immutable() method
I don't know how immutable revisions should be labeled by default, but users
can customize templates whatever they like.
2024-03-14 22:59:43 +09:00
Yuya Nishihara
04d5f59cbb templater: do not rewrite non-argument errors raised from self methods
I'm going to add new "self.immutable()" method, which takes no arguments but
can fail if the configured revset is wrong.
2024-03-14 22:59:43 +09:00
Yuya Nishihara
78104b5e82 cli: extract function that stringifies RevsetParseError 2024-03-14 22:59:43 +09:00
Yuya Nishihara
34eb446037 cli: remove CommandError dependency from revset_util::evaluate()
This function will be called from the templater.
2024-03-14 22:59:43 +09:00
Yuya Nishihara
7dfe04134d cli: check invalid declaration of immutable_heads() alias earlier
I just wanted to remove CommandError from parse_immutable_expression(), which
will be called from the templater, but the new error message looks also better.
2024-03-14 22:59:43 +09:00
Yuya Nishihara
8235e458ed cli: extract primitives for user revset parsing and evaluation
Some of them will be called directly from the commit templater which shouldn't
know WorkspaceCommandHelper. All parameters are passed as function arguments
instead of having a nicer wrapper struct. That's because some resources (e.g.
repo and id prefix context) are also used for different purposes, and it seemed
uneasy to introduce high-level abstraction satisfying all the use cases.
2024-03-14 22:59:43 +09:00
Yuya Nishihara
5806dbfd32 revset_graph: detach CompositeIndex, reimplement as RevWalk
For API consistency. It wouldn't practically matter unless we want to reuse
.iter_graph() in lazy event-driven GUI context.

I don't see significant performance difference:
- jj-0: original impl with look-ahead IndexEntry<'_> buffer
- jj-1: this patch

With dense graph
```
% hyperfine --sort command --warmup 3 --runs 10 -L bin jj-0,jj-1 \
  "target/release-with-debug/{bin} -R ~/mirrors/git --ignore-working-copy log -r.. -T ''"
Benchmark 1: target/release-with-debug/jj-0 -R ~/mirrors/git --ignore-working-copy log -r.. -T ''
  Time (mean ± σ):      1.367 s ±  0.008 s    [User: 1.261 s, System: 0.105 s]
  Range (min … max):    1.357 s …  1.380 s    10 runs

Benchmark 2: target/release-with-debug/jj-1 -R ~/mirrors/git --ignore-working-copy log -r.. -T ''
  Time (mean ± σ):      1.344 s ±  0.017 s    [User: 1.245 s, System: 0.099 s]
  Range (min … max):    1.313 s …  1.369 s    10 runs

Relative speed comparison
        1.02 ±  0.01  target/release-with-debug/jj-0 -R ~/mirrors/git --ignore-working-copy log -r.. -T ''
        1.00          target/release-with-debug/jj-1 -R ~/mirrors/git --ignore-working-copy log -r.. -T ''
```

With sparse graph
```
% hyperfine --sort command --warmup 3 --runs 10 -L bin jj-0,jj-1 \
  "target/release-with-debug/{bin} -R ~/mirrors/git --ignore-working-copy log -r'tags()' -T ''"
Benchmark 1: target/release-with-debug/jj-0 -R ~/mirrors/git --ignore-working-copy log -r'tags()' -T ''
  Time (mean ± σ):      1.347 s ±  0.017 s    [User: 1.216 s, System: 0.130 s]
  Range (min … max):    1.321 s …  1.379 s    10 runs

Benchmark 2: target/release-with-debug/jj-1 -R ~/mirrors/git --ignore-working-copy log -r'tags()' -T ''
  Time (mean ± σ):      1.379 s ±  0.023 s    [User: 1.238 s, System: 0.140 s]
  Range (min … max):    1.328 s …  1.403 s    10 runs

Relative speed comparison
        1.00          target/release-with-debug/jj-0 -R ~/mirrors/git --ignore-working-copy log -r'tags()' -T ''
        1.02 ±  0.02  target/release-with-debug/jj-1 -R ~/mirrors/git --ignore-working-copy log -r'tags()' -T ''
```
2024-03-14 10:07:19 +09:00
Martin von Zweigbergk
93f651d597 next/prev: make first line of help text consistent
This drops the trailing period for consistency with other commands,
and rephrases them a bit for consistency between each other.
2024-03-13 11:11:20 -07:00
Yuya Nishihara
a3839cdf47 commit_templater: allow extension methods to capture repo 2024-03-14 00:00:18 +09:00
Yuya Nishihara
9b42c81d6f templates: add missing "\n" to builtin "root" output 2024-03-13 23:29:27 +09:00