Commit graph

645 commits

Author SHA1 Message Date
Martin von Zweigbergk
1d55a404cc merged_tree: add path_value() 2023-08-15 07:56:55 -07:00
Martin von Zweigbergk
2238c87da1 merged_tree: import create_tree() in tests to reduce line wrapping 2023-08-15 07:56:55 -07:00
Martin von Zweigbergk
0b3b62a777 conflicts: remove redundant num_removes argument from parse_conflict()
Merges always have exactly one more "adds" than "removes" these days.
2023-08-13 09:54:16 +00:00
Martin von Zweigbergk
4c46398b1c conflicts: make update_from_content() write resolved content to store
`update_from_content()` already writes file content for each term of
an unresolved merge, so it seems consistent for it to also write the
file content for resolved merges. I think this should simplify further
refactoring for tree-level conflicts and for preserving the executable
bit.
2023-08-11 23:59:44 +00:00
Martin von Zweigbergk
0b85f06e3d conflicts: make update_from_content() work with only FileIds
Since `update_from_contents()` only works with file contents and not
the executable or other kinds of paths, I think it makes more sense
for it to deal with `FileId`s instead of `TreeValue`s.
2023-08-11 23:59:44 +00:00
Martin von Zweigbergk
94c14d454a tests: levarage the materialize_conflict_string() helper in more places 2023-08-11 23:59:44 +00:00
Martin von Zweigbergk
a995c66635 merge: move some methods back to conflicts as free functions
I think I moved way too many functions onto `Merge<Option<TreeValue>>`
in 82883e648d. This effectively reverts almost all of that
commit. The `Merge<T>` type is simple container and it seems like it
should be at fairly low level in the dependency graph. By moving
functions off of it, we can get rid of the back-depdencies from the
`merge` module to the `conflict` module that I introduced when I moved
`Merge` to the `merge` module. I'm thinking the `conflict` module can
focus on materialized conflicts.
2023-08-11 21:11:25 +00:00
Yuya Nishihara
925d54614d revset: remove round-trip conversion from heads() evaluation
This wouldn't matter much in practice, but I think it's better to stick to
low-level index primitives during revset evaluation.
2023-08-12 02:16:29 +09:00
Martin von Zweigbergk
d1dbe6de98 git: propagate errors for missing commits when importing refs 2023-08-11 05:06:36 +00:00
Yuya Nishihara
530547eb9c tests: test that git::import_refs() can update conflicted remote branch
Per discussion in #2009. This behavior isn't affected by e7e49527ef "git:
ensure that remote branches never diverge", but it's subtle enough to write
a test.
2023-08-10 06:27:16 +09:00
Yuya Nishihara
552c71ed36 tests: move commit_transactions() helper to testutils 2023-08-10 06:27:16 +09:00
Martin von Zweigbergk
ef5f97f8d7 conflicts: move Merge<T> to merge module
The `merge` module now seems like the obvious place for this type.
2023-08-06 22:08:09 +00:00
Martin von Zweigbergk
ecc030848d conflicts: rename Conflict<T> to Merge<T>
Since `Conflict<T>` can also represent a non-conflict state (a single
term), `Merge<T>` seems like better name.

Thanks to @ilyagr for the suggestion in
https://github.com/martinvonz/jj/pull/1774#discussion_r1257547709

Sorry about the churn. It would have been better if I thought of this
name before I introduced `Conflict<T>`.
2023-08-06 22:08:09 +00:00
Martin von Zweigbergk
56109bda38 tests: another attempt to fix remaining flaky tests in test_view.rs
This is another commit like 0f3bd7fb03 and 8e7e32710d. I don't
know how I didn't catch all remaining instances last time :(
2023-08-04 23:36:15 +00:00
Martin von Zweigbergk
4a10ea4e3e tests: attempt to fix more flaky tests in test_view.rs
This is the same kind of fix as in 8e7e3271. I should have just fixed
all instances then.
2023-08-04 21:13:30 +00:00
Martin von Zweigbergk
48b1a1c533 working_copy: in ignored directories, visit only already tracked paths
`.gitignores` in ignored directories should be ignored. Before this
commit, we would visit ignored directories like any others if there
were any ignored paths in them.

I've done a lot of preparation for this commit, but There's still a
bit of duplication between the new code and the existing code. I don't
mind improving it if anyone has suggestions. Otherwise I might end up
doing that when I get back to working on snapshotting tree-level
conflicts soon.

