Replies: 4 comments 10 replies
-
Does this include the case of |
Beta Was this translation helpful? Give feedback.
-
Thanks for starting this discussion! We should also keep in mind the use case of parallelizing commits (#1079, #2274). Also, you didn't explicitly mention the pretty basic Another important use case that The new API seems more complicated to me at first glance. It would be useful to explain how it makes things simpler. I think the main benefit is that the CLI crate will be able to simply call Actually, since your change to |
Beta Was this translation helpful? Give feedback.
-
I wasn't considering about it that deeper. My point was just low-level |
Beta Was this translation helpful? Give feedback.
-
A note about how my plans relate to this. They are rather vague at the moment, so suggestions are welcome in this area as well.
|
Beta Was this translation helpful? Give feedback.
-
Here is a draft my thoughts of where we could go with the rewrite API after #2737 and #2738. This is in a draft state right now, I wrote up my thoughts rather quickly.
The idea is to slowly move logic for the tricky parts of rewrites (especially edge cases like weird ancestry) to the lib crate. It's not entirely obvious what the primitives for the more complicated rewrite operations should be so that one can wrap their mind around them. This write-up is an attempt to pick such primitives.
I hope to reuse pieces of the
DescendantRebaser
implementation to decrease duplication.WDYT, @yuja, @martinvonz? Is there a way to have a simpler mental model that this? Did I miss some important use-case?
Use cases to support
jj split
jj rebase -r -d descendant
jj new --after
orjj rebase -r --after
jj new --before
orjj rebase -r --before
(seems simple on second thought)In all of these cases, the CLI crate should care as little as possible about the possible weird ancestry (#2600, #2650 ) in the commit graph.
Design
Step 1
I assume familiarity with the current
MutRepo
design.I propose adding a bit of config to each rewritten commit, called
RemainingRewriteActions
below. Then, we add customized options of the current API:UPDATE: Instead of
move_branches
, we probably wantabandon_original: bool
. This controls another essential piece ofrebase_descendants
functionality: ifabandon_original
is false, the original commit is not abandoned and branches are not moved. We could in principle allow moving branches without abandoning commit, but I don't think there's a need right now. The rest of this write-up should work unchanged withabandon_original
replacingmove_branches
everywhere.Normal rebase/abandon
No significant changes to their implementation
jj split
Rewrite
jj split
to useto make the parent commit. As a result,
DescendantRebaser
should ignore this rewrite. Then,split
would use a normalrewrite_commit
for the child commit.jj rebase -r X -d descendant
Instead of the current custom code, use
to rebase the descendants of
X
onto the parents ofX
before movingX
itself (instead of current custom code).The above code should change
to
without moving any branches at
X
.Afterwards,
rebase
can actually rebaseX
to its destination.rebase_descendants
should ensure that this works even ifB2
is a descendant ofB1
.Step 2:
--after
Change
RemainingRewriteActions::rebase_descendants
from abool
to andenum
:Let's say we start with
and try
jj rebase -r X --after A1
.If
X
was not a descendant ofA1
, we could rewriteA1
toX
ifX
is an ancestor, but troublesome if it is a descendant.Instead, rebase
X
ontoA1
as usual to getThen use
This should result in
(
jj new --after A1
can be done similarly)rebase_descendants
should ensure that this works even ifB2
is a descendant ofB1
.--before
This seems much easier than
--after
and does not use the new APIs.Let's start with the same graph,
and try
jj new --before B1
.We'd create a new commit
X
withparents(X) = parents(B1)
:Unless I missed something, we only need to now do a simple rebase of
B1
ontoX
. (I was originally thinking about usingRebaseDescendants::Only
)Step A (orthogonal to the above)
Extract the relevant
MutRepo
operations to a wrapper calledIncompleteRewrite
that holds an&mut MutRepo
reference.IncompleteRewrite::drop
calls an analogue ofrebase_descendants
.As a result, when you have a
MutRepo
object, you can be sure it does not need arebase_descendants
to be in a consistent state.This is my interpretation of @yuja's suggestion from #2737 (comment).
Step B (orthogonal to the above)
Remember
parent_mapping
in the rewrite API. Until this happens, the CLI crate would need to callrebase_descendants_return_map
and keep track of the parent mapping.Step C (orthogonal to the above)
Consider consolidating currently existing
RebaseOptions
andRemainingRewriteActions
.Beta Was this translation helpful? Give feedback.
All reactions