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 rebase --skip-empty #2609

Merged
merged 3 commits into from
Nov 24, 2023
Merged

Implement rebase --skip-empty #2609

merged 3 commits into from
Nov 24, 2023

Conversation

matts1
Copy link
Collaborator

@matts1 matts1 commented Nov 21, 2023

Fixes issue #229. See the issue for discussions.

  • Add test helper functions to give full control over the tree.
  • Implement plumbing to add RebaseOptions to rebase_commit and DescendentRebaser.
  • Implement skipping of empty commits.
  • Add a --skip-empty flag to rebase

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

@matts1 matts1 marked this pull request as ready for review November 21, 2023 06:21
Copy link
Collaborator

@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.

Hi, thanks for implementing your feature request.

I left a bunch of comments and I want to remind you that we prefer a linear history in this project, so you'll need to squash this into two or three commits. See https://github.com/martinvonz/jj/blob/main/docs/contributing.md#code-reviews

cli/src/commands/rebase.rs Outdated Show resolved Hide resolved
lib/src/repo.rs Outdated Show resolved Hide resolved
lib/src/rewrite.rs Outdated Show resolved Hide resolved
lib/src/rewrite.rs Outdated Show resolved Hide resolved
lib/tests/test_rewrite.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
lib/testutils/src/lib.rs Outdated Show resolved Hide resolved
lib/testutils/src/lib.rs Outdated Show resolved Hide resolved
lib/src/repo.rs Outdated Show resolved Hide resolved
@matts1 matts1 force-pushed the skip-empty branch 2 times, most recently from dd50d9a to 85ff2f0 Compare November 22, 2023 01:12
Copy link
Collaborator

@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.

The code generally looks good to me, thanks!, but I don't have much expertise around rebase stuff.

lib/src/rewrite.rs Show resolved Hide resolved
cli/src/commands/rebase.rs Show resolved Hide resolved
lib/tests/test_rewrite.rs Outdated Show resolved Hide resolved
Copy link
Member

@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.

Looks great. Thank you!

cli/src/commands/rebase.rs Show resolved Hide resolved
lib/tests/test_rewrite.rs Outdated Show resolved Hide resolved
cli/src/commands/rebase.rs Show resolved Hide resolved
Copy link
Collaborator

@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.

LG, if you want to you can prefix the first commit with lib: and the second with cli:.

@matts1 matts1 merged commit e79c8b6 into jj-vcs:main Nov 24, 2023
15 checks passed
@matts1 matts1 deleted the skip-empty branch November 24, 2023 03:48
ilyagr added a commit to ilyagr/jj that referenced this pull request Nov 26, 2023
This follows up on @matts1 's jj-vcs#2609.

We still allow the `-r` commit to become empty. I would be more comfortable if
there was a test for that, but I haven't done that (yet?) and it seems pretty
safe. If that's a problem, I'm happy to forbid `-r --skip-empty` entirely,
since it is far less useful than `-s --skip-empty` or `-b --skip-empty`.

I think it is reasonable not to empty descendants, since as far as descendants
of `A` are concerned, `jj rebase -r A` should be equivalent to `jj abandon A`,
and `jj abandon` does not empty anything.

Moreover, if we did want -r to empty descendants of `A`, we'd have to improve the
algorithm and add thorough tests. For example, if we have

root -> A -> B -> C

and `jj rebase -r A -d C` empties commit `B` (or `C`), I do not believe the current
algorithm will work correctly.
ilyagr added a commit to ilyagr/jj that referenced this pull request Nov 26, 2023
This follows up on @matts1 's jj-vcs#2609.

We still allow the `-r` commit to become empty. I would be more comfortable if
there was a test for that, but I haven't done that (yet?) and it seems pretty
safe. If that's a problem, I'm happy to forbid `-r --skip-empty` entirely,
since it is far less useful than `-s --skip-empty` or `-b --skip-empty`.

I think it is reasonable not to empty descendants, since as far as descendants
of `A` are concerned, `jj rebase -r A` should be equivalent to `jj abandon A`,
and `jj abandon` does not empty anything.

Moreover, if we did want -r to empty descendants of `A`, we'd have to improve the
algorithm and add thorough tests. For example, if we have

```
root -> A -> B -> C
```

and `jj rebase -r A -d C` empties commit `B` (or `C`), I do not believe the current
algorithm will work correctly.
ilyagr added a commit to ilyagr/jj that referenced this pull request Nov 26, 2023
This follows up on @matts1 's jj-vcs#2609.

We still allow the `-r` commit to become empty. I would be more comfortable if
there was a test for that, but I haven't done that (yet?) and it seems pretty
safe. If that's a problem, I'm happy to forbid `-r --skip-empty` entirely,
since it is far less useful than `-s --skip-empty` or `-b --skip-empty`.

