git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "C.J. Jameson" <cjcjameson@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC PATCH] cherry-pick: set default `--mainline` parent to 1
Date: Wed, 20 Mar 2019 13:45:09 +0900	[thread overview]
Message-ID: <xmqq1s32w3vu.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <CALm+SVJR5BCHi_r7B279gKDukD4mYDQuv=K5guje73YDVmOxug@mail.gmail.com> (C. J. Jameson's message of "Tue, 19 Mar 2019 20:54:48 -0700")

"C.J. Jameson" <cjcjameson@gmail.com> writes:

> When cherry-picking from a standard merge commit, the parent should
> always be 1, as it has the meaningful new changes which were added to
> the mainline. If the source commit is unique in some way and a user
> wants to specify a value other than 1, they still can, but it's up to
> them to be aware of which parent is which.

I do not have a firm opinion for or against the "if the commit being
cherry-picked happens to be a merge, cherry-pick it relative to the
first parent by default, without requiring the '-m 1' option".  It
may not be such a bad idea after all.

But I do have a very strong opinion against adding yet another
option that takes an optional argument.  If we want to allow
cherry-picking a merge commit just as easy as cherrry-picking a
single-parent commit, "git cherry-pick -m merge" (assuming 'merge'
is the tip of a branch that is a merge commit) that still requires
the user to say "-m" is not a good improvement.  We should just
accept "git cherry-pick merge" without any "-m" if we want to move
in this direction, I would think.

> --m parent-number::
> ---mainline parent-number::
> +-m [parent-number]::
> +--mainline [parent-number]::
>   Usually you cannot cherry-pick a merge because you do not know which
>   side of the merge should be considered the mainline.  This
>   option specifies the parent number (starting from 1) of
>   the mainline and allows cherry-pick to replay the change
> - relative to the specified parent.
> + relative to the specified parent. The default parent-number is 1.

I somehow sense a total whitespace breakage.  Usually these lines
are HT indented, but I see only a single whitespace indent around
here.

So, the first part of the paragraph needs to get revamped.  It won't
be "because", but "unless", and with your change, you no longer know
which side is mainline---unless you tell Git otherwise, the first
parent is assumed to be the mainline in the new world order.

	-m <parent-number>::
	--mainline <parent-number>::
                When cherry-picking a merge, by default, the first
                parent is taken as the mainline, and the command
                replays the change relative to the first parent of
                the given commit.  If the merge commit you are
                cherry-picking records the mainline as second or
                later parent, you can use this option to replay
                the change relative to the specified parent (parents
                count from 1, which is the first parent).
	+
	The default parent-number is 1.  Giving a parent number
	larger than the number of parent the cherry-picked commit has
	is an error.

or something like that.

> diff --git a/builtin/revert.c b/builtin/revert.c
> index a47b53ceaf..280d1f00a9 100644
> --- a/builtin/revert.c
> +++ b/builtin/revert.c
> @@ -105,8 +105,8 @@ static int run_sequencer(int argc, const char
> **argv, struct replay_opts *opts)

Line-wrapped patch cannot be applied.

>   OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")),
>   OPT_NOOP_NOARG('r', NULL),
>   OPT_BOOL('s', "signoff", &opts->signoff, N_("add Signed-off-by:")),
> - OPT_CALLBACK('m', "mainline", opts, N_("parent-number"),
> -      N_("select mainline parent"), option_parse_m),
> + { OPTION_INTEGER, 'm', "mainline", &opts->mainline, N_("parent-number"),
> + N_("select mainline parent"), PARSE_OPT_OPTARG, NULL, 1 },

Let's not do optarg.  Use of OPT_INTEGER is fine, if you really want
to, but then you are losing the last caller of option_parse_m() and
the callback function itself must also be removed. 

You'd also need to do a few more things:

#1 make it NONEG, so that we reject "--no-mainline"; in the new
   world order, cherry-picking a non-merge commit is replaying
   against the first parent; there is no situation where use of
   --no-mainline makes sense (perhaps other than cherry-picking the
   initial commit, for which there is no mainline parent).

#2 initialize opts->mainline to 1, so that with no --mainline option
   from the command line, we will still get opt->mainline == 1
   (alternatively, you could initialize opt->mainline == -1 and
   treat opt->mainline <= 0 as if it were set to 1 when the code
   must choose against which parent to replay the changes in a much
   deeper place in the codepath).

#3 think about how you'd loosen option compatibility check around
   --mainline (if you do #2, as opt->mainline would never be 0 now)
   and adjust the verify_opt_compatible() call(s).

#4 as OPT_INTEGER won't ensure that you get a positive integer,
   you'd need to somehow reject --mainline=0 (or --mainline=-1 for
   that matter) given from the command line.

  reply	other threads:[~2019-03-20  4:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-20  3:54 [RFC PATCH] cherry-pick: set default `--mainline` parent to 1 C.J. Jameson
2019-03-20  4:45 ` Junio C Hamano [this message]
2019-03-20 12:01   ` Sergey Organov
2019-03-20 14:39     ` Elijah Newren
2019-03-20 15:59       ` Sergey Organov
2019-03-21  1:51         ` C.J. Jameson
2019-03-21  2:17       ` Junio C Hamano
2019-03-21  3:15         ` Junio C Hamano
2019-03-21  5:40           ` Sergey Organov
2019-03-21  5:47             ` Junio C Hamano
2019-03-21  6:12               ` Sergey Organov
2019-03-21  8:31                 ` Junio C Hamano
2019-03-21  8:31                 ` Junio C Hamano
2019-03-21 11:59                   ` Sergey Organov
2019-03-22  2:24                     ` Junio C Hamano
2019-03-22 15:22                       ` Sergey Organov
2019-03-22 18:27                         ` C.J. Jameson
2019-03-25 14:55                           ` Johannes Schindelin
2019-03-25 15:41                             ` C.J. Jameson
2019-03-21  6:54               ` Sergey Organov
2019-03-22 10:23         ` Johannes Schindelin
2019-03-22 10:13       ` Johannes Schindelin
2019-03-20  9:44 ` Duy Nguyen

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqq1s32w3vu.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=cjcjameson@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).