Commit graph

1012 commits

Author SHA1 Message Date
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
Yuya Nishihara
0e99747728 revset: eliminate double negates
Writing double negates is silly, but it might be hidden by revset alias
if we added such feature.

I made fold_redundant_expression() a separate step from fold_difference()
since I'll probably want to apply the cleanup step before rewriting filter
expressions.
2022-11-29 15:46:15 +09:00
Yuya Nishihara
54044ea8d6 revset: transform negative intersection to difference 2022-11-29 15:46:15 +09:00
Yuya Nishihara
48d10d648c revset: add unary negate (or set complement) operator '~y'
Because a unary negation node '~y' is more primitive than the corresponding
difference node 'x~y', '~y' is easier to deal with while rewriting the tree.
That's the main reason to add RevsetExpression::NotIn node.

As we have a NotIn node, it makes sense to add an operator for that. This
patch reuses '~' token, which I feel intuitive since the other set operators
looks like bitwise ops. Another option is '!'.

The unary '~' operator has the highest precedence among the set operators,
but they are lower than the ranges. This might be counter intuitive, but
useful because a prefix range ':x' can be negated without parens.

Maybe we can remove the redundant infix operator 'x ~ y', but it isn't
decided yet.
2022-11-29 15:46:15 +09:00
Yuya Nishihara
7fbd7b48e5 revset: highlight whole function expression on substitution failed
The error may be caused by arguments passed in to the alias function.
2022-11-29 04:17:12 +09:00
Yuya Nishihara
70292f79b7 revset: implement function alias expansion
Function parameters are processed as local symbols while substituting
alias expression. This isn't as efficient as Mercurial which caches
a tree of fully-expanded function template, but that wouldn't matter in
practice.
2022-11-29 04:17:12 +09:00
Martin von Zweigbergk
d8feed9be4 copyright: change from "Google LLC" to "The Jujutsu Authors"
Let's acknowledge everyone's contributions by replacing "Google LLC"
in the copyright header by "The Jujutsu Authors". If I understand
correctly, it won't have any legal effect, but maybe it still helps
reduce concerns from contributors (though I haven't heard any
concerns).

Google employees can read about Google's policy at
go/releasing/contributions#copyright.
2022-11-28 06:05:45 -10:00
dependabot[bot]
a7ff8d5ee3 cargo: bump insta from 1.21.1 to 1.21.2
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.21.1 to 1.21.2.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.21.1...1.21.2)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-28 05:29:03 -10:00
Yuya Nishihara
e40c041384 revset: merge AmbiguousChange/CommitIdPrefix error into one
Follows up c5ed3e1477. Now change/commit ids are resolved at the same
precedence, which means there are at least three types of ambiguity.
I don't think we would need to discriminate these.
2022-11-28 22:49:07 +09:00
Yuya Nishihara
c5ed3e1477 revset: for short hash, look up both commit and change ids to disambiguate
Because the use of the change id is recommended, any operation should abort
if a valid change id happens to match a commit id. We still try the commit
id lookup first as the change id lookup is more costly.

Ambiguous change/commit id is reported as AmbiguousCommitIdPrefix for now.
Maybe we can merge AmbiguousCommit/ChangeIdPrefix errors into one?

Closes #799
2022-11-28 17:30:53 +09:00
Yuya Nishihara
1fa0392a3e revset: wrap internal symbol resolution result with Option
Option<T> or Result<Option<T>, _> is easier to pattern match than testing
RevsetError::NoSuchRevision.
2022-11-28 17:30:53 +09:00
Benjamin Saunders
e1152c5846 git: revert change to SSH agent detection
84b924946f switched to requiring both
SSH_AUTH_SOCK and SSH_AGENT_PID for an agent to be used. This doesn't
seem to be a typical situation, so perhaps it was not intended.
2022-11-27 18:53:18 -08:00
Yuya Nishihara
11ee2f22c4 revset: implement simple symbol alias expansion
Since syntactic information like symbol or function name is lost after
parse(), alias substitution is inserted to the middle of the post-parsing
stage, not after the whole RevsetExpression tree is built. This is the main
difference from Mercurial. Mercurial also caches parsed aliases, but I don't
think that would have a measurable impact.
2022-11-27 20:12:22 +09:00
Yuya Nishihara
5df25cd834 revset: add origin field to RevsetParseError to chain alias errors
This could be embedded in a variant of RevsetParseErrorKind, but I want to
keep the enum comparable.
2022-11-27 20:12:22 +09:00
Yuya Nishihara
7632466cc0 revset: add table of symbol aliases and pass around parse functions
The CLI will load aliases from config, insert them one by one, and warn if
declaration part is invalid. That's why RevsetAliasesMap is a public struct
and needs to be instantiated by the caller.
2022-11-27 20:12:22 +09:00
Yuya Nishihara
f0b1221749 revset: pack parsing state into struct
I'll add aliases map, substitution stack (to detect recursion), and locals
(for function aliases) there. Fortunately, we can avoid shared mutables
so a copyable struct should be good.

parse_function_argument_to_string() doesn't need a workspace_ctx, but there
should be no reason to explicitly nullify it either.
2022-11-27 20:12:22 +09:00
Ruben Slabbert
01817e4321 feature: support relative timestamps as a config option 2022-11-27 08:35:17 +10:00
Martin von Zweigbergk
a90ef20976 git: on export, delete deleted refs before adding added refs
To reduce conflicts between branches like `main` and `main/sub`, it's
better to first delete refs in git that have been deleted in jj, and
then add/update refs that have been added/updated in jj.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
4a03b94d65 git: on export, skip failed refs instead of failing whole export
Since we now write a (partial) view object of the exported branches to
disk (since 7904474320), we can safely skip exporting some
branches. We already skip conflicted branches. This commit makes us
also skip branches that we fail to write to the backing Git repo,
instead of failing the whole operation (after possibly updating some
Git refs).

I made the `export_refs()` function return the branches that
failed. We should probably make that a struct later and have a
separate field for branches that we skipped due to conflicts.

Closes #493.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
8139a84b22 git: remove stale comment about first export being a no-op
This should have been part of commit 759ddd1e60.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
0dbbd4266f git: update exported_view after updating in Git repo
When skipping branches we fail to update in the backing Git repo, we
must also skip updating the `exported_view` object, so we don't trick
ourselves into thinking the branch was already updated in the Git repo
on the next export.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
a09763f340 git: in export code, work with branch names (not ref names) a bit longer
I'm going to make the export skip branches that we fail to update in
the Git repo. For that, we need to know the branch name while
interacting with the `git2::Repository` object. This little
refactoring prepares for that.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
dbe5615260 git: update mostly incorrect comment in export function
The comment says that we collect the changes to make before making
them, in order to reduce the risk of making some changes before
failing. However, there is nothing in the code that collects changes
that can fail, and it's all doing comparisons in memory, so it should
be very fast. It's been like that since I added it in 47b3abd0f7. We
still need to preserve the structure to avoid mutating `mut_repo`
while iterating over branches, however, so I just updated the comment.
2022-11-26 06:05:29 -10:00