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

Rewrite instead of abandoning empty commits. #2766

Merged
merged 2 commits into from
Jan 4, 2024
Merged

Conversation

matts1
Copy link
Contributor

@matts1 matts1 commented Jan 2, 2024

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

@ilyagr
Copy link
Contributor

ilyagr commented Jan 2, 2024

Ah, so it seems the bug wasn't quite what I thought.

I think that what you wrote, both in the code and the description, sounds reasonable to me. Could you write a test for this, ideally showing both what happened before and what happens now (in the same commit as the fix)? (Make sure to pull from main before writing the test, since I just merged #2738 which slightly changes how tests for rewrite operations are written).

Optionally, if you are willing to write some tests showing the working copy behavior, that would be nice too. I think there's a good chance this PR will just fix all of #2760 without having to do anything special for the working copy, but I'm not entirely sure.

@ilyagr
Copy link
Contributor

ilyagr commented Jan 2, 2024

In fact, I'm a bit worried that, with this change, in the common case when you are editing an empty commit, jj rebase --skip-empty -d somewhere will cause you to unexpectedly start editing the non-empty parent commit

I'm not sure if this is the best solution, but we could compare the change id of the working copy before and after the rebase. If they are different, you could do an analogue of jj new -m old_working_copy_description.

matts1 added a commit to matts1/jj that referenced this pull request Jan 3, 2024
Also verified that this fails without the previous commit.
@matts1
Copy link
Contributor Author

matts1 commented Jan 3, 2024

My preferred solution would be to just set skip-empty to set AbandonNewlyEmpty instead of AbandonAllEmpty, or to add a flag to do something similar. IMO, that's a discussion for another CL though, since this is just a bugfix.

@matts1
Copy link
Contributor Author

matts1 commented Jan 3, 2024

The failing checks appear to be completely unrelated, and they pass locally. I'm guessing it's a flake, which seems especially likely given that the test is for concurrency.

@ilyagr
Copy link
Contributor

ilyagr commented Jan 3, 2024

My preferred solution would be to just set skip-empty to set AbandonNewlyEmpty instead of AbandonAllEmpty

This wouldn't fix the problem, only make it more rare. The working copy commit can be emptied by a rebase even if it wasn't empty before.

I feel like the behavior of accidentally editing a non-empty commit might be even worse than the original bug. So, I'd prefer doing something about it now. Perhaps if we switch AbandonNewlyEmpty, it will be rare enough to not worry too much about it, but then we might forget to fix it entirely.

Fixes jj-vcs#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`
matts1 added a commit to matts1/jj that referenced this pull request Jan 3, 2024
matts1 added a commit to matts1/jj that referenced this pull request Jan 3, 2024
matts1 added a commit to matts1/jj that referenced this pull request Jan 3, 2024
Copy link
Contributor

@ilyagr ilyagr left a comment

Choose a reason for hiding this comment

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

Thank you very much for all the updates and for responding to the bug so quickly!

I have a bunch of minor nits. If you don't have the time or the energy, I can implement them myself, so they are optional. Also, I wrote them in a hurry, so my edits may need further editing.

Overall, this looks great to me. For the record, I'm not sure that my suggestion to never abandon working copy commits is the best long-term option; we can change it if we think of something better and/or people find this behavior confusing. However, I think it's a good patch for the bug for now.

lib/src/rewrite.rs Show resolved Hide resolved
lib/tests/test_rewrite.rs Show resolved Hide resolved
lib/tests/test_rewrite.rs Outdated Show resolved Hide resolved
lib/tests/test_rewrite.rs Outdated Show resolved Hide resolved
lib/tests/test_rewrite.rs Outdated Show resolved Hide resolved
lib/tests/test_rewrite.rs Show resolved Hide resolved
matts1 added a commit to matts1/jj that referenced this pull request Jan 4, 2024
@matts1 matts1 merged commit 3f0a49d into jj-vcs:main Jan 4, 2024
15 checks passed
@ilyagr
Copy link
Contributor

ilyagr commented Jan 4, 2024

Looks good, thanks again!

ilyagr added a commit to ilyagr/jj that referenced this pull request Jan 23, 2024
… empty `@`

This demonstrates the minor bug discussed in
jj-vcs#2766 (comment)
AKA jj-vcs#2869.

It's also interesting whether changing the definition of "discardable" commit
would affect this test, see
jj-vcs#2859 (comment)

(I think it won't, but still)
ilyagr added a commit to ilyagr/jj that referenced this pull request Jan 23, 2024
… empty `@`

This demonstrates the minor bug discussed in
jj-vcs#2766 (comment)
AKA jj-vcs#2869.

It's also interesting whether changing the definition of "discardable" commit
would affect this test, see
jj-vcs#2859 (comment)

(I think it won't, but still)
ilyagr added a commit to ilyagr/jj that referenced this pull request Jan 23, 2024
… empty `@`

This demonstrates the minor bug discussed in
jj-vcs#2766 (comment)
AKA jj-vcs#2869.

It's also interesting whether changing the definition of "discardable" commit
would affect this test, see
jj-vcs#2859 (comment)

(I think it won't, but still)
ilyagr added a commit to ilyagr/jj that referenced this pull request Jan 23, 2024
…est case

This demonstrates the minor bug discussed in
jj-vcs#2766 (comment)
AKA jj-vcs#2869.

It's also interesting whether changing the definition of "discardable" commit
would affect this test, see
jj-vcs#2859 (comment)

(I think it won't, but still)
ilyagr added a commit that referenced this pull request Jan 23, 2024
…est case

This demonstrates the minor bug discussed in
#2766 (comment)
AKA #2869.

It's also interesting whether changing the definition of "discardable" commit
would affect this test, see
#2859 (comment)

(I think it won't, but still)
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.

jj rebase --skip-empty unexpectedly changes the commit graph
3 participants