Commit graph

1614 commits

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