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

cli split: Leave bookmarks associated with the original change id #5618

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

emesterhazy
Copy link
Member

jj split no longer moves bookmarks to the second revision created by the split. Local bookmarks associated with the target revision will point to the first revision (which inherits the target revision's change id) created by the split afterward.

Since the first revision inherits the change id of the target revision, this behavior is less surprising than moving the bookmark to the second revision.

This no-implicit-move behavior also aligns with how jj abandon drops bookmarks instead of moving them to the parent revision.

fixes #3419

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
    • N/A: I didn't see any docs describing the bookmark semantics.
  • I have updated the config schema (cli/src/config-schema.json)
    • N/A: no config changes
  • I have added tests to cover my changes

Comment on lines 232 to 236
// If @ refers to the target commit, move it to the second commit.
if at.id() == commit.id() {
tx.edit(&second_commit)?;
}
Copy link
Member

@martinvonz martinvonz Feb 7, 2025

Choose a reason for hiding this comment

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

This will update working copies in other workspaces. I think we should update the code here (lines 207-235) to use rewrite::move_commits() in order to move the children of commit (i.e. before splitting) to be rebased on top of second_commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

it would also be nice if you spelled out "the working copy commit (@)" in the comment

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I understand. How will using rewrite::move_commits() avoid the issue of edit updating the working copy in other workspaces? I need to read up on how workspaces work, but I'm a little surprised that tx.edit updates workspaces other than the current one.

The code suggests it only acts on the current workspace via the workspace_id?

    pub fn edit(&mut self, commit: &Commit) -> Result<(), EditCommitError> {
        let workspace_id = self.helper.workspace_id().to_owned();
        self.id_prefix_context.take(); // invalidate
        self.tx.repo_mut().edit(workspace_id, commit)
    }

Separately, what should I pass to the targets argument of rewrite::move_commits()? I don't think I have a list of the children of the commit being split. Do I need to evaluate a revset, or is there another way to do it?

Copy link
Member

Choose a reason for hiding this comment

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

How will using rewrite::move_commits() avoid the issue of edit updating the working copy in other workspaces?

Oh, you're right, it won't. I was thinking that this was a workaround for how we rewrite commits in a strange way above, but it's just a consequence of wanting the working copy to move to the second commit.

but I'm a little surprised that tx.edit updates workspaces other than the current one.

It doesn't. That's the problem, kind of. If you had split a commit checked out by another workspace, then that workspace should now point to the rewritten commit.

I think the problem is that split is a bit unusual in how it rewrites the graph:

  1. The change id should stay on the first commit
  2. Bookmarks should stay on the first commit
  3. Working copies should move to the second commit
  4. Descendants should move onto the second commit

Normally they all move in the same way, and that's what building blocks like rebase_descendants() expects. But because we don't want that here, we have to do something more manually. Moving the working-copy pointers manually as you did makes sense. We should just update the code to update all working copies instead of just the current working copy.

Sorry about the confusion.

Copy link
Contributor

@PhilipMetzger PhilipMetzger left a comment

Choose a reason for hiding this comment

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

Thanks for doing this, lgtm. I will leave the last call to Martin.

Comment on lines 232 to 236
// If @ refers to the target commit, move it to the second commit.
if at.id() == commit.id() {
tx.edit(&second_commit)?;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

it would also be nice if you spelled out "the working copy commit (@)" in the comment

`jj split` no longer moves bookmarks to the second revision created by the
split. Local bookmarks associated with the target revision will point to the
first revision (which inherits the target revision's change id) created by the
split afterward.

Since the first revision inherits the change id of the target revision, this
behavior is less surprising than moving the bookmark to the second revision.

This no-implicit-move behavior also aligns with how `jj abandon` drops
bookmarks instead of moving them to the parent revision.

fixes #3419
@emesterhazy
Copy link
Member Author

emesterhazy commented Feb 7, 2025

it would also be nice if you spelled out "the working copy commit (@)" in the comment

Makes sense; done. Thanks for taking a look :)

@martinvonz martinvonz changed the title cli split: Leave bookarks associated with the original change id cli split: Leave bookmarks associated with the original change id Feb 8, 2025
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.

What should jj split do with branches?
3 participants