Commit graph

2484 commits

Author SHA1 Message Date
Martin von Zweigbergk
b549090acc index: adopt ChangeIdIndex and relatives from revset module
The `ChangeIdIndex` type is currently in defined in the `revset`
module because that's the only placed it's used. However, I'd like to
start using it directly from `index`. The idea is to make it possible
to create a `ChangeIdIndex` given a set of heads, without first
creating a `Revset`.
2024-01-08 06:06:47 -08:00
Martin von Zweigbergk
f0182ad4b8 default_index: adopt revset engine and graph iterator modules
The revset engine and the graph iterator are specific to the default
index implementation, so they belong in the same module.
2024-01-07 05:37:47 -08:00
Yuya Nishihara
a6616e9cea object_id: don't allow ObjectId::from_hex() a dynamically allocated string
This isn't technically needed, but it prevents API misuse. Another option
is to do some compile-time substitution, but most callers are tests and the
runtime performance wouldn't matter.
2024-01-06 00:26:36 +09:00
Yuya Nishihara
837ac15052 op_store: add resolve_operation_id_prefix() trait method that uses readdir()
The OpStore backends should have a better way to look up operation by id than
traversing from the op heads. The added method is similar to the commit Index
one, but returns an OpStoreResult because the backend operation can fail.

FWIW, if we want .shortest() in the op log template, we'll probably need a
trait method that returns an OpIndex instead.
2024-01-05 23:36:57 +09:00
Yuya Nishihara
95ea352b0a object_id: add fallible version of ObjectId::from_hex() 2024-01-05 23:36:57 +09:00
Yuya Nishihara
95d83cbfe5 object_id: make ObjectId constructors non-trait methods
I'm going to add try_from_hex(), which requires Self: Sized. Such trait bound
could be added, but I don't think we'll need abstracted ObjectId constructors
at all.
2024-01-05 23:36:57 +09:00
Yuya Nishihara
31b236a70d object_id: move HexPrefix and PrefixResolution from index module 2024-01-05 10:20:57 +09:00
Yuya Nishihara
fa5e40719c object_id: extract ObjectId trait and macros to separate module
I'm going to add a prefix resolution method to OpStore, but OpStore is
unrelated to the index. I think ObjectId, HexPrefix, and PrefixResolution can
be extracted to this module.
2024-01-05 10:20:57 +09:00
Yuya Nishihara
dbaee198e6 hex_util: move common_hex_len() from backend module
This function predates the hex_util module. If there were hex_util, I would
add it there.
2024-01-05 10:20:57 +09:00
Yuya Nishihara
e5255135bb op_walk: add function that reparents (and abandons) operation range
This will be used in "jj op abandon ..op_id" command. The "op_id..@" range will
be reparented onto the root operation.

The current implementation is good enough for local repos, but it won't scale.
We might want to extract it as a trait method or introduce OpIndex for
efficient DAG operation.
2024-01-04 11:44:36 +09:00
Yuya Nishihara
392e83be42 op_heads: ensure that update_op_heads([id], id) fails
The doc states it's invalid, but I made such bug.
2024-01-04 11:44:36 +09:00
Matt Stark
3f0a49dafe Ensure you never drop the working commit with --skip-empty
See #2766 for discussions
2024-01-04 13:33:24 +11:00
Matt Stark
a4aed2391f Rewrite instead of abandoning empty commits.
Fixes #2760


Given the tree:
```
A-B-C
 \
  B2
```
And the command `jj rebase -s B -d B2`

We were previously marking B as abandoned, despite the comment stating that we were marking it as being succeeded by B2. This resulted in a call to `rewrite(rewrites={}, abandoned={B})` instead of `rewrite(rewrites={B=>B2}, abandoned={})`, which then made the new parent of `C` into `A` instead of `B2`
2024-01-04 13:33:24 +11:00
Ilya Grigoriev
6edaa97517 DescendantRebaser: change rebased() method to into_map() that consumes the rebaser
This prevents a clone and does not affect the public API, as suggested
in https://github.com/martinvonz/jj/pull/2738#discussion_r1438903463.
2024-01-01 21:55:18 -08:00
Ilya Grigoriev
ddec3f91b2 lib: mild refactoring made possible by previous commit
Inline `create_descendant_commits`, move some functionality of
`DescendantRebaser::rebase_next` to `rebase_all`, a seemingly more logical
location.
2024-01-01 18:51:36 -08:00
Ilya Grigoriev
277b81ff6f lib: make DescendantRebaser-related APIs private.
Finally, there are no test uses of these APIs. `DescendantRebaser` is made
`pub(crate)`, since it is used by `MutRepo`. Other functions are made private.
2024-01-01 18:51:36 -08:00
Ilya Grigoriev
45cd0bf11b test_rewrite.rs: stop using DescendantRebaser when testing EmptyBehavior
This completes the process of removing DescendantRebaser-related APIs from
tests. It requires creating some new test utils and a new
`rebase_descendants_with_option_return_map`.
2024-01-01 18:51:36 -08:00
Ilya Grigoriev
7cef879ef6 lib repo.rs & rewrite.rs: Move clearing of rewritten/abandoned commits
This commit is a little out of place in this sequence, but
it seems to make more sense for MutRepo to own these maps.

