Commit graph

1821 commits

Author SHA1 Message Date
Martin von Zweigbergk
8af22eb83c working_copy: remove matching that's always against _ 2023-07-06 14:24:38 +02:00
Yuya Nishihara
868188c84e repo: handle empty .jj repo gracefully, include file path in error message 2023-07-06 20:48:46 +09:00
Yuya Nishihara
9560ca94c5 local_backend: remove global error conversion impls for BackendError
We don't care much about error handling in the local backend, but these
conversion impls are globally available and can be misused.
2023-07-06 20:48:46 +09:00
Yuya Nishihara
5346bd734f git_backend: translate io::Error of read_conflict() to ReadObject error
This is the last place in Git backend where io::Error is magically converted
to BackendError::Other.
2023-07-06 20:48:46 +09:00
Yuya Nishihara
4e4ca46998 git_backend: wrap TableStoreError to preserve source error object 2023-07-06 20:48:46 +09:00
Yuya Nishihara
cf8a0466c4 backend: introduce error types specific to init/load phases
Errors that may occur while loading backend would vary per backends, and
it's unlikely that these errors could be mapped to BackendError variants
other than BackendError::Other. So let's extract Other(_) of that kind as
a separate type to clarify there would be no other error variants.

Perhaps, Backend/Error will be renamed to CommitBackend/Error or
CommitStore/Error?, whereas I think BackendInit/LoadError can be shared
among store factories.
2023-07-06 20:48:46 +09:00
Yuya Nishihara
e1e75daa8e backend: make BackendError::Other preserve source error object 2023-07-06 20:48:46 +09:00
Martin von Zweigbergk
99226bb96d tree: simplify diff iterator by leveraging Tree::value()
This is much simpler and I was slightly surprised that it doesn't have
much impact on performance. I tried `jj --ignore-working-copy diff -s
--from root --to v5.15` in the Linux kernel repo, and there was
perhaps a 1.5% slowdown (508 ms -> 515 ms). In more normal cases (like
diffing a single commit against its parent), I couldn't measure any
difference at all.
2023-07-06 11:21:21 +02:00
Yuya Nishihara
5b78fe75b1 git_backend: propagate load() error to caller
#1794
2023-07-06 12:43:49 +09:00
Yuya Nishihara
84060d750b git_backend: propagate init_internal() error to caller 2023-07-06 12:43:49 +09:00
Yuya Nishihara
2db4c906ad git_backend: attach file path to initialization error 2023-07-06 12:43:49 +09:00
Yuya Nishihara
31bb68486e git_backend: insert error type specific to backend initialization
This helps to map initialization error to BackendError without too general
From impl. I don't think io::Error (or our PathError) should be automatically
translated to BackendError::Other because BackendError has more specific
variants depending on context. If the error is specific to initialization,
it makes sense to translate it to Other variant.
2023-07-06 12:43:49 +09:00
Yuya Nishihara
a09a406817 git_backend: leverage std::fs::read/write() helpers 2023-07-06 12:43:49 +09:00
Yuya Nishihara
6d6b87f4b0 file_util: move PathError and its helper trait from repo module
It's generally useful in order to attach context to io::Error.
2023-07-06 12:43:49 +09:00
dependabot[bot]
a7408d8bc9 cargo: bump smallvec from 1.10.0 to 1.11.0
Bumps [smallvec](https://github.com/servo/rust-smallvec) from 1.10.0 to 1.11.0.
- [Release notes](https://github.com/servo/rust-smallvec/releases)
- [Commits](https://github.com/servo/rust-smallvec/compare/v1.10.0...v1.11.0)

---
updated-dependencies:
- dependency-name: smallvec
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-05 22:29:49 +02:00
dependabot[bot]
0e4ef1c8d5 cargo: bump serde_json from 1.0.99 to 1.0.100
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.99 to 1.0.100.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.99...v1.0.100)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-05 15:57:54 +00:00
dependabot[bot]
aea8d1b8e7 cargo: bump regex from 1.8.4 to 1.9.0
Bumps [regex](https://github.com/rust-lang/regex) from 1.8.4 to 1.9.0.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.8.4...1.9.0)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-05 15:45:28 +00:00
dependabot[bot]
33ccd13caa cargo: bump thiserror from 1.0.40 to 1.0.41
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.40 to 1.0.41.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.40...1.0.41)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-05 15:34:28 +00:00
dependabot[bot]
6208cdff2a cargo: bump rustix from 0.38.2 to 0.38.3
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.38.2 to 0.38.3.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.38.2...v0.38.3)

---
updated-dependencies:
- dependency-name: rustix
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-05 15:24:13 +00:00
Martin von Zweigbergk
651a3cbe15 rewrite: delete TODOs about labels for each term in a conflict
I don't think we'll want to record a label for each term, because such
labels would get stale, and it seems hard to make them make sense
after transferring a remote to another repo. I think we'll probably
want to infer labels on demand instead (#1176).
2023-07-05 16:50:27 +02:00
Ilya Grigoriev
597a74d51b git fetch: limit export of deleted refs to provided globs 2023-07-03 11:01:22 -07:00
Ilya Grigoriev
371e7f46e2 git fetch: do a git export of deleted branches before fetch 2023-07-03 11:01:22 -07:00
Ilya Grigoriev
fde3c3f581 git.rs: create export_some_refs 2023-07-03 11:01:22 -07:00
Ilya Grigoriev
a50cfec008 lib/git.rs: inline functions used only once, rename others
I now believe that jj will need to store git-tracking refs for both local and
remote-tracking branches of the git repo for the long term. See
https://github.com/martinvonz/jj/issues/1666#issuecomment-1597806451

More refactoring will likely happen when that bug is fixed.
2023-07-03 11:01:22 -07:00
Ilya Grigoriev
59b354992a git export: export deletion of forgotten remote-tracking branches 2023-07-03 11:01:22 -07: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
dependabot[bot]
88736c7017 cargo: bump rustix from 0.38.0 to 0.38.2
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.38.0 to 0.38.2.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.38.0...v0.38.2)

---
updated-dependencies:
- dependency-name: rustix
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-04 00:46:57 +09:00
Yuya Nishihara
061fbeb2f8 op_store: make RefTarget return removes/adds as slice, .clone() as needed 2023-07-02 14:39:45 +09:00
Waleed Khan
d1453a0c7c cleanup: fix clippy lint 2023-07-01 18:10:32 -07:00
Yuya Nishihara
915f76f4d9 git: use RegexSet in place of concatenating multiple glob patterns
Perhaps, this would handle patterns like ["a(b", "c)"] better. It might not
be correct to error out on "(", but should be better than building wrong
regexp pattern "a(b|c)".
2023-07-02 09:49:07 +09: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
Yuya Nishihara
da3c03206c tree: remove useless pinning of Tree object
Since Tree is Unpin, Pin<Box<Tree>> can be moved and it's basically the same
as Box<Tree>. I heard using Box<T> still violates strict aliasing rule, but
Pin wouldn't give any additional guarantee.

https://morestina.net/blog/1868/self-referential-types-for-fun-and-profit
2023-07-01 17:56:00 +09:00
Martin von Zweigbergk
f32b67ac3d tree: leverage Conflict::flatten() etc 2023-06-30 14:43:58 +02:00
Martin von Zweigbergk
07dbc9fb0d conflicts: add flatten() for flattening nested conflicts 2023-06-30 14:43:58 +02:00
Martin von Zweigbergk
183021f559 conflicts: add try_map() for Result 2023-06-30 14:43:58 +02:00
Martin von Zweigbergk
24c0190f74 conflicts: rename try_map() to maybe_map()
I'm going to add a `Result` version and it makes more sense to call
that `try_map()`.
2023-06-30 14:43:58 +02:00
Martin von Zweigbergk
83fefa9a3b conflicts: add a map(), use in extract_as_single_hunk()
Now that we've replaced `MergeHunk` by a `Conflict`, it makes sense to
convert the input `Conflict<FileId>` by mapping each term. Unlike
`Option::map()` I made `Conflict::map()` take a reference `self`,
because it's not uncommon to want to map the same conflict multiple
times. I'm going to use that for producing a
`Conflict<Option<TreeValue>>` from a `Conflict<Tree>` and a set of
paths.
2023-06-30 14:43:58 +02:00
Martin von Zweigbergk
6bd13382f4 backend: add a function for setting or removing a tree entry 2023-06-30 14:43:58 +02: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
b297c0c0d8 rewrite: propagate errors from merge_trees() 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
Kevin Liao
eac90fd113 Update init_external to return an error instead of unwrapping 2023-06-29 10:03:13 -07:00
dependabot[bot]
00d8cd740d cargo: bump num_cpus from 1.15.0 to 1.16.0
Bumps [num_cpus](https://github.com/seanmonstar/num_cpus) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/seanmonstar/num_cpus/releases)
- [Changelog](https://github.com/seanmonstar/num_cpus/blob/master/CHANGELOG.md)
- [Commits](https://github.com/seanmonstar/num_cpus/compare/v1.15.0...v1.16.0)

---
updated-dependencies:
- dependency-name: num_cpus
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-29 18:49:48 +02:00
Yuya Nishihara
7ad6357c10 revset: add union_all(...) helper to concatenate multiple -rREV options 2023-06-29 19:33:32 +09:00
dependabot[bot]
db87cb2c39 cargo: bump rustix from 0.37.20 to 0.38.0
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.37.20 to 0.38.0.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.37.20...v0.38.0)

---
updated-dependencies:
- dependency-name: rustix
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-28 22:16:49 +02:00
Yuya Nishihara
3779b45b94 git: use type-safe RefName enum extensively in import_some_refs()
I was thinking of adding GitRefName newtype, but the RefName type can serve
the same role.
2023-06-28 23:11:08 +09:00
Yuya Nishihara
1d9552406b git: leverage parse_git_ref() to test reference kind 2023-06-28 23:11:08 +09: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
35e4d5f205 conflicts: add take(), returning the removes and adds Vecs 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
Martin von Zweigbergk
b3946be414 conflicts: avoid unnecessary cloning of conflict content 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
dependabot[bot]
43cedfd0c9 cargo: bump serde_json from 1.0.97 to 1.0.99
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.97 to 1.0.99.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.97...v1.0.99)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-27 07:56:50 +02:00
dependabot[bot]
5e6dd17ed9 cargo: bump whoami from 1.4.0 to 1.4.1
Bumps [whoami](https://github.com/ardaku/whoami) from 1.4.0 to 1.4.1.
- [Changelog](https://github.com/ardaku/whoami/blob/stable/CHANGELOG.md)
- [Commits](https://github.com/ardaku/whoami/compare/v1.4.0...v1.4.1)

---
updated-dependencies:
- dependency-name: whoami
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-26 20:55:03 +02:00
Martin von Zweigbergk
f64e4816df git: remove unused push_commit() 2023-06-26 14:28:51 +02:00
Martin von Zweigbergk
b8221d4e21 conflicts: add try_map() method
This simplifies `to_file_conflict()` and `try_resolve_file_conflict()`
a bit.
2023-06-26 13:47:33 +02:00
Martin von Zweigbergk
b8f6a48c66 merge: fast-path trivial merge of 1-way "conflicts"
I don't think we call `trivial_merge()` for 1-way "conflicts" yet, but
I'll probably end up doing that soon.
2023-06-26 13:47:33 +02:00
Martin von Zweigbergk
9c486ebe45 conflicts: add a method returning the resolved value, if resolved 2023-06-26 13:47:33 +02:00
Yuya Nishihara
ca6b9828d1 id_prefix: only store first few bytes of keys in IdIndex
This eliminates indirect access through Vec<u8> and improves cache locality
while sorting the index entries. We can achieve a similar result by using
SmallVec<[u8; 24]> in place of Commit/ChangeId(Vec<u8>), but we would have
to determine a reasonable id length across backends. Indexing [u8; 4] performs
better, at the cost of the API and implementation complexity.

For temporary Commit/ChangeId allocation in general, I think a borrowed type
like Path/PathBuf will help.

Testing with my "linux" repo, this saves ~670ms needed to initialize both
change id index and disambiguation indexes.
2023-06-25 12:54:18 +09:00
Yuya Nishihara
b789ffb3fc id_prefix: inline IdIndex::resolve_prefix_range()
I'll rewrite resolve_prefix_range() to branch depending on the prefix length,
and the easiest way to do that is passing iterator to continuation function
instead of returning iterator as an either (or boxed) type.
2023-06-25 12:54:18 +09:00
Yuya Nishihara
7ada2196e1 id_prefix: store (CommitId, ChangeId) pairs separately in disambiguation index
I'm going to rewrite IdIndex to store only first few bytes of the key. A
separate table helps there.

At this point, it wouldn't make sense to convert usize to u32, but the new
index will store ([u8; 4], u32) pairs.
2023-06-25 12:54:18 +09:00
Yuya Nishihara
580d8bd92e id_prefix: introduce builder interface to IdIndex
It allows us to build multiple IdIndex instances within a single loop. As the
final sorting is heavy operation, I don't want to implement Default + Extend
for IdIndex to be compatible with Iterator::unzip().
2023-06-25 12:54:18 +09:00
Yuya Nishihara
3799aa44bb id_prefix: test resolve_prefix_with() instead of _to_values()
I'll remove resolve_prefix_to_values() method.
2023-06-25 12:54:18 +09:00
Yuya Nishihara
020aeff903 id_prefix: insert intermediate lookup state to resolve unique len from there 2023-06-25 12:54:18 +09:00
Yuya Nishihara
d1701a5d95 git: on import_refs(), avoid loading git commit object if it's known
With my colocated "linux" repo, this appears to save ~50ms startup overhead.
Since the repo has lots of indirect tags, we can't eliminate tag object
loading at all. But still, it's faster than falling back to peel_to_commit().
2023-06-23 16:26:13 +09:00
dependabot[bot]
e6ab3f132f cargo: bump itertools from 0.10.5 to 0.11.0
Bumps [itertools](https://github.com/rust-itertools/itertools) from 0.10.5 to 0.11.0.
- [Changelog](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-itertools/itertools/compare/v0.10.5...v0.11.0)

---
updated-dependencies:
- dependency-name: itertools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-22 18:18:48 +02:00
dependabot[bot]
8aa8d84f1e cargo: bump insta from 1.29.0 to 1.30.0
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.29.0 to 1.30.0.
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.29.0...1.30.0)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-22 18:18:21 +02:00
Martin von Zweigbergk
ea2d5fdba7 backend: drop deprecated fields from local_store.proto
We don't even try to preserve compatibility with old repos using the
local backend.
2023-06-22 13:49:46 +02:00
Martin von Zweigbergk
da5db27bb0 backend: split up store.proto in git and local versions
It was convenient that what the git backend stored in its "extras"
table is exactly a subset of the fields that local backend stores, but
it's bit ugly and limiting. For example, it makes it possible to
populate the `author` field in the git extras, but that would have no
effect. It's better that it's not possible to do that (we store the
author field in the git commit, of course).

What made me notice this now was that I'm working on tree-level
conflicts (#1624) and I'm thinking of adding a field to the git extras
saying "this commit has single tree, but it's still a new-style
commit", so we can know not to walking such trees to find path-level
conflicts. That's only needed for the git backend because we don't
care about compatibility for the local backend.
2023-06-22 13:49:46 +02:00
Martin von Zweigbergk
c33062e8cd cargo: upgrade pest and pest_derive to 2.7.0
Version 2.6.0 and 2.6.1. have been yanked.
2023-06-22 08:16:14 +02:00
Martin von Zweigbergk
dee5dff20d conflicts: preserve diffs when simplfying a conflict
If we allow `Conflict::simplify()` to swap the removes and adds as
freely as we currently do, we may present the user with a conflict
marker with a diff that has never appeared anywhere before the
simplification. That seems very confusing. Let's instead preserve the
diffs when we simplify conflicts.
2023-06-21 06:42:18 +02:00
Martin von Zweigbergk
8f75a8236a conflicts: add test of higher-arity conflict simplificaton changing diffs
It's a bit weird to simplify a conflict like `A B->C D->E C->F` to `A
B->E D->F` because it changes which diffs are in the conflict, but
that's what we currently do. Let's have a test for that.

We actually already have tests showing how `A B->C D->A` gets
simplified to `C B->D`, but those are less obviously weird because
when rendered as `removes = [B], adds = [C, D]`, it doesn't look that
different from the reverse.
2023-06-21 06:42:18 +02:00
dependabot[bot]
2bf65bd3e9 cargo: bump pest_derive from 2.6.0 to 2.6.1
Bumps [pest_derive](https://github.com/pest-parser/pest) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.6.0...v2.6.1)

---
updated-dependencies:
- dependency-name: pest_derive
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-21 06:18:50 +02: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
dependabot[bot]
8a8b96a448 cargo: bump pest from 2.6.0 to 2.6.1
Bumps [pest](https://github.com/pest-parser/pest) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.6.0...v2.6.1)

---
updated-dependencies:
- dependency-name: pest
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-19 22:43:34 +02: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
038b64d273 conflicts: add resolve_trivial() and test invariants 2023-06-19 08:30:09 +02:00
Martin von Zweigbergk
3f95dafd67 conflicts: resolve trivial merge of A+A-B+C-C to A
This changes the behavior in one of the cases ilyagr@
[mentioned](https://github.com/martinvonz/jj/pull/1610#discussion_r1199823932)
to match his suggestion. After some more thinking while working on
tree-level conflicts, I now think it's clear that the added `+C-C`
terms should have no effect on the result. A very similar argument is
that `Conflict::simplify()` should not change the result of
`trivial_merge()`. I'll add tests for that next.
2023-06-19 08:30:09 +02: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
Martin von Zweigbergk
7a8cabafc9 conflicts: remove unused Conflict::set_{add,remove}()
These seem unused since 19fd8a917a.
2023-06-19 07:05:02 +02:00
dependabot[bot]
d67f41e882 cargo: bump serde_json from 1.0.96 to 1.0.97
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.96 to 1.0.97.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.96...v1.0.97)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-19 06:42:19 +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
Yuya Nishihara
8b0c01d1e9 git: return early from import_refs() if no commits to abandon
This saves another 150ms needed to set up binary heap with ~4000 wanted
and unwanted heads.
2023-06-16 09:45:41 +09:00
Yuya Nishihara
5fda093481 git: unify loop that consumes stale/excluded git refs 2023-06-16 09:45:41 +09:00
Yuya Nishihara
aa2359fdec git: rename new_git_heads to pinned_git_heads as it isn't always "new" 2023-06-16 09:45:41 +09:00
Yuya Nishihara
c8eb1a3c9c git: remove uninteresting old refs from list of heads to abandon
Since unchanged refs should be pinned by new_git_heads, we only need to
consider about "changed" old_git_targets. This allows us to return early
if hidable_git_heads.is_empty().
2023-06-16 09:45:41 +09:00
Yuya Nishihara
cf2c14296b git: on import_refs(), don't clobber view's heads with known HEAD@git
In colocated mid-size "linux" repo, this saves ~450ms needed to do
enforce_view_invariants(). We could instead make add_head() to return early,
but the condition would be a bit weird since HEAD@git is typically a parent
of known heads, not a head itself.
2023-06-16 09:45:41 +09:00
Yuya Nishihara
55f93bfa04 tree: reuse caller-provided path in known_sub_tree(), mark it as private 2023-06-15 00:45:07 +09:00
Yuya Nishihara
db7facb78e tree: rewrite sub_tree_recursive() to not use known_sub_tree()
This is the only place where the caller of known_sub_tree() doesn't know
the full repo path.
2023-06-15 00:45:07 +09:00
Yuya Nishihara
589917a53c repo_path: micro-optimize .join() to not reallocate cloned Vec
While playing with perf.data captured with "jj log", I noticed RepoPath::join()
has measurable cost. The first half is small alloc()s for Vec and Strings, and
the latter is realloc() on Vec::push(). Removing realloc() is easy, so let's
do that.
2023-06-15 00:45:07 +09:00
Martin von Zweigbergk
d886d8c203 conflicts: extract methods for converting to/from generic legacy form
We already have the new `Conflict::from_backend_conflict()` for
converting from a `backend::Conflict`, but we model conflicts in a
similar way in at least `RefTarget`. I'd like to be able to use
`conflicts::Conflict` there too. To prepare for that, let's extract
generic methods from `Conflict::from_backend_conflict()` and
`Conflict::to_backend_conflict()`.

I'm not sure I'll get around to making `RefTarget` use `Conflict` but
this commit seems like nice cleanup either way. It makes the tests
simpler if nothing else.
2023-06-13 21:48:35 +02:00
Martin von Zweigbergk
bbbae2c172 conflicts: fix a typo (lossy conflict -> lossy conversion) 2023-06-13 21:48:35 +02:00
Martin von Zweigbergk
02bb3aecf3 tree: don't read file contents on contents/executable "conflict"
If one side changes the contents and one side changes the executable
bit, we get a non-trivial conflict in the `TreeValue`s, but once we've
split them up into `FileId`s and bools, we can trivially resolve them
separately, without having to read file contents.
2023-06-13 08:49:46 +02:00
Martin von Zweigbergk
6e6ca16fd4 tree: make try_resolve_file_conflict() write resolved file to store
The function takes a `&Conflict<Option<TreeValue>>` argument so it
seems it should return an `Option<TreeValue>` for symmetry.
2023-06-13 08:49:46 +02:00
Martin von Zweigbergk
1f1c6867c7 conflicts: add a simplify() method, taken from tree.rs
It seems generally useful to be able to simplify a conflict, and it's
not specific to merging trees, so let's move it to
`conflicts.rs`. Once we're done with the migration to tree-level
conflicts, I think `Conflict::simplify()` will remain but
`tree::simplify_conflict()` will be gone.

The tests I added there are quite similar to those of
`trivial_merge()`. I hope we can make `Conflict::simplify()` call
`trivial_merge()` later. I think it would also make sense to move
`trivial_merge()` onto `Conflict`, or at least have a
`Conflict::resolve_trivial()` calling `trivial_merge()`.
2023-06-13 08:49:46 +02:00
Martin von Zweigbergk
e5a28996b4 tree: specialize and inline tree_value_to_conflict()
It seems that this function didn't serve the purpose I intended it to;
we only passed in `TreeValue::Conflict` variants to it.
2023-06-13 08:49:46 +02:00
Martin von Zweigbergk
ee98d1eee8 tree: remove check for conflict-simplification resulting in deletion
Since we switched to the new `conflicts::Conflict` type, we represent
a missing tree entry by a `None` value in the conflict, not a missing
"add", so the condition removed in this commit will never happen, and
the case will be handled by the case just below it instead.
2023-06-13 08:49:46 +02: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
a483252cf2 revset: allow checking out git-tracking (@git) branches 2023-06-12 14:31:44 -07:00
Ilya Grigoriev
8df945b71d cmd: have jj branch list report git-tracking (@git) branches
This doesn't change the way @git branches are stored in `git_refs` as opposed
to inside `BranchTarget` like normal remote-tracking branches. There are
subtle differences in behavior with e.g. `jj branch forget` and I'm not sure
how easy it is to rewrite `jj git import/export` to support a different
way of storage.

I've decided to call these "local-git tracking branches" since they track
branches in the local git repository. "local git-tracking" branches sounds a
bit more natural, but these could be confused with there are no remote
git-tracking branches. If one had the idea these might exist, they would be
confused with remote-tracking branches in the local git repo.

This addresses a portion of #1666
2023-06-12 14:31:44 -07:00
dependabot[bot]
abe5d098c5 cargo: bump rustix from 0.37.19 to 0.37.20
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.37.19 to 0.37.20.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.37.19...v0.37.20)

---
updated-dependencies:
- dependency-name: rustix
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 12:29:26 -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
Yuya Nishihara
7a6f832e14 operation: iterate ancestors incrementally with timestamp-based heuristic
Suppose the operation log is mostly linear, this means "jj op log" iterator
won't look ahead more than one entry.

Another idea is to either add a "generation" number to operation data, or
build index of operations. Since we'll eventually add GC command, I don't
think op index would be required. I think readdir() is good enough to resolve
hex prefix against ~10k entries.

For now, walk_ancestors() is a free function. If we add Repo-like abstraction
over OpStore + OpHeadsStore, this function will probably be migrated there.
2023-06-11 11:38:03 +09:00
Yuya Nishihara
5cecdb54ce dag_walk: add lazy topo-order iterator for chronological data
The idea is that the DAG can be split at single fork point while walking
chronologically, and run DFS-based topological sort for each sub graph.
This works well for operation log.

We could also build a topo-sort stack while splitting, but we couldn't detect
cycles in that way. It would also be quite expensive on pessimistic cases.
2023-06-11 11:38:03 +09:00
Yuya Nishihara
fb7fff4409 dag_walk: extract topo-order helper that doesn't reverse the result
I'll add an iterator wrapper that pop()s the sorted result.
2023-06-11 11:38:03 +09:00
Yuya Nishihara
4987c74d4b dag_walk: flatten nested loops in topo_order_reverse() 2023-06-11 11:38:03 +09:00
Yuya Nishihara
d9c417dcb8 dag_walk: add a few more tests for topo_order_reverse(), extract callbacks
I'm going to add an iterator version which can load linear part of the
operation history lazily.
2023-06-11 11:38:03 +09:00
Yuya Nishihara
459e9174ad dag_walk: remove unneeded trait bound on node type 2023-06-11 11:38:03 +09:00
dependabot[bot]
840c283cac cargo: bump tempfile from 3.5.0 to 3.6.0
Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.5.0 to 3.6.0.
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Stebalien/tempfile/compare/v3.5.0...v3.6.0)

---
updated-dependencies:
- dependency-name: tempfile
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-08 22:53:55 -07:00
Martin von Zweigbergk
de71df2447 conflicts: move conversion to FileId conflict to callers
This simplifies a bit, in particular by removing the error case from
`extract_file_conflict_as_single_hunk()`.
2023-06-07 13:45:16 -07:00
Martin von Zweigbergk
ad667d6bb5 conflicts: convert TreeValue to FileId conflict to avoid panic!
By converting a `Conflict<Option<TreeValue>>` to a
`Conflict<Option<FileId>>`, we don't have to check later that
`TreeValue` really is a `File`.
2023-06-07 13:45:16 -07:00
Waleed Khan
74b846870c feat(diff): add ui.diff-instructions option to suppress JJ-INSTRUCTIONS file 2023-06-06 22:43:14 -07:00
dependabot[bot]
eb1fafa89e cargo: bump once_cell from 1.17.2 to 1.18.0
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.17.2 to 1.18.0.
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.17.2...v1.18.0)

---
updated-dependencies:
- dependency-name: once_cell
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-05 16:22:45 +00:00
dependabot[bot]
4b0b98a3da cargo: bump regex from 1.8.3 to 1.8.4
Bumps [regex](https://github.com/rust-lang/regex) from 1.8.3 to 1.8.4.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.8.3...1.8.4)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-05 16:11:29 +00:00
Waleed Khan
23a4124d20 feat(revset): suggest similar branch names 2023-06-05 11:11:17 -05:00
Waleed Khan
f61cbae022 refactor(revset): move collect_similar from cli_util to revset 2023-06-05 11:11:17 -05:00
Martin von Zweigbergk
ac8313f119 cli: in jj git push, create transaction in a single place
I added a function for updating the description on an existing
transaction. That way we can create the transaction earlier. I'll try
to make `--change` and `--branch` not mutually exclusive next.
2023-06-04 20:50:11 -07: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
43c55fcbc9 tree: replace uses of backend::Conflict 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
9907cccf37 conflicts: use an early return to reduce indentation
Thanks to @ilyagr for the suggestion.
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
Martin von Zweigbergk
1fdc25fe45 conflicts: replace backend::Conflict in materialize_conflict() 2023-06-04 06:48:34 -07:00
Martin von Zweigbergk
5733e3a442 conflicts: introduce generic type for conflicts
For support for tree-level conflicts (#1624), I'm probably going to
introduce a `MergedTree` type representing a set of trees to
merge. That will be similar to `Tree`, but instead of having values of
type `TreeValue`, it will have values that can represent a single
state or a conflict. The `TreeValue` type itself will eventually lose
its `Conflict` variant.

To prepare for that, this commit introduces a `Conflict<T>` type. That
type is intended to be close to what the future
`MergedTree::path_value()`, `MergedTree::entries()`, etc. The next few
commits will replace most current uses of `backend::Conflict` by this
new `conflicts::Conflict` type. They will use `Option<TreeValue>` as
type parameter. Unlike the current `backend::Conflict` type, the
explicit tracking of `None` values will let us better preserve the
ordering and tying it to the tree-level conflict's order.
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
d5d1dbcd3e dag_walk: reorder and adjust signature of neighbors_fn for consistency 2023-06-04 11:47:49 +09:00
Yuya Nishihara
a28e672633 dag_walk: unbox topo_order_reverse() callback 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
522308bb9c dag_walk: simply pass callback function by value 2023-06-04 11:47:49 +09:00
Yuya Nishihara
6872051270 tree_builder: populate base trees by recursion
Suppose many override entries share the same parent directories, it should
be cheaper to look up the tree_cache from leaf than root. I also think
recursion is easier to follow than for loop.
2023-06-02 12:23:37 +09:00
Yuya Nishihara
941f41e62e tree_builder: initialize base trees with the root entry
This helps to rewrite populate_trees() as recursive function call.
2023-06-02 12:23:37 +09:00
Yuya Nishihara
7cf96bcae0 tree_builder: ensure override file path never points to root tree 2023-06-02 12:23:37 +09:00
Yuya Nishihara
f475122b7e tree_builder: simply map Tree to backend::Tree in later pass
I'll rewrite populate_trees() as a recursive function, so I want to minimize
the objects to be passed to the function.
2023-06-02 12:23:37 +09:00
Yuya Nishihara
0846d7fc8b tree_builder: remove unneeded "mut" self 2023-06-02 12:23:37 +09:00
dependabot[bot]
59ee431467 cargo: bump criterion from 0.4.0 to 0.5.1
Bumps [criterion](https://github.com/bheisler/criterion.rs) from 0.4.0 to 0.5.1.
- [Changelog](https://github.com/bheisler/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bheisler/criterion.rs/compare/0.4.0...0.5.1)

---
updated-dependencies:
- dependency-name: criterion
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-01 09:20:14 -07: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
68a30c934d tree_builder: when writing trees, rely on lexicographical order of RepoPath 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
3a69fa48f6 conflicts: delete unused conflict_to_materialized_value() 2023-05-31 17:31:08 -07:00
dependabot[bot]
581b6ef28c cargo: bump chrono from 0.4.25 to 0.4.26
Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.25 to 0.4.26.
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono/compare/v0.4.25...v0.4.26)

---
updated-dependencies:
- dependency-name: chrono
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-31 16:10:03 +00: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
Martin von Zweigbergk
97b81a0f12 working_copy: get conflict id from the current tree
This prepares for allowing the base tree to be a conflict at the
root-tree level (#1624).

We could remove the `Conflict` variant completely. I tried doing that
and it slowed down `jj diff` by ~3% in the Linux repo with a clean
working copy with only mtime bumped on all files.
2023-05-31 06:28:15 -07:00
Martin von Zweigbergk
a5883eba15 merge: make trivial_merge() return a reference
I don't know why I made it return an owned value. It seems like an
unnecessary restriction that the value implements `Clone`, so let's
return a reference instead.
2023-05-31 06:28:01 -07:00
Martin von Zweigbergk
3ca42908ee cleanup: avoid some unnecessary uses of Cursor
Most of our uses of `Cursor` can be replaced by just mutable slices,
which seems simpler, so I guess that's preferred.
2023-05-30 21:06:24 -07:00
dependabot[bot]
04a107babf cargo: bump once_cell from 1.17.1 to 1.17.2
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.17.1 to 1.17.2.
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.17.1...v1.17.2)

---
updated-dependencies:
- dependency-name: once_cell
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-29 20:26:10 +02:00
dependabot[bot]
f27fef09d9 cargo: bump chrono from 0.4.24 to 0.4.25
Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.24 to 0.4.25.
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono/compare/v0.4.24...v0.4.25)

---
updated-dependencies:
- dependency-name: chrono
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-29 20:25:38 +02:00
dependabot[bot]
b9f2f634be cargo: bump git2 from 0.17.1 to 0.17.2
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.17.1 to 0.17.2.
- [Changelog](https://github.com/rust-lang/git2-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/git2-rs/compare/0.17.1...0.17.2)

---
updated-dependencies:
- dependency-name: git2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-29 20:25:04 +02:00
Yuya Nishihara
f27ac22ba4 index: unify evaluate_revset() implementations
The lifetime is a bit tricky since CompositeIndex is a reference wrapper
whereas Index trait has no notion about ownership.
2023-05-29 08:15:40 +09: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
b9c8fd8ef3 index: make ReadonlyIndexImpl crate local
This ensure that callers will use ReadonlyIndexWrapper as the implementation
type.
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
Yuya Nishihara
92c1b7091b index: make CompositeIndex copyable to clarify it is a cheap reference type
Well, I might change it to an owned wrapper later, but if I made such change,
the current CompositeIndex<'_> would be replaced with &CompositeIndex.
2023-05-29 08:15:40 +09:00
Martin von Zweigbergk
d047a8fbd4 tree: respect matcher.visit() when walking entries
This handles the basic case of where the matcher says that a whole
subtree is not matched. In the Linux repo, That's already enough to
speed up `jj --ignore-working-copy files samples` from 298 ms to 129
ms.
2023-05-28 07:28:16 -07:00
Martin von Zweigbergk
dbcecf7244 tree: rewrite recursive entries iterator to not use machine stack
In the same vein as c02c4168fe.
2023-05-28 07:28:16 -07:00
Martin von Zweigbergk
a897b27770 revset: minor fixes to documentation of graph iterator 2023-05-26 15:55:29 -07:00
dependabot[bot]
fe90574b37 cargo: bump regex from 1.8.2 to 1.8.3
Bumps [regex](https://github.com/rust-lang/regex) from 1.8.2 to 1.8.3.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.8.2...1.8.3)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-26 16:11:49 +00:00
Aaron Bull Schaefer
d10af403a5 cleanup: fix minor typos in function names
> error: `mutliple` should be `multiple`
> error: `visble` should be `visible`

Found via typos:
- https://github.com/crate-ci/typos
2023-05-25 08:43:06 -07:00
Martin von Zweigbergk
d087e64abf cleanup: consistently (?) put removed conflict terms before added ones 2023-05-25 04:24:26 -07:00
Martin von Zweigbergk
97c64d8071 tree: leverage trivial_merge() for file executable bit 2023-05-24 22:00:38 -07: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
Martin von Zweigbergk
28d3ad6f1d files: add more multi-hunk tests
We seemed to have poor coverage of merges affecting multiple hunks, so
I added a few. Thanks to @quark-zju for providing the last of them.
2023-05-24 22:00:38 -07:00
Martin von Zweigbergk
1c284322b3 files: leverage trivial_merge() in merge()
Note that one test changed because the new `trivial_merge()` is more
strict than the old algorithm. I don't think that's a problem because
5-way conflicts are not very common, and I prefer to be strict now and
possibly relax it later if we decide that we would prefer that.
2023-05-24 22:00:38 -07:00
Martin von Zweigbergk
61c1b9f4eb files: add another test of a 5-way merge
Just to show that this case doesn't change in the next commit.
2023-05-24 22:00:38 -07:00
Martin von Zweigbergk
1ec906b114 files: make merge() require one more adds than removes
All call paths already check before calling the function that the
condition is true. One caller - `tree::try_resolve_file_conflict()` -
checks it itself. The other caller -
`conflicts::materialize_merge_result()` - doesn't, but its callers
have checked it via `extract_file_conflict_as_single_hunk()`.

The deleted comment about empty strings seems to be obsolete since
e48ace56d1. The caller pads the inputs with empty strings since that
commit.

I think we should ideally change this function's signature to make it
impossible to call it with bad inputs, and I hope to get back to that
soon.
2023-05-24 22:00:38 -07:00
Martin von Zweigbergk
3069718c0f refs: leverage trivial_merge() in merge_ref_targets() 2023-05-24 22:00:38 -07:00
Martin von Zweigbergk
451af92912 tree: leverage trivial_merge() in merge_trees() 2023-05-24 22:00:38 -07:00
Martin von Zweigbergk
ef7b831411 merge: optimize 3-way merge case
I haven't done any profiling to see if this is actually useful, but
it's also pretty simple to do.
2023-05-24 22:00:38 -07:00
Martin von Zweigbergk
aa2792c5e5 merge: add a generic function for resolving trivial N-way merges
We already resolve merge conflicts between hunks, trees, and refs, and
maybe more. They each have their own code for the handling trivial
merges (where the output is equal to one of the inputs). They look
surprisingly different. This commit adds a generic function for doing
that. Curiously, this new implementation uses implements it in yet
another way (basically using a multi-set).
2023-05-24 22:00:38 -07:00
dependabot[bot]
3c1183fb38 cargo: bump regex from 1.8.1 to 1.8.2
Bumps [regex](https://github.com/rust-lang/regex) from 1.8.1 to 1.8.2.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.8.1...1.8.2)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-23 16:13:49 +00:00
Yuya Nishihara
8157c4a926 index: remove walk_revs() from trait API
It only makes sense for the DefaultIndexStore.
2023-05-24 01:02:37 +09: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
6ba684a395 index: replace use of walk_revs() with revset API
I've added a helper function because the construction of the range expression
is a bit noisy. It could be a Repo method, but I don't want to make it a
default implementation of the trait method.

revset::walk_revs() let the caller handle RevsetEvaluationError since the
evaluation engine may error out even with such a trivial query. For now, most
callers just .unwrap() the error as before.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
0b2f0eca05 revset: add Revset::count() API
The default-engine implementation is pretty much the same as iter().count(),
but custom engine may have an optimal path.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
5b568cabcc revset: add iterator of (CommitId, ChangeId) pairs, use it in id_index
There are a few more places where we need these pairs.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
4d39fdf614 id_prefix: remove redundant CommidId field from disambiguation index 2023-05-24 01:02:37 +09:00
Yuya Nishihara
44927be7c9 id_prefix: add IdIndex method that looks up unambiguous key
resolve_prefix_with() is changed to return both key and values.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
e93ff5815c id_prefix: rename IdIndex::resolve_prefix() to resolve_prefix_to_values()
I'll add a key resolution method.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
e7f83e7681 index: add PrefixResolution::map() helper
I'm going to make IdIndex::resolve_prefix_with() return (key, values) pair,
and add convenient wrappers that .map() the pair to either key or values.
2023-05-24 01:02:37 +09:00
dependabot[bot]
3575c1f499 cargo: bump digest from 0.10.6 to 0.10.7
Bumps [digest](https://github.com/RustCrypto/traits) from 0.10.6 to 0.10.7.
- [Commits](https://github.com/RustCrypto/traits/compare/digest-v0.10.6...digest-v0.10.7)

---
updated-dependencies:
- dependency-name: digest
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-22 16:16:04 +00:00
Yuya Nishihara
1675aec388 git: handle lock error that could occur while adding GC-preventing refs
If I spawned ~20 "jj status &" processes, some of them panicked there.
Spotted when debugging #924.
2023-05-22 08:36:29 +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
Yuya Nishihara
fe97dccd02 git_backend: move add_entry() of extra metadata table to caller
I'm going to add a caller which will insert multiple entries at once.
2023-05-21 08:29:00 +09:00
Yuya Nishihara
e6addf7905 git_backend: extract helper that converts git2::Commit to backend::Commit
The root parent id is filled by caller because empty parents list is more
convenient while walking ancestors.
2023-05-21 08:29:00 +09:00
Yuya Nishihara
0149e7b311 git_backend: generate change id from git2::Commit object
I'm going to extract a helper function that converts git2::Commit to
backend::Commit struct, and the commit id can also be obtained from the
git2::Commit object.
2023-05-21 08:29:00 +09:00
Yuya Nishihara
5dba0502cb git_backend: cache head of saved extra metadata table
Just because we know the latest table head.
2023-05-21 08:29:00 +09:00
Yuya Nishihara
a9422460cb git_backend: ensure change id generated from git commit id never reassigned
Fixes #924
2023-05-20 15:53:23 +09:00
Yuya Nishihara
9aa72f6f1d git_backend: add lock to prevent racy change id assignments
My first attempt was to fix up corrupted index when merging, but it turned
out to be not easy because the self side may contain corrupted data. It's
also possible that two concurrent commit operations have exactly the same
view state (because change id isn't hashed into commit id), and only the
table heads diverge.

#924
2023-05-20 15:53:23 +09:00
Yuya Nishihara
e224044dea git_backend: consistently use CommitId type to look up extra metadata table 2023-05-20 15:53:23 +09:00
Yuya Nishihara
78c8dbc8fe git_backend: extract helper to add extra metadata entry and save table 2023-05-20 15:53:23 +09:00
Yuya Nishihara
8a0fcfb032 git_backend: leverage read_extra_metadata_table() in write_commit()
And use the readonly table for lookup, which allows us to extract a helper
method to add/save entry.
2023-05-20 15:53:23 +09:00
Yuya Nishihara
14243a85a0 git_backend: extract helper to read extra metadata table and maintain cache 2023-05-20 15:53:23 +09:00
Yuya Nishihara
83753e59f6 stacked_table: extract method that resolves head without releasing lock
GitBackend will reuse this lock to not assign multiple change ids to a
single commit. We could add a separate lock file that covers the section
from get_head() to save_table(), but I think reusing the table lock is good
enough.
2023-05-20 15:53:23 +09:00
Yuya Nishihara
3655da4f01 tests: add tests for concurrent git commit/change id assignment
Since non-Git metadata isn't hashed, we can't rely on the consistency
provided by content-addressed storage. The problem is also described in
https://github.com/martinvonz/jj/issues/3#issuecomment-947998487

#924
2023-05-20 15:53:23 +09:00
Yuya Nishihara
b8e0ba9872 stacked_table: do not remove head on empty save_table()
If the head is unchanged, it shouldn't be removed. Otherwise the next reader
wouldn't find the existing table.
2023-05-18 22:55:26 +09:00