git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/4] sequencer: Do not require `allow_empty` for redundant commit options

From
Brian Lyles <brianmlyles@gmail.com>
Date
Jan 27, 2024, 23:30 UTC
Message-ID
<CAHPHrSeKY2Ou9VCq6rtADTOwycc0KCTPaCCwtqf94yLi0wj0OQ@mail.gmail.com>
In-Reply-To
<7229fe62-cf9b-4829-80ec-c6b44c52163e@gmail.com>
[+cc Junio]
Hi Phillip
On Tue, Jan 23, 2024 at 8:23 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 6 quoted lines
>
> Hi Brian
>
> Let me start by saying that overall I'm impressed with the quality of
> this submission. I've left quite a few comments but for a first patch
> series it is very good.
Thank you for the kind words!
Show 17 quoted lines
> On 19/01/2024 05:59, brianmlyles@gmail.com wrote:
> > From: Brian Lyles <brianmlyles@gmail.com>
> >
> > Previously, a consumer of the sequencer that wishes to take advantage of
> > either the `keep_redundant_commits` or `drop_redundant_commits` feature
> > must also specify `allow_empty`.
> >
> > The only consumer of `drop_redundant_commits` is `git-rebase`, which
> > already allows empty commits by default and simply always enables
> > `allow_empty`. `keep_redundant_commits` was also consumed by
> > `git-cherry-pick`, which had to specify `allow-empty` when
> > `keep_redundant_commits` was specified in order for the sequencer's
> > `allow_empty()` to actually respect `keep_redundant_commits`.
>
> I think it might be more persuasive to start the commit message by
> explaining what user visible change you're trying to make and why rather
> than concentrating on the implementation details.

I struggled a bit with this initially because the motivation behind the change in this particular commit was driven by a technical issue in my mind. The side-effect with git-cherry-pick(s) `--allow-empty` and `--keep-redundant-commits` was mildly problematic, but less concerning that the future problem that we'd have once git-cherry-pick(1) got the more robust `--empty` option in a later commit in this series.

I think my problem came down to this commit trying to solve two problems at once -- the underlying technical concern _and_ the git-cherry-pick(1) behavior.

In v2, I intend to break this commit into two:
- Update `allow_empty()` to not require `allow_empty`, but without
  actually changing any consumers (and thus without making any
  functional change)
- Update git-cherry-pick(1) such that `--keep-redundant-commits` no
  longer implies `--allow-empty`.

This allows me to better justify the technical change technically and the functional change functionally, while also making it easier to drop the functional change if we decide that a breaking change is not warranted to address this.

Show 6 quoted lines
> Do you have a practical example of where you want to keep the commits
> that become empty but not the ones that start empty? I agree there is a
> distinction but I think the common case is that the user wants to keep
> both types of empty commit or none. I'm not against giving the user the
> option to keep one or the other if it is useful but I'm wary of changing
> the default.

That practical example is documented in the initial discussion[1], which I should have ought to have linked in a cover letter for this series (and will do so in v2). I'll avoid copying the details here, but we'd very much like to be able to programmatically drop the commits that become empty when doing the automated cherry-pick described there.

[1]: https://lore.kernel.org/git/CAHPHrSevBdQF0BisR8VK=jM=wj1dTUYEVrv31gLerAzL9=Cd8Q@mail.gmail.com/
Show 9 quoted lines
> rebase always sets "opts->allow_empty = 1" in
> builtin/rebase.c:get_replay_opts() and if the user passes
> --no-keep-empty drops commits that start empty from the list of commits
> to be picked. This is slightly confusing but is more efficient as we
> don't do waste time trying to pick a commit we're going to drop. Can we
> do something similar for "git cherry-pick"? When cherry-picking a
> sequence of commits I think it should just work because the code is
> shared with rebase, for a single commit we'd need to add a test to see
> if it is empty in single_pick() before calling pick_commits().

Just noting here for future readers here that you sent a followup email indicating this was not viable:

