{"thread":{"id":"19524","subject":"[PATCHv3 0/4] git-am foreign patch support","startedAt":"2009-05-27T09:25:15Z","lastAt":"2009-05-27T21:20:12Z","messageCount":6,"participants":["Giuseppe Bilotta"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"114785","messageId":"1243416319-31477-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19524","inReplyTo":null,"subject":"[PATCHv3 0/4] git-am foreign patch support","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-27T09:25:15Z","receivedAt":"2009-05-27T09:25:15Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Third attempt at introducing foreign patch support for git-am. The only\nsignificant change from the previous round is the StGIT-to-mbox format\nconversion which is now done via perl instead of awk.\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 |  133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--\n 1 files changed, 129 insertions(+), 4 deletions(-)\n"},{"id":"114786","messageId":"1243416319-31477-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19524","inReplyTo":"1243416319-31477-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 1/4] git-am foreign patch support: introduce patch_format","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-27T09:25:16Z","receivedAt":"2009-05-27T09:25:16Z","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.274.gd2e8.dirty\n"},{"id":"114787","messageId":"1243416319-31477-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19524","inReplyTo":"1243416319-31477-2-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 2/4] git-am foreign patch support: autodetect some patch formats","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-27T09:25:17Z","receivedAt":"2009-05-27T09:25:17Z","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 |   40 +++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 39 insertions(+), 1 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex da160de..192ad1e 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -142,7 +142,45 @@ 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\t\"From \"*|\"From: \"*)\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\tcase \"$l2,$l3\" in\n+\t\t\t\t\t,\"From: \"*|,\"Author: \"*|,\"Date: \"*)\n+\t\t\t\t\t\tpatch_format=stgit\n+\t\t\t\t\t\t;;\n+\t\t\t\t\t*)\n+\t\t\t\t\t\t;;\n+\t\t\t\tesac\n+\t\t\t\t;;\n+\t\tesac\n+\t} < \"$1\"\n }\n \n split_patches () {\n-- \n1.6.3.1.274.gd2e8.dirty\n"},{"id":"114788","messageId":"1243416319-31477-4-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19524","inReplyTo":"1243416319-31477-3-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 3/4] git-am foreign patch support: StGIT support","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-27T09:25:18Z","receivedAt":"2009-05-27T09:25:18Z","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 perl-based converter\nmimicking StGIT's own parse_patch. Also support StGIT patch series by\n'exploding' the index into a list of files and re-running the mail\nsplitting with patch_format set to stgit.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-am.sh |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 57 insertions(+), 0 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 192ad1e..3757269 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -191,6 +191,63 @@ 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\t# Perl 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\tperl -ne 'BEGIN { $subject = 0 }\n+\t\t\t\tif ($subject > 1) { print ; }\n+\t\t\t\telsif (/^\\s+$/) { next ; }\n+\t\t\t\telsif (/^Author:/) { print s/Author/From/ ; }\n+\t\t\t\telsif (/^(From|Date)/) { print ; }\n+\t\t\t\telsif ($subject) {\n+\t\t\t\t\t$subject = 2 ;\n+\t\t\t\t\tprint \"\\n\" ;\n+\t\t\t\t\tprint ;\n+\t\t\t\t} else {\n+\t\t\t\t\tprint \"Subject: \", $_ ;\n+\t\t\t\t\t$subject = 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.274.gd2e8.dirty\n"},{"id":"114789","messageId":"1243416319-31477-5-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19524","inReplyTo":"1243416319-31477-4-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 4/4] git-am: refactor 'cleaning up and aborting'","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-27T09:25:19Z","receivedAt":"2009-05-27T09:25:19Z","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\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\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 3757269..588beea 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@@ -180,22 +189,18 @@ check_patch_format () {\n \t\t\t\tesac\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@@ -210,7 +215,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@@ -239,18 +244,14 @@ split_patches () {\n \t\t\t\t\tprint \"Subject: \", $_ ;\n \t\t\t\t\t$subject = 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.274.gd2e8.dirty\n"},{"id":"114842","messageId":"1243459212-6074-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"19524","inReplyTo":"1243416319-31477-3-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3bis 2/4] git-am foreign patch support: autodetect some patch formats","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-05-27T21:20:12Z","receivedAt":"2009-05-27T21:20:12Z","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 |   40 +++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 39 insertions(+), 1 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex da160de..8519701 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -142,7 +142,45 @@ 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\"From \"*|\"From: \"*)\n+\t\t\tpatch_format=mbox\n+\t\t\t;;\n+\t\t'# This series applies on GIT commit'*)\n+\t\t\tpatch_format=stgit-series\n+\t\t\t;;\n+\t\t\"# HG changeset patch\")\n+\t\t\tpatch_format=hg\n+\t\t\t;;\n+\t\t*)\n+\t\t\t# if the second line is empty and the third is\n+\t\t\t# a From, Author or Date entry, this is very\n+\t\t\t# likely an StGIT patch\n+\t\t\tcase \"$l2,$l3\" in\n+\t\t\t,\"From: \"*|,\"Author: \"*|,\"Date: \"*)\n+\t\t\t\tpatch_format=stgit\n+\t\t\t\t;;\n+\t\t\t*)\n+\t\t\t\t;;\n+\t\t\tesac\n+\t\t\t;;\n+\t\tesac\n+\t} < \"$1\"\n }\n \n split_patches () {\n-- \n1.6.3.1.274.gd2e8.dirty\n"}]}