{"thread":{"id":"24084","subject":"[PATCH] cherry-pick: Add an option to prepend a string to the commit message","startedAt":"2010-06-12T05:07:17Z","lastAt":"2010-06-14T18:03:54Z","messageCount":9,"participants":["Bobby Powers","Jonathan Nieder","Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"143548","messageId":"1276319237-12010-1-git-send-email-bobbypowers@gmail.com","threadId":"24084","inReplyTo":null,"subject":"[PATCH] cherry-pick: Add an option to prepend a string to the commit message","fromName":"Bobby Powers","fromEmail":"bobbypowers@gmail.com","sentAt":"2010-06-12T05:07:17Z","receivedAt":"2010-06-12T05:07:17Z","isPatch":true,"sender":{"key":"bobbypowers@gmail.com","avatar":"https://avatars.githubusercontent.com/u/854918?v=4"},"body":"This can be useful situations where you have a batch of commits to\ncherry-pick and need to prefix each new commit message with similar\ninformation (such as the subversion revision, when used in conjunction\nwith git-svn).\n\nSigned-off-by: Bobby Powers <bobbypowers@gmail.com>\n---\n Documentation/git-cherry-pick.txt |    7 +++++++\n builtin/revert.c                  |    8 +++++++-\n 2 files changed, 14 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt\nindex d71607a..2526e13 100644\n--- a/Documentation/git-cherry-pick.txt\n+++ b/Documentation/git-cherry-pick.txt\n@@ -62,6 +62,13 @@ OPTIONS\n \toption is used, your index does not have to match the\n \tHEAD commit.  The cherry-pick is done against the\n \tbeginning state of your index.\n+\n+--prepend::\n+\tSpecify a string to prepend to the commit message.  This\n+\tcan be useful situations where you have a batch of commits\n+\tto cherry-pick and need to prefix each new commit message\n+\twith similar information (such as the subversion revision,\n+\twhen used in conjunction with git-svn).\n +\n This is useful when cherry-picking more than one commits'\n effect to your index in a row.\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 7976b5a..45091ac 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -44,6 +44,7 @@ static int allow_rerere_auto;\n \n static const char *me;\n static const char *strategy;\n+static const char *prepend;\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n \n@@ -64,7 +65,7 @@ static void parse_args(int argc, const char **argv)\n \t\tOPT_INTEGER('m', \"mainline\", &mainline, \"parent number\"),\n \t\tOPT_RERERE_AUTOUPDATE(&allow_rerere_auto),\n \t\tOPT_STRING(0, \"strategy\", &strategy, \"strategy\", \"merge strategy\"),\n-\t\tOPT_END(),\n+\t\tOPT_STRING(0, \"prepend\", &prepend, \"message\", \"string to prepend to the commit message\"),\n \t\tOPT_END(),\n \t\tOPT_END(),\n \t};\n@@ -392,6 +393,8 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \t\t\tdie(\"cherry-pick --ff cannot be used with -x\");\n \t\tif (edit)\n \t\t\tdie(\"cherry-pick --ff cannot be used with --edit\");\n+\t\tif (prepend)\n+\t\t\tdie(\"cherry-pick --ff cannot be used with --prepend\");\n \t}\n \n \tif (read_cache() < 0)\n@@ -482,6 +485,9 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \t\tnext = commit;\n \t\tnext_label = msg.label;\n \t\tset_author_ident_env(msg.message);\n+\t\tif (prepend) {\n+\t\t\tstrbuf_addstr(&msgbuf, prepend);\n+\t\t}\n \t\tadd_message_to_msg(&msgbuf, msg.message);\n \t\tif (no_replay) {\n \t\t\tstrbuf_addstr(&msgbuf, \"(cherry picked from commit \");\n-- \n1.7.1.251.g92a7.dirty\n"},{"id":"143549","messageId":"20100612055831.GA2426@burratino","threadId":"24084","inReplyTo":"1276319237-12010-1-git-send-email-bobbypowers@gmail.com","subject":"Re: [PATCH] cherry-pick: Add an option to prepend a string to the commit message","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-06-12T05:58:32Z","receivedAt":"2010-06-12T05:58:32Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Bobby Powers wrote:\n\n> This can be useful situations where you have a batch of commits to\n> cherry-pick and need to prefix each new commit message with similar\n> information\n\nSounds reasonable.\n\nCc-ing Christian who is closer to an area expert.\n\n> (such as the subversion revision, when used in conjunction\n> with git-svn).\n\nCould you give an example?  I am imagining\n\n  git cherry-pick --prepend='r3815: ' HEAD..svn/Trunk\n\nbut I haven’t figured out the context.\n\nThe patch itself is clean.  Two tiny nitpicks:\n\n> --- a/builtin/revert.c\n> +++ b/builtin/revert.c\n> @@ -64,7 +65,7 @@ static void parse_args(int argc, const char **argv)\n>  \t\tOPT_INTEGER('m', \"mainline\", &mainline, \"parent number\"),\n>  \t\tOPT_RERERE_AUTOUPDATE(&allow_rerere_auto),\n>  \t\tOPT_STRING(0, \"strategy\", &strategy, \"strategy\", \"merge strategy\"),\n> -\t\tOPT_END(),\n> +\t\tOPT_STRING(0, \"prepend\", &prepend, \"message\", \"string to prepend to the commit message\"),\n>  \t\tOPT_END(),\n>  \t\tOPT_END(),\n>  \t};\n\nThis adds an option to cherry-pick and revert...\n\n[...]\n> @@ -482,6 +485,9 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n>  \t\tnext = commit;\n>  \t\tnext_label = msg.label;\n>  \t\tset_author_ident_env(msg.message);\n> +\t\tif (prepend) {\n> +\t\t\tstrbuf_addstr(&msgbuf, prepend);\n> +\t\t}\n>  \t\tadd_message_to_msg(&msgbuf, msg.message);\n>  \t\tif (no_replay) {\n>  \t\t\tstrbuf_addstr(&msgbuf, \"(cherry picked from commit \");\n\n... and implements it only for cherry-pick (with unnecessary braces).\n\nI would be interested to hear from those who might know whether\nsomething generic like the applypatch-msg hook could work (which is\nnot to say a convenient command-line option would not be handy to have\nin addition to that.)\n\nJonathan\n"},{"id":"143550","messageId":"7vsk4sg4du.fsf@alter.siamese.dyndns.org","threadId":"24084","inReplyTo":"20100612055831.GA2426@burratino","subject":"Re: [PATCH] cherry-pick: Add an option to prepend a string to the commit message","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-12T06:18:53Z","receivedAt":"2010-06-12T06:18:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> Bobby Powers wrote:\n>\n>> This can be useful situations where you have a batch of commits to\n>> cherry-pick and need to prefix each new commit message with similar\n>> information\n>\n> Sounds reasonable.\n\nIt might be \"usable in some limited context\", but does not sound\n\"reasonable\" at all, sorry.\n\nEspecially since we will be getting \"replay more than one commits in\nsequence\", I would say it would make more sense to allow this kind of\nper-invocation (iow, command line option) commit transmonger a bit more\nflexibility, e.g. being a filter, or even a script that takes the original\ncommit object name (so that it can consult git-vs-svn mapping in it if it\nwants to, for example).\n"},{"id":"143552","messageId":"20100612062812.GA12685@coredump.intra.peff.net","threadId":"24084","inReplyTo":"20100612055831.GA2426@burratino","subject":"Re: [PATCH] cherry-pick: Add an option to prepend a string to the commit message","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-06-12T06:28:12Z","receivedAt":"2010-06-12T06:28:12Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jun 12, 2010 at 12:58:32AM -0500, Jonathan Nieder wrote:\n\n> I would be interested to hear from those who might know whether\n> something generic like the applypatch-msg hook could work (which is\n> not to say a convenient command-line option would not be handy to have\n> in addition to that.)\n\nWhat bothers me is how specific this munging is. What if I want to\nappend to the message? Or put something after the subject line, but\nbefore the commit body? Or add a pseudo-header (like signed-off-by) to\nthe set of pseudo-headers at the end, properly adding a newline if it is\nthe first such pseudo-header.\n\nFWIW, we can already do this kind of stuff with:\n\n  GIT_EDITOR=\"sed -i 1i$prefix\" git cherry-pick -e $ref\n\nor\n\n  git cherry-pick -n $ref &&\n  sed -i 1i$prefix .git/MERGE_MSG\n  GIT_EDITOR=true git commit\n\nI'll admit the first one is not very intuitive. But it is easy to script\naround the second form. For one of my examples, I would probably do:\n\n  git cherry-pick -n $ref &&\n  git log -1 --format='%s%n%ncontent between subject and body%n%b' |\n  git commit -F -\n\nThe specifics aren't important, but I think you can see that the \"don't\ncommit automatically, make a message as you like, and then use the\nregular message-specifiers for commit to commit it\" technique is pretty\nstraightforward and very flexible.\n\nIt's obviously more typing for occasional interactive use, but in that\ncase, why not just use \"git cherry-pick -e\" and use your editor?\n\n-Peff\n"},{"id":"143553","messageId":"4C132C7E.5090606@gmail.com","threadId":"24084","inReplyTo":"20100612062812.GA12685@coredump.intra.peff.net","subject":"Re: [PATCH] cherry-pick: Add an option to prepend a string to the commit message","fromName":"Bobby Powers","fromEmail":"bobbypowers@gmail.com","sentAt":"2010-06-12T06:43:10Z","receivedAt":"2010-06-12T06:43:10Z","isPatch":true,"sender":{"key":"bobbypowers@gmail.com","avatar":"https://avatars.githubusercontent.com/u/854918?v=4"},"body":"On 06/11/2010 11:28 PM, Jeff King wrote:\n> On Sat, Jun 12, 2010 at 12:58:32AM -0500, Jonathan Nieder wrote:\n>\n>> I would be interested to hear from those who might know whether\n>> something generic like the applypatch-msg hook could work (which is\n>> not to say a convenient command-line option would not be handy to have\n>> in addition to that.)\n>\n> What bothers me is how specific this munging is. What if I want to\n> append to the message? Or put something after the subject line, but\n> before the commit body? Or add a pseudo-header (like signed-off-by) to\n> the set of pseudo-headers at the end, properly adding a newline if it is\n> the first such pseudo-header.\n\nWhat prompted this was a large project I had checked out through \ngit-svn.  I had made a number of commits to trunk, interspersed with \nother dev's work.  I needed to cherry-pick my work into a stable branch, \nbut each commit needed to start with 'cherry-pick rXXX:', where XXX was \nthe subversion commit number.\n\nMy solution was the following:\n\n$ git checkout $RELEASE_BRANCH\n$ export WHAT=\"my-subsystem:\"\n$ export SINCE=\"Jun 1 2010\"\n$ for i in `git log --grep=\"$WHAT\" --oneline master --after=\"$SINCE\" \\\n             | cut -d ' ' -f 1 | tac`;                                \\\n       do git cherry-pick $i -x                                       \\\n              --prepend \"cherry pick r$(echo $(git log -1 $i) | perl  \\\n                                   -pe 's|.*/trunk@(\\d+).*|\\1|'): \";  \\\n   done\n\nbut, as you point out, I could have accomplished the same thing through \nother means.\n\n> FWIW, we can already do this kind of stuff with:\n>\n>    GIT_EDITOR=\"sed -i 1i$prefix\" git cherry-pick -e $ref\n>\n> or\n>\n>    git cherry-pick -n $ref&&\n>    sed -i 1i$prefix .git/MERGE_MSG\n>    GIT_EDITOR=true git commit\n>\n> I'll admit the first one is not very intuitive. But it is easy to script\n> around the second form. For one of my examples, I would probably do:\n>\n>    git cherry-pick -n $ref&&\n>    git log -1 --format='%s%n%ncontent between subject and body%n%b' |\n>    git commit -F -\n\nI like this; it clearly hadn't occurred to me.  I can just use this \nformat instead.\n\nyours,\nBobby\n\n> The specifics aren't important, but I think you can see that the \"don't\n> commit automatically, make a message as you like, and then use the\n> regular message-specifiers for commit to commit it\" technique is pretty\n> straightforward and very flexible.\n>\n> It's obviously more typing for occasional interactive use, but in that\n> case, why not just use \"git cherry-pick -e\" and use your editor?\n>\n> -Peff\n"},{"id":"143555","messageId":"20100612071850.GA2765@burratino","threadId":"24084","inReplyTo":"4C132C7E.5090606@gmail.com","subject":"Re: [PATCH] cherry-pick: Add an option to prepend a string to the commit message","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-06-12T07:18:50Z","receivedAt":"2010-06-12T07:18:50Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Bobby Powers wrote:\n> On 06/11/2010 11:28 PM, Jeff King wrote:\n\n>> FWIW, we can already do this kind of stuff with:\n>>\n>>   GIT_EDITOR=\"sed -i 1i$prefix\" git cherry-pick -e $ref\n>>\n>> or\n>>\n>>   git cherry-pick -n $ref&&\n>>   sed -i 1i$prefix .git/MERGE_MSG\n>>   GIT_EDITOR=true git commit\n>>\n>> I'll admit the first one is not very intuitive. But it is easy to script\n>> around the second form. For one of my examples, I would probably do:\n>>\n>>   git cherry-pick -n $ref&&\n>>   git log -1 --format='%s%n%ncontent between subject and body%n%b' |\n>>   git commit -F -\n>\n> I like this; it clearly hadn't occurred to me.  I can just use this\n> format instead.\n\nSorry to misunderstand.  Maybe something like this could help.  Patch\napplies on top of cc/cherry-pick-series.\n\n-- %< --\nSubject: Documentation: explain use of cherry-pick -n in scripts\n\nAdd an example to indicate how to munge a commit while cherry-picking it.\n\nThe formatting is ugly because I do not know how to ask asciidoc to\nuse a multiline heading in a definition list.\n\nBased-on-work-by: Jeff King <peff@peff.net>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\ndiff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt\nindex bcb4c75..4769ca5 100644\n--- a/Documentation/git-cherry-pick.txt\n+++ b/Documentation/git-cherry-pick.txt\n@@ -113,6 +113,17 @@ git cherry-pick --ff ..next::\n \tare in next but not HEAD to the current branch, creating a new\n \tcommit for each new change.\n \n+------------\n+git checkout maint &&\n+git cherry-pick -n bugfix &&\n+git add new_file.txt &&\n+git show -s bugfix --format='%s%n%n%b%n%nAlso add a new file.' |\n+git commit -F -\n+------------\n+\n+\tApply a bugfix on top of the maint branch and tweak it before\n+\tcreating a new commit to record it.\n+\n Author\n ------\n Written by Junio C Hamano <gitster@pobox.com>\n-- \n"},{"id":"143558","messageId":"20100612081925.GA19525@coredump.intra.peff.net","threadId":"24084","inReplyTo":"20100612071850.GA2765@burratino","subject":"Re: [PATCH] cherry-pick: Add an option to prepend a string to the commit message","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-06-12T08:19:25Z","receivedAt":"2010-06-12T08:19:25Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jun 12, 2010 at 02:18:50AM -0500, Jonathan Nieder wrote:\n\n> Subject: Documentation: explain use of cherry-pick -n in scripts\n> \n> Add an example to indicate how to munge a commit while cherry-picking it.\n> \n> The formatting is ugly because I do not know how to ask asciidoc to\n> use a multiline heading in a definition list.\n\nI don't think there is a way to do what you want. Even an explicit \" +\"\nat the end of line, which is supposed to cause a line-break, doesn't\nseem to work.\n\nHowever, I wonder if all of the examples should actually be in \"----\"\nlisting blocks. That would generally render them in a monospaced\ntypewriter font (though in the manpage, it doesn't matter much), and\nyour multiline addition would be rendered properly, too.\n\n> +------------\n> +git checkout maint &&\n> +git cherry-pick -n bugfix &&\n> +git add new_file.txt &&\n> +git show -s bugfix --format='%s%n%n%b%n%nAlso add a new file.' |\n> +git commit -F -\n> +------------\n\nYou can use the much shorter \"%B\" instead of \"%s%n%n%b\" these days, and\nas a bonus, it will use the right number of newlines for a subject-only\ncommit.\n\n-Peff\n"},{"id":"143633","messageId":"7v7hm2ch55.fsf@alter.siamese.dyndns.org","threadId":"24084","inReplyTo":"20100612081925.GA19525@coredump.intra.peff.net","subject":"Re: [PATCH] cherry-pick: Add an option to prepend a string to the commit message","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-14T05:33:42Z","receivedAt":"2010-06-14T05:33:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> You can use the much shorter \"%B\" instead of \"%s%n%n%b\" these days, and\n> as a bonus, it will use the right number of newlines for a subject-only\n> commit.\n\n... or \"%s%n%+b\".\n"},{"id":"143694","messageId":"7vk4q1a3ud.fsf@alter.siamese.dyndns.org","threadId":"24084","inReplyTo":"20100612071850.GA2765@burratino","subject":"Re: [PATCH] cherry-pick: Add an option to prepend a string to the commit message","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-14T18:03:54Z","receivedAt":"2010-06-14T18:03:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> +git checkout maint &&\n> +git cherry-pick -n bugfix &&\n> +git add new_file.txt &&\n> +git show -s bugfix --format='%s%n%n%b%n%nAlso add a new file.' |\n> +git commit -F -\n\nThis is cute, I somehow doubt any sane person would prefer doing the above\nover running \"git commit\" and fixing it up with the editor for a single\ncommit.\n\nIt is completely a different matter if the above were in a loop that\nmunges many commits, though.  But if that is the case, the example should\nprobably illustrate that loop as well.\n"}]}