All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: brianmlyles@gmail.com, git@vger.kernel.org
Cc: me@ttaylorr.com, newren@gmail.com
Subject: Re: [PATCH 1/4] sequencer: Do not require `allow_empty` for redundant commit options
Date: Tue, 23 Jan 2024 14:23:52 +0000	[thread overview]
Message-ID: <7bf5036b-9f55-4451-a13c-8a2c815dfbb7@gmail.com> (raw)
In-Reply-To: <20240119060721.3734775-2-brianmlyles@gmail.com>

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.

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.

> The latter is an interesting case: As noted in the docs, this means that
> `--keep-redundant-commits` implies `--allow-empty`, despite the two
> having distinct, non-overlapping meanings:
> 
> - `allow_empty` refers specifically to commits which start empty, as
>    indicated by the documentation for `--allow-empty` within
>    `git-cherry-pick`:
> 
>    "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."
> 
> - `keep_redundant_commits` refers specifically to commits that do not
>    start empty, but become empty due to the content already existing in
>    the target history. This is indicated by the documentation for
>    `--keep-redundant-commits` within `git-cherry-pick`:
> 
>    "If a commit being cherry picked duplicates a commit already in the
>    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."
> 
> This implication of `--allow-empty` therefore seems incorrect: One
> should be able to keep a commit that becomes empty without also being
> forced to pick commits that start as empty.

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.

> However, today, the
> following series of commands would result in both the commit that became
> empty and the commit that started empty being picked despite only
> `--keep-redundant-commits` being specified:
> 
>      git init
>      echo "a" >test
>      git add test
>      git commit -m "Initial commit"
>      echo "b" >test
>      git commit -am "a -> b"
>      git commit --allow-empty -m "empty"
>      git cherry-pick --keep-redundant-commits HEAD^ HEAD
> 
> The same cherry-pick with `--allow-empty` would fail on the redundant
> commit, and with neither option would fail on the empty commit.
> 
> In a future commit, an `--empty` option will be added to
> `git-cherry-pick`, meaning that `drop_redundant_commits` will be
> available in that command. For that to be possible with the current
> implementation of the sequencer's `allow_empty()`, `git-cherry-pick`
> would need to specify `allow_empty` with `drop_redundant_commits` as
> well, which is an even less intuitive implication of `--allow-empty`: in
> order to prevent redundant commits automatically, initially-empty
> commits would need to be kept automatically.
>
> Instead, this commit rewrites the `allow_empty()` logic to remove the
> over-arching requirement that `allow_empty` be specified in order to
> reach any of the keep/drop behaviors. Only if the commit was originally
> empty will `allow_empty` have an effect.

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().

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

> This is primarily out of caution -- I am not positive what downstream
> impacts this might have.
> 
> 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.

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

> This is the first in a series of commits that aims to introduce an
> `--empty` option to `git-cherry-pick` that provides the same flexibility
> as the `--empty` options for `git-rebase` and `git-am`, as well as
> improve the consistency in the values and documentation for this option
> across the three commands.

I think that is a good aim

> The main thing that may be controversial with this particular commit is
> that I am proposing a breaking change. As described in the above
> message, I do not think that it makes sense to tie `--allow-empty` and
> `--keep-redundant-commits` together since they appear to be intended to
> work with different types of empty commits. That being said, if it is
> deemed unacceptable to make this breaking change, we can consider an
> alternative approach where we maintain the behavior of
> `--keep-redundant-commits` implying `--allow-empty`, while preventing
> the need for the future `--empty=drop` to have that same implication.

As I said above I think it would be worth looking at what "git rebase" 
does to see if we can do the same thing for "git cherry-pick".

 > [...]> +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).

Best Wishes

Phillip

  parent reply	other threads:[~2024-01-23 14:23 UTC|newest]