@yuja [pointed out] that any tests written using `create_descendant_rebaser` now
need to do this cleanup, but there are no longer any such tests after the
previous commits and a follow-up commit removes `create_descendant_rebaser`
entirely.

[pointed out]: https://github.com/martinvonz/jj/pull/2737#discussion_r1435754370
2024-01-01 18:51:36 -08:00
Ilya Grigoriev
4461d61254 test_rewrite: test branches of descendants of divergent commits
A TODO left over from a previous PR
2024-01-01 18:51:36 -08:00
Ilya Grigoriev
b2abba07e9 tests: (mostly) stop using soon-to-be-private DescendantRebaser-related APIs
This removes uses of `DescendantRebaser::new` or
`MutRepo::create_descendant_rebaser` from most tests. The exceptions  are the
tests having to do with abandoning empty commits on rebase, since adjusting
those is a bit more elaborate (see follow-up commits).
2024-01-01 18:51:36 -08:00
Yuya Nishihara
3eafca65ea op_walk: add support for op_id+ (children) operator
A possible use case is when doing some archaeology around a certain operation.

The current implementation is quadratic if + is repeated. Suppose op_id is
usually close to the current op heads, I think it'll practically work better
than building a reverse lookup table.
2024-01-02 10:30:08 +09:00
Yuya Nishihara
ab299a6af5 op_walk: reimplement prefix lookup by using walk_ancestors() and HexPrefix
Perhaps, OpStore should provide prefix resolution method, but let's think
that later.
2024-01-02 10:30:08 +09:00
Yuya Nishihara
c53748d732 op_walk: allow walk_ancestors() from more than one head operations 2024-01-02 10:30:08 +09:00
Yuya Nishihara
51691ea22c tests: add lib tests for op id resolution, migrate some from cli
CLI testing is slow and harder to set up crafted environment.
2024-01-02 10:30:08 +09:00
Yuya Nishihara
dad890b960 operation: make parent_ids() return slice instead of Vec reference 2024-01-02 02:47:41 +09:00
Yuya Nishihara
c9b581589c op_walk: simplify arguments passed to high-level "opset" query functions 2024-01-01 10:22:23 +09:00
Yuya Nishihara
26b5f38f45 op_walk: move "opset" query functions from jj_cli 2024-01-01 10:22:23 +09:00
Yuya Nishihara
e4460d5386 op_walk: add error types for fake "opset" expression
This removes CommandError dependency from these resolution functions. We might
want to refactor the error types again if we introduce a real "opset" evaluator.

The error message for unresolved op heads now includes "@" instead of the whole
expression.
2024-01-01 10:22:23 +09:00
Yuya Nishihara
94fc32ab47 op_walk: extract walk_ancestors() to new module
I'm going to extract fake "opset" resolution functions there, and I think
walk_ancestors() belongs to the same category.
2024-01-01 10:22:23 +09:00
Yuya Nishihara
6dd936f72f op_heads: let caller decide resolve_op_heads() error type
The resolver callback usually returns wider error type, which I don't think
is a variant of OpHeadResolutionError.

To help type inference, resolver's error type is E, not E1 where E: From<E1>.
2024-01-01 10:22:23 +09:00
Martin von Zweigbergk
90744fb770 working copy: read files ahead when updating
If the commit backend has high latency, it can make a big difference
to read files concurrently. This patch updates the working copy code
to do that in the update code (when reading files from the backend to
write to the working copy). Because our backend at Google reads files
from a local daemon process that already does a lot of prefetching,
this patch doesn't actually help us. I think it's still the right
thing to do for backends that don't do the same kind of
prefetching. It speeds up `jj sparse set --add` by >10x when I disable
the prefetching in our daemon (our `Backend::concurrency()` is 100).
2023-12-29 13:37:13 -08:00
Yuya Nishihara
f9e9058b9b index: show bad operation id if commit lookup failed during reindexing
My jj repo contains such head commits, and "jj debug reindex" fails. To address
this problem, we'll probably need to implement GC, and the user will discard
operations before the first bad op id.
2023-12-29 13:05:58 +09:00
Yuya Nishihara
43e016a7d1 index: add explicit reindexing method that can propagate error 2023-12-29 13:05:58 +09:00
Yuya Nishihara
ab1c8656a4 index: rename private index_at_operation methods, reorder arguments
I'm going to add a public method that rebuilds index, and its return type will
be different. I also added "build_" because "index" could be misinterpreted
as noun.