Show 10 quoted lines
> On Wed, Jan 24, 2024 at 5:01 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> Having thought about this again I don't think we can reuse the same
> approach as rebase because cherry-pick and rebase have different
> behaviors. "git rebase --no-keep-empty" drops empty commits whereas "git
> cherry-pick" wants to error out if it sees an empty commit. So I think
> your approach of reworking allow_empty() in the sequencer is the right
> approach.
>
> Sorry for the confusion

No worries. If you have any suggestions for how I might better explain these changes in the commit message, please let me know.

Show 9 quoted lines
> > For some amount of backwards compatibility with the existing code and
> > tests, I have opted to preserve the behavior of returning 0 when:
> >
> > - `allow_empty` is specified, and
> > - either `is_index_unchanged` or `is_original_commit_empty` indicates an
> >    error
>
> I'm not sure that is a good idea as it is hiding an error that we didn't
> hit before because we returned early.

I think you're right -- Previously the error could not have been hit, but now it can. An error is still an error, and we should handle it regardless of how `allow_empty` was set. I'll address this in v2 by simply returning the error.

Show 13 quoted lines
> > Note that this commit is a breaking change: `--keep-redundant-commits`
> > will no longer imply `--allow-empty`. It would be possible to maintain
> > the current behavior of `--keep-redundant-commits` implying
> > `--allow-empty` if it were needed to avoid a breaking change, but I
> > believe that decoupling them entirely is the correct behavior.
>
> Thank you for being clear about the change in behavior, as I said above
> I'm wary of changing the default unless there is a compelling reason but
> I'm happy to support
>
>      git cherry-pick --keep-redundant-commits --no-allow-empty
>
> if it is needed.
I totally understand being wary here.

I've certainly convinced myself that having the future `--empty=drop` behavior introduced later in this patch should not imply `--allow-empty`.

I also _think_ that the existing behavior of `--keep-redundant-commits` is probably technically not ideal or correct, but could be convinced that changing it now is not worthwhile. I will defer to group consensus here.

