{"thread":{"id":"47054","subject":"[PATCH] cherry-pick: add --keep-existing-origin option","startedAt":"2017-10-28T12:05:03Z","lastAt":"2017-10-28T14:21:26Z","messageCount":2,"participants":["Anthony Wong","Kevin Daudt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"331218","messageId":"20171028120440.2022-1-yp@anthonywong.net","threadId":"47054","inReplyTo":null,"subject":"[PATCH] cherry-pick: add --keep-existing-origin option","fromName":"Anthony Wong","fromEmail":"anthony.wong@canonical.com","sentAt":"2017-10-28T12:04:40Z","receivedAt":"2017-10-28T12:05:03Z","isPatch":true,"sender":{"key":"anthony.wong@canonical.com","avatar":null},"body":"When cherry-picking from a commit whose commit message already\ncontains the \"(cherry picked from commit ...)\" line, this option will\nnot add another one. This is useful when you are cherry-picking from a\nbunch of commits, some are cherry-picks and already contains the\nupstream hash but some do not. Use with -x.\n\nSigned-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\ndiff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt\nindex d35d771fc..7a074511f 100644\n--- a/Documentation/git-cherry-pick.txt\n+++ b/Documentation/git-cherry-pick.txt\n@@ -71,6 +71,14 @@ OPTIONS\n \tdevelopment branch), adding this information can be\n \tuseful.\n \n+--keep-existing-origin::\n+\tThis option has to be used with -x to take effect. When\n+\tcherry-picking from a commit whose commit message already\n+\tcontains the \"(cherry picked from commit ...)\" line, this\n+\toption will not add another one. This is useful when you are\n+\tcherry-picking from a bunch of commits, some are cherry-picks\n+\tand already contains the upstream hash but some do not.\n+\n -r::\n \tIt used to be that the command defaulted to do `-x`\n \tdescribed above, and `-r` was to disable it.  Now the\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 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 \t\t\tOPT_BOOL(0, \"allow-empty\", &opts->allow_empty, N_(\"preserve initially empty commits\")),\n \t\t\tOPT_BOOL(0, \"allow-empty-message\", &opts->allow_empty_message, N_(\"allow commits with empty messages\")),\n \t\t\tOPT_BOOL(0, \"keep-redundant-commits\", &opts->keep_redundant_commits, N_(\"keep redundant, empty commits\")),\n+\t\t\tOPT_BOOL(0, \"keep-existing-origin\", &opts->keep_existing_origin, N_(\"do not add another hash if one already exists, use with -x\")),\n \t\t\tOPT_END(),\n \t\t};\n \t\toptions = 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 \t\t\t\t\"--ff\", opts->allow_ff,\n \t\t\t\t\"--rerere-autoupdate\", opts->allow_rerere_auto == RERERE_AUTOUPDATE,\n \t\t\t\t\"--no-rerere-autoupdate\", opts->allow_rerere_auto == RERERE_NOAUTOUPDATE,\n+\t\t\t\t\"--keep-existing-origin\", opts->keep_existing_origin,\n \t\t\t\tNULL);\n \t}\n \ndiff --git a/sequencer.c b/sequencer.c\nindex 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 \t\t\tstrbuf_addstr(&msgbuf, p);\n \n \t\tif (opts->record_origin) {\n-\t\t\tstrbuf_complete_line(&msgbuf);\n-\t\t\tif (!has_conforming_footer(&msgbuf, NULL, 0))\n-\t\t\t\tstrbuf_addch(&msgbuf, '\\n');\n-\t\t\tstrbuf_addstr(&msgbuf, cherry_picked_prefix);\n-\t\t\tstrbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));\n-\t\t\tstrbuf_addstr(&msgbuf, \")\\n\");\n+\t\t\tif (!opts->keep_existing_origin || strstr(msgbuf.buf, cherry_picked_prefix) == NULL) {\n+\t\t\t\tstrbuf_complete_line(&msgbuf);\n+\t\t\t\tif (!has_conforming_footer(&msgbuf, NULL, 0))\n+\t\t\t\t\tstrbuf_addch(&msgbuf, '\\n');\n+\t\t\t\tstrbuf_addstr(&msgbuf, cherry_picked_prefix);\n+\t\t\t\tstrbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));\n+\t\t\t\tstrbuf_addstr(&msgbuf, \")\\n\");\n+\t\t\t}\n \t\t}\n \t}\n \ndiff --git a/sequencer.h b/sequencer.h\nindex 6f3d3df82..a907c0947 100644\n--- a/sequencer.h\n+++ b/sequencer.h\n@@ -24,6 +24,7 @@ struct replay_opts {\n \tint allow_empty;\n \tint allow_empty_message;\n \tint keep_redundant_commits;\n+\tint keep_existing_origin;\n \tint verbose;\n \n \tint mainline;\n-- \n2.14.1\n\n"},{"id":"331220","messageId":"20171028142120.GA12833@alpha.vpn.ikke.info","threadId":"47054","inReplyTo":"20171028120440.2022-1-yp@anthonywong.net","subject":"Re: [PATCH] cherry-pick: add --keep-existing-origin option","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2017-10-28T14:21:20Z","receivedAt":"2017-10-28T14:21:26Z","isPatch":true,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"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>  \tdevelopment branch), adding this information can be\n>  \tuseful.\n>  \n> +--keep-existing-origin::\n> +\tThis option has to be used with -x to take effect. When\n> +\tcherry-picking from a commit whose commit message already\n> +\tcontains the \"(cherry picked from commit ...)\" line, this\n> +\toption will not add another one. This is useful when you are\n> +\tcherry-picking from a bunch of commits, some are cherry-picks\n> +\tand already contains the upstream hash but some do not.\n> +\n>  -r::\n>  \tIt used to be that the command defaulted to do `-x`\n>  \tdescribed 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>  \t\t\tOPT_BOOL(0, \"allow-empty\", &opts->allow_empty, N_(\"preserve initially empty commits\")),\n>  \t\t\tOPT_BOOL(0, \"allow-empty-message\", &opts->allow_empty_message, N_(\"allow commits with empty messages\")),\n>  \t\t\tOPT_BOOL(0, \"keep-redundant-commits\", &opts->keep_redundant_commits, N_(\"keep redundant, empty commits\")),\n> +\t\t\tOPT_BOOL(0, \"keep-existing-origin\", &opts->keep_existing_origin, N_(\"do not add another hash if one already exists, use with -x\")),\n>  \t\t\tOPT_END(),\n>  \t\t};\n>  \t\toptions = 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>  \t\t\t\t\"--ff\", opts->allow_ff,\n>  \t\t\t\t\"--rerere-autoupdate\", opts->allow_rerere_auto == RERERE_AUTOUPDATE,\n>  \t\t\t\t\"--no-rerere-autoupdate\", opts->allow_rerere_auto == RERERE_NOAUTOUPDATE,\n> +\t\t\t\t\"--keep-existing-origin\", opts->keep_existing_origin,\n>  \t\t\t\tNULL);\n>  \t}\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>  \t\t\tstrbuf_addstr(&msgbuf, p);\n>  \n>  \t\tif (opts->record_origin) {\n> -\t\t\tstrbuf_complete_line(&msgbuf);\n> -\t\t\tif (!has_conforming_footer(&msgbuf, NULL, 0))\n> -\t\t\t\tstrbuf_addch(&msgbuf, '\\n');\n> -\t\t\tstrbuf_addstr(&msgbuf, cherry_picked_prefix);\n> -\t\t\tstrbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));\n> -\t\t\tstrbuf_addstr(&msgbuf, \")\\n\");\n> +\t\t\tif (!opts->keep_existing_origin || strstr(msgbuf.buf, cherry_picked_prefix) == NULL) {\n> +\t\t\t\tstrbuf_complete_line(&msgbuf);\n> +\t\t\t\tif (!has_conforming_footer(&msgbuf, NULL, 0))\n> +\t\t\t\t\tstrbuf_addch(&msgbuf, '\\n');\n> +\t\t\t\tstrbuf_addstr(&msgbuf, cherry_picked_prefix);\n> +\t\t\t\tstrbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));\n> +\t\t\t\tstrbuf_addstr(&msgbuf, \")\\n\");\n> +\t\t\t}\n>  \t\t}\n>  \t}\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>  \tint allow_empty;\n>  \tint allow_empty_message;\n>  \tint keep_redundant_commits;\n> +\tint keep_existing_origin;\n>  \tint verbose;\n>  \n>  \tint mainline;\n> -- \n> 2.14.1\n> \n\nI'm wondering if it isn't better to detect that there is already an\norigin present and not add another one. \n\nOr are there situations where you do want multiple cherry-pick origins?\n\nKevin\n"}]}