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

2941 commits

Author SHA1 Message Date
Yuya Nishihara
8745c01f98 revset: rename parse_expression_rule() to lower_expression()
As I said, revset has another symbol resolution stage. That's why this function
isn't called resolve_expression().
2024-06-05 10:39:32 +09:00
Yuya Nishihara
9f33d13dfd revset: replace ParseState with &RevsetParseContext
There's no longer a mutable state to be tracked.
2024-06-05 10:39:32 +09:00
Yuya Nishihara
cbffa17bf0 revset: move primitive typed expression helpers to parser module 2024-06-05 10:39:32 +09:00
Yuya Nishihara
e383d41d22 revset: rename typed expression helpers
This is the naming convention we use in templater. These helper functions no
longer requires the passed node is a function argument.
2024-06-05 10:39:32 +09:00
Yuya Nishihara
b281bcd5cb revset: inline invalid_arguments() constructor
There are only two callers, and this change might help if we want to extract
parse_function_call_node() to dsl_util.
2024-06-05 10:39:32 +09:00
Yuya Nishihara
14421ac126 revset: omit function name from type error messages
This simplifies the interface of helper functions. While revset doesn't have
top-level string pattern or integer literal, these parsing helpers could be
used to parse array subscript or n-th parent operator if any.
2024-06-05 10:39:32 +09:00
Martin von Zweigbergk
650eeb8935 cli: add jj fix proof of concept 2024-06-04 14:28:21 -05:00
Yuya Nishihara
3a4258916c revset: inline parse_function_call_args()
The separate function looked rather verbose.
2024-06-04 09:56:21 +09:00
Yuya Nishihara
8a4abee87d revset: insert named "function" rules
This patch copies function rule processing from templater and fileset. Since
function and identifier rules are quite different, it's better to not rely on
the subtle difference between identifier and function_name tokens.
2024-06-04 09:56:21 +09:00
Yuya Nishihara
127e4d3455 revset: flatten symbol rule
This makes it clear that the identifier node is special. For the other
constructs, we don't distinguish between bare symbol and quoted string.
2024-06-04 09:56:21 +09:00
Yuya Nishihara
674d897352 revset: inline trivial parsing functions to eliminate obvious assertions 2024-06-04 09:56:21 +09:00
Yuya Nishihara
2c9132adfc revset: remove RevsetExpression::StringPattern hack
It's no longer needed since we have proper AST tree now.
2024-06-02 10:28:54 +09:00
Yuya Nishihara
89ac3a1851 revset: split AST-level parsing and expression lowering stages
This will allows us to parse "file(..)" arguments as fileset expression by
transforming AST for example. I'm not sure if that's good or bad, but we'll
probably want to embed fileset expressions without quoting.

parse_expression_rule() is split to the first str->ExpressionNode stage and
the second ExpressionNode->RevsetExpression stage. The latter is called
"resolve_*()" in fileset, but we have another "symbol" resolution stage in
revset. So I choose "lower_*()" instead.
2024-06-02 10:28:54 +09:00
Yuya Nishihara
444e88e3b8 revset: backport AST types and helpers from templater and fileset
These types and helper functions will be enabled by the next patch.
2024-06-02 10:28:54 +09:00
Yuya Nishihara
2ea173185d revset: add expect_exact_arguments() helper, replace expect_one_argument()
Prepares for migration to dsl_util::FunctionCallNode.
2024-06-02 10:28:54 +09:00
Yuya Nishihara
5e7cb3435e git: unset unborn HEAD ref on export
Otherwise, newly created default branch would be re-imported as a new Git HEAD.
This could be addressed by cmd_git_init(), but the same situation can be
crafted by using "git checkout -b".
2024-06-01 11:01:16 +09:00
mlcui
458580cee2 working_copy: Add is_file_states_sorted to tree state proto
See #2651 and a935a4f70c for more
background.

This speeds up `jj log` in a large repo with watchman enabled by around
9%:

```
$ hyperfine --sort command --warmup 3 --runs 20 -L bin \
jj-before,jj-after "target/release/{bin} -R ~/chromiumjj/src log"
Benchmark 1: target/release/jj-before -R ~/chromiumjj/src log
  Time (mean ± σ):     788.3 ms ±   3.4 ms    [User: 618.6 ms, System: 168.8 ms]
  Range (min … max):   783.1 ms … 793.3 ms    20 runs

Benchmark 2: target/release/jj-after -R ~/chromiumjj/src log
  Time (mean ± σ):     713.4 ms ±   5.2 ms    [User: 536.1 ms, System: 176.2 ms]
  Range (min … max):   706.6 ms … 724.7 ms    20 runs

Relative speed comparison
        1.11 ±  0.01  target/release/jj-before -R ~/chromiumjj/src log
        1.00          target/release/jj-after -R ~/chromiumjj/src log
```
2024-05-31 22:28:35 +10:00
Martin von Zweigbergk
404f31cbc1 backend: add error variant for access denied, handle when diffing
Some backends, like the one we have at Google, can restrict access to
certain files. For such files, if they return a regular
`BackendError::ReadObject`, then that will terminate iteration in many
cases (e.g. when diffing or listing files). This patch adds a new
error variant for them to return instead, plus handling of such errors
in diff output and in the working copy.

