Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement transform_descendants(), rewrite jj parallelize #3521

Merged
merged 9 commits into from
Apr 19, 2024

Conversation

martinvonz
Copy link
Member

@bnjmnt4n: This PR includes the transform_descendants() function.

@emesterhazy: FYI, this is how I'm planning to rewrite jj parallelize.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@martinvonz martinvonz changed the base branch from main to push-rlknuwzmnzks April 17, 2024 13:44
Copy link
Contributor

@emesterhazy emesterhazy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. Overall this is really cool and the descendants rebasing API seems very powerful!

cli/src/commands/parallelize.rs Show resolved Hide resolved
cli/tests/test_parallelize_command.rs Show resolved Hide resolved
cli/tests/test_parallelize_command.rs Show resolved Hide resolved
cli/tests/test_parallelize_command.rs Outdated Show resolved Hide resolved
cli/tests/test_parallelize_command.rs Show resolved Hide resolved
cli/tests/test_parallelize_command.rs Show resolved Hide resolved
@martinvonz martinvonz force-pushed the push-msstusvklrml branch 3 times, most recently from b549ada to bebd5fe Compare April 18, 2024 05:02
Copy link
Member Author

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now ready for review

cli/tests/test_parallelize_command.rs Show resolved Hide resolved
cli/tests/test_parallelize_command.rs Show resolved Hide resolved
cli/tests/test_parallelize_command.rs Show resolved Hide resolved
cli/tests/test_parallelize_command.rs Show resolved Hide resolved
@martinvonz martinvonz marked this pull request as ready for review April 18, 2024 05:03
lib/src/repo.rs Show resolved Hide resolved
lib/src/rewrite.rs Outdated Show resolved Hide resolved
cli/src/commands/parallelize.rs Outdated Show resolved Hide resolved
cli/src/commands/parallelize.rs Outdated Show resolved Hide resolved
cli/src/commands/parallelize.rs Outdated Show resolved Hide resolved
cli/src/commands/parallelize.rs Outdated Show resolved Hide resolved
cli/tests/test_parallelize_command.rs Show resolved Hide resolved
Base automatically changed from push-rlknuwzmnzks to main April 18, 2024 15:08
@martinvonz martinvonz force-pushed the push-msstusvklrml branch 2 times, most recently from a072d6c to c50227a Compare April 18, 2024 15:30
…nts()`

There are several existing commands that would benefit from an API
that makes it easier to rewrite a whole graph of commits while
transforming them in some way.

`jj squash` is one example. When squashing into an ancestor, that
command currently rewrites the ancestor, then rebases descendants, and
then rewrites the rewritten source commit. It would be better to
rewrite the source commit (and any descendants) only once.

Another example is the future `jj fix`. That command will want to
rewrite a graph while updating the trees. There's currently no good
API for that; you have to manually iterate over descendants and
rewrite them.

This patch adds a new `MutableRepo::transform_descendants()` method
that takes a callback which gets a `CommitRewriter` passed to it. The
callback can then decide to change the parents, the tree, etc. The
callback is also free to leave the commit in place or to abandon it.

I updated the regular `rebase_descendants()` to use the new function
in order to exercise it. I hope we can replace all of the
`rebase_descendant_*()` flavors later.

I added a `replace_parent()` method that was a bit useful for the test
case. It could easily be hard-coded in the test case instead, but I
think the method will be useful for `jj git sync` and similar in the
future.
We always call `.to_vec()` on the slice, so let's just have the caller
pass in an owned vector instead.
`jj parallelize` was a good example of a command that can be
simplified by the new API, so I decided to rewrite it as an example.

The rewritten version is more flexible and doesn't actually need the
restrictions from the old version (such as checking that the commits
are connected). I still left the check for now to keep this patch
somewhat small. A subsequent commit will remove the restrictions.
The new API makes it easy to leave commits in place if their parents
didn't change, so let's do that.
I'm going to make some `jj parallelize` cases that currently error out
instead be successful. Some of the will result in ancestor merges with
the root commit. This patch updates those tests to avoid that.
Should make it easier to understand the graph shape when there are
lots of crossing lines.
The checks are not needed by the new implementation, so just drop
them.
The rewritten code is already a no-op when there's a single input. I
don't think the case is common enough to warrant having a special case
for performance reasons either. Also, by not having the special case,
`jj parallelize <immutable commit>` fails consistently with the
non-singleton case.
@martinvonz martinvonz changed the title DRAFT: Implement transform_descendants(), rewrite jj parallelize Implement transform_descendants(), rewrite jj parallelize Apr 18, 2024
@martinvonz martinvonz enabled auto-merge (rebase) April 19, 2024 00:24
@martinvonz martinvonz disabled auto-merge April 19, 2024 00:25
@martinvonz
Copy link
Member Author

@yuja: This PR still requires an approval. I don't mean to rush you, just making sure you didn't forget it (I sometimes think that I had approved a PR that I had not approved). Take your time if you need.

Copy link
Contributor

@yuja yuja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just thought it might be better to be reviewed by others, but the change looks good to me.

@martinvonz
Copy link
Member Author

I just thought it might be better to be reviewed by others, but the change looks good to me.

Makes sense. Thanks for reviewing!

@bnjmnt4n, @emesterhazy, and/or @ilyagr might want to take a look. I'll merge it based on Yuya's review and to unblock e.g. Benjamin's rebase --insert-before/-after series. I'm happy to send fixes as separate PRs if you have any thoughts.

@martinvonz martinvonz merged commit 449fc42 into main Apr 19, 2024
16 checks passed
@martinvonz martinvonz deleted the push-msstusvklrml branch April 19, 2024 04:06
emesterhazy added a commit that referenced this pull request Apr 20, 2024
This is following on the rewrite for `parallelize`.

- #3521

Since rebase_descendants from rebase.rs is no longer used outside of that file,
it can be made private again.
emesterhazy added a commit that referenced this pull request Apr 20, 2024
This is following on the rewrite for `parallelize`.

- #3521

Since rebase_descendants from rebase.rs is no longer used outside of that file,
it can be made private again.
emesterhazy added a commit that referenced this pull request Apr 20, 2024
This is following on the rewrite for `parallelize`.

- #3521

Since rebase_descendants from rebase.rs is no longer used outside of that file,
it can be made private again.
emesterhazy added a commit that referenced this pull request Apr 21, 2024
This is following on the rewrite for `parallelize`.

- #3521

Since rebase_descendants from rebase.rs is no longer used outside of that file,
it can be made private again.
emesterhazy added a commit that referenced this pull request Apr 21, 2024
This is following on the rewrite for `parallelize`.

- #3521

Since rebase_descendants from rebase.rs is no longer used outside of that file,
it can be made private again.
emesterhazy added a commit that referenced this pull request Apr 21, 2024
This is following on the rewrite for `parallelize`.

- #3521

Since rebase_descendants from rebase.rs is no longer used outside of that file,
it can be made private again.
emesterhazy added a commit that referenced this pull request Apr 21, 2024
This is following on the rewrite for `parallelize`.

- #3521

Since rebase_descendants from rebase.rs is no longer used outside of that file,
it can be made private again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants