{"thread":{"id":"31509","subject":"Ambiguous date handling","startedAt":"2012-09-12T09:35:50Z","lastAt":"2012-09-12T16:58:20Z","messageCount":5,"participants":["Chris Packham","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"198820","messageId":"1347442551-7105-1-git-send-email-judge.packham@gmail.com","threadId":"31509","inReplyTo":null,"subject":"Ambiguous date handling","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2012-09-12T09:35:50Z","receivedAt":"2012-09-12T09:35:50Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"Hi,\n\nI think this has come up before [1],[2] but we ran into this at $dayjob today.\nOur default MUA has an annoying habit of using a non RFC822 date format when\nsaving an email as plaintext. This means the first 12 days of every month we\nrun into the ambiguous date problem (our date convention is dd/mm/yy).\n\nI see code in date.c for refusing a date in the future which would have caught\nthis but it doesn't appear to be working for us.\n\nFollowing this is a patch adding a testcase for this. With the following\nresults:\n\n  ok 1 - apply patch with ambiguous date\n  not ok 2 - check ambiguous date # TODO known breakage\n  ok 3 - apply patch with european date separator\n  ok 4 - check european date\n  # still have 1 known breakage(s)\n  # passed all remaining 3 test(s)\n  1..4\n\nThanks,\nChris\n\n--\n[1] - http://thread.gmane.org/gmane.comp.version-control.git/18412/focus=18417\n[2] - http://thread.gmane.org/gmane.comp.version-control.git/84512/focus=85735\n"},{"id":"198821","messageId":"1347442551-7105-2-git-send-email-judge.packham@gmail.com","threadId":"31509","inReplyTo":"1347442551-7105-1-git-send-email-judge.packham@gmail.com","subject":"[PATCH] Add test for ambiguous patch dates","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2012-09-12T09:35:51Z","receivedAt":"2012-09-12T09:35:51Z","isPatch":true,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"--\nThis testcase is only good for the next couple of months. For a longer term\ntest the current time would need to be set in the test setup.\n\n---\n t/t4255-am-author-date.sh |   85 +++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 85 insertions(+)\n create mode 100755 t/t4255-am-author-date.sh\n\ndiff --git a/t/t4255-am-author-date.sh b/t/t4255-am-author-date.sh\nnew file mode 100755\nindex 0000000..62bceee\n--- /dev/null\n+++ b/t/t4255-am-author-date.sh\n@@ -0,0 +1,85 @@\n+#!/bin/sh\n+\n+test_description='git am with ambiguous date'\n+. ./test-lib.sh\n+\n+cat >patch.diff <<EOF\n+From:   A U Thor <au.thor@example.com>\n+To:     C O Mmitter <co.mmitter@example.com>\n+Date:   12/9/2012 12:00 AM\n+Subject:       [PATCH] add file.txt\n+---\n+ file.txt |    7 +++++++\n+ 1 file changed, 7 insertions(+)\n+ create mode 100644 file.txt\n+\n+diff --git a/file.txt b/file.txt\n+new file mode 100644\n+index 0000000..fe745d6\n+--- /dev/null\n++++ b/file.txt\n+@@ -0,0 +1,7 @@\n++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam pulvinar\n++tempus ligula vitae ornare. Vestibulum ante ipsum primis in faucibus orci\n++luctus et ultrices posuere cubilia Curae; Aenean dapibus mauris non quam\n++commodo a porta sapien suscipit. Mauris venenatis, dui nec malesuada mattis,\n++ante mauris ornare ipsum, ac tincidunt ipsum lectus aliquet tortor. Nulla ipsum\n++felis, egestas at condimentum quis, accumsan nec arcu. Phasellus fringilla\n++viverra tempus. Integer vel rhoncus odio.\n+EOF\n+\n+test_expect_success 'apply patch with ambiguous date' '\n+\tgit am patch.diff\n+'\n+\n+cat >expected <<EOF\n+Date:   Wed Sep 12 00:00:00 2012 +0000\n+EOF\n+\n+test_expect_failure 'check ambiguous date' '\n+\tgit show HEAD | grep Date >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+cat >patch.diff <<EOF\n+From:   A N Other <an.other@example.com>\n+To:     C O Mmitter <co.mmitter@example.com>\n+Date:   12.9.2012 12:00 AM\n+Subject:       [PATCH] update file.txt\n+---\n+ file.txt |    9 +++++++++\n+ 1 file changed, 9 insertions(+)\n+\n+diff --git a/file.txt b/file.txt\n+index fe745d6..cd45361 100644\n+--- a/file.txt\n++++ b/file.txt\n+@@ -5,3 +5,12 @@ commodo a porta sapien suscipit. Mauris venenatis, dui nec malesuada mattis,\n+ ante mauris ornare ipsum, ac tincidunt ipsum lectus aliquet tortor. Nulla ipsum\n+ felis, egestas at condimentum quis, accumsan nec arcu. Phasellus fringilla\n+ viverra tempus. Integer vel rhoncus odio.\n++\n++Donec et ante eu mi aliquam sodales non ut massa. Nullam a luctus dui. Etiam ac\n++eros elit. Pellentesque habitant morbi tristique senectus et netus et malesuada\n++fames ac turpis egestas. Curabitur commodo ligula id leo iaculis vel lobortis\n++leo pulvinar. Aenean adipiscing cursus arcu quis consectetur. Morbi eget lectus\n++nec neque interdum lacinia. Nam quis metus eget ligula faucibus imperdiet in et\n++ligula. Aenean eu urna sit amet metus sagittis interdum non cursus orci.\n++Maecenas imperdiet feugiat tellus, non ultrices nulla dictum sed. Nulla vel\n++lorem ac massa euismod faucibus et ut leo.\n+EOF\n+\n+test_expect_success 'apply patch with european date separator' '\n+\tgit am patch.diff\n+'\n+\n+cat >expected <<EOF\n+Date:   Wed Sep 12 00:00:00 2012 +0000\n+EOF\n+\n+test_expect_success 'check european date' '\n+\tgit show HEAD | grep Date >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_done\n-- \n1.7.10.4\n"},{"id":"198822","messageId":"7v4nn3fu6s.fsf@alter.siamese.dyndns.org","threadId":"31509","inReplyTo":"1347442551-7105-1-git-send-email-judge.packham@gmail.com","subject":"Re: Ambiguous date handling","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-09-12T09:48:27Z","receivedAt":"2012-09-12T09:48:27Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chris Packham <judge.packham@gmail.com> writes:\n\n> Our default MUA has an annoying habit of using a non RFC822 date format when\n> saving an email as plaintext. This means the first 12 days of every month we\n> run into the ambiguous date problem (our date convention is dd/mm/yy).\n>\n> I see code in date.c for refusing a date in the future which would have caught\n> this...\n\nThe most sane thing to do when you know that your MUA *consistently*\ndoes dd/mm/yy (even though it may annoy you) is to massage its\noutput before feeding it to Git.  And it should be a very simple\nmatter of a one-liner filter, no?\n\nRegardless of the correctness of that \"we reject timestamps way into\nthe future\" logic, it should be taken as the last resort.  If you\nare on September 1st, both 9/12 and 12/9 will look like into the\nfuture for more than ten days (which is the cut-off, I think).  If\nyou are on December 28th, both look like sufficiently in the past.\n"},{"id":"198825","messageId":"50505F61.8040100@gmail.com","threadId":"31509","inReplyTo":"7v4nn3fu6s.fsf@alter.siamese.dyndns.org","subject":"Re: Ambiguous date handling","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2012-09-12T10:09:37Z","receivedAt":"2012-09-12T10:09:37Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"On 09/12/2012 09:48 PM, Junio C Hamano wrote:\n> Chris Packham <judge.packham@gmail.com> writes:\n> \n>> Our default MUA has an annoying habit of using a non RFC822 date format when\n>> saving an email as plaintext. This means the first 12 days of every month we\n>> run into the ambiguous date problem (our date convention is dd/mm/yy).\n>>\n>> I see code in date.c for refusing a date in the future which would have caught\n>> this...\n> \n> The most sane thing to do when you know that your MUA *consistently*\n> does dd/mm/yy (even though it may annoy you) is to massage its\n> output before feeding it to Git.  And it should be a very simple\n> matter of a one-liner filter, no?\n\nConsistent as long as you save as the default .txt. Some people have\ntrained themselves to use the save as .eml option which uses RFC822\nstyle output. sed 's|Date: (\\d+)/(\\d+)/(\\d+)|\\1.\\2.\\3|' should correct\nthe former and ignore the latter. Could this be done in a applypatch-msg\nhook?\n\n> \n> Regardless of the correctness of that \"we reject timestamps way into\n> the future\" logic, it should be taken as the last resort.  If you\n> are on September 1st, both 9/12 and 12/9 will look like into the\n> future for more than ten days (which is the cut-off, I think).  If\n> you are on December 28th, both look like sufficiently in the past.\n> \n\nDuly noted. And I'm implying that the reject timestamps in future isn't\nactually working. I've just started looking at t0006-date.sh so see if I\ncan prove it.\n"},{"id":"198853","messageId":"7vligfdvpv.fsf@alter.siamese.dyndns.org","threadId":"31509","inReplyTo":"50505F61.8040100@gmail.com","subject":"Re: Ambiguous date handling","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-09-12T16:58:20Z","receivedAt":"2012-09-12T16:58:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chris Packham <judge.packham@gmail.com> writes:\n\n> Consistent as long as you save as the default .txt. Some people have\n> trained themselves to use the save as .eml option which uses RFC822\n> style output.\n\nYuck.\n\n> Could this be done in a applypatch-msg\n> hook?\n\nIsn't the hook about fixing up the log message?  Also I do not think\nthe name of the original file is given to the hook, so there is no\nsufficient information to allow it to switch between two behaviours\nbased on .txt or .eml.\n\nBut if you are massaging the _input_ to \"git am\", then you can\ncertainly do the massaging even _before_ you feed it to \"git am\", no?\n\nWe could think about adding a new hook to \"git am\", though.  It\ncannot just be an option to \"git am\" (or \"git mailinfo\") that says\n\"if the input is .txt, assume European date order for \\d+/\\d+/\\d+\ndates, and otherwise assume US style\", as that is too specific to\nyour particular set-up and will not match general needs.  If we were\nto add such a hook, $GIT_DIR/hooks/am-input-filter might look\nsomething like this (it is left as an exercise to enhance it to\navoid munging a payload outside the header that happens to begin\nwith \"Date: \"):\n\n\t#!/bin/sh\n        case \"$#\" in\n\t0)\n\t\tcat\n        \t;;\n\t*)\n        \tfor i\n                do\n                \tcase \"$i\" in\n\t\t        *.txt)\n\t\t\t\tsed -e 's/^\\(Date: \\)(\\d+/)(\\d+/)(\\d+)/\\1\\3\\2\\4/' \"$i\"\n\t\t\t\t;;\n\t\t\t*)\n                        \tcat \"$i\"\n\t\t\t\t;;\n\t\t\tesac\n\t\tdone\n                ;;\n\tesac\n\nand then teach \"am\" to use the hook, perhaps like the attached.\n\nBut at that point, wouldn't it be far simpler and cleaner if you did\n\n\t$ my-mbox-munge mail.txt | git am\n\nin the first place?\n\n git-am.sh | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git i/git-am.sh w/git-am.sh\nindex c682d34..42654a0 100755\n--- i/git-am.sh\n+++ w/git-am.sh\n@@ -265,7 +265,16 @@ split_patches () {\n \t\telse\n \t\t    keep_cr=\n \t\tfi\n-\t\tgit mailsplit -d\"$prec\" -o\"$dotest\" -b $keep_cr -- \"$@\" > \"$dotest/last\" ||\n+\n+\t\tif test -x \"$GIT_DIR\"/hooks/am-input-filter\n+\t\tthen\n+\t\t\tmif=\"$GIT_DIR\"/hooks/am-input-filter\n+\t\telse\n+\t\t\tmif=cat\n+\t\tfi\n+\n+\t\t\"$mif\" \"$@\" |\n+\t\tgit mailsplit -d\"$prec\" -o\"$dotest\" -b $keep_cr >\"$dotest/last\" ||\n \t\tclean_abort\n \t\t;;\n \tstgit-series)\n"}]}