In order to test the feature, I added a new commit backend that
returns the new `ReadAccessDenied` error when the caller tries to read
certain objects.
2024-05-30 18:27:38 -07:00
Benjamin Tan
e0e123873b revset_graph: rename to graph and make generic over graph node type 2024-05-31 02:39:34 +08:00
Martin von Zweigbergk
3090adfd5c repo: consider empty and undescribed merge commits as discardable 2024-05-29 06:54:30 -07:00
Martin von Zweigbergk
5d2c0347a2 MutableRepo: add test of updating away from empty merge commit
Merge commits are very similar to non-merge commits in jj. An empty
merge commit with no description is not really different from an empty
non-merge commit with no description. As we discussed on
https://github.com/martinvonz/jj/issues/2859, we should not treat
merge commits differently when updating away from them. This patch
adds test for the current behavior (which is to leave the merge commit
in place).
2024-05-29 06:54:30 -07:00
Martin von Zweigbergk
28050e9da1 repo: update some stale mentions of MutableRepo::check_out() 2024-05-29 06:54:30 -07:00
Martin von Zweigbergk
e02622b143 repo: when abandoning a working copy that a merge, recreate it
I recently needed to test something on top of a two branches at the
same time, so I created a new commit on top of both of them (i.e. a
merge commit). I then ran tests and made some adjustments to the
code. These adjustments belonged in one of the parent branches, so I
used `jj squash --into` to squash it in there. Unfortunately, that
meant that my working copy became a single-parent commit based on one
of the branches only. We already had #2859 for tracking this issue.