The method arguments are reordered to follow the public IndexStore interface.
2023-12-29 13:05:58 +09:00
Yuya Nishihara
3abe6be384 index: propagate DefaultIndexStore::init/reinit() errors 2023-12-29 13:05:58 +09:00
Yuya Nishihara
955f6e356a repo: add error propagation path to IndexStore initialization and loading
The error types are shared with the commit store backend. We could add per-store
error types, but it's unlikely that the caller needs to discriminate them.
2023-12-29 13:05:58 +09:00
Yuya Nishihara
bb73cd491f clenaup: don't use debug format to embed ObjectId in error message
Also fixed typo, s/a/an/.
2023-12-29 13:05:58 +09:00
Martin von Zweigbergk
d06764eb7c op heads: remove now-unused methods for adding/removing op heads 2023-12-28 09:17:42 -08:00
Martin von Zweigbergk
65a6aa61db op heads: replace last use of remove_op_head() by update_op_heads() 2023-12-28 09:17:42 -08:00
Martin von Zweigbergk
76516bb46b op heads: inline handle_ancestor_ops()
This gets us closer to being able to use the new `update_op_heads()`
function here (without calling it multiple times).
2023-12-28 09:17:42 -08:00
Martin von Zweigbergk
4221c7cf5c op heads: remove handle_ancestor_ops() from trait
I think the idea behind `handle_ancestor_ops()` was to let our backend
at Google delegate the work to the server, which could then avoid
walking ancestors. However, we're now thinking that we're going to
make our server resolve divergent operations on its own instead, so
the client will never see more than one op head, unless it manually
creates the second op head itself (e.g. because the user ran two
concurrent commands). In those cases it should be fine to do the
walk. So let's simplify the trait by removing the function.
2023-12-28 09:17:42 -08:00
Martin von Zweigbergk
f969f4b0b0 op heads: remove lifetime from OpHeadsStoreLock 2023-12-28 09:17:42 -08:00
Martin von Zweigbergk
c304777a35 op heads: remove promote_new_op()
`OpHeadsStoreLock::promote_new_op()` doesn't add much over the new
`update_op_heads()`, so let's switch to the latter.
2023-12-28 09:17:42 -08:00
Martin von Zweigbergk
b8e45d196f op heads: add a new trait method combining add and remove of op heads
Consider how one would implment the current `OpHeadsStore` interface
for a cloud-based backend. After `OpHeadsStore::add_op_head()` is
called, the set of op heads temporarily contains two heads (typically)
until `OpHeadsStore::remove_op_head()` is called. That's not invalid,
but it's annoying to have to deal with that state more than
necessary. Also, it's unnecessarily inefficient to send the addition
and removal of op heads as separate RPCs. This patch therefore adds a
`update_op_heads()` method that takes a list of old heads to remove
and a single new head to add. Coming patches will start migrating to
that method.
2023-12-28 09:17:42 -08:00
Martin von Zweigbergk
8137975785 op heads: drop support for old location/format
We move `.jj/repo/op_heads/*` into `.jj/repo/op_heads/heads/*` almost
a year ago, in commits 90a66ec262 and 37ba17589d. We said we would
drop support for it in 0.9+. I think we said that before we started
doing monthly releases, but I we're still past the goal of 6 months
(which is what I think we were aiming for).
2023-12-28 09:17:42 -08:00
Yuya Nishihara
dde42b9c05 index: rename resolve_prefix() to resolve_commit_id_prefix()
I'll probably add change id lookup methods to CompositeIndex. The Index trait
won't gain resolve_change_id_prefix(), but I also renamed its resolve_prefix()
for consistency.
2023-12-26 01:03:10 +09:00
Yuya Nishihara
0f2f566188 index: remove "segment_" prefix from IndexSegment methods
Since Readonly/MutableIndexSegment no longer implement Index trait, there's
no ambiguity between segment-local and index-global operations. Let's shorten
the method names.
2023-12-26 01:03:10 +09:00
Yuya Nishihara
c9b9e2864e index: introduce newtype that represents segment-local position
I'm thinking of changing some IndexSegment methods to return LocalPosition
instead of global IndexPosition, and using u32 there would be a source of bugs.
2023-12-26 01:03:10 +09:00
Yuya Nishihara
ee8d5e279a index: make segment-level lookup return neighbor commit ids instead of positions
Both readonly and mutable segments know the commit ids to return, and the
caller only needs the ids. Since segment_commit_id(local_pos) scans the graph
entries, doing that would increase the chance of cache miss.
2023-12-26 01:03:10 +09:00
Yuya Nishihara
0e7834feb9 index: inline segment_entry_by_pos()
There's no reasonable way to abstract the IndexEntry construction.
2023-12-26 01:03:10 +09:00