Commit graph

1958 commits

Author SHA1 Message Date
Martin von Zweigbergk
389f27f042 working_copy: move writing of conflict objects into new tree builder
This introduces a `MergedTreeBuilder` type, which takes a set of base
trees and overrides. The idea is that it will be able to write
multiple trees or a legacy tree. For now, it's only able to write
legacy trees. To show that it works, the working copy's snaphotting
code has been updated to use it.
2023-08-26 08:16:57 -07:00
Martin von Zweigbergk
e4ba6a42fc backends: store tree id conflicts as list with alternating signs
Now that we have `Merge::iter()` and friends, it's simpler to store
the tree ids in a single list.
2023-08-26 07:02:04 -07:00
Martin von Zweigbergk
fd4146d485 backend: use new enum for Commit::root_tree
We currently represent the root tree id in a commit by `Merge<TreeId>`
plus a boolean `uses_tree_conflict_format`. It's better to use an enum
for that. That makes it harder to forget to check which type of tree
it is, and it makes it impossible to store a legacy tree with multiple
ids (as we could with `uses_tree_conflict_format=false`,
`root_tree=Merge::new(...)`).

Maybe more importantly, we're also going to want to pass around this
information in most places where we currently pass a single `TreeId`,
and passing two separate values would be annoying.
2023-08-26 07:02:04 -07:00
Martin von Zweigbergk
e3d67d5e45 local_backend: allow storing legacy trees
Unlike the git backend, we don't need to support path-level conflicts
for existing repos because we don't care about compatibility with
existing repos using the native backend. However, we still need to
support both formats until all code paths are able to handle
tree-level conflicts.
2023-08-26 07:02:04 -07:00
Martin von Zweigbergk
589e0db3c5 git_backend: remove unused proto field for resolved tree id
We store resolved tree ids in the regular Git commit, so we we never
ended up using the `resolved` variant in the `root_tree`.
2023-08-26 07:02:04 -07:00
Martin von Zweigbergk
2fe4372121 tree_builder: remove unnecessary has_overrides() method
It's easy to instead check if the new tree id is different from the
tree id.
2023-08-26 07:02:04 -07:00
Martin von Zweigbergk
598cfcb89b merged_tree: in diff iterator, maintain legacy/modern variant in subtree
As #2165 showed, when diffing two `MergedTree::Legacy` variants (or
one of each variant) and re recurse into a subtree, we need to treat
that as a legacy tree too, so we expand `TreeValue::Conflict`s found
in the diff.
2023-08-26 05:58:54 -07:00
Martin von Zweigbergk
f3fbdf9f84 merged_tree: pass MergedTree into TreeDiffIterator::tree()
This converts `TreeDiffIterator::tree()` and
`TreeDiffIterator::single_tree()` into associated functions and passes
in the `&MergedTree` into the former. This prepares for fixing #2165,
and it removes the need for the `TreeDiffIterator::store` field.
2023-08-26 05:58:54 -07:00
Martin von Zweigbergk
769c248c49 working_copy: show bug when checking out conflict in subdir 2023-08-26 05:58:54 -07:00
Yuya Nishihara
79291a3ca4 revset: add separate name@remote node to discriminate it from quoted one
A local branch named "name@remote" no longer shadows a remote branch "name"
at "remote".
2023-08-26 07:47:12 +09:00
Yuya Nishihara
75ebdf69a1 revset: parse @ like operator (but without alias substitution)
This is what I proposed in #2095. @ is now an operator to concatenate symbols.

Unlike the other operators, lhs/rhs of @ is not a target of alias substitution.
'x' in 'x@y' doesn't look like a named variable, though it's technically
possible to allow definition of an alias expanded to a symbol of specific remote
or vice versa. This will probably apply to the kind:pattern syntax, where
aliases are expanded due to the current implementation restriction. I've added
a TODO comment about that.
2023-08-26 07:47:12 +09:00
Yuya Nishihara
8c2baafe5c revset: extract symbol parsing and resolution helper
These helpers will be used by name@remote handling.
2023-08-26 07:47:12 +09:00
Yuya Nishihara
81dda498e5 test_revset: rewrite resolve_symbol() to go through normal parse/resolve paths
I'm going to change the parsing rule of name@remote, and @ will no longer be
included in a symbol identifier. I could add a separate test for remote symbols,
but I think it's better to write tests that cover both "x"@"y" and "x@y" paths.
2023-08-26 07:47:12 +09:00
Martin von Zweigbergk
ab4d44df85 conflicts: leverage Merge::iter_mut() and Merge::into_iter() 2023-08-25 08:54:49 -07:00
Martin von Zweigbergk
2063f2f44e merge: implement iter_mut() and into_iter()
These two are trivial to implement using `itertools::interleave()`. I
don't think we even need tests.
2023-08-25 08:54:49 -07:00
Martin von Zweigbergk
d0be24ac62 merge: rewrite iter() using itertools::interleave()
`itertools::interleave()` does exactly what we want for
`Merge::iter()`. I had just not thought to look for it
before. Hopefully it's not noticeably slow.
2023-08-25 08:54:49 -07:00
Martin von Zweigbergk
f877610792 merge: add Merge::num_sides()
An alternative name for it would be `arity()`, but `num_sides()`
probably more clearly says that it's not about the number of removes
or the total number of terms.
2023-08-25 08:54:49 -07:00
Martin von Zweigbergk
f0efdf116e merge: add missing doc comments 2023-08-25 08:54:49 -07:00
Martin von Zweigbergk
0b27c33a13 working_copy: remove last use of current_tree()
We were using `current_tree()` only for an assertion where we were
walking its entries. Now that `MergedTree` supports that, we can
replace `current_tree()` by `current_merged_tree()`.