This fixes #1785.
2023-08-01 06:31:52 +00:00
Martin von Zweigbergk
02f2325fae working_copy: add test for .gitignores in ignored directory
This tests the scenario that was repored in #1785.
2023-08-01 06:31:52 +00:00
Martin von Zweigbergk
aff483c431 working_copy: test changes in tracked-but-ignored directory
It's currently the same code path for handling changes to tracked
paths in ignored directories as outside ignored directories, but I'm
about to change that.

I also updated the assertion in the test to compare all entries
instead of just the tree id, so it's easier to spot errors if it
fails.
2023-08-01 06:31:52 +00:00
Yuya Nishihara
b3ae7e7657 revset_graph: preserve original parents order
It seemed awkward if merged PR is sometimes rendered as a first branch.
Instead of sorting edges in index order, let's build a HashSet only when
deduplication is needed.
2023-07-29 05:36:09 +09:00
Martin von Zweigbergk
3ef552c4c1 tests: add TestWorkspace::snapshot() to simplify snapshotting
It's currently a bit complicated to snapshot the working copy and
there's a lot of duplication in tests. This commit introduces a
function to simplify it. I made the function snapshot the working copy
and save the updated state. Some of the tests I changed previously
discarded the changes instead of saving them, but I think they all did
so because it was simpler. I left a few call sites unchanged because
they make concurrent changes.
2023-07-28 09:32:18 -07:00
Martin von Zweigbergk
2ccd3247f9 tests: remove a duplicate code block
It looks like this has been duplicated since I added the test in
cd4fbd3565.
2023-07-28 09:32:18 -07:00
Yuya Nishihara
4834d12c37 simple_op_store: serialize RefTarget in new format (breaks downgrades)
This is breaking change. Old jj binary will panic if it sees a view saved by
new jj. Alternatively, we can store both new and legacy data for backward
compatibility.
2023-07-27 15:32:48 +09:00
Martin von Zweigbergk
4348d0b487 working_copy: leverage create_tree() in test
This also lets us compare the resulting tree because the working copy
now exactly matches the tree (it used to be that the `.gitignore` file
wasn't initially snapshotted).
2023-07-26 23:30:10 -07:00
Martin von Zweigbergk
84a60d15bc op_store: make ViewId and OperationId implement ObjectId 2023-07-26 14:17:21 -07:00
Waleed Khan
70d3c64b1e operation: propagate OpStoreError
This is a rote propagation of the error value to hopefully improve the panic in https://github.com/martinvonz/jj/issues/1907.
2023-07-25 12:46:59 -05:00
Martin von Zweigbergk
8d1cb1e1d7 working_copy: add test of racy checkout followed by file write
We don't seem to have any tests that our protection from undetected
changes caused by writes happening right after checkout, so let's add
one. The test case loops 100 times and each iteration fails slightly
more than 80% of the time on my machine (if I remove the protection in
`TreeState::update_file_state()`), so it seems quite good at
triggering the race.
2023-07-24 16:41:44 -07:00
Martin von Zweigbergk
e364c49854 test_working_copy_concurrent: run only with git backend
I don't see any reason for these tests to differ depending on backend,
so let's avoid running them twice (there are probably lots of other
tests that we're also running with different backends for little
reason).
2023-07-24 16:41:44 -07:00
Yuya Nishihara
e2f9ed439e revset: extract graph-related types to separate module
I'm going to add a topo-grouping iterator adapter, and the revset module is
already big enough to split.
2023-07-25 01:45:37 +09:00
Yuya Nishihara
2bbaa4352a refs: rename RefTarget::is_conflict() to has_conflict()
Copied from MergedTree::has_conflict(). I feel it's slightly better since
RefTarget "is" always a Conflict-based type. It could be inverted to
RefTarget::is_resolved(), but refs are usually resolved, and all callers
have special case for !is_resolved() state.
2023-07-23 22:25:57 +09:00
Martin von Zweigbergk
deb4ae476d merged_tree: add an iterator over conflicts
With `MergedTree`, we can iterate over conflicts by descending into
only the subdirectories that cannot be trivially resolved. We assume
that the trees have previously been resolved as much as possible, so
we don't attempt to resolve conflicts again.
2023-07-19 22:04:16 -07:00
Martin von Zweigbergk
828d528361 merged_tree: add a function for resolving conflicts
This adds a function for resolving conflicts that can be automatically
resolved, i.e. like our current `merge_trees()` function. However, the
new function is written to merge an arbitrary number of trees and, in
case of unresolvable conflicts, to produce a `Conflict<TreeId>` as
result instead of writing path-level conflicts to the backend. Like
`merge_trees()`, it still leaves conflicts unresolved at the file
level if any hunks conflict, and it resolves paths that can be
trivially resolved even if there are other paths that do conflict.
2023-07-19 22:04:16 -07:00
Martin von Zweigbergk
4f30417ffd merged_tree: introduce a type for a set of trees to merge on the fly
In order to store conflicts in the commit, as conflicts between a set
of trees, we want to be able merge those trees on the fly. This
introduces a type for that. It has a `Merge(Conflict(Tree))` variant,
where the individual trees cannot have path-level conflicts. It also
has a `Legacy(Tree)` variant, which does allow path-level conflicts. I
think that should help us with the migration.
2023-07-19 22:04:16 -07:00
Yuya Nishihara
84f0c96c8f view: replace .tags().get(name) with .get_tag(name) 2023-07-19 08:27:42 +09:00
Yuya Nishihara
bf46eb5ad2 view: replace .branches().get(name) with .get_branch(name) 2023-07-19 08:27:42 +09:00
Yuya Nishihara
ecb0850f1a view: return RefTarget by reference, clone() by caller 2023-07-19 08:27:42 +09:00
Yuya Nishihara
4da8483228 refs: reimplement RefTarget as Conflict<Option<CommitId>> wrapper
ContentHash is preserved at this point. I'll update it together with the
serialization format changes.
2023-07-18 18:12:09 +09:00
Yuya Nishihara
b6967a1dc9 refs: pass &Option<RefTarget> into merge_ref_targets() 2023-07-18 18:12:09 +09:00
Yuya Nishihara
443391bf8f view: store Option<RefTarget> in maps, add extension trait to flatten Option
Alternatively, we can wrap BTreeMap<String, Option<RefTarget>> to flatten
Option<&Option<..>> internally, but doing that would be tedious. It would
also be unclear if map.remove(name) should construct an absent RefTarget if
the ref doesn't exist.
2023-07-18 18:12:09 +09:00
Yuya Nishihara
7461370f6e view: add wrapper that will exclude absent RefTarget entries from ContentHash
The next commit will change these maps to store Option<RefTarget> entries, but
None entries will still be omitted from the serialized data. Since ContentHash
should describe the serialized data, relying on the generic ContentHash would
cause future hash conflict where absent RefTarget entries will be preserved.