This patch changes the behavior so we create a new working-copy commit
with all of the previous parents.
2024-05-29 06:54:30 -07:00
Yuya Nishihara
b0845d1df2 dsl_util: add keyword arguments and parsing helper to FunctionCallNode
This will replace revset_parser::expect_named_arguments(). More tests will be
added by migrating revset parsing.
2024-05-29 22:36:15 +09:00
Yuya Nishihara
da2ef7fe4e dsl_util: use .ok() to drop unprintable error
I used .map_err(|_: Vec<_>|) to clarify that the original data is returned as
an error (so it can't be .unwrap()-ed.) However, it can be said that the error
detail isn't important and .map_err() is too verbose.
2024-05-29 22:36:15 +09:00
Yuya Nishihara
db16a5968b dsl_util: forward upper-bounded expect_*_arguments() to common function
I'm going to add keyword arguments handling, and I want to deduplicate check
for unsupported arguments.
2024-05-29 22:36:15 +09:00
Yuya Nishihara
b55c62beb5 dsl_util: add helper function that formats arguments count error message 2024-05-29 22:36:15 +09:00
Yuya Nishihara
89270a37fb fileset: insert missed blank line 2024-05-29 22:36:15 +09:00
mlcui
4c03506fb5 git: Avoid resetting Git index when trees are identical
This accounts for commit message-only changes which do not change the
tree ID, as well as checkouts between commits with identical tree
contents.

See #3748 for previous work on avoiding resetting HEAD when the
*commits* are identical.
2024-05-29 18:11:26 +10:00
mlcui
e4cfbc10e5 git: Refactor reset_head to share set_git_head_target call
This shares some common code to both the root and the non-root case, and
provides easier access to `mut_repo` in the function - as
`set_git_head_target` mutably borrows `mut_repo`.

This will be used for a cleaner implementation of #3767.
2024-05-29 15:44:47 +10:00
Ilya Grigoriev
e3bb825a21 jj git push: remove the NotFastForward error
Now that we always force push, it should not occur in practice.
2024-05-28 21:38:26 -07:00
Ilya Grigoriev
12081166f6 test_git.rs: delete now-useless test 2024-05-28 21:38:26 -07:00
Ilya Grigoriev
777da99533 jj git push: always force-push, all safety logic now in push_negotiation
This should be a no-op, though that is not necessarily obvious in corner
cases.

Note that libgit2 already performs the push negotiation even when
pushing without force (without `+` in the refspec).
2024-05-28 21:38:26 -07:00
Ilya Grigoriev
8d3dd17b51 jj git push: safety checks in push negotiation, "force-with-lease"
As explained in the commit, our logic is a bit more complicated than
that of `git push --force-with-lease`. This is to match the behavior of
`jj git fetch` and branch conflict resolution rules.
2024-05-28 21:38:26 -07:00
Ilya Grigoriev
b0306eb742 jj git push: no-op push negotiation, plumb data to it
Hopefully, splitting the no-op portion will make the following commits
easier to review.
2024-05-28 21:38:26 -07:00
Ilya Grigoriev
b54d962d58 test_git.rs: add two more commits to PushSetup, rename them
The new names are a bit clearer. Soem tests already use a
`sideways_commit`, `parent_of_main_commit` will be needed in
an upcoming test.
2024-05-28 21:38:26 -07:00
Martin von Zweigbergk
1e3b49abf5 revset: use FsRepoPathUiConverter in RevsetWorkspaceContext 2024-05-28 21:36:40 -07:00
Martin von Zweigbergk
058461ebb1 fileset: replace FilesetParseContext by RepoPathUiConverter 2024-05-28 21:36:40 -07:00
Martin von Zweigbergk
3b702250a6 repo_path: add type for formatting and parsing RepoPath, use in CLI
We want to move UI-independent logic that's currently in `jj-cli` into
`jj-lib`. `WorkspaceCommandHelper` is perhaps the most important part
to start moving. As I was looking into what to move from
`WorkspaceCommandHelper`, the first thing I saw there was the
`cwd`. It might seem like a good candidate to start moving. However,
when running a server, you might be running operations on repos stored
in database, so `cwd` and the workspace root don't make sense then
(because the repo is not stored at a particular path).

So, instead, this patch starts abstracting out our uses of those two
paths by adding an enum for converting between `RepoPath` and paths as
they are presented in the UI. I added a variant for repos stored in a
file system, and made `WorkspaceCommandHelper` use that to show that
it works. We'll probably add a server variant later.

I put the new type in `repo_path.rs` because at least the
file-system-based implementation is closely related to
`RepoPath::parse_fs_path()`.
2024-05-28 21:36:40 -07:00
Martin von Zweigbergk
7e6a968415 conflicts: consider the empty tree a non-legacy tree
Since we no longer depend on legacy trees being preserved when we
build new trees or merge trees, we can consider the root tree a
non-legacy tree.
2024-05-27 06:25:27 -07:00
Martin von Zweigbergk
43bf8667d8 conflicts: always write tree-level conflicts from MergedTreeBuilder
Before this patch, `MergedTreeBuilder::write_tree()` would create a
new legacy tree if the base tree was a legacy tree. This patch makes
it always write multiple root trees instead (if there are conflicts).

We still support reading legacy conflicts if the
`format.tree-level-conflicts` config is set.
2024-05-27 06:25:27 -07:00
Martin von Zweigbergk
8e6e04b929 conflicts: always use tree-level format for merged trees
It's been about six months since we started using tree-level conflicts
by default. I can't imagine we would switch back. So let's continue
the migration by always using tree-level conflicts when merging trees,
even if all inputs were legacy trees.
2024-05-27 06:25:27 -07:00
Martin von Zweigbergk
26085f236e rewrite: minor simplification of rebase_with_empty_behavior()
This is a small refactoring to return a bit less information from the
block where we merge trees.
2024-05-27 06:22:12 -07:00
mlcui
a075a5c6ca git: Only reset Git index if non-empty
In chromium/src.git, this gives an approximate ~0.83s speedup for
commands if the Git index is empty, and a ~0.14s slowdown if the Git
index is non-empty.

As most users using jj will likely be using jj to write to a colocated
repo - and therefore avoid modifying the Git index - this should be a
general speedup for most colocated checkouts.
2024-05-27 11:35:13 +10:00
Yuya Nishihara
b31f75bc94 dsl_util: introduce visitor-based generic alias substitution
The original expand_node() body is migrated as follows:
- Identifier -> fold_identifier()
- FunctionCall -> fold_function_call()

expand_defn() now manages states stack by itself, which simplifies lifetime
parameters.
2024-05-26 11:21:45 +09:00
Yuya Nishihara
0efd2aa316 dsl_util: add trait for alias body parsing
This could be a closure argument passed to expand_aliases(), but it's nice
that the parsing function is constrained by the aliases map type.
2024-05-26 11:21:45 +09:00
Yuya Nishihara
7be4a0a560 dsl_util: add visitor-like API primarily designed for alias substitution
The templater implementation of FoldableExpression is a stripped-down version
of expand_node(). It's visitor-like because I'm going to write generic alias
substitution rules over abstract expression types (template, revset, fileset.)

Naming comes from rustc.
https://rust-unofficial.github.io/patterns/patterns/creational/fold.html
2024-05-26 11:21:45 +09:00
Yuya Nishihara
5061d4b831 dsl_util: add trait for alias substitution errors
This is basically the same as the previous patch, but for error types. Some
of these functions could be encoded as "E: From<AliasExpandError<'i>>", but
alias substitution logic is recursive, so it would have to convert E back and
force.
2024-05-26 11:21:45 +09:00
Yuya Nishihara
cf6357459d dsl_util: add trait that constructs ExpressionKind of basic AST node types
This isn't fancy, but we'll need some generic way to return either original
or substituted expression node. I think this is the simplest abstraction.
2024-05-26 11:21:45 +09:00
Yuya Nishihara
68160a4e77 git_backend: forcibly invalidate in-memory packed-refs cache on gc()
gix 0.63 is now available.

#3537
2024-05-24 10:09:44 +09:00