Re: [PATCH v4 5/9] rebase: add coverage of other incompatible options
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Jan 24, 2023, 16:48 UTC
- Message-ID
- <0418e5b6-8cbd-9dc9-085e-31380beda89b@dunelm.org.uk>
- In-Reply-To
- <CABPp-BHVUc7EdY9z_TPcHspCak6Yc3mfDXUkivj4zq_fJem3SQ@mail.gmail.com>
Hi Elijah
On 24/01/2023 15:41, Elijah Newren wrote:
Show 65 quoted lines
> Ah, despite looking over the code multiple times to check my
> statements, I somehow kept missing this:
>
> if (keep_base && options.reapply_cherry_picks)
> options.upstream = options.onto;
>
> which is how --[no-]reapply-cherry-picks is supported in conjunction
> with --keep-base. Thanks.
>
>>>> For all four cases (A)-(D), the apply backend will ignore whatever
>>>> --[no-]reapply-cherry-picks flag is provided.
>>>
>>> For (D) the flag is respected, (C) errors out, the other cases
>>> correspond to the default so it's like saying
>>>
>>> git rebase --merge --no-reapply-cherry-picks
>>>
>>> ignores the flag.
>>
>> On reflection that is only true for (B). I agree that we should error
>> out on (A) which we don't at the moment.
>>
>> I'd support a change that errors out on (A) and (C) but continues to
>> allow (B) and (D). I think we can do that with the diff below
>>
>>
>> diff --git a/builtin/rebase.c b/builtin/rebase.c
>> index 1481c5b6a5..66aef356b8 100644
>> --- a/builtin/rebase.c
>> +++ b/builtin/rebase.c
>> @@ -1230,12 +1230,6 @@ int cmd_rebase(int argc, const char **argv, const
>> char *prefix)
>> if (options.fork_point < 0)
>> options.fork_point = 0;
>> }
>> - /*
>> - * --keep-base defaults to --reapply-cherry-picks to avoid losing
>> - * commits when using this option.
>> - */
>> - if (options.reapply_cherry_picks < 0)
>> - options.reapply_cherry_picks = keep_base;
>>
>> if (options.root && options.fork_point > 0)
>> die(_("options '%s' and '%s' cannot be used
>> together"), "--root", "--fork-point");
>> @@ -1412,11 +1406,17 @@ int cmd_rebase(int argc, const char **argv,
>> const char *prefix)
>> if (options.empty != EMPTY_UNSPECIFIED)
>> imply_merge(&options, "--empty");
>>
>> - /*
>> - * --keep-base implements --reapply-cherry-picks by altering
>> upstream so
>> - * it works with both backends.
>> - */
>> - if (options.reapply_cherry_picks && !keep_base)
>> + if (options.reapply_cherry_picks < 0)
>> + /*
>> + * --keep-base defaults to --reapply-cherry-picks to
>> + * avoid losing commits when using this option.
>> + */
>
> I know you were copying the previous comment, but this comment is
> really confusing to me. Shouldn't it read "--reapply-cherry-picks
> defaults to --keep-base" instead of vice-versa?Clearly this comment has not been as helpful as I indented it to be. I think maybe we should spell out the defaults with and without --keep-base. Perhaps something like
default to --no-reapply-cherry-picks unless --keep-base is given in which case default to --reapply-cherry-picks
Show 7 quoted lines
>> + options.reapply_cherry_picks = keep_base; >> + else if (!keep_base) >> + /* >> + * --keep-base implements --reapply-cherry-picks by > > Should this be --[no-]reapply-cherry-picks, to clarify that it handles > both cases? Especially given how many times I missed it?
This has obviously proved to be confusing. The aim was to explain that in order to work with the apply backend "[--reapply-cherry-picks] --keep-base" was doing something unusual with `upstream` to reapply cherry picks. "--no-reapply-cherry-picks --keep-base" does not do anything unusual with `upstream`. I don't think changing it to --[no-]reapply-cherry-picks quite captures that. I came up with
To support --reapply-cherry-picks (which is not supported by the apply backend) --keep-base alters upstream to prevent cherry picked commits from being dropped.
but it really needs to mention that --keep-base also supports --no-reapply-cherry-picks in the usual way
Show 9 quoted lines
>> + * altering upstream so it works with both backends. >> + */ >> imply_merge(&options, "--reapply-cherry-picks"); > > And perhaps this should be > > imply_merge(&options, options.reapply_cherry_picks ? > "--reapply-cherry-picks" : > "--no-reapply-cherry-picks");
That's a good idea
> Also, the comment in git-rebase.txt about incompatibilities would become > > * --[no-]reapply-cherry-picks, when --keep-base is not provided
Yes, that's good
Thanks again for working on this
Phillip