Commit graph

704 commits

Author SHA1 Message Date
Yuya Nishihara
8d0414549b cli: unblock "jj git init --colocate" in existing Git repo directory
I'm not sure what's the conclusion in #2747, but I don't think there is a
disagreement on allowing --colocate to import existing Git repo.
2024-02-28 09:03:16 +09:00
Yuya Nishihara
356037379a cli: narrow scope of canonicalized cwd in git_init()
It's only needed to calculate relative path of canonicalized workspace_root,
and I'm going to remove it.
2024-02-28 09:03:16 +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
de1e4a39f4 revset: add hint to innermost error
This seems more useful if aliases are nested. The innermost error usually
contains the problem, and the outer errors are contexts where aliases are
expanded.
2024-02-28 09:03:04 +09:00
Yuya Nishihara
a235aa51f6 templater: move build_core_method() to table object
Just for convenience.
2024-02-28 09:03:04 +09:00
Yuya Nishihara
bdbb2dec65 templater: migrate core template methods to symbol table
Except for the generic list and template methods. We'll need a bit more
refactoring to migrate List<T> method builders to be compatible with
non-capturing fn() type.
2024-02-28 09:03:04 +09:00
Yuya Nishihara
e1864d90dd templater: extract substr() method body to function
This function isn't trivial, so it's probably better to not inline in the
templater binding.
2024-02-28 09:03:04 +09:00
Martin von Zweigbergk
81e9ba3d51 workspace: make recovery commit empty instead of deleting everything
The recovery commit we create when we run into a stale working copy
with a missing operation currently has an empty tree. Our commit
backend at Google creates an index of which files changed in each
commit. That gets really expensive when a commit deletes all files in
the repo, as these recovery commits do. So for our backend, it is much
better to make the recovery commit empty instead. That's what this
patch does.