There's more work needed before the working copy can fully work with
tree-level conflicts. We still need to be able to store multiple tree
ids in the `tree_state` file, and we need to be able to create
multiple trees instead of writing conflict objects to the backend.
2023-08-25 07:06:20 -07:00
Martin von Zweigbergk
416fa2741c merged_tree: add entry iterator 2023-08-25 07:06:20 -07:00
Martin von Zweigbergk
85bdba5bea working_copy: use MergedTree for diffing in reset() 2023-08-25 07:06:20 -07:00
Martin von Zweigbergk
23509e939e working_copy: get diff from MergedTrees
To support tree-level conflicts, we're going to need to update the
working copy from one `MergedTree` to another. We're going need to
store multiple tree ids in the `tree_state` file. This patch gets us
closer to that by getting the diff from `MergedTree`s`, even though we
assume that they are legacy trees for now, so we can write to the
single-tree `tree_state` file.
2023-08-25 06:40:36 -07:00
Martin von Zweigbergk
d5ceefcd8e merged_tree: add diff iterator
If we're going to be able to replace most instances of `Tree` by
`MergedTree`, we'll need to be able to diff two `MergedTree`s. This
implements support for that. The implementation copies a lot from the
diff iterator we have for `Tree`. I suspect we should be able to reuse
some of the code by introducing some traits that can then be
implemented by both `Tree` and `MergedTree`. I've left a TODO about
that.
2023-08-25 06:40:36 -07:00
Martin von Zweigbergk
5610525c29 working_copy: pass in Merge arguments to closure in update()
When we do an update between two `MergedTree` instances, we'll get
diffs between two `Merge<Option<TreeValue>>`. This commit prepares for
that by changing the type of the `before` and `after` arguments we
pass into the closure in `update()`.
2023-08-25 06:40:36 -07:00
Martin von Zweigbergk
4b12dba186 merge: add Merge::is_absent() and Merge::is_present()
These turned out to only be (very marginally) useful in `RefTarget`
right now, but I plan to add a few more uses elsewhere.
2023-08-25 06:40:36 -07:00
Martin von Zweigbergk
c65fcabdf8 working_copy: collect code for updating update stats in one place
I think it's a little easier to follow if we don't update the stats in
the large callback. It also reduces the risk of forgetting to update
the stats in some case (like in the exec-bit-optimization case I just
removed).
2023-08-25 06:40:36 -07:00
Martin von Zweigbergk
2151fd8930 working_copy: drop optimization for exec-bit-only change
When updating the working copy from one tree to another, if only the
executable bit has changed between the two trees, we set the
executable bit on the file without touching its contents. The
optimization probably gets used quite rarely. Maybe it's even so
rarely that it's a pessimization overall. Perhaps its value lies more
in that we avoid updating the file's mtime unnecessarily. Either way,
I'm about to change this code to use `Merge<Option<TreeValue>>` and
that will make this block more complex. I don't think it's worth the
complexity even it provides some small benefit sometimes.
2023-08-25 06:40:36 -07:00
Martin von Zweigbergk
6b5544f335 tree_builder: add a set_or_remove() and simplify callers
Many of the `TreeBuilder` users have an `Option<TreeValue>` and call
either `set()` or `remove()` or the builder depending on whether the
value is present. Let's centralize this logic in a new
`TreeBuilder::set_or_remove()`.
2023-08-24 06:08:25 -07:00
Waleed Khan
134d85e635 backend: reduce BackendError size somewhat
One of the error types that I later created embedded `BackendError`, but `clippy` complained that the size of the type was too large. This helps address that.
2023-08-23 21:11:15 -07:00
Piotr Kufel
2109a7b488 Fix .gitignore handling of ignored directories
- Ignore .gitignore files from untracked directories
 - Do not allow un-ignoring files within ignored directories
2023-08-22 22:08:32 -07:00
Waleed Khan
1633eccdca Use { workspace = true } to appease VS Code's Cargo.toml parser
The VS Code "Better TOML" plugin (which I think most of our VS Code developers use?) doesn't support the `x.y = z` syntax at the top level, even though it's valid TOML. 

This is also useful if we ever want to add additional properties in different sub-crates (although unlikely for the near future).
2023-08-22 21:38:53 -07:00
Ilya Grigoriev
6161f26a72 clippy: add some static lifetimes
Result of `cargo +nightly clippy --workspace --fix`.

Apparently, the current version will become illegal in a future
version of Rust.
2023-08-22 19:16:13 -07:00
Yuya Nishihara
c5b6e9705d git: extract add_remote() function, and map git2::Error there
I'm going to add check for remote named "git" there.
2023-08-23 10:02:52 +09:00
Yuya Nishihara
61172b1c1e git: on rename_remote(), check conflicts of new remote name 2023-08-23 10:02:52 +09:00
Yuya Nishihara
46dd6dd9c6 git: handle remote not found error by remove/rename_remote() 2023-08-23 10:02:52 +09:00
Yuya Nishihara
66f871c0c9 git: extract helper that maps git2::Error to NoSuchRemote 2023-08-23 10:02:52 +09:00
Yuya Nishihara
78dfec9701 git: remove unused GitExportError variants
Conflicted branches are no longer error, and we use the state stored in the
view.
2023-08-23 10:02:52 +09:00
Martin von Zweigbergk
49fb26fdae working_copy: write state file even if only mtimes changed
When the main `TreeState::snapshot()` thread doesn't receive any
updated tree entries over the channel, it correctly doesn't write a
new tree. However, it also doesn't write the working copy state file
(`.jj/working_copy/tree_state`). This resulted in performance
regression in 3f97a6da78. From that commit, repeated snapshotting
would have to re-read all files from disk because it didn't remember
the updated mtime from the previous time.

This patch fixes the bug by also writing the file if there were any
new file states.
2023-08-22 14:45:52 -07:00
Martin von Zweigbergk
5641ef9a42 working_copy: don't send unchanged file states over channel
This doesn't seem to make any difference right now, but it will if we
write the state file when there are mtime-only changes, which we
currently don't do.
2023-08-22 14:45:52 -07:00
Martin von Zweigbergk
e1c0d4fd5f cleanup: replace x[n..n+l] by x[n..][..l]
This avoids repeating the `n` in these expressions. Thanks to
@Dr-Emann for the suggestion.
2023-08-21 22:29:46 -07:00
Martin von Zweigbergk
c43a3067eb revset: pass all context arguments to parse() via an object
`revset::parse()` already has a `RevsetWorkspaceContext` argument, so
I think it makes sense to put that and the other context arguments
into a larger `RevsetParseContext` object.
2023-08-20 21:30:06 -07:00
Martin von Zweigbergk
5f3df4aaea revset: resolve "@" symbol's workspace id earlier (while parsing)
We resolve file paths into repo-relative paths while parsing the
revset expression, so I think it's consistent to also resolve which
workspace "@" refers to while parsing it. That means we won't need the
workspace context both while parsing and while resolving symbols.

In order to break things like `author("martinvonz@")` (thanks to @yuja
for catching this), I also changed the parsing of working-copy
expressions so they are not allowed to be
quoted. `author(martinvonz@)` will therefore be an error now. That
seems like a small improvement anyway, since we have recently talked
about making `root` and `[workspace]@` not parsed as other symbols.
2023-08-20 17:57:18 -07:00
Martin von Zweigbergk
f9b3211d58 revset: drop an unnecessary return keyword 2023-08-20 17:57:18 -07:00
Yuya Nishihara
b6794ca04a revset: rename literal:"" prefix to exact:""
Per discussion in #2107, I believe "exact" is preferred.

We can also change the default to exact match, but it doesn't always make
sense. Exact match would be useful for branches(), but not for description().
We could define default per predicate function, but I'm pretty sure I cannot
remember which one is which.
2023-08-19 11:33:57 +09:00
Yuya Nishihara
ebdc22a65e revset: add support for explicit substring:"..." prefix
git-branchless calls it a substring, so let's do the same.

FWIW, I copied literal:_ from Mercurial, but it's exact:_ in git-branchless.
I have no idea which one is preferred. Since this feature isn't released, we
can freely change it if exact:_ makes more sense.

https://github.com/arxanas/git-branchless/wiki/Reference:-Revsets#patterns
2023-08-19 10:32:59 +09:00
Emily Fox
3f8ac2198d commits: use empty strings instead of placeholders for missing name or email
This commit replaces the functions `UserSettings::user_name_placeholder()`` and
`UserSettings::user_email_placeholder()` with `const` `&str`s to emphasize that
the placeholder strings must not be changed to support commits without
names or email addresses made before this change.
2023-08-18 17:22:59 -05:00
Emily Fox
2c88da02b4 git: teach backend to handle empty name and email strings 2023-08-18 17:22:59 -05:00
Benjamin Saunders
4bd05e8285 tests: hack around broken lint 2023-08-17 19:29:38 -07:00
Benjamin Saunders
417035cb20 tests: validate snapshot.max-new-file-size behavior 2023-08-17 19:29:38 -07:00
Benjamin Saunders
54f1d310c4 testutils: propagate snapshot errors 2023-08-17 19:29:38 -07:00