ok/jj
1
0
Fork 0
forked from mirrors/jj
jj/lib
Ilya Grigoriev 316ab8efb8 rewrite.rs: refactor new_parents to depend only on parent_mapping
Previously, the function relied on both the `self.parent_mapping` and
`self.rebased`. If `(A,B)` was in `parent_mapping` and `(B,C)` was in `rebased`,
`new_parents` would map `A` to `C`.

Now, `self.rebased` is ignored by `new_parents`. In the same situation,
DescendantRebaser is changed so that both `(A,B)` and `(B,C)` are in
`parent_mapping` before. `new_parents` now applies `parent_mapping` repeatedly,
and will map `A` to `C` in this situation.

## Cons

- The semantics are changed; `new_parents` now panics if `self.parent_mapping`
  contain cycles. AFAICT, such cycles never happen in `jj` anyway, except for
one test that I had to fix. I think it's a sensible restriction to live with;
if you do want to swap children of two commits, you can call
`rebase_descendants` twice.

## Pros

- I find the new logic much easier to reason about. I plan to extract it into a
function, to be used in refactors for `jj rebase -r` and `jj new --after`. It
will make it much easier to have a correct implementation of `jj rebase -r
--after`, even when rebasing onto a descendant.

- The de-duplication is no longer O(n^2). I tried to keep the common case fast.

## Alternatives

- We could make `jj rebase` and `jj new` use a separate function with the
algorithm shown here, without changing DescendantRebaser. I believe that the new
algorithm makes DescendatRebaser easier to understand, though, and it feels more
elegant to reduce code duplication.

- The de-duplication optimization here is independent of other changes, and
could be used on its own.
2023-12-12 19:35:51 -08:00
..
benches
gen-protos Use { workspace = true } to appease VS Code's Cargo.toml parser 2023-08-22 21:38:53 -07:00
src rewrite.rs: refactor new_parents to depend only on parent_mapping 2023-12-12 19:35:51 -08:00
tests rewrite.rs: refactor new_parents to depend only on parent_mapping 2023-12-12 19:35:51 -08:00
testutils gc: implement basic GC for Git backend 2023-12-03 07:40:12 -08:00
Cargo.toml cargo: add ref-cast dependency 2023-11-26 18:21:40 +09:00
LICENSE cargo: add LICENSE file to each crate we publish 2023-09-22 21:48:28 -07:00