I think it is reasonable not to empty descendants, since as far as descendants
of `A` are concerned, `jj rebase -r A` should be equivalent to `jj abandon A`,
and `jj abandon` does not remove emptid commits. It also doesn't seem very
useful to do that to descendant commits.

Moreover, if we did want -r to empty descendants of `A`, we'd have to improve the
algorithm and add thorough tests. For example, if we have

```
root -> A -> B -> C
```

and `jj rebase -r A -d C` empties commit `B` (or `C`), I do not know whether the
current algorithm will work correctly. It seems possible that it would, but that
depends on the fact that empty merge commits are not abandoned. That seems
dangerous to rely on without tests.
ilyagr added a commit to ilyagr/jj that referenced this pull request Nov 26, 2023
This follows up on @matts1 's jj-vcs#2609.

We still allow the `-r` commit to become empty. I would be more comfortable if
there was a test for that, but I haven't done that (yet?) and it seems pretty
safe. If that's a problem, I'm happy to forbid `-r --skip-empty` entirely,
since it is far less useful than `-s --skip-empty` or `-b --skip-empty`.

I think it is undesired to abandon emptied descendants, since as far as
descendants of `A` are concerned, `jj rebase -r A` should be equivalent to `jj
abandon A`, and `jj abandon` does not remove emptied commits. It also doesn't
seem very useful to do that to descendant commits, since I think they'd only
become empty in pathological cases.

Additionally, if we did want -r to empty descendants of `A`, we'd have to add
thorough tests and possibly improve the algorithm. I want to refactor `rebase -r`
and add features to it, and considering these cases makes everything harder.

For example, if we have

```
root -> A -> B -> C
```

and `jj rebase -r A -d C` empties commit `B` (or `C`), I do not know whether the
current algorithm will work correctly. It seems possible that it would, but that
depends on the fact that empty merge commits are not abandoned. That seems
dangerous to rely on without tests.
ilyagr added a commit to ilyagr/jj that referenced this pull request Nov 26, 2023
This follows up on @matts1 's jj-vcs#2609.

We still allow the `-r` commit to become empty. I would be more comfortable if
there was a test for that, but I haven't done that (yet?) and it seems pretty
safe. If that's a problem, I'm happy to forbid `-r --skip-empty` entirely,
since it is far less useful than `-s --skip-empty` or `-b --skip-empty`.

I think it is undesired to abandon emptied descendants, since as far as
descendants of `A` are concerned, `jj rebase -r A` should be equivalent to `jj
abandon A`, and `jj abandon` does not remove emptied commits. It also doesn't
seem very useful to do that to descendant commits, since I think they'd only
become empty in pathological cases.

Additionally, if we did want -r to empty descendants of `A`, we'd have to add
thorough tests and possibly improve the algorithm. I want to refactor `rebase -r`
and add features to it, and considering these cases makes everything harder.

For example, if we have

```
root -> A -> B -> C
```

and `jj rebase -r A -d C` empties commit `B` (or `C`), I do not know whether
the current algorithm will work correctly. It seems possible that it would, but
that depends on the fact that empty merge commits are not abandoned for
descendants. That seems dangerous to rely on without tests.

Making DescendantRebaser return more information (which I am likely to do as part
of implementing `-r --after`) should help make such code more obviously correct.
ilyagr added a commit to ilyagr/jj that referenced this pull request Nov 26, 2023
This follows up on @matts1 's jj-vcs#2609.

We still allow the `-r` commit to become empty. I would be more comfortable if
there was a test for that, but I haven't done that (yet?) and it seems pretty
safe. If that's a problem, I'm happy to forbid `-r --skip-empty` entirely,
since it is far less useful than `-s --skip-empty` or `-b --skip-empty`.

I think it is undesired to abandon emptied descendants. As far as descendants
of `A` are concerned, `jj rebase -r A` should be equivalent to `jj abandon A`,
and `jj abandon` does not remove emptied commits. It also doesn't seem very
useful to do that, since I think descendant commits of an abandoned (or moved
with `-r`) commit only become empty in pathological cases.

Additionally, if we did want -r to empty descendants of `A`, we'd have to add
thorough tests and possibly improve the algorithm. I want to refactor `rebase
-r` and add features to it, and having to consider cases of commits becoming
abandoned makes everything harder.

For example, if we have

```
root -> A -> B -> C
```

and `jj rebase -r A -d C` empties commit `B` (or `C`), I do not know whether
the current algorithm will work correctly. It seems possible that it would, but
that depends on the fact that empty merge commits are not abandoned for
descendants. That seems dangerous to rely on without tests.

