{"thread":{"id":"19506","subject":"[PATCHv2 1/4] git-am foreign patch support: introduce patch_format","startedAt":"2009-05-26T00:38:06Z","lastAt":"2009-05-27T20:50:35Z","messageCount":11,"participants":["Giuseppe Bilotta","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"114722","messageId":"1243298290-5909-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19506","inReplyTo":null,"subject":"[PATCHv2 0/4] git-am support for foreign patches","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-26T00:38:06Z","receivedAt":"2009-05-26T00:38:06Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"This patch series introduces a framework to allow git-am to support\npatches that are not in mailbox format.\n\nThe first patch introduces the command-line settable patch_format\nvariable, describing the patch format.\n\nThe second patch introduces some patch format autodetection heuristics,\nfor mercurial and StGIT.\n\nThe third patch introduces actual support for StGIT patches (both series\nand single patches).\n\nThe last one does some refactoring for the 'remove $dotest and exit 1'.\n\nGiuseppe Bilotta (4):\n  git-am foreign patch support: introduce patch_format\n  git-am foreign patch support: autodetect some patch formats\n  git-am foreign patch support: StGIT support\n  git-am: refactor 'cleaning up and aborting'\n\n git-am.sh |  148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--\n 1 files changed, 144 insertions(+), 4 deletions(-)\n"},{"id":"114721","messageId":"1243298290-5909-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19506","inReplyTo":"1243298290-5909-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv2 1/4] git-am foreign patch support: introduce patch_format","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-26T00:38:07Z","receivedAt":"2009-05-26T00:38:07Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Set up a framework to allow git-am to support patches which are not in\nmailbox format. Introduce a patch_format variable that presently can\nonly be set from the command line, defaulting to 'mbox' (the only\nsupported format) if not specified.\n---\n git-am.sh |   37 +++++++++++++++++++++++++++++++++----\n 1 files changed, 33 insertions(+), 4 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 578780b..da160de 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -18,6 +18,7 @@ whitespace=     pass it through git-apply\n directory=      pass it through git-apply\n C=              pass it through git-apply\n p=              pass it through git-apply\n+patch-format=   format the patch(es) are in\n reject          pass it through git-apply\n resolvemsg=     override error message when patch failure occurs\n r,resolved      to be used after a patch failure\n@@ -133,6 +134,32 @@ It does not apply to blobs recorded in its index.\"\n     unset GITHEAD_$his_tree\n }\n \n+patch_format=\n+\n+check_patch_format () {\n+\t# early return if patch_format was set from the command line\n+\tif test -n \"$patch_format\"\n+\tthen\n+\t\treturn 0\n+\tfi\n+\tpatch_format=mbox\n+}\n+\n+split_patches () {\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 supported.\"\n+\t\texit 1\n+\t\t;;\n+\tesac\n+}\n+\n prec=4\n dotest=\"$GIT_DIR/rebase-apply\"\n sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=\n@@ -175,6 +202,8 @@ do\n \t\tgit_apply_opt=\"$git_apply_opt $(sq \"$1=$2\")\"; shift ;;\n \t-C|-p)\n \t\tgit_apply_opt=\"$git_apply_opt $(sq \"$1$2\")\"; shift ;;\n+\t--patch-format)\n+\t\tshift ; patch_format=\"$1\" ;;\n \t--reject)\n \t\tgit_apply_opt=\"$git_apply_opt $1\" ;;\n \t--committer-date-is-author-date)\n@@ -274,10 +303,10 @@ 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-\t\texit 1\n-\t}\n+\n+\tcheck_patch_format \"$@\"\n+\n+\tsplit_patches \"$@\"\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.248.gb44be\n"},{"id":"114723","messageId":"1243298290-5909-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19506","inReplyTo":"1243298290-5909-2-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv2 2/4] git-am foreign patch support: autodetect some patch formats","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-26T00:38:08Z","receivedAt":"2009-05-26T00:38:08Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Default to mbox format if input is from stdin. Otherwise, look at the\nfirst few lines of the first patch to try to guess its format.\n\nInclude checks for mailboxes, stgit patch series, stgit single patches\nand hg patches.\n---\n git-am.sh |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 51 insertions(+), 1 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex da160de..4cf66aa 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -142,7 +142,57 @@ check_patch_format () {\n \tthen\n \t\treturn 0\n \tfi\n-\tpatch_format=mbox\n+\n+\t# we default to mbox format if input is from stdin and for\n+\t# directories\n+\tif test $# = 0 || test \"x$1\" = \"x-\" || test -d \"$1\"\n+\tthen\n+\t\tpatch_format=mbox\n+\t\treturn 0\n+\tfi\n+\n+\t# otherwise, check the first few lines of the first patch to try\n+\t# to detect its format\n+\t{\n+\t\tread l1\n+\t\tread l2\n+\t\tread l3\n+\t\tcase \"$l1\" in\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'# This series applies on GIT commit'*)\n+\t\t\t\tpatch_format=stgit-series\n+\t\t\t\t;;\n+\t\t\t\"# HG changeset patch\")\n+\t\t\t\tpatch_format=hg\n+\t\t\t\t;;\n+\t\t\t*)\n+\t\t\t\t# if the second line is empty and the third is\n+\t\t\t\t# a From, Author or Date entry, this is very\n+\t\t\t\t# likely an StGIT patch\n+\t\t\t\tif test \"x$l2\" = 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\tDate:\\ *)\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\tesac\n+\t} < \"$1\"\n }\n \n split_patches () {\n-- \n1.6.3.1.248.gb44be\n"},{"id":"114726","messageId":"1243298290-5909-4-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19506","inReplyTo":"1243298290-5909-3-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv2 3/4] git-am foreign patch support: StGIT support","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-26T00:38:09Z","receivedAt":"2009-05-26T00:38:09Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Support StGIT patches by implementing a simple awk-based converter\nmimicking StGIT's own parse_patch. Also support StGIT patch series by\n'exploding' the index into a lif of files and re-running the mail\nsplitting with patch_format set to stgit.\n---\n git-am.sh |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 60 insertions(+), 0 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 4cf66aa..1a00830 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -203,6 +203,66 @@ split_patches () {\n \t\t\texit 1\n \t\t}\n \t\t;;\n+\tstgit-series)\n+\t\tif test $# -ne 1\n+\t\tthen\n+\t\t\techo \"Only one StGIT patch series can be applied at once\"\n+\t\t\texit 1\n+\t\tfi\n+\t\tseries_dir=`dirname \"$1\"`\n+\t\tseries_file=\"$1\"\n+\t\tshift\n+\t\t{\n+\t\t\tset x\n+\t\t\twhile read filename\n+\t\t\tdo\n+\t\t\t\tset \"$@\" \"$series_dir/$filename\"\n+\t\t\tdone\n+\t\t\t# remove the safety x\n+\t\t\tshift\n+\t\t\t# remove the arg coming from the first-line comment\n+\t\t\tshift\n+\t\t} < \"$series_file\"\n+\t\t# set the patch format appropriately\n+\t\tpatch_format=stgit\n+\t\t# now handle the actual StGIT patches\n+\t\tsplit_patches \"$@\"\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. The first nonemptyline\n+\t\t\t# not starting with Author, From or Date is the\n+\t\t\t# subject, and the body starts with the next nonempty\n+\t\t\t# line not starting with Author, From or Date\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 supported.\"\n \t\texit 1\n-- \n1.6.3.1.248.gb44be\n"},{"id":"114724","messageId":"1243298290-5909-5-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19506","inReplyTo":"1243298290-5909-4-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv2 4/4] git-am: refactor 'cleaning up and aborting'","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-26T00:38:10Z","receivedAt":"2009-05-26T00:38:10Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Introduce a clean_abort function that echoes an optional error message\nto standard error, removes the dotest directory and exits with status 1.\n\nUse it when patch format detection or patch splitting fails early.\n---\n git-am.sh |   29 +++++++++++++++--------------\n 1 files changed, 15 insertions(+), 14 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 1a00830..057acfe 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -134,6 +134,15 @@ It does not apply to blobs recorded in its index.\"\n     unset GITHEAD_$his_tree\n }\n \n+clean_abort () {\n+\tif test $# -gt 0\n+\tthen\n+\t\techo \"$@\" > /dev/stderr\n+\tfi\n+\trm -fr \"$dotest\"\n+\texit 1\n+}\n+\n patch_format=\n \n check_patch_format () {\n@@ -192,22 +201,18 @@ check_patch_format () {\n \t\t\t\tfi\n \t\t\t\t;;\n \t\tesac\n-\t} < \"$1\"\n+\t} < \"$1\" || clean_abort\n }\n \n split_patches () {\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\tgit mailsplit -d\"$prec\" -o\"$dotest\" -b -- \"$@\" > \"$dotest/last\" || clean_abort\n \t\t;;\n \tstgit-series)\n \t\tif test $# -ne 1\n \t\tthen\n-\t\t\techo \"Only one StGIT patch series can be applied at once\"\n-\t\t\texit 1\n+\t\t\tclean_abort \"Only one StGIT patch series can be applied at once\"\n \t\tfi\n \t\tseries_dir=`dirname \"$1\"`\n \t\tseries_file=\"$1\"\n@@ -222,7 +227,7 @@ split_patches () {\n \t\t\tshift\n \t\t\t# remove the arg coming from the first-line comment\n \t\t\tshift\n-\t\t} < \"$series_file\"\n+\t\t} < \"$series_file\" || clean_abort\n \t\t# set the patch format appropriately\n \t\tpatch_format=stgit\n \t\t# now handle the actual StGIT patches\n@@ -254,18 +259,14 @@ split_patches () {\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\t\t}' \"$stgit\" > \"$dotest/$msgnum\" || clean_abort\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 supported.\"\n-\t\texit 1\n+\t\tclean_abort \"Patch format $patch_format is not supported.\"\n \t\t;;\n \tesac\n }\n-- \n1.6.3.1.248.gb44be\n"},{"id":"114775","messageId":"7v7i03j9mb.fsf@alter.siamese.dyndns.org","threadId":"19506","inReplyTo":"1243298290-5909-4-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCHv2 3/4] git-am foreign patch support: StGIT support","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-27T07:19:40Z","receivedAt":"2009-05-27T07:19:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n\n> Support StGIT patches by implementing a simple awk-based converter\n> mimicking StGIT's own parse_patch. Also support StGIT patch series by\n> 'exploding' the index into a lif of files and re-running the mail\n> splitting with patch_format set to stgit.\n> ---\n>  git-am.sh |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  1 files changed, 60 insertions(+), 0 deletions(-)\n>\n> diff --git a/git-am.sh b/git-am.sh\n> index 4cf66aa..1a00830 100755\n> --- a/git-am.sh\n> +++ b/git-am.sh\n> @@ -203,6 +203,66 @@ split_patches () {\n>  \t\t\texit 1\n>  \t\t}\n>  \t\t;;\n> +\tstgit-series)\n> +\t\tif test $# -ne 1\n> +\t\tthen\n> +\t\t\techo \"Only one StGIT patch series can be applied at once\"\n> +\t\t\texit 1\n> +\t\tfi\n> +\t\tseries_dir=`dirname \"$1\"`\n> +\t\tseries_file=\"$1\"\n> +\t\tshift\n> +\t\t{\n> +\t\t\tset x\n> +\t\t\twhile read filename\n> +\t\t\tdo\n> +\t\t\t\tset \"$@\" \"$series_dir/$filename\"\n> +\t\t\tdone\n> +\t\t\t# remove the safety x\n> +\t\t\tshift\n> +\t\t\t# remove the arg coming from the first-line comment\n> +\t\t\tshift\n> +\t\t} < \"$series_file\"\n> +\t\t# set the patch format appropriately\n> +\t\tpatch_format=stgit\n> +\t\t# now handle the actual StGIT patches\n> +\t\tsplit_patches \"$@\"\n\nCan an stgit patch file (or the leading pathname for that matter) have IFS\ncharacter in its name?\n\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\nPortability tip from an old timer: do not create a new empty file with\n\"touch\" (only use that command to update the timestamp of an existing\nfile).\n\nInstead say\n\n\t>\"$dotest/$msgnum\"\n\n> +\t\t\t# Awk version of StGIT parse_patch. The first nonemptyline\n> +\t\t\t# not starting with Author, From or Date is the\n> +\t\t\t# subject, and the body starts with the next nonempty\n> +\t\t\t# line not starting with Author, From or Date\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\nCan any token that match Author other than the initial \"Author: \" appear\non this line?\n\nSince we rely on Perl but not awk in core-ish part of the scripted\nPorcelains, it might be a good idea to write this in Perl as well.\n\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 supported.\"\n>  \t\texit 1\n> -- \n> 1.6.3.1.248.gb44be\n"},{"id":"114777","messageId":"7vd49vj9mb.fsf@alter.siamese.dyndns.org","threadId":"19506","inReplyTo":"1243298290-5909-3-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCHv2 2/4] git-am foreign patch support: autodetect some patch formats","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-27T07:19:40Z","receivedAt":"2009-05-27T07:19:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n\n> +\t# otherwise, check the first few lines of the first patch to try\n> +\t# to detect its format\n> +\t{\n> +\t\tread l1\n> +\t\tread l2\n> +\t\tread l3\n> +\t\tcase \"$l1\" in\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'# This series applies on GIT commit'*)\n> +\t\t\t\tpatch_format=stgit-series\n> +\t\t\t\t;;\n> +\t\t\t\"# HG changeset patch\")\n> +\t\t\t\tpatch_format=hg\n> +\t\t\t\t;;\n> +\t\t\t*)\n> +\t\t\t\t# if the second line is empty and the third is\n> +\t\t\t\t# a From, Author or Date entry, this is very\n> +\t\t\t\t# likely an StGIT patch\n> +\t\t\t\tif test \"x$l2\" = 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\tDate:\\ *)\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\tesac\n\nDon't make the case unnecessary too deep nor redundant.\n\n\t...\n\tread l3\n\tcase \"$l1\" in\n\t\"From \"* | \"From: \"* )\n\t\tpatch_format=mbox\n\t\t;;\n\t\"# This ...\")\n\t\t...\n\t\t;;\n\t*)\n\t\tcase \"$l2,$l3\" in\n\t\t,\"From: \"* | ,\"Author: \"* | ,\"Date: \"*)\n\t\t\tpatch_format=stgit\n\t\t\t;;\n\t\tesac\n\t\t;;\n\tesac\n\n> +\t} < \"$1\"\n>  }\n>  \n>  split_patches () {\n> -- \n> 1.6.3.1.248.gb44be\n"},{"id":"114776","messageId":"7v1vqbj9ma.fsf@alter.siamese.dyndns.org","threadId":"19506","inReplyTo":"1243298290-5909-5-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCHv2 4/4] git-am: refactor 'cleaning up and aborting'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-27T07:19:41Z","receivedAt":"2009-05-27T07:19:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n\n> Introduce a clean_abort function that echoes an optional error message\n> to standard error, removes the dotest directory and exits with status 1.\n>\n> Use it when patch format detection or patch splitting fails early.\n> ---\n\nS-o-b;\n\n>  git-am.sh |   29 +++++++++++++++--------------\n>  1 files changed, 15 insertions(+), 14 deletions(-)\n>\n> diff --git a/git-am.sh b/git-am.sh\n> index 1a00830..057acfe 100755\n> --- a/git-am.sh\n> +++ b/git-am.sh\n> @@ -134,6 +134,15 @@ It does not apply to blobs recorded in its index.\"\n>      unset GITHEAD_$his_tree\n>  }\n>  \n> +clean_abort () {\n> +\tif test $# -gt 0\n> +\tthen\n> +\t\techo \"$@\" > /dev/stderr\n\n\techo >&2 \"$@\"\n\n> +\tfi\n> +\trm -fr \"$dotest\"\n> +\texit 1\n> +}\n> +\n>  patch_format=\n>  \n>  check_patch_format () {\n> @@ -192,22 +201,18 @@ check_patch_format () {\n>  \t\t\t\tfi\n>  \t\t\t\t;;\n>  \t\tesac\n> -\t} < \"$1\"\n> +\t} < \"$1\" || clean_abort\n>  }\n>  \n>  split_patches () {\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\tgit mailsplit -d\"$prec\" -o\"$dotest\" -b -- \"$@\" > \"$dotest/last\" || clean_abort\n>  \t\t;;\n>  \tstgit-series)\n>  \t\tif test $# -ne 1\n>  \t\tthen\n> -\t\t\techo \"Only one StGIT patch series can be applied at once\"\n> -\t\t\texit 1\n> +\t\t\tclean_abort \"Only one StGIT patch series can be applied at once\"\n>  \t\tfi\n>  \t\tseries_dir=`dirname \"$1\"`\n>  \t\tseries_file=\"$1\"\n> @@ -222,7 +227,7 @@ split_patches () {\n>  \t\t\tshift\n>  \t\t\t# remove the arg coming from the first-line comment\n>  \t\t\tshift\n> -\t\t} < \"$series_file\"\n> +\t\t} < \"$series_file\" || clean_abort\n>  \t\t# set the patch format appropriately\n>  \t\tpatch_format=stgit\n>  \t\t# now handle the actual StGIT patches\n> @@ -254,18 +259,14 @@ split_patches () {\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\t\t}' \"$stgit\" > \"$dotest/$msgnum\" || clean_abort\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 supported.\"\n> -\t\texit 1\n> +\t\tclean_abort \"Patch format $patch_format is not supported.\"\n>  \t\t;;\n>  \tesac\n>  }\n> -- \n> 1.6.3.1.248.gb44be\n"},{"id":"114781","messageId":"cb7bb73a0905270119w30d1053ah6427363b9cbe4428@mail.gmail.com","threadId":"19506","inReplyTo":"7vd49vj9mb.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv2 2/4] git-am foreign patch support: autodetect some patch formats","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-27T08:19:41Z","receivedAt":"2009-05-27T08:19:41Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Wed, May 27, 2009 at 9:19 AM, Junio C Hamano <gitster@pobox.com> wrote:\n\n> Don't make the case unnecessary too deep nor redundant.\n>\n>        ...\n>        read l3\n>        case \"$l1\" in\n>        \"From \"* | \"From: \"* )\n>                patch_format=mbox\n>                ;;\n\nOh thanks. I think I had tried the construct this way but failed to\nmake * and | work together. Looks like I was doing it wrong.\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"},{"id":"114784","messageId":"cb7bb73a0905270129j375ac104yb9ca8601312ddbde@mail.gmail.com","threadId":"19506","inReplyTo":"7v7i03j9mb.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv2 3/4] git-am foreign patch support: StGIT support","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-27T08:29:06Z","receivedAt":"2009-05-27T08:29:06Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Wed, May 27, 2009 at 9:19 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n>\n>> +             # set the patch format appropriately\n>> +             patch_format=stgit\n>> +             # now handle the actual StGIT patches\n>> +             split_patches \"$@\"\n>\n> Can an stgit patch file (or the leading pathname for that matter) have IFS\n> character in its name?\n\nStGIT sanitizes filenames in a way similar to what format-patch does.\n\n>> +             ;;\n>> +     stgit)\n>> +             this=0\n>> +             for stgit in \"$@\"\n>> +             do\n>> +                     this=`expr \"$this\" + 1`\n>> +                     msgnum=`printf \"%0${prec}d\" $this`\n>> +                     touch \"$dotest/$msgnum\"\n>\n> Portability tip from an old timer: do not create a new empty file with\n> \"touch\" (only use that command to update the timestamp of an existing\n> file).\n>\n> Instead say\n>\n>        >\"$dotest/$msgnum\"\n>\n>> +                     # Awk version of StGIT parse_patch. The first nonemptyline\n>> +                     # not starting with Author, From or Date is the\n>> +                     # subject, and the body starts with the next nonempty\n>> +                     # line not starting with Author, From or Date\n>> +                     awk 'BEGIN { subject=0 }\n>> +                     {\n>> +                             if (subject > 1)\n>> +                                     print ;\n>> +                             else if (/^$/) next ;\n>> +                             else if (/^Author:/) print sub(\"Author\", \"From\"), $ORS ;\n>\n> Can any token that match Author other than the initial \"Author: \" appear\n> on this line?\n\nIrrelevant, sub only substitutes the first hit so only the initial\nAuthor: is replaced.\n\n> Since we rely on Perl but not awk in core-ish part of the scripted\n> Porcelains, it might be a good idea to write this in Perl as well.\n\nBy 'as well' you mean in case awk is missing, and have both, or by\nonly keeping a perl version?\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"},{"id":"114837","messageId":"7vmy8yi82s.fsf@alter.siamese.dyndns.org","threadId":"19506","inReplyTo":"cb7bb73a0905270129j375ac104yb9ca8601312ddbde@mail.gmail.com","subject":"Re: [PATCHv2 3/4] git-am foreign patch support: StGIT support","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-27T20:50:35Z","receivedAt":"2009-05-27T20:50:35Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n\n> On Wed, May 27, 2009 at 9:19 AM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n>>\n>>> +             # set the patch format appropriately\n>>> +             patch_format=stgit\n>>> +             # now handle the actual StGIT patches\n>>> +             split_patches \"$@\"\n>>\n>> Can an stgit patch file (or the leading pathname for that matter) have IFS\n>> character in its name?\n>\n> StGIT sanitizes filenames in a way similar to what format-patch does.\n\nGood ;-)\n\n>> Since we rely on Perl but not awk in core-ish part of the scripted\n>> Porcelains, it might be a good idea to write this in Perl as well.\n>\n> By 'as well' you mean in case awk is missing, and have both, or by\n> only keeping a perl version?\n\n\"As well\" I meant \"Using Perl instead of awk, just like other scripted\nPorcelains.\"\n"}]}