It almost doesn't matter functionally what tree we use for it since we
don't care much about the current tree when snapshotting the working
copy. It does matter in a few cases, however. One case is for
conflicts. In that case, it's likely better to use the recovery
commit's parent as base tree (as we do by making the recovery commit
empty) than to use an empty tree, as that would guarantee that all
conflicts would be considered resolved. (Side note: perhaps we should
start looking at the current commit's parent instead of looking at the
current commit when snapshotting, but that's a topic for another day.)
2024-02-27 06:45:25 -08:00
Yuya Nishihara
9ad2fee72b templater: migrate operation template methods to symbol table 2024-02-27 11:00:33 +09:00
Yuya Nishihara
10acfdcb86 templater: extract generic type aliases for method build fn and table
I also added a type alias for HashMap<&'static str, _> because it's tedious to
repeat that in function body.
2024-02-27 11:00:33 +09:00
Yuya Nishihara
523f8b26ec templater: migrate other commit template methods to symbol table 2024-02-27 11:00:33 +09:00
Yuya Nishihara
8226584ae9 templater: inline parse_optional_integer() in method body
If each method body is split to closure, this parse helper will no longer be
able to capture the environment.
2024-02-27 11:00:33 +09:00
Yuya Nishihara
1b4c339203 templater: extract stub function that resolves method name
We'll probably add "Did you mean?" hint there.
2024-02-27 11:00:33 +09:00
Martin von Zweigbergk
a976b5d482 cli: document that we create a new working-copy commit for abandoned one
When we abandon a working-copy commit, we create a new working-copy
commit on top. This behave is very useful, but it's not obvious. Let's
document it.

Thankfully, 2bbefcc338 (rewrite: default to not simplifying ancestor
merges) means that there are much fewer commands where we need to
document this behavior.
2024-02-25 18:52:10 -08:00
Yuya Nishihara
fd4acf679c templater: clone WorkspaceId/OperationId into templater to simplify lifetime
There would be no measurable cost to clone a couple of id objects.
2024-02-26 10:27:45 +09:00
Yuya Nishihara
68b1f869b6 templater: extract Commit methods to HashMap
There are two major goals:
 * provide typo hints in a similar way to revset
 * make methods extensible

The created method table is bound to the 'repo lifetime because of the problem
described in the inline comment. It would be nice if we can build cachable
core method table for<'repo> CommitTemplateLanguage<'repo, '_>, but I couldn't
figure out how.
2024-02-26 10:27:45 +09:00
Yuya Nishihara
0d77ce5ba9 templater: inline capture variables in each method body of Commit type
Each method body will be turned into a closure.
2024-02-26 10:27:45 +09:00
Paulo Coelho
e9243a7638 cli branch list: list tracked branches
Add an option to list tracked branches only

This option keeps most of the current `--all` printing logic, but:

- Omits local Git-tracking branches by default (can be extended to
  support filtering by remote).
- Skip over the branch altogether if it doesn't contain tracked remotes
- Don't print the untracked_remote_refs at the end

Usage:

`jj branch list -t`
`jj branch list --tracked`
`jj branch list --tracked <branch name>`
2024-02-26 01:05:07 +00:00
Martin von Zweigbergk
b695fa1d82 cli: make rebase --skip-empty keep already empty commits
I think the user usually wants to abandon only newly empty commits. I
think they should use `jj abandon` if they want to get rid of already
empty commits. By keeping already empty commits, we don't need to
special-case the working copy and merge commits.
2024-02-25 16:39:05 -08:00
Yuya Nishihara
7525fac12a templater: add special "self" variable to refer to top-level object
This allows us to call alias function with the top-level object.

For convenience, all self.<method>()s are available as keywords. I don't think
we'll want to deprecate them. It would be tedious if we had to specify
-T'self.commit_id()' instead of -Tcommit_id.
2024-02-25 09:01:04 +09:00
Yuya Nishihara
bbf88643cc templater: inline wrap_fn() helpers
If I remember correctly, wrap_fn() was added to help type inference. It no
longer makes sense because the type is coerced by TemplateFunction::new()
and language.wrap_*().
2024-02-25 09:00:56 +09:00
Yuya Nishihara
f0ce448609 templater: merge build_*_keyword_opt() functions into method builders
template_parser::expect_no_arguments(function) is copied to each method body.
We might want to add some helper macros later.
2024-02-25 09:00:56 +09:00
Yuya Nishihara
ebf90384f6 operation: add shorthand for .store_operation().metadata 2024-02-25 09:00:56 +09:00
Martin von Zweigbergk
9767620292 cli: restore documentation of jj diff lost in split of commands module
The description of `jj diff` was lost in commit b5e4e670. We later got
a short description for it in b5e4e670. This patch restores the
original description.
2024-02-23 09:45:19 -08:00
Yuya Nishihara
e80b906188 templater: translate keywords to "self" methods by core template engine
This eliminates the separate keywords table. All keywords are resolved through
the pseudo "self" property. Maybe we'll add "self" keyword/variable later.
2024-02-23 10:13:25 +09:00
Yuya Nishihara
6e5eff5423 templater: update test templater to be compatible with "self" methods
Prepares for the removal of build_keyword().
2024-02-23 10:13:25 +09:00
Yuya Nishihara
e9b420f592 templater: add Operation type and methods
There are no keywords or methods that return Operation yet, but we might add
"self" keyword that returns the context object.
2024-02-23 10:13:25 +09:00
Yuya Nishihara
4e0fa6695f templater: extract operation keywords to method-compatible form
This is copied from the commit templater. I'm going to extract the "self"
property handling to the core template builder, and build_keyword() methods
will be replaced with that.
2024-02-23 10:13:25 +09:00
Yuya Nishihara
62f0cb8c3f cli: change default log revset to not include all tagged heads
The default immutable_heads() includes tags(), which makes sense, but computing
heads(tags()) can be expensive because the tags() set is usually sparse. For
example, "jj bench revset 'heads(tags())'" took 157ms in my linux stable
mirror. We can of course optimize the heads evaluation by using bit set or
segmented index, but the query includes many historical heads if the repository
has per-release branches, which are uninteresting anyway. So, this patch
replaces heads(immutable_heads()) with trunk().

The reason we include heads(immutable_heads()) is to mitigate the following
problem. Suppose trunk() is the branch to be based off, I think using trunk()
here is pretty good.

```
A   B
*---*----* trunk() ⊆ immutable_heads()
     \
      * C
```
https://github.com/martinvonz/jj/pull/2247#discussion_r1335078879
2024-02-23 00:25:58 +09:00
Yuya Nishihara
f21c078249 revset: ad-hoc optimization for range queries containing unwanted wanted heads
In my linux stable mirror, this makes the default log revset evaluation super
fast. immutable_heads(), if configured properly, includes many historical
branch heads which are also the visible heads.

revsets/immutable_heads()..
---------------------------
0     12.27     117.1±0.77m
3      1.00       9.5±0.08m
2024-02-22 23:26:29 +09:00
Daehyeok Mun
a9f489ccdf Switch to ignore crate for gitignore handling.
Co-authored-by: Waleed Khan <me@waleedkhan.name>
2024-02-20 09:12:46 -08:00
Martin von Zweigbergk
11c67cf979 op_store: add metadata flag for ops representing working-copy snapshot
It should be useful at least in the presentation layer to know which
operations correspond to working-copy snapshots. They might be
rendered differently in the graph, for example. Or maybe an undo
command wants to warn if you just undid a snapshot operation. This
patch just introduces a field in the metadata to store the
information.
2024-02-19 22:44:38 -08:00
Julien Vincent
1516c90aa9 sign: Update config-schema.json 2024-02-20 00:02:08 +00:00
Martin von Zweigbergk
a898847333 cli: make jj rebase not simplify ancestor merges
I think I prefer this behavior because it's less lossy. The user can
manually simplify the history with `jj rebase -s <merge commit> -d
<one of the parents>` afterwards. We can roll this change back later
if we find it annoying.
2024-02-19 14:20:18 -08:00
Martin von Zweigbergk
3f1d75f518 rewrite: default to not simplifying ancestor merges
This means auto-rebase will no longer simplify ancestor merges.
2024-02-19 14:20:18 -08:00
Martin von Zweigbergk
29cd491559 cli: drop redundant test of ancestor merge
We now have lots of tests of ancestor merges in `test_bug_2600()`, so
we don't need the ones in `test_basics()`. Since it doesn't have the
"nottherootcommit" commit, it would break when we change the default
to preserve ancestor merges.
2024-02-19 14:20:18 -08:00
Martin von Zweigbergk
a9d0300b11 rewrite: make simplification of ancestor merges optional
I think the conclusion from #2600 is that at least auto-rebasing
should not simplify merge commits that merge a commit with its
ancestor. Let's start by adding an option for that in the library.
2024-02-19 14:20:18 -08:00
Alexis (Poliorcetics) Bourget
c75230747a completion: Add support for Nushell completions 2024-02-18 19:08:38 +01:00
Alexis (Poliorcetics) Bourget
b533cdc538 feat(cli): Add -f/-t for --from/--to to jj move 2024-02-18 18:58:48 +01:00
Alexis (Poliorcetics) Bourget
0fc5005b8a cli: rename --verbose to --debug to better fit what it does 2024-02-18 18:45:48 +01:00
Vladimir Petrzhikovskii
06d67f02d8 cli: list new remote branches during git fetch 2024-02-18 17:36:01 +01:00
Yuya Nishihara
3c7aa75b9b index: switch to persistent change id index
The shortest change id prefix will become a few digits longer, but I think
that's acceptable. Entries included in the "revsets.short-prefixes" set are
unaffected.

The reachable set is calculated eagerly, but this is still faster as we no
longer need to sort the reachable entries by change id. The lazy version will
save another ~100ms in mid-size repos.

"jj log" without working copy snapshot:
```
% hyperfine --sort command --warmup 3 --runs 20 -L bin jj-0,jj-1,jj-2 \
  -s "target/release-with-debug/{bin} -R ~/mirrors/linux debug reindex" \
  "target/release-with-debug/{bin} -R ~/mirrors/linux \
   --ignore-working-copy log -r.. -l100 --config-toml='revsets.short-prefixes=\"\"'"
Benchmark 1: target/release-with-debug/jj-0 -R ~/mirrors/linux --ignore-working-copy log -r.. -l100 --config-toml='revsets.short-prefixes=""'
  Time (mean ± σ):     353.6 ms ±  11.9 ms    [User: 266.7 ms, System: 87.0 ms]
  Range (min … max):   329.0 ms … 365.6 ms    20 runs

Benchmark 2: target/release-with-debug/jj-1 -R ~/mirrors/linux --ignore-working-copy log -r.. -l100 --config-toml='revsets.short-prefixes=""'
  Time (mean ± σ):     271.3 ms ±   9.9 ms    [User: 183.8 ms, System: 87.7 ms]
  Range (min … max):   250.5 ms … 282.7 ms    20 runs

Relative speed comparison
        1.99 ±  0.16  target/release-with-debug/jj-0 -R ~/mirrors/linux --ignore-working-copy log -r.. -l100 --config-toml='revsets.short-prefixes=""'
        1.53 ±  0.12  target/release-with-debug/jj-1 -R ~/mirrors/linux --ignore-working-copy log -r.. -l100 --config-toml='revsets.short-prefixes=""'
```

"jj status" with working copy snapshot (watchman enabled):
```
% hyperfine --sort command --warmup 3 --runs 20 -L bin jj-0,jj-1,jj-2 \
  -s "target/release-with-debug/{bin} -R ~/mirrors/linux debug reindex" \
  "target/release-with-debug/{bin} -R ~/mirrors/linux \
   status --config-toml='revsets.short-prefixes=\"\"'"
Benchmark 1: target/release-with-debug/jj-0 -R ~/mirrors/linux status --config-toml='revsets.short-prefixes=""'
  Time (mean ± σ):     396.6 ms ±  10.1 ms    [User: 300.7 ms, System: 94.0 ms]
  Range (min … max):   373.6 ms … 408.0 ms    20 runs

Benchmark 2: target/release-with-debug/jj-1 -R ~/mirrors/linux status --config-toml='revsets.short-prefixes=""'
  Time (mean ± σ):     318.6 ms ±  12.6 ms    [User: 219.1 ms, System: 94.1 ms]
  Range (min … max):   294.2 ms … 333.0 ms    20 runs

Relative speed comparison
        1.85 ±  0.14  target/release-with-debug/jj-0 -R ~/mirrors/linux status --config-toml='revsets.short-prefixes=""'
        1.48 ±  0.12  target/release-with-debug/jj-1 -R ~/mirrors/linux status --config-toml='revsets.short-prefixes=""'
```
2024-02-18 09:44:57 +09:00
Alexis (Poliorcetics) Bourget
fb10e3f296 completion: Update docs for new style with positional argument 2024-02-17 19:26:30 +01:00
Martin von Zweigbergk
866e862ab0 cli: make new workspace inherit sparse pattern from old workspace 2024-02-17 10:17:38 -08:00
Martin von Zweigbergk
6d7affc4da cli: add test of workspaces with sparse patterns
When adding a new workspace, I would expect that it inherits the
patterns from the workspace I ran the command in. We currently don't
do that. That's quite annoying when your repo has very many files
(like at Google).
2024-02-17 10:17:38 -08:00
Aleksey Kuznetsov
89cf6a00a1 graphlog: refactor graphlog::Edge enum and its usage
`graphlog::Edge` is used somewhat inconsistently. I've replaced `Edge::Present`
with two distinct `Edge::Direct` and `Edge::Indirect` which simplifies the
construction of the enum.
2024-02-17 20:54:20 +05:00
Evan Mesterhazy
e1fd402d39 Fix the ContentHash implementations for std::Option, MergedTreeId, and RemoteRefState
The `ContentHash` documentation specifies that implementations for enums should
hash the ordinal number of the variant contained in the enum as a 32-bit
little-endian number and then hash the contents of the variant, if any.

The current implementations for `std::Option`, `MergedTreeId`, and
`RemoteRefState` are non-conformant since they hash the ordinal number as a u8
with platform specific endianness.


Fixes #3051
2024-02-16 09:27:32 -05:00
Yuya Nishihara
5b9f422d1d cli: change workspace@ symbol color to green (the color of HEAD@git)
I think it makes sense because workspace@ is similar to HEAD@git. They are
symbols that aren't branches nor tags.
2024-02-16 11:12:43 +09:00
Yuya Nishihara
c73a092759 cli: drop handling of legacy revset dag range operator
This basically reverts the change c183b94aef "cli: warn when using `:` revset
operator."
2024-02-14 10:04:56 +09:00