{"thread":{"id":"19502","subject":"[PATCH 0/2] git-am foreign patch support","startedAt":"2009-05-25T19:14:04Z","lastAt":"2009-05-25T22:49:14Z","messageCount":7,"participants":["Giuseppe Bilotta","Sverre Rabbelier","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"114689","messageId":"1243278846-14120-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19502","inReplyTo":null,"subject":"[PATCH 0/2] git-am foreign patch support","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-25T19:14:04Z","receivedAt":"2009-05-25T19:14:04Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"This small patchset introduces a framework to allow git-am to support\npatchsets not in mailbox format.\n\nThe first patch introduces a new patch_format variable that holds the\n(autodetected) patch format. All patches are assumed to be in the same\nformat. Autodetection for Mercurial and StGIT patches is also\nimplemented, including series index expansion for StGIT.\n\nThe second patch introduces actual support for StGIT patches by using\nsome awk code to convert them to mailbox format.\n\nGiuseppe Bilotta (2):\n  git-am foreign patch support: format autodetection\n  git-am foreign patch support: StGIT\n\n git-am.sh |  140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 137 insertions(+), 3 deletions(-)\n"},{"id":"114691","messageId":"1243278846-14120-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19502","inReplyTo":"1243278846-14120-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCH 1/2] git-am foreign patch support: format autodetection","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-25T19:14:05Z","receivedAt":"2009-05-25T19:14:05Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"This patch is the first step towards the introduction of a framework to\nallow git-am to import patches not in mailbox format.\n\nCurrently detected formats are\n  * the mailbox format itself, which is assumed by default if input is\n    form stdin\n  * Mercurial's output from 'hg export'\n  * Stacked Git's output from 'stg export' with the default export\n    template; StGIT patch series are also detected and expanded.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-am.sh |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--\n 1 files changed, 105 insertions(+), 3 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 578780b..3508b7e 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -274,10 +274,112 @@ else\n \t\tdone\n \t\tshift\n \tfi\n-\tgit mailsplit -d\"$prec\" -o\"$dotest\" -b -- \"$@\" > \"$dotest/last\" ||  {\n-\t\trm -fr \"$dotest\"\n+\n+\t# format of the patch(es) to be processed. we assume they are all\n+\t# of the same kind\n+\tpatch_format=none\n+\n+\t# from stdin we only accept mboxes, because peeking at stdin\n+\t# to detect the format is destructive\n+\tcase $# in\n+\t0)\n+\t\tpatch_format=mbox\n+\t\t;;\n+\t1)\n+\t\tif test x\"$1\" = x\"-\"\n+\t\tthen\n+\t\t\t# stdin, so assume mbox\n+\t\t\tpatch_format=mbox\n+\t\telse\n+# a single non-stdin argument was passed, check if it's a StGit patch series\n+# index by checking if the first line begins with '# This series'\n+\t\t\t{\n+\t\t\t\tread l1\n+\t\t\t\tcase \"$l1\" in\n+\t\t\t\t'# This series '*)\n+# replace the argument list with the files listed in the series index,\n+# prefixing them with the series index dirname, skipping comment lines\n+\t\t\t\t\tseries_dir=`dirname \"$1\"`\n+\t\t\t\t\twhile read filename\n+\t\t\t\t\tdo\n+\t\t\t\t\t\tset \"$@\" \"$series_dir/$filename\"\n+\t\t\t\t\tdone\n+\t\t\t\t\t# remove the series index name\n+\t\t\t\t\tshift\n+\t\t\t\t\t# set the patch format appropriately\n+\t\t\t\t\tpatch_format=stgit\n+\t\t\t\t\t;;\n+\t\t\t\t*)\n+\t\t\t\t\t;;\n+\t\t\t\tesac\n+\t\t\t} < \"$1\"\n+\t\tfi\n+\t\t;;\n+\t*)\n+\t\t;;\n+\tesac\n+\n+\t# if the format is not defined yet, we can look at the first patch\n+\t# (which is not stdin) to try to understand the format.\n+\tif test $patch_format = none\n+\tthen\n+\t\techo \"$patch_format\"\n+\t\t# if it's a directory, assume mbox format\n+\t\t# TODO we could suppot StGIT patch series here too\n+\t\tif test -d \"$1\"\n+\t\tthen\n+\t\t\tpatch_format=mbox\n+\t\telse\n+\t\t\t# read the first four lines\n+\t\t\t{\n+\t\t\t\tread l1\n+\t\t\t\tread l2\n+\t\t\t\tread l3\n+\t\t\t\tread l4\n+\t\t\t} < \"$1\"\n+\t\t\tcase \"$l1\" in\n+\t\t\t\"# HG changeset patch\")\n+\t\t\t\tpatch_format=hg\n+\t\t\t\t;;\n+\t\t\tFrom\\ *)\n+\t\t\t\tpatch_format=mbox\n+\t\t\t\t;;\n+\t\t\tFrom:\\ *)\n+\t\t\t\tpatch_format=mbox\n+\t\t\t\t;;\n+\t\t\t*)\n+\t\t\t\t# if the second and fourth lines are empty,\n+\t\t\t\t# this might be an StGIT patch\n+\t\t\t\tif test x\"$l2$l4\" = x\n+\t\t\t\tthen\n+\t\t\t\t\tcase \"$l3\" in\n+\t\t\t\t\t\tFrom:\\ *)\n+\t\t\t\t\t\t\tpatch_format=stgit\n+\t\t\t\t\t\t\t;;\n+\t\t\t\t\t\tAuthor:\\ *)\n+\t\t\t\t\t\t\tpatch_format=stgit\n+\t\t\t\t\t\t\t;;\n+\t\t\t\t\t\t*)\n+\t\t\t\t\t\t\t;;\n+\t\t\t\t\tesac\n+\t\t\t\tfi\n+\t\t\t\t;;\n+\t\t\tesac\n+\t\tfi\n+\tfi\n+\n+\tcase \"$patch_format\" in\n+\tmbox)\n+\t\tgit mailsplit -d\"$prec\" -o\"$dotest\" -b -- \"$@\" > \"$dotest/last\" ||  {\n+\t\t\trm -fr \"$dotest\"\n+\t\t\texit 1\n+\t\t}\n+\t\t;;\n+\t*)\n+\t\techo \"Patch format $patch_format is not currently handled, sorry\"\n \t\texit 1\n-\t}\n+\t\t;;\n+\tesac\n \n \t# -s, -u, -k, --whitespace, -3, -C and -p flags are kept\n \t# for the resuming session after a patch failure.\n-- \n1.6.3.1.245.g4529.dirty\n"},{"id":"114690","messageId":"1243278846-14120-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19502","inReplyTo":"1243278846-14120-2-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCH 2/2] git-am foreign patch support: StGIT","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-25T19:14:06Z","receivedAt":"2009-05-25T19:14:06Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Convert StGIT patches to mbox format so that they can be imported.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-am.sh |   32 ++++++++++++++++++++++++++++++++\n 1 files changed, 32 insertions(+), 0 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 3508b7e..5199354 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -375,6 +375,38 @@ else\n \t\t\texit 1\n \t\t}\n \t\t;;\n+\tstgit)\n+\t\tthis=0\n+\t\tfor stgit in \"$@\"\n+\t\tdo\n+\t\t\tthis=`expr \"$this\" + 1`\n+\t\t\tmsgnum=`printf \"%0${prec}d\" $this`\n+\t\t\ttouch \"$dotest/$msgnum\"\n+\t\t\t# Awk version of StGIT parse_patch\n+\t\t\tawk 'BEGIN { subject=0 }\n+\t\t\t{\n+\t\t\t\tif (subject > 1)\n+\t\t\t\t\tprint ;\n+\t\t\t\telse if (/^$/) next ;\n+\t\t\t\telse if (/^Author:/) print sub(\"Author\", \"From\"), $ORS ;\n+\t\t\t\telse if (/^(From|Date)/) print ;\n+\t\t\t\telse if (subject) {\n+\t\t\t\t\tsubject = 2 ;\n+\t\t\t\t\tprint \"\" ;\n+\t\t\t\t\tprint ;\n+\t\t\t\t} else {\n+\t\t\t\t\tprint \"Subject:\", $0 ;\n+\t\t\t\t\tsubject = 1;\n+\t\t\t\t}\n+\t\t\t}' \"$stgit\" > \"$dotest/$msgnum\" || {\n+\t\t\t\techo \"Failed to import $patch_format patch $stgit\"\n+\t\t\t\texit 1\n+\t\t\t}\n+\t\tdone\n+\t\techo \"$this\" > \"$dotest/last\"\n+\t\tthis=\n+\t\tmsgnum=\n+\t\t;;\n \t*)\n \t\techo \"Patch format $patch_format is not currently handled, sorry\"\n \t\texit 1\n-- \n1.6.3.1.245.g4529.dirty\n"},{"id":"114693","messageId":"fabb9a1e0905251219q3fbd2d17hb08649b9113baba8@mail.gmail.com","threadId":"19502","inReplyTo":"1243278846-14120-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCH 0/2] git-am foreign patch support","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-05-25T19:19:33Z","receivedAt":"2009-05-25T19:19:33Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Mon, May 25, 2009 at 21:14, Giuseppe Bilotta\n<giuseppe.bilotta@gmail.com> wrote:\n> Autodetection for Mercurial [...] patches is also implemented, [...]\n\nSweet! I now have a vested interest to see this accepted :P.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"114694","messageId":"cb7bb73a0905251224r31e36422nbc221b860002be80@mail.gmail.com","threadId":"19502","inReplyTo":"fabb9a1e0905251219q3fbd2d17hb08649b9113baba8@mail.gmail.com","subject":"Re: [PATCH 0/2] git-am foreign patch support","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-25T19:24:08Z","receivedAt":"2009-05-25T19:24:08Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Mon, May 25, 2009 at 9:19 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:\n> Heya,\n>\n> On Mon, May 25, 2009 at 21:14, Giuseppe Bilotta\n> <giuseppe.bilotta@gmail.com> wrote:\n>> Autodetection for Mercurial [...] patches is also implemented, [...]\n>\n> Sweet! I now have a vested interest to see this accepted :P.\n\nKeep in mind that presently it just detects them, it doesn't actually\nimport them. But their conversion to mbox format seems rather\nstraightforward, so it can be added easily.\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"},{"id":"114714","messageId":"7vk544u8hx.fsf@alter.siamese.dyndns.org","threadId":"19502","inReplyTo":"1243278846-14120-2-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCH 1/2] git-am foreign patch support: format autodetection","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-25T22:23:54Z","receivedAt":"2009-05-25T22:23:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n\n> This patch is the first step towards the introduction of a framework to\n> allow git-am to import patches not in mailbox format.\n>\n> Currently detected formats are\n>   * the mailbox format itself, which is assumed by default if input is\n>     form stdin\n>   * Mercurial's output from 'hg export'\n>   * Stacked Git's output from 'stg export' with the default export\n>     template; StGIT patch series are also detected and expanded.\n\nI personally do not trust \"autodetection\" (especially done by others ;-),\nand prefer to have an explicit override by the users, but that aside...\n\n> +\t# from stdin we only accept mboxes, because peeking at stdin\n> +\t# to detect the format is destructive\n> +\tcase $# in\n> +\t0)\n> +\t\tpatch_format=mbox\n> +\t\t;;\n> +\t1)\n> +\t\tif test x\"$1\" = x\"-\"\n> +\t\tthen\n> +\t\t\t# stdin, so assume mbox\n> +\t\t\tpatch_format=mbox\n> +\t\telse\n\n\t# have parseopt to set explicit patch_format before this part...\n\n\tif test -z \"$patch_format\" && {\n           test $# = 0 || test \"x$1\" = x-\n        }\n        then\n        \tpatch_format=mbox\n\telse\n        \tpatch_format=$(guess_patch_format)\n\tfi\n\nHaving this extra logic inside the main codeflow makes it extremely harder\nto read; have it in a separate shell function.\n\n> +# a single non-stdin argument was passed, check if it's a StGit patch series\n> +# index by checking if the first line begins with '# This series'\n> +\t\t\t{\n> +\t\t\t\tread l1\n> +\t\t\t\tcase \"$l1\" in\n> +\t\t\t\t'# This series '*)\n> +# replace the argument list with the files listed in the series index,\n> +# prefixing them with the series index dirname, skipping comment lines\n\nCan the \"series-index-name\" file begin with '-' (which would affect the\nway how 'set \"@\"' works in the loop below)?  A standard trick would be to\ndo something like this.\n\n\tseries_index=\"$1\"\n\tshift ;# discard\n        set x\n        while ...\n\tdo\n        \tset \"$@\" another\n\tdone\n        shift ;# discard 'x' protection\n\n> +\t# (which is not stdin) to try to understand the format.\n> +\tif test $patch_format = none\n\nI do not understand this duplication and inconsistency.  Why have the\ndetection in two places?\n\n> +\tcase \"$patch_format\" in\n> +\tmbox)\n> +\t\tgit mailsplit -d\"$prec\" -o\"$dotest\" -b -- \"$@\" > \"$dotest/last\" ||  {\n> +\t\t\trm -fr \"$dotest\"\n> +\t\t\texit 1\n> +\t\t}\n> +\t\t;;\n> +\t*)\n> +\t\techo \"Patch format $patch_format is not currently handled, sorry\"\n>  \t\texit 1\n\nNo fixing broken \"Subject:\" line for your format here?\n"},{"id":"114716","messageId":"cb7bb73a0905251549s49d7fc28ge63b12e52029dd0b@mail.gmail.com","threadId":"19502","inReplyTo":"7vk544u8hx.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 1/2] git-am foreign patch support: format autodetection","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-25T22:49:14Z","receivedAt":"2009-05-25T22:49:14Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Tue, May 26, 2009 at 12:23 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n>\n>> This patch is the first step towards the introduction of a framework to\n>> allow git-am to import patches not in mailbox format.\n>>\n>> Currently detected formats are\n>>   * the mailbox format itself, which is assumed by default if input is\n>>     form stdin\n>>   * Mercurial's output from 'hg export'\n>>   * Stacked Git's output from 'stg export' with the default export\n>>     template; StGIT patch series are also detected and expanded.\n>\n> I personally do not trust \"autodetection\" (especially done by others ;-),\n> and prefer to have an explicit override by the users, but that aside...\n\nNo problem. --patch-format or just --format ?\n\n>        if test -z \"$patch_format\" && {\n>           test $# = 0 || test \"x$1\" = x-\n>        }\n>        then\n>                patch_format=mbox\n>        else\n>                patch_format=$(guess_patch_format)\n>        fi\n>\n> Having this extra logic inside the main codeflow makes it extremely harder\n> to read; have it in a separate shell function.\n\nI assume you mean the patch format detection, yes?\n\n>> +# a single non-stdin argument was passed, check if it's a StGit patch series\n>> +# index by checking if the first line begins with '# This series'\n>> +                     {\n>> +                             read l1\n>> +                             case \"$l1\" in\n>> +                             '# This series '*)\n>> +# replace the argument list with the files listed in the series index,\n>> +# prefixing them with the series index dirname, skipping comment lines\n>\n> Can the \"series-index-name\" file begin with '-' (which would affect the\n> way how 'set \"@\"' works in the loop below)?  A standard trick would be to\n> do something like this.\n>\n>        series_index=\"$1\"\n>        shift ;# discard\n>        set x\n>        while ...\n>        do\n>                set \"$@\" another\n>        done\n>        shift ;# discard 'x' protection\n\nAh, good point. I'll do it that way.\n\n>> +     # (which is not stdin) to try to understand the format.\n>> +     if test $patch_format = none\n>\n> I do not understand this duplication and inconsistency.  Why have the\n> detection in two places?\n\nIt's not in two places. The first part sets the patch format only if\nwe are either reading from stdin or have been passed a stgit patch\nseries. Otherwise, we still don't know what we're getting, so now we\ninspect the first patch to see what format it's in. (Consider for\nexample the case of appication of a StGIT patch which is not part of a\nseries.)\n\n>> +     case \"$patch_format\" in\n>> +     mbox)\n>> +             git mailsplit -d\"$prec\" -o\"$dotest\" -b -- \"$@\" > \"$dotest/last\" ||  {\n>> +                     rm -fr \"$dotest\"\n>> +                     exit 1\n>> +             }\n>> +             ;;\n>> +     *)\n>> +             echo \"Patch format $patch_format is not currently handled, sorry\"\n>>               exit 1\n>\n> No fixing broken \"Subject:\" line for your format here?\n\nNo, I put that in the second patch, because it was a different thing\n(patch processing as opposed to format detection).\n\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"}]}