Thread overview: 118+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19  5:59 [PATCH 1/4] sequencer: Do not require `allow_empty` for redundant commit options brianmlyles
2024-01-19  5:59 ` [PATCH 2/4] docs: Clean up `--empty` formatting in `git-rebase` and `git-am` brianmlyles
2024-01-23 14:24   ` Phillip Wood
2024-01-27 21:22     ` Brian Lyles
2024-02-01 14:02       ` Phillip Wood
2024-01-19  5:59 ` [PATCH 3/4] rebase: Update `--empty=ask` to `--empty=drop` brianmlyles
2024-01-23 14:24   ` Phillip Wood
2024-01-27 21:49     ` Brian Lyles
2024-02-01 14:02       ` Phillip Wood
2024-01-19  5:59 ` [PATCH 4/4] cherry-pick: Add `--empty` for more robust redundant commit handling brianmlyles
2024-01-20 20:24   ` Kristoffer Haugsbakk
2024-01-21 18:28     ` Brian Lyles
2024-01-21 22:05       ` Kristoffer Haugsbakk
2024-01-21 22:41       ` Junio C Hamano
2024-01-22 10:40       ` Phillip Wood
2024-01-22 20:55       ` Kristoffer Haugsbakk
2024-01-23  5:23         ` Brian Lyles
2024-01-23  7:11           ` Kristoffer Haugsbakk
2024-01-23 17:32           ` Junio C Hamano
2024-01-23 18:41             ` Subject: [PATCH] CoC: whitespace fix Junio C Hamano
2024-01-24  3:06               ` Elijah Newren
2024-01-23 18:49             ` [PATCH 4/4] cherry-pick: Add `--empty` for more robust redundant commit handling Junio C Hamano
2024-01-23 14:25   ` Phillip Wood
2024-01-23 18:01     ` Junio C Hamano
2024-01-28  0:07       ` Brian Lyles
2024-01-27 23:56     ` Brian Lyles
2024-01-20 21:38 ` [PATCH 1/4] sequencer: Do not require `allow_empty` for redundant commit options Kristoffer Haugsbakk
2024-01-21 18:19   ` Brian Lyles
2024-01-23 14:23 ` Phillip Wood [this message]
2024-01-23 18:18   ` Junio C Hamano
2024-01-24 11:01   ` Phillip Wood
2024-01-24 11:01 ` Phillip Wood
2024-01-27 23:30   ` Brian Lyles
2024-01-28 16:36     ` Brian Lyles
2024-01-29 10:55       ` Phillip Wood
2024-02-10  5:50         ` Brian Lyles
2024-02-01 10:57     ` Phillip Wood
2024-02-10  4:34       ` Brian Lyles
2024-02-10  7:43 ` [PATCH v2 0/8] cherry-pick: add `--empty` Brian Lyles
2024-02-22 16:39   ` phillip.wood123
2024-02-10  7:43 ` [PATCH v2 1/8] docs: address inaccurate `--empty` default with `--exec` Brian Lyles
2024-02-10  7:43 ` [PATCH v2 2/8] docs: clean up `--empty` formatting in git-rebase(1) and git-am(1) Brian Lyles
2024-02-10  7:43 ` [PATCH v2 3/8] rebase: update `--empty=ask` to `--empty=drop` Brian Lyles
2024-02-11  4:54   ` Brian Lyles
2024-02-14 11:05     ` Phillip Wood
2024-02-22 16:34   ` phillip.wood123
2024-02-22 18:27     ` Junio C Hamano
2024-02-10  7:43 ` [PATCH v2 4/8] sequencer: treat error reading HEAD as unborn branch Brian Lyles
2024-02-22 16:34   ` phillip.wood123
2024-02-23  5:28     ` Brian Lyles
2024-02-25 16:57       ` phillip.wood123
2024-02-10  7:43 ` [PATCH v2 5/8] sequencer: do not require `allow_empty` for redundant commit options Brian Lyles
2024-02-22 16:35   ` phillip.wood123
2024-02-10  7:43 ` [PATCH v2 6/8] cherry-pick: decouple `--allow-empty` and `--keep-redundant-commits` Brian Lyles
2024-02-22 16:35   ` Phillip Wood
2024-02-22 18:41     ` Junio C Hamano
2024-02-10  7:43 ` [PATCH v2 7/8] cherry-pick: enforce `--keep-redundant-commits` incompatibility Brian Lyles
2024-02-22 16:35   ` Phillip Wood
2024-02-23  6:23     ` Brian Lyles
2024-02-23 17:41       ` Junio C Hamano
2024-02-25 16:58       ` phillip.wood123
2024-02-26  3:04         ` Brian Lyles
2024-02-10  7:43 ` [PATCH v2 8/8] cherry-pick: add `--empty` for more robust redundant commit handling Brian Lyles
2024-02-11 20:50   ` Jean-Noël AVILA
2024-02-12  1:35     ` Brian Lyles
2024-02-22 16:36   ` phillip.wood123
2024-02-23  6:58     ` Brian Lyles
2024-02-25 16:57       ` phillip.wood123
2024-02-26  2:21         ` Brian Lyles
2024-02-26  3:32         ` Brian Lyles
2024-02-27 10:39           ` phillip.wood123
2024-02-27 17:33             ` Junio C Hamano
2024-03-10 18:41 ` [PATCH v3 0/7] " Brian Lyles
2024-03-13 16:12   ` phillip.wood123
2024-03-10 18:42 ` [PATCH v3 1/7] docs: address inaccurate `--empty` default with `--exec` Brian Lyles
2024-03-10 18:42 ` [PATCH v3 2/7] docs: clean up `--empty` formatting in git-rebase(1) and git-am(1) Brian Lyles
2024-03-10 18:42 ` [PATCH v3 3/7] rebase: update `--empty=ask` to `--empty=stop` Brian Lyles
2024-03-10 18:42 ` [PATCH v3 4/7] sequencer: treat error reading HEAD as unborn branch Brian Lyles
2024-03-11  0:07   ` Junio C Hamano
2024-03-11 16:54     ` Junio C Hamano
2024-03-12  2:04       ` Brian Lyles
2024-03-12 22:25         ` Junio C Hamano
2024-03-16  3:05           ` Brian Lyles
2024-03-13 15:10   ` phillip.wood123
2024-03-16  3:07     ` Brian Lyles
2024-03-10 18:42 ` [PATCH v3 5/7] sequencer: do not require `allow_empty` for redundant commit options Brian Lyles
2024-03-10 18:42 ` [PATCH v3 6/7] cherry-pick: enforce `--keep-redundant-commits` incompatibility Brian Lyles
2024-03-10 18:42 ` [PATCH v3 7/7] cherry-pick: add `--empty` for more robust redundant commit handling Brian Lyles
2024-03-13 16:10   ` phillip.wood123
2024-03-13 17:17     ` Junio C Hamano
2024-03-16  5:20       ` Brian Lyles
2024-03-20 19:35         ` phillip.wood123
2024-03-20 23:36 ` [PATCH v4 0/7] " Brian Lyles
2024-03-25 14:38   ` phillip.wood123
2024-03-25 16:12     ` Brian Lyles
2024-03-25 19:36       ` phillip.wood123
2024-03-25 20:57         ` Junio C Hamano
2024-03-20 23:36 ` [PATCH v4 1/7] docs: address inaccurate `--empty` default with `--exec` Brian Lyles
2024-03-20 23:36 ` [PATCH v4 2/7] docs: clean up `--empty` formatting in git-rebase(1) and git-am(1) Brian Lyles
2024-03-20 23:36 ` [PATCH v4 3/7] rebase: update `--empty=ask` to `--empty=stop` Brian Lyles
2024-03-20 23:36 ` [PATCH v4 4/7] sequencer: handle unborn branch with `--allow-empty` Brian Lyles
2024-03-21  9:52   ` Dirk Gouders
2024-03-21 16:22     ` Junio C Hamano
2024-03-21 19:45       ` Dirk Gouders
2024-03-20 23:37 ` [PATCH v4 5/7] sequencer: do not require `allow_empty` for redundant commit options Brian Lyles
2024-03-20 23:37 ` [PATCH v4 6/7] cherry-pick: enforce `--keep-redundant-commits` incompatibility Brian Lyles
2024-03-20 23:37 ` [PATCH v4 7/7] cherry-pick: add `--empty` for more robust redundant commit handling Brian Lyles
2024-03-25 23:16 ` [PATCH v5 0/7] " Brian Lyles
2024-03-26 14:45   ` phillip.wood123
2024-03-26 18:28     ` Junio C Hamano
2024-03-27 16:37       ` phillip.wood123
2024-03-25 23:16 ` [PATCH v5 1/7] docs: address inaccurate `--empty` default with `--exec` Brian Lyles
2024-03-25 23:16 ` [PATCH v5 2/7] docs: clean up `--empty` formatting in git-rebase(1) and git-am(1) Brian Lyles
2024-03-25 23:16 ` [PATCH v5 3/7] rebase: update `--empty=ask` to `--empty=stop` Brian Lyles
2024-03-25 23:16 ` [PATCH v5 4/7] sequencer: handle unborn branch with `--allow-empty` Brian Lyles
2024-03-25 23:16 ` [PATCH v5 5/7] sequencer: do not require `allow_empty` for redundant commit options Brian Lyles
2024-03-25 23:16 ` [PATCH v5 6/7] cherry-pick: enforce `--keep-redundant-commits` incompatibility Brian Lyles
2024-03-25 23:16 ` [PATCH v5 7/7] cherry-pick: add `--empty` for more robust redundant commit handling Brian Lyles

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7bf5036b-9f55-4451-a13c-8a2c815dfbb7@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=brianmlyles@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    --cc=newren@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.