I hope (but can't promise) that in the near future, making DescendantRebaser
return more information  should help make it possible to create such
functionality in a more robust way. I am likely to attempt this as part of
implementing `-r --after`.
ilyagr added a commit to ilyagr/jj that referenced this pull request Nov 26, 2023
This follows up on @matts1 's jj-vcs#2609.

We still allow the `-r` commit to become empty. I would be more comfortable if
there was a test for that, but I haven't done that (yet?) and it seems pretty
safe. If that's a problem, I'm happy to forbid `-r --skip-empty` entirely,
since it is far less useful than `-s --skip-empty` or `-b --skip-empty`.

I think it is undesired to abandon emptied descendants. As far as descendants
of `A` are concerned, `jj rebase -r A` should be equivalent to `jj abandon A`,
and `jj abandon` does not remove emptied commits. It also doesn't seem very
useful to do that, since I think descendant commits of an abandoned (or moved
with `-r`) commit only become empty in pathological cases.

Additionally, if we did want -r to empty descendants of `A`, we'd have to add
thorough tests and possibly improve the algorithm. I want to refactor `rebase
-r` and add features to it, and having to consider cases of commits becoming
abandoned makes everything harder.

For example, if we have

```
root -> A -> B -> C
```

and `jj rebase -r A -d C` empties commit `B` (or `C`), I do not know whether
the current algorithm will work correctly. It seems possible that it would, but
that depends on the fact that empty merge commits are not abandoned for
descendants. That seems dangerous to rely on without tests.

I hope (but can't promise) that in the near future, making DescendantRebaser
return more information  should help make it possible to create such
functionality in a more robust way. I am likely to attempt this as part of
implementing `-r --after`.
ilyagr added a commit to ilyagr/jj that referenced this pull request Nov 26, 2023
This follows up on @matts1 's jj-vcs#2609.

We still allow the `-r` commit to become empty. I would be more comfortable if
there was a test for that, but I haven't done that (yet?) and it seems pretty
safe. If that's a problem, I'm happy to forbid `-r --skip-empty` entirely,
since it is far less useful than `-s --skip-empty` or `-b --skip-empty`.

I think it is undesired to abandon emptied descendants. As far as descendants
of `A` are concerned, `jj rebase -r A` should be equivalent to `jj abandon A`,
and `jj abandon` does not remove emptied commits. It also doesn't seem very
useful to do that, since I think descendant commits of an abandoned (or moved
with `-r`) commit only become empty in pathological cases.

Additionally, if we did want -r to empty descendants of `A`, we'd have to add
thorough tests and possibly improve the algorithm. I want to refactor `rebase
-r` and add features to it, and having to consider cases of commits becoming
abandoned makes everything harder.

For example, if we have

```
root -> A -> B -> C
```

and `jj rebase -r A -d C` empties commit `B` (or `C`), I do not know whether
the current algorithm will work correctly. It seems possible that it would, but
that depends on the fact that empty merge commits are not abandoned for
descendants. That seems dangerous to rely on without tests.

I hope (but can't promise) that in the near future, making DescendantRebaser
return more information  should help make it possible to create such
functionality in a more robust way. I am likely to attempt this as part of
implementing `-r --after`.
ilyagr added a commit that referenced this pull request Nov 26, 2023
This follows up on @matts1 's #2609.

We still allow the `-r` commit to become empty. I would be more comfortable if
there was a test for that, but I haven't done that (yet?) and it seems pretty
safe. If that's a problem, I'm happy to forbid `-r --skip-empty` entirely,
since it is far less useful than `-s --skip-empty` or `-b --skip-empty`.

I think it is undesired to abandon emptied descendants. As far as descendants
of `A` are concerned, `jj rebase -r A` should be equivalent to `jj abandon A`,
and `jj abandon` does not remove emptied commits. It also doesn't seem very
useful to do that, since I think descendant commits of an abandoned (or moved
with `-r`) commit only become empty in pathological cases.

Additionally, if we did want -r to empty descendants of `A`, we'd have to add
thorough tests and possibly improve the algorithm. I want to refactor `rebase
-r` and add features to it, and having to consider cases of commits becoming
abandoned makes everything harder.

For example, if we have

```
root -> A -> B -> C
```

and `jj rebase -r A -d C` empties commit `B` (or `C`), I do not know whether
the current algorithm will work correctly. It seems possible that it would, but
that depends on the fact that empty merge commits are not abandoned for
descendants. That seems dangerous to rely on without tests.

I hope (but can't promise) that in the near future, making DescendantRebaser
return more information  should help make it possible to create such
functionality in a more robust way. I am likely to attempt this as part of
implementing `-r --after`.
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.

6 participants