{"thread":{"id":"47056","subject":"Re: [PATCH] cherry-pick: add --keep-existing-origin option","startedAt":"2017-10-28T15:45:57Z","lastAt":"2017-10-28T15:45:57Z","messageCount":1,"participants":["Anthony Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"331223","messageId":"CAC=0FnGyYzOReS4-ZA8E99DHpgnn9waFm6-fc=D8_QghSQQ_cQ@mail.gmail.com","threadId":"47056","inReplyTo":null,"subject":"Re: [PATCH] cherry-pick: add --keep-existing-origin option","fromName":"Anthony Wong","fromEmail":"yp@anthonywong.net","sentAt":"2017-10-28T15:45:03Z","receivedAt":"2017-10-28T15:45:57Z","isPatch":true,"sender":{"key":"yp@anthonywong.net","avatar":null},"body":"On 28 October 2017 at 22:21, Kevin Daudt <me@ikke.info> wrote:\n>\n> On Sat, Oct 28, 2017 at 08:04:40PM +0800, Anthony Wong wrote:\n> > When cherry-picking from a commit whose commit message already\n> > contains the \"(cherry picked from commit ...)\" line, this option will\n> > not add another one. This is useful when you are cherry-picking from a\n> > bunch of commits, some are cherry-picks and already contains the\n> > upstream hash but some do not. Use with -x.\n> >\n> > Signed-off-by: Anthony Wong <yp@anthonywong.net>\n> > ---\n> >  Documentation/git-cherry-pick.txt |  8 ++++++++\n> >  builtin/revert.c                  |  2 ++\n> >  sequencer.c                       | 14 ++++++++------\n> >  sequencer.h                       |  1 +\n> >  4 files changed, 19 insertions(+), 6 deletions(-)\n> >\n> > diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt\n> > index d35d771fc..7a074511f 100644\n> > --- a/Documentation/git-cherry-pick.txt\n> > +++ b/Documentation/git-cherry-pick.txt\n> > @@ -71,6 +71,14 @@ OPTIONS\n> >       development branch), adding this information can be\n> >       useful.\n> >\n> > +--keep-existing-origin::\n> > +     This option has to be used with -x to take effect. When\n> > +     cherry-picking from a commit whose commit message already\n> > +     contains the \"(cherry picked from commit ...)\" line, this\n> > +     option will not add another one. This is useful when you are\n> > +     cherry-picking from a bunch of commits, some are cherry-picks\n> > +     and already contains the upstream hash but some do not.\n> > +\n> >  -r::\n> >       It used to be that the command defaulted to do `-x`\n> >       described above, and `-r` was to disable it.  Now the\n> > diff --git a/builtin/revert.c b/builtin/revert.c\n> > index b9d927eb0..a1900cc1d 100644\n> > --- a/builtin/revert.c\n> > +++ b/builtin/revert.c\n> > @@ -122,6 +122,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)\n> >                       OPT_BOOL(0, \"allow-empty\", &opts->allow_empty, N_(\"preserve initially empty commits\")),\n> >                       OPT_BOOL(0, \"allow-empty-message\", &opts->allow_empty_message, N_(\"allow commits with empty messages\")),\n> >                       OPT_BOOL(0, \"keep-redundant-commits\", &opts->keep_redundant_commits, N_(\"keep redundant, empty commits\")),\n> > +                     OPT_BOOL(0, \"keep-existing-origin\", &opts->keep_existing_origin, N_(\"do not add another hash if one already exists, use with -x\")),\n> >                       OPT_END(),\n> >               };\n> >               options = parse_options_concat(options, cp_extra);\n> > @@ -157,6 +158,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)\n> >                               \"--ff\", opts->allow_ff,\n> >                               \"--rerere-autoupdate\", opts->allow_rerere_auto == RERERE_AUTOUPDATE,\n> >                               \"--no-rerere-autoupdate\", opts->allow_rerere_auto == RERERE_NOAUTOUPDATE,\n> > +                             \"--keep-existing-origin\", opts->keep_existing_origin,\n> >                               NULL);\n> >       }\n> >\n> > diff --git a/sequencer.c b/sequencer.c\n> > index f2a10cc4f..c96add16e 100644\n> > --- a/sequencer.c\n> > +++ b/sequencer.c\n> > @@ -1050,12 +1050,14 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n> >                       strbuf_addstr(&msgbuf, p);\n> >\n> >               if (opts->record_origin) {\n> > -                     strbuf_complete_line(&msgbuf);\n> > -                     if (!has_conforming_footer(&msgbuf, NULL, 0))\n> > -                             strbuf_addch(&msgbuf, '\\n');\n> > -                     strbuf_addstr(&msgbuf, cherry_picked_prefix);\n> > -                     strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));\n> > -                     strbuf_addstr(&msgbuf, \")\\n\");\n> > +                     if (!opts->keep_existing_origin || strstr(msgbuf.buf, cherry_picked_prefix) == NULL) {\n> > +                             strbuf_complete_line(&msgbuf);\n> > +                             if (!has_conforming_footer(&msgbuf, NULL, 0))\n> > +                                     strbuf_addch(&msgbuf, '\\n');\n> > +                             strbuf_addstr(&msgbuf, cherry_picked_prefix);\n> > +                             strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));\n> > +                             strbuf_addstr(&msgbuf, \")\\n\");\n> > +                     }\n> >               }\n> >       }\n> >\n> > diff --git a/sequencer.h b/sequencer.h\n> > index 6f3d3df82..a907c0947 100644\n> > --- a/sequencer.h\n> > +++ b/sequencer.h\n> > @@ -24,6 +24,7 @@ struct replay_opts {\n> >       int allow_empty;\n> >       int allow_empty_message;\n> >       int keep_redundant_commits;\n> > +     int keep_existing_origin;\n> >       int verbose;\n> >\n> >       int mainline;\n> > --\n> > 2.14.1\n> >\n>\n> I'm wondering if it isn't better to detect that there is already an\n> origin present and not add another one.\n>\n> Or are there situations where you do want multiple cherry-pick origins?\n\nI don't. But because that's how git behaves now, I don't know if\nanyone is relying on that behaviour so I am reluctant to change that.\n\nThanks,\nAnthony\n\n>\n> Kevin\n"}]}