{"thread":{"id":"39631","subject":"[PATCH v2 0/5] am: improve test coverage and touch up foreign patch parsing","startedAt":"2015-06-15T11:08:08Z","lastAt":"2015-06-15T19:38:51Z","messageCount":7,"participants":["Paul Tan","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":5},"messages":[{"id":"263848","messageId":"1434366493-27155-1-git-send-email-pyokagan@gmail.com","threadId":"39631","inReplyTo":null,"subject":"[PATCH v2 0/5] am: improve test coverage and touch up foreign patch parsing","fromName":"Paul Tan","fromEmail":"pyokagan@gmail.com","sentAt":"2015-06-15T11:08:08Z","receivedAt":"2015-06-15T11:08:08Z","isPatch":true,"sender":{"key":"pyokagan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/109479?v=4"},"body":"This is a re-roll of [v1].\n\nPrevious versions:\n\n[v1] http://thread.gmane.org/gmane.comp.version-control.git/271053\n\ngit-am is able to parse StGit and mercurial patches. However, there are no\nregression tests in the test suite for these patch formats, and there are some\nsmall bugs as well:\n\n* the mercurial and stgit patch parsers does not support reading from stdin\n\n* the mercurial patch parser parsed the patch date wrongly and git-am is thus\n  unable to reconstruct the exact commit.\n\nSome patches are based on Chris' patch series[1], which I've credited accordingly.\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/256502\n\n\nPaul Tan (5):\n  t4150: test applying StGit patch\n  am: teach StGit patch parser how to read from stdin\n  t4150: test applying StGit series\n  am: use gmtime() to parse mercurial patch date\n  am: teach mercurial patch parser how to read from stdin\n\n git-am.sh     | 12 +++++----\n t/t4150-am.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 89 insertions(+), 5 deletions(-)\n\n-- \n2.1.4\n"},{"id":"263849","messageId":"1434366493-27155-2-git-send-email-pyokagan@gmail.com","threadId":"39631","inReplyTo":"1434366493-27155-1-git-send-email-pyokagan@gmail.com","subject":"[PATCH v2 1/5] t4150: test applying StGit patch","fromName":"Paul Tan","fromEmail":"pyokagan@gmail.com","sentAt":"2015-06-15T11:08:09Z","receivedAt":"2015-06-15T11:08:09Z","isPatch":true,"sender":{"key":"pyokagan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/109479?v=4"},"body":"By default, an StGit patch separates the subject from the commit message\nand headers as follows:\n\n\t$subject\n\n\tFrom: $author_name <$author_email>\n\n\t$message\n\t---\n\t$diffstats\n\nWe test git-am's ability to detect such a patch as an StGit patch, and\nits ability to be able to extract the commit author, date and message\nfrom such a patch.\n\nBased-on-patch-by: Chris Packham <judge.packham@gmail.com>\nSigned-off-by: Paul Tan <pyokagan@gmail.com>\n---\n t/t4150-am.sh | 22 ++++++++++++++++++++++\n 1 file changed, 22 insertions(+)\n\ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex 306e6f3..0ead529 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -104,6 +104,18 @@ test_expect_success setup '\n \t\techo \"X-Fake-Field: Line Three\" &&\n \t\tgit format-patch --stdout first | sed -e \"1d\"\n \t} > patch1-ws.eml &&\n+\t{\n+\t\tsed -ne \"1p\" msg &&\n+\t\techo &&\n+\t\techo \"From: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>\" &&\n+\t\techo \"Date: $GIT_AUTHOR_DATE\" &&\n+\t\techo &&\n+\t\tsed -e \"1,2d\" msg &&\n+\t\techo &&\n+\t\techo \"Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\" &&\n+\t\techo \"---\" &&\n+\t\tgit diff-tree --no-commit-id --stat -p second\n+\t} >patch1-stgit.eml &&\n \n \tsed -n -e \"3,\\$p\" msg >file &&\n \tgit add file &&\n@@ -187,6 +199,16 @@ test_expect_success 'am applies patch e-mail with preceding whitespace' '\n \ttest \"$(git rev-parse second^)\" = \"$(git rev-parse HEAD^)\"\n '\n \n+test_expect_success 'am applies stgit patch' '\n+\trm -fr .git/rebase-apply &&\n+\tgit checkout -f first &&\n+\tgit am patch1-stgit.eml &&\n+\ttest_path_is_missing .git/rebase-apply &&\n+\tgit diff --exit-code second &&\n+\ttest_cmp_rev second HEAD &&\n+\ttest_cmp_rev second^ HEAD^\n+'\n+\n test_expect_success 'setup: new author and committer' '\n \tGIT_AUTHOR_NAME=\"Another Thor\" &&\n \tGIT_AUTHOR_EMAIL=\"a.thor@example.com\" &&\n-- \n2.1.4\n"},{"id":"263851","messageId":"1434366493-27155-3-git-send-email-pyokagan@gmail.com","threadId":"39631","inReplyTo":"1434366493-27155-1-git-send-email-pyokagan@gmail.com","subject":"[PATCH v2 2/5] am: teach StGit patch parser how to read from stdin","fromName":"Paul Tan","fromEmail":"pyokagan@gmail.com","sentAt":"2015-06-15T11:08:10Z","receivedAt":"2015-06-15T11:08:10Z","isPatch":true,"sender":{"key":"pyokagan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/109479?v=4"},"body":"git-mailsplit, which splits mbox patches, will read the patch from stdin\nwhen the filename is \"-\" or there are no files listed on the\ncommand-line.\n\nTo be consistent with this behavior, teach the StGit patch parser to\nread from stdin if the filename is \"-\" or no files are listed on the\ncommand-line.\n\nBased-on-patch-by: Chris Packham <judge.packham@gmail.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Paul Tan <pyokagan@gmail.com>\n---\n\nNotes:\n    v2\n    \n    * Just pass the filename directly to perl. Hmm, I think we should add a\n      \"--\" in front so that filenames that start with a dash won't be\n      interpreted as a command-line switch by perl?\n\n git-am.sh     |  3 ++-\n t/t4150-am.sh | 10 ++++++++++\n 2 files changed, 12 insertions(+), 1 deletion(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 761befb..5ea2e4d 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -297,6 +297,7 @@ split_patches () {\n \t\t;;\n \tstgit)\n \t\tthis=0\n+\t\ttest 0 -eq \"$#\" && set -- -\n \t\tfor stgit in \"$@\"\n \t\tdo\n \t\t\tthis=$(expr \"$this\" + 1)\n@@ -318,7 +319,7 @@ 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\" || clean_abort\n+\t\t\t' -- \"$stgit\" >\"$dotest/$msgnum\" || clean_abort\n \t\tdone\n \t\techo \"$this\" > \"$dotest/last\"\n \t\tthis=\ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex 0ead529..51962e4 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -209,6 +209,16 @@ test_expect_success 'am applies stgit patch' '\n \ttest_cmp_rev second^ HEAD^\n '\n \n+test_expect_success 'am --patch-format=stgit applies stgit patch' '\n+\trm -fr .git/rebase-apply &&\n+\tgit checkout -f first &&\n+\tgit am --patch-format=stgit <patch1-stgit.eml &&\n+\ttest_path_is_missing .git/rebase-apply &&\n+\tgit diff --exit-code second &&\n+\ttest_cmp_rev second HEAD &&\n+\ttest_cmp_rev second^ HEAD^\n+'\n+\n test_expect_success 'setup: new author and committer' '\n \tGIT_AUTHOR_NAME=\"Another Thor\" &&\n \tGIT_AUTHOR_EMAIL=\"a.thor@example.com\" &&\n-- \n2.1.4\n"},{"id":"263850","messageId":"1434366493-27155-4-git-send-email-pyokagan@gmail.com","threadId":"39631","inReplyTo":"1434366493-27155-1-git-send-email-pyokagan@gmail.com","subject":"[PATCH v2 3/5] t4150: test applying StGit series","fromName":"Paul Tan","fromEmail":"pyokagan@gmail.com","sentAt":"2015-06-15T11:08:11Z","receivedAt":"2015-06-15T11:08:11Z","isPatch":true,"sender":{"key":"pyokagan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/109479?v=4"},"body":"A StGit series is a directory containing a \"series\" file which begins\nwith the line:\n\n\t# This series applies on GIT commit XXXXX\n\nwhere XXXXX is the commit ID that the patch series applies on. Every\nfollowing line names a patch in the directory to be applied.\n\nTest that git-am, when given this \"series\" file, is able to detect it as\nan StGit series and apply all the patches in the series.\n\nSigned-off-by: Paul Tan <pyokagan@gmail.com>\n---\n t/t4150-am.sh | 17 +++++++++++++++++\n 1 file changed, 17 insertions(+)\n\ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex 51962e4..7aad8f8 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -116,6 +116,13 @@ test_expect_success setup '\n \t\techo \"---\" &&\n \t\tgit diff-tree --no-commit-id --stat -p second\n \t} >patch1-stgit.eml &&\n+\tmkdir stgit-series &&\n+\tcp patch1-stgit.eml stgit-series/patch &&\n+\t{\n+\t\techo \"# This series applies on GIT commit $(git rev-parse first)\" &&\n+\t\techo \"patch\"\n+\t} >stgit-series/series &&\n+\n \n \tsed -n -e \"3,\\$p\" msg >file &&\n \tgit add file &&\n@@ -219,6 +226,16 @@ test_expect_success 'am --patch-format=stgit applies stgit patch' '\n \ttest_cmp_rev second^ HEAD^\n '\n \n+test_expect_success 'am applies stgit series' '\n+\trm -fr .git/rebase-apply &&\n+\tgit checkout -f first &&\n+\tgit am stgit-series/series &&\n+\ttest_path_is_missing .git/rebase-apply &&\n+\tgit diff --exit-code second &&\n+\ttest_cmp_rev second HEAD &&\n+\ttest_cmp_rev second^ HEAD^\n+'\n+\n test_expect_success 'setup: new author and committer' '\n \tGIT_AUTHOR_NAME=\"Another Thor\" &&\n \tGIT_AUTHOR_EMAIL=\"a.thor@example.com\" &&\n-- \n2.1.4\n"},{"id":"263853","messageId":"1434366493-27155-5-git-send-email-pyokagan@gmail.com","threadId":"39631","inReplyTo":"1434366493-27155-1-git-send-email-pyokagan@gmail.com","subject":"[PATCH v2 4/5] am: use gmtime() to parse mercurial patch date","fromName":"Paul Tan","fromEmail":"pyokagan@gmail.com","sentAt":"2015-06-15T11:08:12Z","receivedAt":"2015-06-15T11:08:12Z","isPatch":true,"sender":{"key":"pyokagan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/109479?v=4"},"body":"An example of the line in a mercurial patch that specifies the date of\nthe commit would be:\n\n\t# Date 1433753301 25200\n\nwhere the first number is the number of seconds since the unix epoch (in\nUTC), and the second number is the offset of the timezone, in second s\nwest of UTC (negative if the timezone is east of UTC).\n\ngit-am uses localtime() to break down the first number into its\ncomponents (year, month, day, hours, minutes, seconds etc.). However,\nthe returned components are relative to the user's time zone. As a\nresult, if the user's time zone does not match the time zone specified\nin the patch, the resulting commit will have the wrong author date.\n\nFix this by using gmtime() instead, which uses UTC instead of the user's\ntime zone.\n\nSigned-off-by: Paul Tan <pyokagan@gmail.com>\n---\n git-am.sh     |  6 +++---\n t/t4150-am.sh | 23 +++++++++++++++++++++++\n 2 files changed, 26 insertions(+), 3 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 5ea2e4d..f0b6c16 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -343,11 +343,11 @@ split_patches () {\n \t\t\t\telsif (/^\\# User /) { s/\\# User/From:/ ; print ; }\n \t\t\t\telsif (/^\\# Date /) {\n \t\t\t\t\tmy ($hashsign, $str, $time, $tz) = split ;\n-\t\t\t\t\t$tz = sprintf \"%+05d\", (0-$tz)/36;\n+\t\t\t\t\t$tz_str = sprintf \"%+05d\", (0-$tz)/36;\n \t\t\t\t\tprint \"Date: \" .\n \t\t\t\t\t      strftime(\"%a, %d %b %Y %H:%M:%S \",\n-\t\t\t\t\t\t       localtime($time))\n-\t\t\t\t\t      . \"$tz\\n\";\n+\t\t\t\t\t\t       gmtime($time-$tz))\n+\t\t\t\t\t      . \"$tz_str\\n\";\n \t\t\t\t} elsif (/^\\# /) { next ; }\n \t\t\t\telse {\n \t\t\t\t\tprint \"\\n\", $_ ;\ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex 7aad8f8..4beb4b3 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -122,6 +122,19 @@ test_expect_success setup '\n \t\techo \"# This series applies on GIT commit $(git rev-parse first)\" &&\n \t\techo \"patch\"\n \t} >stgit-series/series &&\n+\t{\n+\t\techo \"# HG changeset patch\" &&\n+\t\techo \"# User $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>\" &&\n+\t\techo \"# Date $test_tick 25200\" &&\n+\t\techo \"#      $(git show --pretty=\"%aD\" -s second)\" &&\n+\t\techo \"# Node ID $_z40\" &&\n+\t\techo \"# Parent  $_z40\" &&\n+\t\tcat msg &&\n+\t\techo &&\n+\t\techo \"Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\" &&\n+\t\techo &&\n+\t\tgit diff-tree --no-commit-id -p second\n+\t} >patch1-hg.eml &&\n \n \n \tsed -n -e \"3,\\$p\" msg >file &&\n@@ -236,6 +249,16 @@ test_expect_success 'am applies stgit series' '\n \ttest_cmp_rev second^ HEAD^\n '\n \n+test_expect_success 'am applies hg patch' '\n+\trm -fr .git/rebase-apply &&\n+\tgit checkout -f first &&\n+\tgit am patch1-hg.eml &&\n+\ttest_path_is_missing .git/rebase-apply &&\n+\tgit diff --exit-code second &&\n+\ttest_cmp_rev second HEAD &&\n+\ttest_cmp_rev second^ HEAD^\n+'\n+\n test_expect_success 'setup: new author and committer' '\n \tGIT_AUTHOR_NAME=\"Another Thor\" &&\n \tGIT_AUTHOR_EMAIL=\"a.thor@example.com\" &&\n-- \n2.1.4\n"},{"id":"263852","messageId":"1434366493-27155-6-git-send-email-pyokagan@gmail.com","threadId":"39631","inReplyTo":"1434366493-27155-1-git-send-email-pyokagan@gmail.com","subject":"[PATCH v2 5/5] am: teach mercurial patch parser how to read from stdin","fromName":"Paul Tan","fromEmail":"pyokagan@gmail.com","sentAt":"2015-06-15T11:08:13Z","receivedAt":"2015-06-15T11:08:13Z","isPatch":true,"sender":{"key":"pyokagan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/109479?v=4"},"body":"git-mailsplit, which splits mbox patches, will read the patch from stdin\nwhen the filename is \"-\" or there are no files listed on the\ncommand-line.\n\nTo be consistent with this behavior, teach the mercurial patch parser to\nread from stdin if the filename is \"-\" or no files are listed on the\ncommand-line.\n\nBased-on-patch-by: Chris Packham <judge.packham@gmail.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Paul Tan <pyokagan@gmail.com>\n---\n\nNotes:\n    v2\n    \n    * Pass the filename directly to perl instead.\n\n git-am.sh     |  3 ++-\n t/t4150-am.sh | 10 ++++++++++\n 2 files changed, 12 insertions(+), 1 deletion(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex f0b6c16..a8d33ef 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -327,6 +327,7 @@ split_patches () {\n \t\t;;\n \thg)\n \t\tthis=0\n+\t\ttest 0 -eq \"$#\" && set -- -\n \t\tfor hg in \"$@\"\n \t\tdo\n \t\t\tthis=$(( $this + 1 ))\n@@ -353,7 +354,7 @@ split_patches () {\n \t\t\t\t\tprint \"\\n\", $_ ;\n \t\t\t\t\t$subject = 1;\n \t\t\t\t}\n-\t\t\t' <\"$hg\" >\"$dotest/$msgnum\" || clean_abort\n+\t\t\t' -- \"$hg\" >\"$dotest/$msgnum\" || clean_abort\n \t\tdone\n \t\techo \"$this\" >\"$dotest/last\"\n \t\tthis=\ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex 4beb4b3..3ebafd9 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -259,6 +259,16 @@ test_expect_success 'am applies hg patch' '\n \ttest_cmp_rev second^ HEAD^\n '\n \n+test_expect_success 'am --patch-format=hg applies hg patch' '\n+\trm -fr .git/rebase-apply &&\n+\tgit checkout -f first &&\n+\tgit am --patch-format=hg <patch1-hg.eml &&\n+\ttest_path_is_missing .git/rebase-apply &&\n+\tgit diff --exit-code second &&\n+\ttest_cmp_rev second HEAD &&\n+\ttest_cmp_rev second^ HEAD^\n+'\n+\n test_expect_success 'setup: new author and committer' '\n \tGIT_AUTHOR_NAME=\"Another Thor\" &&\n \tGIT_AUTHOR_EMAIL=\"a.thor@example.com\" &&\n-- \n2.1.4\n"},{"id":"263886","messageId":"xmqq7fr492yc.fsf@gitster.dls.corp.google.com","threadId":"39631","inReplyTo":"1434366493-27155-1-git-send-email-pyokagan@gmail.com","subject":"Re: [PATCH v2 0/5] am: improve test coverage and touch up foreign patch parsing","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-15T19:38:51Z","receivedAt":"2015-06-15T19:38:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This round looks good to me.\n\nThanks all.\n"}]}