ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

447 commits

Author SHA1 Message Date
Martin von Zweigbergk
8048d9641e commands: rewrite jj op undo using new MutableRepo::merge() 2021-03-14 10:57:57 -07:00
Martin von Zweigbergk
a7f4f4cf5b rustfmt: configure to merge imports by module
Perhaps we should even set the config to "Item" to reduce merge conflicts.
2021-03-14 10:53:14 -07:00
Martin von Zweigbergk
4b8484e561 rustfmt: configure to group imports 2021-03-14 10:46:25 -07:00
Martin von Zweigbergk
ac9fb1832d OpHeadsStore: move logic for merging repos to MutableRepo
This adds `MutableRepo::merge()`, which applies the difference between
two `ReadonRepo`s to itself. That results in much simpler code than
the current code in `merge_op_heads()`. It also lets us write `undo`
using the new function. Finally -- and this is the actual reason I did
it now -- it prepares for using the index when enforcing view
invariants.
2021-03-14 10:43:39 -07:00
Martin von Zweigbergk
e9ddfdd8bc Repo: repurpose ReadonlyRepo::loader() to return loader for existing repo
It's sometimes useful to create a `RepoLoader` given an existing
`ReadonlyRepo`. We already do that in `ReadonlyRepo::reload()`. This
patch repurposes `ReadonlyRepo::reload()` for that.
2021-03-14 10:34:18 -07:00
Martin von Zweigbergk
82c683bf63 Transaction: rename as_repo_mut() to mut_repo()
I think the `as_` prefix of `as_repo_mut()` makes it sound like it
returns a view of the `Transaction`, but the `MutableRepo` is actually
a part of it. Also, the convention seems to be to put the `mut_` in
the name first if the function returns a name with a matching name
(like `MutableRepo` does).
2021-03-14 00:25:05 -08:00
Martin von Zweigbergk
7ea0c6a868 View: move op_id/base_op_id to Repo
This is yet another step towards making the `View` types
simpler. Perhaps we eventually won't need to wrap the types returned
from the `OpStore` at all.
2021-03-14 00:25:02 -08:00
Martin von Zweigbergk
c1de8b0f3a View: move creation of Operation to Transaction
This continues the work to make the `View` types be only about the
state of the current view and not about operations in general (which
has been moved out `OpStore` and qOpHeadsStore`).
2021-03-14 00:16:21 -08:00
Martin von Zweigbergk
cf2baf58a7 OpHeadsStore: simplify by returning Operation from get_single_op_head() 2021-03-14 00:16:21 -08:00
Martin von Zweigbergk
f6488e2e9f OpHeadsStore: check for fast-forward merge before calling merge_op_heads()
This is another little refactoring to prepare for using the
`Transaction` API in `merge_op_heads()`.
2021-03-14 00:16:13 -08:00
Martin von Zweigbergk
9452d17b75 OpHeadsStore: pass around RepoLoader instead of various stores
This is to prepare for using the regular `Transaction` API for
creating the merge operation in `OpHeadStore`.
2021-03-14 00:15:04 -08:00
Martin von Zweigbergk
eac0c9f579 OpHeadsStore: when merging ops, also remove ancestor op from disk early
This is more code, but I think it's clearer because the code for
removing the ancestors from the set of parents and from disk is now
close. I hope this will also help prepare for some further changes.
2021-03-14 00:13:04 -08:00
Martin von Zweigbergk
d4c39d399f OpHeadsStore: read operation objects before calling merge_op_heads()
This is just a little refactoring to prepare for filtering out
ancestors earlier.
2021-03-14 00:13:04 -08:00
Martin von Zweigbergk
27293829d6 Transaction: allow writing a transaction to the OpStore without publishing it
It can be useful to write an operation to the `OpStore` without also
making it visible when you load the repo. I had planned to add that
functionality at least for hooks, so the hooks can be run commands
with `jj --at-op=<operation>` and decide whether to publish the
operation. However, the immediate goal is to let us rewrite
`op_heads_store::merge_op_heads()` to use the usual `Transaction`
API. That needs to be able to just write the operation without
publishing it, since the publishing step takes a long, which
`op_heads_store::merge_op_heads()` (its caller, actually) has already
taken.
2021-03-14 00:12:57 -08:00
Martin von Zweigbergk
337b15c98d cleanup: replace #[cfg(not(windows))] by $[cfg(unix)]
I didn't realize that the `unix` configuration existed before.
2021-03-12 15:45:55 -08:00
Martin von Zweigbergk
f79874d612 view: let repo get current operation from OpHeadsStore and pass in
This makes the View types a lot simpler.
2021-03-11 22:23:02 -08:00
Martin von Zweigbergk
82a3ff6ef8 repo: make OpHeadsStore accessible directly on ReadonlyRepo
We can now get rid of `MutableView::update_op_heads()`.
2021-03-10 23:27:36 -08:00
Martin von Zweigbergk
212dd35d01 view: let repo create OpHeadsStore and pass in to view 2021-03-10 23:14:00 -08:00
Martin von Zweigbergk
ec07104126 view: move creation of initial operation to OpHeadsStore
This is a step towards getting rid of
`MutableView::update_op_heads()`.
2021-03-10 22:57:59 -08:00
Martin von Zweigbergk
2590e127f7 view: move get_single_op_head() onto OpHeadsStore 2021-03-10 21:59:32 -08:00
Martin von Zweigbergk
b4d4cd143a view: move locking of .jj/view/op_heads/ to OpHeadsStore 2021-03-10 21:51:08 -08:00
Martin von Zweigbergk
4bd121dab5 view: split out separate type for keeping track of op heads 2021-03-10 21:34:11 -08:00
Martin von Zweigbergk
2955bc4a29 repo: let repo types directly have an OpStore
I'd like to make `ReadonlyView` and `MutableView` focused on just the
state of the view (i.e. the set of heads, git refs, etc.). The
responsibility for managing the `.jj/view/op_heads/` directory should
be moved out of it. This prepares for that.
2021-03-10 20:55:56 -08:00
Martin von Zweigbergk
48d7903925 repo: simplify and clarify name of base_op_head_id() functions 2021-03-10 15:39:15 -08:00
Martin von Zweigbergk
9ee521d9d3 transaction: fix (mostly harmless) race where index can get re-calculated 2021-03-10 15:22:03 -08:00
Martin von Zweigbergk
47a7cf7101 view: extract function for updating operation heads
This will be used to address the race in `Transaction::commit()`.
2021-03-10 15:17:54 -08:00
Martin von Zweigbergk
fc73ef8d6e view: delete an incorrect comment about a race
Unlike in `Transaction::commit()`, in the `view` module, we actually
don't update the `.jj/view/op_heads/` directory until after we've
recorded the index associated with the operation, so there's no race
there.
2021-03-10 14:30:27 -08:00
Martin von Zweigbergk
a715fd0ae7 view: drop stale comment about resolving concurrent operations
The comment was from the time when we resolved divergent operations at
write time.
2021-03-08 23:18:26 -08:00
Martin von Zweigbergk
e6aa2402a6 view: drop redundant filtering of ancestors of public heads
I added `enforce_invariants()` in 1f593a4193 and then forgot to use
it in 4db3d8d3a6.
2021-03-08 23:18:26 -08:00
Martin von Zweigbergk
f755c3f740 cleanup: access integer types' MAX constants directly on the type
Using `std::u32::MAX` is deprecated.
2021-03-08 23:18:17 -08:00
Martin von Zweigbergk
02e6420606 repo: inline MutableRepo's {view,index,evolution}_mut() methods
The methods are now only called from within the type. Inlining means
that the borrow checker will let us borrow these separate fields
concurrently. We'll take advantage of that soon.
2021-03-08 23:17:29 -08:00
Martin von Zweigbergk
9f7854f02c repo: stop wrapping view and index in Option in MutableRepo
I think the `Option<>` wrapping was from the time when `MutableView`
had a reference back to the repo (and `MutableIndex` was probably
wrapped out of habit).
2021-03-08 00:08:02 -08:00
Martin von Zweigbergk
ef16d102e2 transaction: move most functionality to MutableRepo
Most methods on `Transaction` only need the `MutableRepo`, so it makes
for that functionality to be on the latter. That will let us update
the methods to also update the index, which would otherwise have been
harder because it would require a mutable borrow of both the view and
the index. This patch makes most current methods on `Transaction` just
delegate to `MutableRepo`. We may want to remove some of these
delegating methods later.
2021-03-07 23:10:32 -08:00
Martin von Zweigbergk
1e623bd019 index: update in memory and on disk while resolving operation conflicts
Updating the index on disk means that reader won't have to calculate
the state. Updating it in memory means that we can take advantage of
it while resolving conflicts. We will do that soon.
2021-03-06 23:30:03 -08:00
Martin von Zweigbergk
779db67f8f index_store: avoid passing whole repo into get_index_at_op()
I want to be able to load the index at an operation before the repo
has been loaded.
2021-03-06 23:06:35 -08:00
Martin von Zweigbergk
d1509ffdd4 index: extract a function for adding all commits from a segment
I also restructured the loop in `maybe_squash_with_ancestors()` to
hopefully make it a little clearer.
2021-03-06 20:30:12 -08:00
Martin von Zweigbergk
3fc35288c0 index: remove dir field from ReadonlyIndex and MutableIndex 2021-03-06 10:02:19 -08:00
Martin von Zweigbergk
502ba895f5 index: move ReadonlyFile::associate_with_operation() to IndexStore
After this patch, the `index` module no longer knows about the
".jj/index/operations/" directory; that knowledge is now only in
`IndexStore`.
2021-03-06 10:00:30 -08:00
Martin von Zweigbergk
c4fe7aab10 index: move ReadonlyRepo::load_at_operation() to IndexStore 2021-03-06 09:52:44 -08:00
Martin von Zweigbergk
12bfbc489c index: move ReadonlyIndex::index() to IndexStore 2021-03-06 09:52:38 -08:00
Martin von Zweigbergk
2fdf9721c0 index: move load() to IndexStore 2021-03-06 09:52:27 -08:00
Martin von Zweigbergk
403e86c138 index: introduce IndexStore, which owns ReadonlyIndex files
This patch introduces a new `IndexStore` struct. The idea is that it
will know about the directory in which the index files are stored, the
associations with operations. It may also cache `Arc<ReadonlyIndex>`
instances so if multiple `ReadonlyIndex` instances are loaded, they
can be returned from the cache. That may be useful when merging
operations because the operations are likely to share a large parent
index file. For now, however, all the new type has is `init()`,
`load()`, and `reinit()`.
2021-03-06 09:52:16 -08:00
Martin von Zweigbergk
0a4ef1030f repo: add support for loading at given operation without loading head op first
The only way to load the repo at a current operation (as with
`--at-op`) is currently to first load it at the head operation and
then call `reload()` on the repo. This patch makes it so we can load
the repo directly at the requested operation.
2021-03-06 09:52:10 -08:00
Martin von Zweigbergk
df53871daf repo: extract a type for loading the repo in two stages
We'll want to be able to load the repo at a given operation without
first loading the head operation as we do today. This patch introduces
a struct for keeping the state of a half-loaded repo. In that
half-loaded state, the store and the op-store have been loaded, but
the view has not yet been loaded. That makes it possible for callers
to use the loaded op-store for looking up an operation to load the
view at.
2021-03-06 09:52:10 -08:00
Martin von Zweigbergk
5a32118af1 repo: move creation of OpStore out of View
We want to support loading the repo at a specific operation without
first loading the head operation (like we currently do). One reason
for that is of course efficiency. A possibly more important reason is
that the head operation may be conflicted, depending on how we decide
to deal with operation-level conflicts. In order to do that, it makes
sense to move the creation of the `OpStore` outside of the
`View`. That also suggests that the `.jj/view/op_store/` directory
should move to `.jj/op_store/`, so this patch also does that. That's
consistent with how `.jj/store/` is outside of `.jj/working_copy/`.
2021-03-06 09:52:00 -08:00
Martin von Zweigbergk
e2e9fe8f0d index: add stats for number of change ids and pruned commits 2021-03-06 09:50:22 -08:00
Martin von Zweigbergk
bc64cf02c7 index: don't use an all-0 change id in tests
It was weird to have the same change id for all commits. I think that
was a leftover from a me just quickly getting tests to pass.
2021-03-06 09:30:52 -08:00
Martin von Zweigbergk
031a39ecba cleanup: fix lots of issues found in the lib crate by clippy
I had forgotten to pass `--workspace` to clippy all this time :P
2021-02-26 23:15:43 -08:00
Martin von Zweigbergk
48b800e5c4 cleanup: fix a few things reported by upgraded rustc and clippy 2021-02-26 22:48:12 -08:00
Martin von Zweigbergk
d961f61623 evolution: calculate state using index
All the information needed for calculating the evolution state is now
in the index, so let's use it. This speeds up calculation of the
evolution state from 1.53s to 150ms in the git.git repo. In the Linux
repo, it was sped up from 28.9s to 3.07s. That's still unbearably slow
(and still pretty slow in the git.git repo too). We may need to keep a
persistent cache of the evolution state, but that will have to come
later; this improvement is good enough for now.
2021-02-26 21:19:18 -08:00