Show 13 quoted lines
> > Signed-off-by: Brian Lyles <brianmlyles@gmail.com>
> > ---
> >
> > Disclaimer: This is my first contribution to the git project, and thus
> > my first attempt at submitting a patch via `git-send-email`. It is also
> > the first time I've touched worked in C in over a decade, and I really
> > didn't work with it much before that either. I welcome any and all
> > feedback on what I may have gotten wrong regarding the patch submission
> > process, the code changes, or my commit messages.
>
> As others have mentioned I think it would be useful to have a
> cover-letter where we can discuss the aim of the patch series
> independently of the individual patches.
Absolutely, will do in v2.
Show 7 quoted lines
>  > [...]> +test_expect_success 'cherry pick an empty non-ff commit with
> --keep-redundant-commits' '
> > +     git checkout main &&
> > +     test_must_fail git cherry-pick --keep-redundant-commits empty-change-branch
>
> When using test_must_fail it is a good idea to check the error message
> to make sure that it's failing for the reason we expect (see patch 4).
Thanks for the tip, I'll add this in v2.
On Wed, Jan 24, 2024 at 5:01 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 57 quoted lines
> Here are some code comments now I've realized why we need to change it
>
> On 19/01/2024 05:59, brianmlyles@gmail.com wrote:
> > From: Brian Lyles <brianmlyles@gmail.com>
>  >   Documentation/git-cherry-pick.txt | 10 +++++++---
>  >   builtin/revert.c                  |  4 ----
>  >   sequencer.c                       | 18 ++++++++++--------
>  >   t/t3505-cherry-pick-empty.sh      |  5 +++++
>  >   4 files changed, 22 insertions(+), 15 deletions(-)
>  >
>  > diff --git a/Documentation/git-cherry-pick.txt
> b/Documentation/git-cherry-pick.txt
>  > index fdcad3d200..806295a730 100644
>  > --- a/Documentation/git-cherry-pick.txt
>  > +++ b/Documentation/git-cherry-pick.txt
>  > @@ -131,8 +131,8 @@ effect to your index in a row.
>  >       even without this option.  Note also, that use of this option only
>  >       keeps commits that were initially empty (i.e. the commit
> recorded the
>  >       same tree as its parent).  Commits which are made empty due to a
>  > -    previous commit are dropped.  To force the inclusion of those
> commits
>  > -    use `--keep-redundant-commits`.
>  > +    previous commit will cause the cherry-pick to fail.  To force the
>  > +    inclusion of those commits use `--keep-redundant-commits`.
>  >
>  >   --allow-empty-message::
>  >       By default, cherry-picking a commit with an empty message will
> fail.
>  > @@ -144,7 +144,11 @@ effect to your index in a row.
>  >       current history, it will become empty.  By default these
>  >       redundant commits cause `cherry-pick` to stop so the user can
>  >       examine the commit. This option overrides that behavior and
>  > -    creates an empty commit object.  Implies `--allow-empty`.
>  > +    creates an empty commit object. Note that use of this option only
>  > +    results in an empty commit when the commit was not initially empty,
>  > +    but rather became empty due to a previous commit. Commits that were
>  > +    initially empty will cause the cherry-pick to fail. To force the
>  > +    inclusion of those commits use `--allow-empty`.
>  >
>  >   --strategy=<strategy>::
>  >       Use the given merge strategy.  Should only be used once.
>  > diff --git a/builtin/revert.c b/builtin/revert.c
>  > index e6f9a1ad26..b2cfde7a87 100644
>  > --- a/builtin/revert.c
>  > +++ b/builtin/revert.c
>  > @@ -136,10 +136,6 @@ static int run_sequencer(int argc, const char
> **argv, const char *prefix,
>  >       prepare_repo_settings(the_repository);
>  >       the_repository->settings.command_requires_full_index = 0;
>  >
>  > -    /* implies allow_empty */
>  > -    if (opts->keep_redundant_commits)
>  > -        opts->allow_empty = 1;
>
> I'm wary of this, especially after Juino's comments in
> https://lore.kernel.org/git/xmqqy1cfnca7.fsf@gitster.g/

As noted above, I've split this commit into two, and am open to discussing dropping the functional change to `--keep-redundant-commits`

Show 14 quoted lines
>  >       if (cleanup_arg) {
>  >           opts->default_msg_cleanup = get_cleanup_mode(cleanup_arg, 1);
>  >           opts->explicit_cleanup = 1;
>  > diff --git a/sequencer.c b/sequencer.c
>  > index d584cac8ed..582bde8d46 100644
>  > --- a/sequencer.c
>  > +++ b/sequencer.c
>  > @@ -1739,22 +1739,24 @@ static int allow_empty(struct repository *r,
>  >        *
>  >        * (4) we allow both.
>  >        */
>
> The comment above should be updated if we change the behavior of this
> function.
Of course, good catch.
Show 9 quoted lines
> I don't think we want to hide the error here or below from
> originally_empty()
>
>  >       if (!index_unchanged)
>  >           return 0; /* we do not have to say --allow-empty */
>  >
>  > -    if (opts->keep_redundant_commits)
>  > -        return 1;
>  > -
Agreed, will address in v2 as mentioned above.

Thanks, Brian Lyles

Previous: Phillip WoodNext: Brian Lyles
Message 33 of 118 in “sequencer: Do not require `allow_empty` for redundant commit options”
  1. 1/4 sequencer: Do not require `allow_empty` for redundant commit optionsbrianmlyles@gmail.com, Jan 19, 2024
  2. 2/4 docs: Clean up `--empty` formatting in `git-rebase` and `git-am`brianmlyles@gmail.com, Jan 19, 2024
  3. Phillip WoodJan 23, 2024
  4. Brian LylesJan 27, 2024
  5. Phillip WoodFeb 1, 2024
  6. 3/4 rebase: Update `--empty=ask` to `--empty=drop`brianmlyles@gmail.com, Jan 19, 2024
  7. Phillip WoodJan 23, 2024
  8. Brian LylesJan 27, 2024
  9. Phillip WoodFeb 1, 2024
  10. 4/4 cherry-pick: Add `--empty` for more robust redundant commit handlingbrianmlyles@gmail.com, Jan 19, 2024
  11. Kristoffer HaugsbakkJan 20, 2024
  12. Brian LylesJan 21, 2024
  13. Kristoffer HaugsbakkJan 21, 2024
  14. Junio C HamanoJan 21, 2024
  15. Phillip WoodJan 22, 2024
  16. Kristoffer HaugsbakkJan 22, 2024
  17. Brian LylesJan 23, 2024
  18. Kristoffer HaugsbakkJan 23, 2024
  19. Junio C HamanoJan 23, 2024
  20. Subject: [PATCH] CoC: whitespace fixJunio C Hamano, Jan 23, 2024
  21. Elijah NewrenJan 24, 2024
  22. Junio C HamanoJan 23, 2024
  23. Phillip WoodJan 23, 2024
  24. Junio C HamanoJan 23, 2024
  25. Brian LylesJan 28, 2024
  26. Brian LylesJan 27, 2024
  27. Kristoffer HaugsbakkJan 20, 2024
  28. Brian LylesJan 21, 2024
  29. Phillip WoodJan 23, 2024
  30. Junio C HamanoJan 23, 2024
  31. Phillip WoodJan 24, 2024
  32. Phillip WoodJan 24, 2024
  33. Brian LylesJan 27, 2024
  34. Brian LylesJan 28, 2024
  35. Phillip WoodJan 29, 2024
  36. Brian LylesFeb 10, 2024
  37. Phillip WoodFeb 1, 2024
  38. Brian LylesFeb 10, 2024
  39. 0/8 cherry-pick: add `--empty`Brian Lyles, Feb 10, 2024
  40. phillip.wood123@gmail.comFeb 22, 2024
  41. 1/8 docs: address inaccurate `--empty` default with `--exec`Brian Lyles, Feb 10, 2024
  42. 2/8 docs: clean up `--empty` formatting in git-rebase(1) and git-am(1)Brian Lyles, Feb 10, 2024
  43. 3/8 rebase: update `--empty=ask` to `--empty=drop`Brian Lyles, Feb 10, 2024
  44. Brian LylesFeb 11, 2024
  45. Phillip WoodFeb 14, 2024
  46. phillip.wood123@gmail.comFeb 22, 2024
  47. Junio C HamanoFeb 22, 2024
  48. 4/8 sequencer: treat error reading HEAD as unborn branchBrian Lyles, Feb 10, 2024
  49. phillip.wood123@gmail.comFeb 22, 2024
  50. Brian LylesFeb 23, 2024
  51. phillip.wood123@gmail.comFeb 25, 2024
  52. 5/8 sequencer: do not require `allow_empty` for redundant commit optionsBrian Lyles, Feb 10, 2024
  53. phillip.wood123@gmail.comFeb 22, 2024
  54. 6/8 cherry-pick: decouple `--allow-empty` and `--keep-redundant-commits`Brian Lyles, Feb 10, 2024
  55. Phillip WoodFeb 22, 2024
  56. Junio C HamanoFeb 22, 2024
  57. 7/8 cherry-pick: enforce `--keep-redundant-commits` incompatibilityBrian Lyles, Feb 10, 2024
  58. Phillip WoodFeb 22, 2024
  59. Brian LylesFeb 23, 2024
  60. Junio C HamanoFeb 23, 2024
  61. phillip.wood123@gmail.comFeb 25, 2024
  62. Brian LylesFeb 26, 2024
  63. 8/8 cherry-pick: add `--empty` for more robust redundant commit handlingBrian Lyles, Feb 10, 2024
  64. Jean-Noël AVILAFeb 11, 2024
  65. Brian LylesFeb 12, 2024
  66. phillip.wood123@gmail.comFeb 22, 2024
  67. Brian LylesFeb 23, 2024
  68. phillip.wood123@gmail.comFeb 25, 2024
  69. Brian LylesFeb 26, 2024
  70. Brian LylesFeb 26, 2024
  71. phillip.wood123@gmail.comFeb 27, 2024
  72. Junio C HamanoFeb 27, 2024
  73. 0/7 cherry-pick: add `--empty` for more robust redundant commit handlingBrian Lyles, Mar 10, 2024
  74. phillip.wood123@gmail.comMar 13, 2024
  75. 1/7 docs: address inaccurate `--empty` default with `--exec`Brian Lyles, Mar 10, 2024
  76. 2/7 docs: clean up `--empty` formatting in git-rebase(1) and git-am(1)Brian Lyles, Mar 10, 2024
  77. 3/7 rebase: update `--empty=ask` to `--empty=stop`Brian Lyles, Mar 10, 2024
  78. 4/7 sequencer: treat error reading HEAD as unborn branchBrian Lyles, Mar 10, 2024
  79. Junio C HamanoMar 11, 2024
  80. Junio C HamanoMar 11, 2024
  81. Brian LylesMar 12, 2024
  82. Junio C HamanoMar 12, 2024
  83. Brian LylesMar 16, 2024
  84. phillip.wood123@gmail.comMar 13, 2024
  85. Brian LylesMar 16, 2024
  86. 5/7 sequencer: do not require `allow_empty` for redundant commit optionsBrian Lyles, Mar 10, 2024
  87. 6/7 cherry-pick: enforce `--keep-redundant-commits` incompatibilityBrian Lyles, Mar 10, 2024
  88. 7/7 cherry-pick: add `--empty` for more robust redundant commit handlingBrian Lyles, Mar 10, 2024
  89. phillip.wood123@gmail.comMar 13, 2024
  90. Junio C HamanoMar 13, 2024
  91. Brian LylesMar 16, 2024
  92. phillip.wood123@gmail.comMar 20, 2024
  93. 0/7 cherry-pick: add `--empty` for more robust redundant commit handlingBrian Lyles, Mar 20, 2024
  94. phillip.wood123@gmail.comMar 25, 2024
  95. Brian LylesMar 25, 2024
  96. phillip.wood123@gmail.comMar 25, 2024
  97. Junio C HamanoMar 25, 2024
  98. 1/7 docs: address inaccurate `--empty` default with `--exec`Brian Lyles, Mar 20, 2024
  99. 2/7 docs: clean up `--empty` formatting in git-rebase(1) and git-am(1)Brian Lyles, Mar 20, 2024
  100. 3/7 rebase: update `--empty=ask` to `--empty=stop`Brian Lyles, Mar 20, 2024
  101. 4/7 sequencer: handle unborn branch with `--allow-empty`Brian Lyles, Mar 20, 2024
  102. Dirk GoudersMar 21, 2024
  103. Junio C HamanoMar 21, 2024
  104. Dirk GoudersMar 21, 2024
  105. 5/7 sequencer: do not require `allow_empty` for redundant commit optionsBrian Lyles, Mar 20, 2024
  106. 6/7 cherry-pick: enforce `--keep-redundant-commits` incompatibilityBrian Lyles, Mar 20, 2024
  107. 7/7 cherry-pick: add `--empty` for more robust redundant commit handlingBrian Lyles, Mar 20, 2024
  108. 0/7 cherry-pick: add `--empty` for more robust redundant commit handlingBrian Lyles, Mar 25, 2024
  109. phillip.wood123@gmail.comMar 26, 2024
  110. Junio C HamanoMar 26, 2024
  111. phillip.wood123@gmail.comMar 27, 2024
  112. 1/7 docs: address inaccurate `--empty` default with `--exec`Brian Lyles, Mar 25, 2024
  113. 2/7 docs: clean up `--empty` formatting in git-rebase(1) and git-am(1)Brian Lyles, Mar 25, 2024
  114. 3/7 rebase: update `--empty=ask` to `--empty=stop`Brian Lyles, Mar 25, 2024
  115. 4/7 sequencer: handle unborn branch with `--allow-empty`Brian Lyles, Mar 25, 2024
  116. 5/7 sequencer: do not require `allow_empty` for redundant commit optionsBrian Lyles, Mar 25, 2024
  117. 6/7 cherry-pick: enforce `--keep-redundant-commits` incompatibilityBrian Lyles, Mar 25, 2024
  118. 7/7 cherry-pick: add `--empty` for more robust redundant commit handlingBrian Lyles, Mar 25, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.