Commit graph

1034 commits

Author SHA1 Message Date
Yuya Nishihara
4a889b986c index: implement generation filter on RevWalkGenerationRange
This will be a building block of 'parents(base)' revset. 'base---' will
be .filter_by_generation(3..4) for example. I think 'ancestors(base)' can
also have an optional generation parameter, but I haven't considered any
particular syntax yet.
2022-12-11 13:14:19 +09:00
Yuya Nishihara
832cf8d838 index: add RevWalk variant that tracks generation
Even though I couldn't determine if RevWalkGenerationRange has a measurable
cost compared to RevWalk, I'm not comfortable with enabling generation
tracking by default. So this patch adds a separate struct. I duplicated
Iterator::next() method as it seemed rather complicated to extract a common
iterator wrapper.

Actual filtering function and tests will be added by the next commit.
2022-12-11 13:14:19 +09:00
Yuya Nishihara
4740d7fac1 index: add slot to track state of wanted RevWalk items
RevWalkWorkItem<u32> to track generation for example.
2022-12-11 13:14:19 +09:00
Yuya Nishihara
03eff13d52 index: extract a couple of RevWalk helper functions to inner struct 2022-12-11 13:14:19 +09:00
Yuya Nishihara
a124f84949 index: move core RevWalk logic to inner struct
I'll add a RevWalk that can filter entries by generation range.
2022-12-11 13:14:19 +09:00
Yuya Nishihara
a569ac07f6 revset: alias 'empty()' to '~file(*)'
We're more likely to filter out empty commits, so this should be slightly
faster in practice.

The extra Option<> isn't needed, but it should clarify that "prefix([])"
is not "everything".
2022-12-07 23:38:17 +09:00
Yuya Nishihara
1eaa05b6fd revset: remove uninteresting expressions early
Since internalize_filter() should no longer insert redundant 'all() & x'
nodes, it's simpler to clean up uninteresting nodes first.
2022-12-07 23:38:17 +09:00
Yuya Nishihara
75e072b80c revset: remove stale comment about filter intersection with 'all()'
This should have been removed at e17fc89a8d "revset: make filter node unary,
move candidates to outer intersection".
2022-12-07 23:38:17 +09:00
Yuya Nishihara
222d9a6527 revset: rewrite 'x ~ y' to 'x & ~y' first to apply filter optimization
This is remainder of 48d10d648c "revset: add unary negate (or set
complement) operator '~y'".
2022-12-07 23:38:17 +09:00
Yuya Nishihara
951eb0b61a revset: use filter intersection for tree containing filter
This basically transforms 's1 & (f() | s2)' to
's1.iter().filter(all && f || s2)'. Still the predicate part includes "all",
the filter function doesn't need to load commit data for every entry since
's1.iter().filter(all)' is tested first. To optimize "all" predicate out,
maybe we can add a wrapper that returns '|_: &IndexEntry| true'.