For example, ([remove], [None, add]) will be serialized as ([remove], [add]),
and deserialized to ([remove], [add, None]). If we add support for lossless
serialization, hash(([remove], [None, add])) should differ from the lossy one.
2023-07-18 18:12:09 +09:00
Austin Seipp
9d05e9902a refactor(jj-lib): remove allow(unknown_lints)
Summary: Unneeded with the MSRV bump. The other one
will have to wait until Rust 1.72.0

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Change-Id: Ifb3d862aedd3f2aeb05a86ce76978d4f
2023-07-17 18:38:26 -05:00
Yuya Nishihara
0461a8575a refs: add stub constructors for absent RefTarget, replace None with it
Now we're mostly ready to reimplement RefTarget on top of
Conflict<Option<CommitId>>.
2023-07-17 08:24:24 +09:00
Yuya Nishihara
9c69a7cb15 refs: leverage Option<RefTarget> extension methods
is_fast_forward() has any() loop that defaults to true, so comment added.
2023-07-17 08:24:24 +09:00
Yuya Nishihara
4cfe2591b6 refs: turn RefTarget::adds()/removes() into iterator, rename accordingly
Since RefTarget will be reimplemented on top of Conflict<Option<CommitId>>,
we won't be able to simply return a slice of type &[CommitId]. These functions
are also renamed in order to disambiguate from Conflict::adds()/removes().
2023-07-17 08:24:24 +09:00
Martin von Zweigbergk
8e7e32710d tests: attempt to fix a flaky test
We saw a failure in `test_merge_views_git_heads()` in the GitHub CI,
but I wasn't able to reproduce it locally. Using the
`commit_transactions()` helper in the test should fix it.
2023-07-16 23:06:13 +01:00
Yuya Nishihara
a1e92563ae refs: add constructor of Some(RefTarget::Conflict { .. })
It's named after Conflict::from_legacy_form(). If RefTarget is migrated to
new Conflict type, from_legacy_form([], [add]) will create a normal target,
and from_legacy_form([], []) will be equivalent to the current None target.
That's why this function isn't named as RefTarget::conflict().
2023-07-17 01:13:21 +09:00
Yuya Nishihara
e55c533add refs: add constructor of Some(RefTarget::Normal(id))
If RefTarget is migrated to new Conflict type, this function will create
RefTarget(Conflict::resolved(Some(id))).

