Commit graph

1644 commits

Author SHA1 Message Date
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