Instead of inserting AsFilter(_) node, I could add a recursive is_filter()
function. That would also work so long as the height of RevsetExpression tree
is limited. I chose node insertion just for ease of snapshot testing.
2022-12-07 11:01:59 +09:00
Yuya Nishihara
f2e7a5ad03 revset: introduce trait that turns evaluated revset into predicate function
This allows us to evaluate 's1 & (f() | s2)' as 's1.iter().filter(f || s2)'
instead of 's1 & (all.iter().filter(f) | s2)'.
2022-12-07 11:01:59 +09:00
Yuya Nishihara
f64f96251f revset: add basic tests for revset combinator
I've made MutableIndex::add_commit_data() crate-public since it's convenient
to build an IndexEntry by that function.
2022-12-07 11:01:59 +09:00
dependabot[bot]
5834a1b191 cargo: bump pest_derive from 2.5.0 to 2.5.1
Bumps [pest_derive](https://github.com/pest-parser/pest) from 2.5.0 to 2.5.1.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.0...v2.5.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>
2022-12-06 08:11:18 -08:00
dependabot[bot]
ed7908e9ed cargo: bump zstd from 0.12.0+zstd.1.5.2 to 0.12.1+zstd.1.5.2
Bumps [zstd](https://github.com/gyscos/zstd-rs) from 0.12.0+zstd.1.5.2 to 0.12.1+zstd.1.5.2.
- [Release notes](https://github.com/gyscos/zstd-rs/releases)
- [Commits](https://github.com/gyscos/zstd-rs/commits)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-06 08:10:53 -08:00
Ilya Grigoriev
581cdad1b0 Upgrade insta from 1.21.2 to 1.22.0 2022-12-05 22:29:05 -08:00
Martin von Zweigbergk
5caade2705 release: release version 0.6.1
The only changes is that we now depend on a released version of
`thrift`.
2022-12-05 20:50:48 -08:00
Martin von Zweigbergk
dfde44255c cargo: depend on now-released thrift 0.17.0
This should let us publish our crates to crates.io.
2022-12-05 20:50:48 -08:00
Martin von Zweigbergk
80ccfa8bcc release: release version 0.6.0
Lots of new features and important bugfixes. Thanks, everyone!
2022-12-05 10:38:56 -08:00
dependabot[bot]
92f3dca4bd cargo: bump pest from 2.5.0 to 2.5.1
Bumps [pest](https://github.com/pest-parser/pest) from 2.5.0 to 2.5.1.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.0...v2.5.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-05 09:48:28 -08:00
dependabot[bot]
2deb2f5e71 cargo: bump config from 0.13.2 to 0.13.3
Bumps [config](https://github.com/mehcode/config-rs) from 0.13.2 to 0.13.3.
- [Release notes](https://github.com/mehcode/config-rs/releases)
- [Changelog](https://github.com/mehcode/config-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mehcode/config-rs/compare/0.13.2...0.13.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-05 09:35:44 -08:00
Ilya Grigoriev
acb0e9751d Add a Tree method to return conflicts matching a matcher
This is useful for `jj resolve`.
2022-12-04 22:39:45 -08:00
Yuya Nishihara
f4953cdb60 index: return early from RevWalk if items get filled with unwanted 2022-12-05 14:31:14 +09:00
Yuya Nishihara
2a00481ec5 index: make RevWalk push all parents and deduplicate later on pop()
The idea behind this is to extend RevWalk to track generation (or depth from
the initial wanted items.) Basic DAG walk doesn't need such data, but a query
like 'rev---' could be translated to a RevWalk yielding nth ancestors.
The default log revset can also be expressed as 0/1-th ancestors of
'(remote_branches() | tags())..'.

Also, this appears to be faster than using boundary sets, based on the
bench extracted from test_index_commits_criss_cross().
2022-12-05 14:31:14 +09:00
Ilya Grigoriev
c52a14eac6 Remove an unused import warning on recent versions of Rust
This warning used to show up, at least, on Rust nightly:
     unused import: `crate::nightly_shims::BTreeSetExt`
2022-12-04 13:15:42 -08:00
Yuya Nishihara
e17fc89a8d revset: make filter node unary, move candidates to outer intersection
In order to optimize a query like '(author(_) | @) & main..', we'll probably
need a predicate form of an iterable set so that the query can be evaluated
to '(main..).iter().filter(author(_) | @)'. And if a predicate function can
terminate the source iterator early (by returning true/false/false_forever),
complexity of a filtered revset is basically the same as an intersection of
iterator pair. This means we can eventually merge IntersectionRevset with
FilterRevset.

With that in mind, this patch removes the redundant 'candidates' field from
the filter node, which would otherwise appear in the predicate function as
'candidates.contains(entry)'. A filter node with candidates was somewhat
useful while rewriting the tree, but that can be dealt with a view function
like as_filter_intersection() in this patch.

This also simplify the subsequent filter transformation as we no longer need
to test if candidates == All.
2022-12-05 00:32:18 +09:00
Yuya Nishihara
6d977c73e4 revset: add test of filter intersection over non-linear tree
Previously we only have a test for the left recursion. The added test
contains right recursion path, which should have caught the error I made
while working on the next "unary filter node" patch.
2022-12-05 00:32:18 +09:00
Yuya Nishihara
48d426529c revset: update doc of filter transformation, apply minor style change
The doc comment summarizes what I'm going to implement. I'm not sure if
we'll add all of them because revset evaluation isn't the key performance
bottleneck at the moment. Anyway, I don't think any of these ideas would
logically conflict with segmented changelog adaptation unless we decide to
replace the whole revset stack with Eden/Sapling's.
2022-12-05 00:32:18 +09:00
Yuya Nishihara
ec6f2cf393 revset: extract function that builds predicate function from spec 2022-12-05 00:32:18 +09:00
Martin von Zweigbergk
be383cebc7 git: on import, add GC-preventing refs to all seen refs
To prevent git's GC from breaking a repo, we already add a git ref to
commits we create in the git backend. However, we don't add refs to
commits we import from git. This fixes that.

Closes #815.
2022-12-03 22:50:26 -08:00
Martin von Zweigbergk
9df247f87c git: on import, update record of ref only if it changed
There's no need to update our record of the ref if it didn't
change. This is just about making it clearer; I doubt it will have
measurable performance impact.
2022-12-03 22:50:26 -08:00
Martin von Zweigbergk
84a4dee673 thrift: add legacy-thrift Cargo feature
This patch adds a `legacy-thrift` Cargo feature that's enabled by
default. If it's disabled, the upgrade from Thrift-based operation log
does not happen, and the `thrift` depdendency is not included.
2022-12-03 22:31:02 -08:00
Martin von Zweigbergk
6b964218bf legacy_thrift_op_store: remove implementation write methods 2022-12-03 22:31:02 -08:00
Martin von Zweigbergk
c269b72fb3 op_store: auto-upgrade existing repos from Thrift to Protobuf
With this patch, we auto-upgrade existing repos that use Thrift format
for the operation log to use Protobuf format. That would only be repos
used with an unreleased version of jj after 0.5.1 (which may be the
majority of repos?).

The upgrade from Thrift is simpler because we now use the same hashing
scheme for the Protobuf-based storage, so the operation and view IDs
remain the same as they were in the Thrift-based storage. We could
simplify the code a bit more as a result, but since this code is
supposed to be short-lived, I didn't bother.

Since the change from the Protobuf format with the old hashing scheme
to a the (same) Protobuf format with the new hashing scheme shouldn't
impact users, I removed the entry we had in the changelog about the
format change.
2022-12-03 22:31:02 -08:00
Martin von Zweigbergk
5a9d1e5fdd op_store: rename variables in upgrade code to be direction-agnostic
The code for migrating from ProtoBuf to Thrift is almost completely
independent of which direction the upgrade goes, so we can very easily
reuse it for migrating from Thrift to Protobuf. This patch renames
some variables to "old/new" instead of "proto/thrift", making the next
patch even simpler.
2022-12-03 22:31:02 -08:00
Martin von Zweigbergk
472dee6403 op_store: move ThriftOpStore to new file
Since we're now allowed to use the `protobuf` crate, I'm going to make
`SimpleOpStore` use it again. This moves the `ThriftOpStore` into a
new `legacy_thrift_op_store.rs` file.
2022-12-03 22:31:02 -08:00
Martin von Zweigbergk
fdf43b845a content_hash: absorb duplicate hash() functions
We use the same blake2b hash for `ContentHash` impls in several
places, and I'm about to add more places, so let's centralize the
helper function.
2022-12-03 22:31:02 -08:00
Martin von Zweigbergk
c0a819e94a op_store: remove legacy_protobuf Cargo feature
Since we now have approval to use the `protobuf` crate at Google, it's
no longer the "legacy" format, so we should remove it. I'll almost
definitely soon add `legacy_thrift` feature instead.
2022-12-03 22:31:02 -08:00
Ilya Grigoriev
55762e3681 Rename FileConflictData to ConflictHunk, use it in files.rs.
There's no point in having two identical types used for the same
purpose in two different places.
2022-12-03 15:12:40 -08:00
Ilya Grigoriev
85b472b507 Expose functions useful for conflict resolution UI
This refactors `conflicts.rs` to:

1. Make `describe_conflict` public

2. Extract the functionality to create text version of
a conflict as the `materialize_merge_result` function.

3. Extract the functionality to turn a conflicted file
into the complete contents of each version of the file
"added" or removed" (when possible). This becomes the
`extract_file_conflict_data` function.

This is useful in order to present these text versions
in a merge tool.
2022-12-03 15:12:40 -08:00
Martin von Zweigbergk
b3fe52305a git: inline export_changes()
The function doesn't do much at all now and there's a single caller,
so let's inline it.

I tried to clean up the code a bit futher so it wouldn't even create
the `old_view`, but it was harder than I had hoped. I might get back
to it later.
2022-12-03 09:32:49 -08:00
Martin von Zweigbergk
8a440d8042 git: on export, use repo view's git_refs as record of old export state
@yuja asked on #701 about the difference between the state in the
`git_export_view` and what we have in `mut_repo.view()`. It's true
that the branches in `mut_repo.view().git_refs()` should match what we
wrote to disk. We can therefore remove the on-disk storage and
simplify quite a bit. For now, I create the `last_export_view` from
the `mut_repo.view().git_refs()` before calling
`export_changes()`. I'll clean up a bit more next.

I think this is correct even considering e.g. undo. Let's consider
what would happen in a non-colocated Git repo (not because tricky
cases cannot happen there but because the explicit exports and imports
make it easier to discuss, and more cases can occur). If the user
moved a branch and then did `jj git export`, `jj undo`, and then `jj
git export` again, we would think on the second export that we should
perform the same changes to the Git repo, which should have no effect.

This patch also fixes the bug we were forced to work around in the
test case in the previous patch.

This removes one of our uses of Thrift.
2022-12-03 09:32:49 -08:00
Martin von Zweigbergk
39792368ba git: when exporting, don't overwrite changes made by git
This fixes the bugs shown by the tests added in the previous patch by
checking that the git branches we're about to update have not been
updated by git since our last export. If they have, we fail those
branches. The user can then re-import from the git repo and resolve
any conflicts before exporting again.

I had to update the `test_export_import_sequence` to make it
pass. That shows a new bug, which I'll fix next. The problem is that
the exported view doesn't get updated on import, so we would try to
export changes compared to an earlier export, even though we actually
knew (because of the `jj git import`) that the state in git had
changed.
2022-12-03 09:32:49 -08:00
Martin von Zweigbergk
9b59461242 git: add test for concurrent change in git repo between exports
If you update a branch using regular `git` (or some Git-based tool)
between two `jj git export`, we will overwrite that change if you had
also changed the branch in jj land. There's a similar problem if you
delete the branch in jj land. Let's have a test for that. I'm going to
make us not overwrite it soon. This patch adds a test for those cases,
plus many other cases in consistent way. Since the new test covers
some cases tested by existing tests, I removed those tests.
2022-12-03 09:32:49 -08:00
Martin von Zweigbergk
25008b63a4 local_backend: switch from Thrift back to Protobuf
The Protobuf team at Google decided to let us use Protobufs internally
after all. That will make things a little easier for us with the
Google-internal adapations, and the `protobuf` crate is noticeably
faster than the `thrift` crate.

This effectively rolls back commit 5b10c9aa0a. I resolved some
conflicts caused by the rename from `NormalFile` to `File`. I also
kept the changelog entry, but I changed it to say that the hashing
scheme has changed (not the format), but since the hashes are just
used for identity, existing repos should still work.
2022-12-02 19:29:45 -08:00
Martin von Zweigbergk
b80c39d77c view: test that merging divergent rewrites results in both commits visible
It seems that we didn't have a test for this simple case. I wrote this
test case while working on #111 but I don't know why I didn't push it
back then.
2022-12-01 19:20:38 -08:00
Pranay Sashank
47067c1368 git: do not delete or track git submodules.
A new FileType, GitSubmodule is added which is ignored. Files or
directories having this type are not added to the work queue and
are ignored in snapshot. Submodules are not created by jujutsu
when resetting or checking out a tree, they should be currently
managed using git.
2022-12-01 23:14:55 +05:30
Yuya Nishihara
5cc99b6451 revset: inline ChildrenRevsetIterator by using .filter() 2022-11-30 23:42:51 +09:00
Yuya Nishihara
fae3822422 revset: inline FilterRevsetIterator by using .filter() 2022-11-30 23:42:51 +09:00
Yuya Nishihara
5b13c0b38f revset: inline RevWalkRevsetIterator which is just an identity iterator 2022-11-30 23:42:51 +09:00
Glen Choo
f4f0fbbd5d settings: move cli-specific settings to src/ui.rs 2022-11-30 06:14:39 +08:00