We still need some .unwrap() to insert Option<RefTarget> into map, but maps
will be changed to store new RefTarget type, and their mutation API will
guarantee that Conflict::resolved(None) is eliminated.
2023-07-17 01:13:21 +09:00
Yuya Nishihara
5ed070a78a view: use get_git_ref(name) where extra .clone() wouldn't matter
Perhaps, all view.get_<kind>(name) functions can return reference, but I'm
not willing to change the interface at this point. I'll revisit this after
migrating Option<RefTarget> to new Conflict-based type.
2023-07-15 05:57:49 +09:00
Yuya Nishihara
d80a719042 view: unify set/remove_local_branch() functions to take Option<RefTarget> 2023-07-15 05:57:49 +09:00
Yuya Nishihara
78eea06c36 view: unify set/remove_remote_branch() functions to take Option<RefTarget> 2023-07-15 05:57:49 +09:00
Yuya Nishihara
fc609a6d8d view: unify set/remove_tag() functions to take Option<RefTarget> 2023-07-15 05:57:49 +09:00
Yuya Nishihara
3be462266c view: unify set/remove_git_ref() functions to take Option<RefTarget>
New function takes name by reference since it doesn't always need an owned
String.
2023-07-15 05:57:49 +09:00
Yuya Nishihara
5218591a82 view: unify set/clear_git_head() functions to take Option<RefTarget>
If we migrate RefTarget to new Conflict-based type, it won't store
Conflict<CommitId>, but Conflict<Option<CommitId>>. As the Option will
be internalized, new RefTarget type will also represent an absent target.
The 'target: Option<RefTarget>' argument will be replaced with new RefTarget
type.

I've also renamed the function for consistency with the following changes.
It would be surprising if set_local_branch(name, target) could remove the
branch. I feel the name set_local_branch_target() is less confusing.
2023-07-15 05:57:49 +09:00
Waleed Khan
6d7998f8c5 working_copy: return Result from WorkingCopy::tree_state/WorkingCopy::tree_state_mut 2023-07-14 13:45:40 -07:00
Waleed Khan
60f1d7e307 working_copy: create and propagate TreeStateError 2023-07-14 13:03:57 -07:00
Yuya Nishihara
424786def1 refs: leverage Conflict::flatten() and simplify() to premerge ref targets
The order of conflicted ids slightly changed since Conflict::simplify()
tries to preserve diff pairs. It shouldn't matter so long as the result is
stable.
2023-07-12 21:29:41 +09:00
Yuya Nishihara
ddaf226108 tests: make RefTarget::Conflict { .. } assertion not rely on id order
Here we don't need to care about the order at all. We have test_refs.rs
to ensure that the order is stable.
2023-07-12 21:29:41 +09:00
Yuya Nishihara
9f06bf8be5 repo: do not discard old working-copy commit if it's pointed by local branch
It would be confusing if a branch moved backwards by checking out unrelated
commit.

#1854
2023-07-12 21:29:11 +09:00
Yuya Nishihara
f5f61f6bfe revset: resolve "HEAD@git" just like other pseudo @git branches
I don't think this would be practically useful, but consistent UX is
important.

Fixes #1843
2023-07-11 16:29:27 +09:00
Yuya Nishihara
79955d9cb3 git: do not import/export local branch named "HEAD"
Git CLI rejects it (though the data model would probably work fine with
"HEAD" branch.) This ensures that HEAD@git in JJ world is not an exported
branch named "HEAD".
2023-07-11 16:29:27 +09:00
Yuya Nishihara
9aa308fb4a revset: include pseudo @git remote in suggestion
Since collect_branch_symbols() doesn't have to be fast, I made it simply
build a new branches map.
2023-07-10 06:17:44 +09:00
Martin von Zweigbergk
aac5b7aa25 cargo: rename crates from jujutsu/jujutsu-lib to jj-cli/jj-lib
Almost everyone calls the project "jj", and there seeems to be
consensus that we should rename the crates. I originally wanted the
crates to be called `jj` and `jj-lib`, but `jj` was already
taken. `jj-cli` is probably at least as good for it anyway.

Once we've published a 0.8.0 under the new names, we'll release 0.7.1
versions under the old names with pointers to the new crates names.
2023-07-09 06:40:43 +02:00
Yuya Nishihara
3e294ca2d6 revset: do not suggest deleted local branches, suggest @remote branches
It seemed too verbose to always include @remote branches, so synced remotes
are omitted by default. If the given symbol contained '@', all remote symbols
are populated so that the distance of remote fragment is taken into account.
2023-07-09 10:42:14 +09:00
Yuya Nishihara
4a5060a618 revset: don't resolve deleted branch symbol to empty set
A deleted branch disappears immediately if there's no remote counterpart,
so I don't think a local name should be resolvable like zombie.
2023-07-09 10:42:14 +09:00
Yuya Nishihara
5c1352d31c revset: add tests for branch symbol resolution
I'm going to fix resolution of remote-only branches. This also includes some
typo tests because I need to fix suggestion as well.
2023-07-09 10:42:14 +09:00
Yuya Nishihara
564506a7c7 tests: fix test_fetch_prune_deleted_ref() to set up refs on remote
This is broken since aa78f97d55 "git: refactor tests by extracting some
common setup."
2023-07-09 10:08:46 +09:00
Waleed Khan
ef83f2beeb feat(fsmonitor): Watchman filesystem monitor implementation 2023-07-08 18:48:14 +03:00
Waleed Khan
092dce0625 refactor(working_copy): create SnapshotOptions struct
Required in a later commit.
2023-07-08 18:48:14 +03:00
Ilya Grigoriev
b6a9423f38 git export: (almost) no-op refactor to export_refs to use RefName
This follows 3779b45, but in this case the refactor makes the logic more
complicated. The main goal here is to prepare for the next commit.
2023-07-03 11:01:22 -07:00
Yuya Nishihara
a07574a233 git: pass RefName enum to git_ref_filter callback
I think it's slightly better to compare each ref fragment than building
"refs/remotes/{remote}/{branch}" pattern to be matched.
2023-07-02 09:49:07 +09:00
Martin von Zweigbergk
c0ffce781e store: cache tree on write and return it
This matches what we do when writing commits.
2023-06-30 14:12:36 +02:00
Martin von Zweigbergk
134efabcef test_merge_trees: make merge_trees() wrapper's signature match original 2023-06-30 14:12:36 +02:00
Martin von Zweigbergk
779b8ba318 files: replace uses of MergeHunk by Conflict<ContentHunk>
Since `Conflict`s can represent the resolved state, so
`Conflict<ContentHunk>` can represent the states that we use
`MergeHunk` for. `MergeHunk` does force the user to handle the
resolved case, which may be useful. I suppose one could use the same
argument for making `Conflict` an enum, i.e. if we think that
`MergeHunk`'s two variants are beneficial, then we should consider
making `Conflict` an enum with those two variants.
2023-06-28 06:51:37 +02:00
Martin von Zweigbergk
c625e9352d files: make MergeHunk::Conflict be a Conflict<ContentHunk>
The `ConflictHunk` type doesn't add anything over
`Conflict<ContentHunk>`.
2023-06-27 21:06:32 +02:00
Martin von Zweigbergk
b1f2e80349 files: add a newtype around Vec<u8> for content hunks
It's useful to have a more readable `Debug` format for `Vec<u8>`
(`"foo"` is better than `[102, 111, 111]`). It might also make types
in function signatures and elsewhere more readable.
2023-06-27 21:06:32 +02:00
Glen Choo
7afaa2487b git: add .gitmodules parser
This only parses the fields relevant to us, i.e.:

- name: the stable identifier of the submodule
- path: the path to the submodule in the current commit
- url: the remote we can clone the submodule from

The full list of .gitmodules fields can be found at
https://git-scm.com/docs/gitmodules.
2023-06-27 10:07:00 -07:00
Kevin Liao
86b6a11e63 Fix jj init --git-repo fails and leaves broken .jj folder
This commit fixes #1305

Before this commit, running `jj init --git-repo=./` in a folder that
does not have a .git would cause jj to panick and leave an unfinished corrupted jj repo.

This commit fixes that by changing the call chain to return an error
instead of calling .unwrap() and panicking. This commit also adds logic to delete the unfinished jj
repository when the git backend initialization failed.

Before this commit, running the above command would result in the following
```
Running `jj/target/debug/jj init --git-repo=./`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { code: -3, klass: 2, message: "failed to resolve path '/Users/kevincliao/github/jj/test-repo/.jj/repo/store/../../../.git': No such file or directory" }', lib/src/git_backend.rs:83:75
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

After this commit, the result is the following and the jj repo is deleted:
```
Running `jj/target/debug/jj init --git-repo=./`
Error: Failed to access the repository: Error: Failed to open git repository: failed to resolve path '/Users/kevincliao/github/jj/test-repo/.jj/repo/store/../../../.git': No such file or directory; class=Os (2); code=NotFound (-3)
```
2023-06-20 11:02:06 -07:00
Glen Choo
6621f261cc repo: add submodule_store, default impl
..and other assorted boilerplate. These are just stubs for now, but now
that we've reserved the `submodule_store` subdirectory, we can start
adding more functionality.
2023-06-19 09:48:58 -07:00
Martin von Zweigbergk
82883e648d conflicts: move describe_conflict() etc. onto Conflict
Before we had `conflicts::Conflict`, most of these functions took a
`backend::Conflict`. I think I didn't want to pollute the `backend`
module with this kind of logic, trying to keep it focused on
storage. Now that we have the type in `conflicts`, however, I think it
makes sense to move these functions onto it.
2023-06-19 07:05:02 +02:00
Yuya Nishihara
a67d8b5a65 index: turn CompositeIndex::walk_revs() into position-based API
This gets rid of round-trip conversion from queries like "(main..)-". I have
such expression in my default log/disambiguation revset, and the query could
take ~150ms to convert head positions back and forth if the repository had
tons of unmerged commits.
2023-06-19 13:41:43 +09:00
Martin von Zweigbergk
19fd8a917a conflicts: remove ConflictId from update_conflict_from_content()
For tree-level conflicts (#1624), I plan to remove `ConflictId`
completely. This commit removes `ConflictId` from
`update_conflict_from_content()` by instead making it take a
`Conflict<Option<TreeValue>>` and return a possibly different such
value.

I made the call site in `working_copy` avoid writing the conflict to
the store if it's unchanged, but I didn't make the same optimization
in `merge_tools` becuase it's much more likely to have changed there.
2023-06-13 08:49:46 +02:00
Ilya Grigoriev
096538ba18 revsets: stop jj parsing br as a git_ref refs/heads/br
Use `br@git` instead.

Before, if there is not a local branch `br`, jj tried to resolve
it as a git ref `refs/heads/br`. Unchanged from before, `br` can
still be resolved as a tag `refs/tag/br`.
2023-06-12 14:31:44 -07:00
Ilya Grigoriev
738f99ddf1 test_revset.rs: disable nightly clippy false-positive warning
I opened a bug for the clippy error:
https://github.com/frondeus/test-case/issues/122
2023-06-11 13:11:01 -07:00
Waleed Khan
23a4124d20 feat(revset): suggest similar branch names 2023-06-05 11:11:17 -05:00
Martin von Zweigbergk
29b676f24f store: do conversion to/from backend::Conflict
We now convert to/from `backend::Conflict` right before/after calling
the `Store` methods, so we can simplify by having the `Store` do the
conversion.
2023-06-04 06:48:34 -07:00
Martin von Zweigbergk
c378503991 conflicts: replace remaining uses of backend::Conflict 2023-06-04 06:48:34 -07:00
Martin von Zweigbergk
f4499aa65e conflicts: fix bug when modifying modify/delete conflicts
Currently, if the user modifies a modify/delete conflict, we always
consider the result resolved. That happens because we materialize the
missing side of the conflict as an empty string but when we parse the
conflict, we expect only the number of sides in the input
conflict. For example, if the input is a regular modify/delete
conflict with one remove and one add, the materialized markers will
have one remove and two adds (one of them empty), but when we try to
parse it, we expect one remove and only one add. When we fail to parse
it, we consider it resolved.

This commit fixes the bug by using
`conflicts::Conflict<Option<TreeValue>>` and keeping track of which
sides were supposed to be empty. We could have fixed the bug without
switching to `conflicts::Conflict`, but we want to switch anyway, and
the fix happens naturally when switching.
2023-06-04 06:48:34 -07:00
Yuya Nishihara
78a64edb22 dag_walk: rename bfs() to dfs() because it's depth-first
No callers appear to rely on traversal order, so let's just fix the function
name. Maybe it was a typo.
2023-06-04 11:47:49 +09:00
Yuya Nishihara
3ba544414c dag_walk: unbox bfs() callback, use iter::from_fn() to implement iterator
I just wanted to remove syntactic noise from callers. iter::from_fn() helps
to avoid declaring struct with lots of type parameters.
2023-06-04 11:47:49 +09:00
Yuya Nishihara
3d449c55b7 tree_builder: do not omit file entry which was previously a directory 2023-06-01 09:38:06 +09:00
Yuya Nishihara
ae9f7aba52 tests: add test for file-directory-file transition
TreeBuilder fails to handle directory-file transition right now, and leaves
the dirty file as "clean".
2023-06-01 09:38:06 +09:00
Martin von Zweigbergk
fb17e6a50e revset: use different errors for ambiguous commit/change IDs
I made a typo and got something like this:

```
Error: Commit or change id prefix "wl" is ambiguous
```

Since we can tell commit ids from change ids these days, let's make
the error message say which kind of id it is. Changing that also kind
of forced me to make a special error for empty strings. Otherwise we
would have to arbitrarily say that an empty string is a commit id or
change id. A specific error message for empty strings seems helpful,
so that's probably for the better anyway.
2023-05-31 06:28:32 -07:00
Yuya Nishihara
b7b9b8c88e index: pass only CompositeIndex to default_revset_engine::evaluate() 2023-05-29 08:15:40 +09:00
Yuya Nishihara
cf5cb380bb index: implement Index for CompositeIndex
We can't get rid of the other "impl Index"es because .as_composite() must
return a real reference type. Maybe we could turn CompositeIndex into an
owned wrapper, but I don't know if that would be worth the effort.
2023-05-29 08:15:40 +09:00
Yuya Nishihara
5989bdf781 index: move Index::as_any() to MutableIndex, obtain CompositeIndex from there
It might sound scary to add public .mutable_index() accessor, but I think
it's okay because immutable MutableIndex reference has no more power than
Index.

This allows us to implement Index for lifetime-bound type such as
CompositeIndex<'_>.
2023-05-29 08:15:40 +09:00
Yuya Nishihara
93284a153f index: obtain CompositeIndex from ReadonlyIndexWrapper
I'll remove Index::as_any() so that Index can be implemented for reference
wrapper.
2023-05-29 08:15:40 +09:00
Yuya Nishihara
fb77c55268 index: use as_composite() to access to index stats
The idea is that .as_composite() is equivalent to .as_index(), but for the
implementation type. I'm going to add "impl Index for CompositeIndex" to
clean up index references passed to revset engine.
2023-05-29 08:15:40 +09:00
Martin von Zweigbergk
f838d083d3 tree: add test of merge of executable bit
We didn't seem to have any tests of this, so let's add one before I
change the implementation.
2023-05-24 22:00:38 -07:00
Yuya Nishihara
e24fe817c9 tests: invoke .walk_revs() through CompositeIndex
Prepares for removal of the index trait method.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
b01614bbdd cleanup: leverage scoped thread in tests 2023-05-21 21:02:58 +09:00
Yuya Nishihara
38a7e7fd62 git_backend: on read_commit(), bulk-update extra metadata table of ancestors
Otherwise, "jj init --git-repo ." would create extra table files per commit,
and merge them.

I considered adding an explicit GitBackend method to be called from
git::import_refs(), but the call order matters. The method should be invoked
before calling store.get_commit(..) or mut_repo.add_head(..). Since commits
are likely to be loaded from the head, we can instead make read_commit()
import ancestor metadata at all.

Alternatively, we could make a Git commit hidden until it's inserted into
the extra table. It's rather big change, and I wouldn't like to do that
without thinking more thoroughly.
2023-05-21 08:29:00 +09:00