{"thread":{"id":"28808","subject":"git rev-parse --since=1970-01-01 does not work reliably","startedAt":"2011-10-31T16:17:09Z","lastAt":"2011-11-04T00:36:28Z","messageCount":6,"participants":["Dmitry V. Levin","Nguyen Thai Ngoc Duy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"178565","messageId":"20111031161708.GA29924@altlinux.org","threadId":"28808","inReplyTo":null,"subject":"git rev-parse --since=1970-01-01 does not work reliably","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2011-10-31T16:17:09Z","receivedAt":"2011-10-31T16:17:09Z","isPatch":false,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"Hi,\n\ngit rev-parse --since=1970-01-01 (and other git commands that take\ndate string arguments like --since) may fail when --since=1970-01-01 is\ngiven.  Whether it fails or not depends on current time and timezone data.\nFor example, \"TZ=Europe/Paris git rev-parse --since=1970-01-01\" fails two\nhours a day (between 00:00 and 02:00 CET), and those who use more eastern\ntimezones are even less lucky.  In artificial timezones like UTC-24 it\nalways fails:\n\n$ TZ=UTC-24 git rev-parse --since=1970-01-01\n--max-age=18446744073709523490\n\nThe problem is that several internal git functions implicitly convert\ntime_t to unsigned long, so when time_t gets negative, all date string\nprocessing breaks.\n\n\n-- \nldv\n"},{"id":"178602","messageId":"20111031231320.GA3857@do","threadId":"28808","inReplyTo":"20111031161708.GA29924@altlinux.org","subject":"Re: git rev-parse --since=1970-01-01 does not work reliably","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-10-31T23:13:20Z","receivedAt":"2011-10-31T23:13:20Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Oct 31, 2011 at 08:17:09PM +0400, Dmitry V. Levin wrote:\n> Hi,\n> \n> git rev-parse --since=1970-01-01 (and other git commands that take\n> date string arguments like --since) may fail when --since=1970-01-01 is\n> given.  Whether it fails or not depends on current time and timezone data.\n> For example, \"TZ=Europe/Paris git rev-parse --since=1970-01-01\" fails two\n> hours a day (between 00:00 and 02:00 CET), and those who use more eastern\n> timezones are even less lucky.  In artificial timezones like UTC-24 it\n> always fails:\n> \n> $ TZ=UTC-24 git rev-parse --since=1970-01-01\n> --max-age=18446744073709523490\n\nOut of curiosity, why do you need to work with a time so close to that\ndate?\n\n> The problem is that several internal git functions implicitly convert\n> time_t to unsigned long, so when time_t gets negative, all date string\n> processing breaks.\n\nI don't think it's worth supporting negative time_t, but we should at\nleast avoid misconversion.\n\n-- 8< --\nSubject: [PATCH] Do not accept negative time_t\n\nWe use unsigned long internally to present time, negative value just\nbreaks thing.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n date.c |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/date.c b/date.c\nindex 353e0a5..9cbd521 100644\n--- a/date.c\n+++ b/date.c\n@@ -653,8 +653,12 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)\n \tif (*timestamp == -1)\n \t\treturn -1;\n \n-\tif (!tm_gmt)\n+\tif (!tm_gmt) {\n+\t\tif ((time_t)*timestamp < (time_t)*offset * 60)\n+\t\t\tdie(\"unsupported time before Epoch\");\n \t\t*timestamp -= *offset * 60;\n+\t}\n+\n \treturn 0; /* success */\n }\n \n@@ -722,6 +726,8 @@ static unsigned long update_tm(struct tm *tm, struct tm *now, unsigned long sec)\n \n \tn = mktime(tm) - sec;\n \tlocaltime_r(&n, tm);\n+\tif (n < 0)\n+\t\tdie(\"unsupported time before Epoch\");\n \treturn n;\n }\n \n-- \n1.7.4.74.g639db\n-- 8< --\n"},{"id":"178622","messageId":"20111101124434.GB22229@altlinux.org","threadId":"28808","inReplyTo":"20111031231320.GA3857@do","subject":"Re: git rev-parse --since=1970-01-01 does not work reliably","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2011-11-01T12:44:34Z","receivedAt":"2011-11-01T12:44:34Z","isPatch":false,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"On Tue, Nov 01, 2011 at 06:13:20AM +0700, Nguyen Thai Ngoc Duy wrote:\n> On Mon, Oct 31, 2011 at 08:17:09PM +0400, Dmitry V. Levin wrote:\n> > \n> > git rev-parse --since=1970-01-01 (and other git commands that take\n> > date string arguments like --since) may fail when --since=1970-01-01 is\n> > given.  Whether it fails or not depends on current time and timezone data.\n> > For example, \"TZ=Europe/Paris git rev-parse --since=1970-01-01\" fails two\n> > hours a day (between 00:00 and 02:00 CET), and those who use more eastern\n> > timezones are even less lucky.  In artificial timezones like UTC-24 it\n> > always fails:\n> > \n> > $ TZ=UTC-24 git rev-parse --since=1970-01-01\n> > --max-age=18446744073709523490\n> \n> Out of curiosity, why do you need to work with a time so close to that\n> date?\n\nThere is an utility that used to invoke \"git log --since='1970-01-01 UTC'\"\nby default, and I was unlucky enough to use it during these hours of\nfailure.  The utility is now fixed (it no longer calls git log with\n--since option unless explicitly instructed to do so), and I hope git\nis going to be fixed as well.\n\nBTW, the timezone specifier (UTC) in \"git rev-parse --since='1970-01-01 UTC'\"\nseems to be completely ignored by date string parser.\n\n\n-- \nldv\n"},{"id":"178770","messageId":"CACsJy8C8540-LVrGS_byAvPig2Kq9k2upkbd2psbBJ+Skjs1KA@mail.gmail.com","threadId":"28808","inReplyTo":"20111101124434.GB22229@altlinux.org","subject":"Re: git rev-parse --since=1970-01-01 does not work reliably","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-11-03T12:36:52Z","receivedAt":"2011-11-03T12:36:52Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2011/11/1 Dmitry V. Levin <ldv@altlinux.org>:\n> BTW, the timezone specifier (UTC) in \"git rev-parse --since='1970-01-01 UTC'\"\n> seems to be completely ignored by date string parser.\n\nIt takes this \"00:00 1970-01-01 UTC\"\n-- \nDuy\n"},{"id":"178804","messageId":"CACsJy8AewxbocqQ3gvgcrbSuNyKa0BCqDn6OV31m_6-P1AxJCA@mail.gmail.com","threadId":"28808","inReplyTo":"20111031231320.GA3857@do","subject":"Re: git rev-parse --since=1970-01-01 does not work reliably","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-11-03T23:37:12Z","receivedAt":"2011-11-03T23:37:12Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2011/11/1 Nguyen Thai Ngoc Duy <pclouds@gmail.com>:\n> Subject: [PATCH] Do not accept negative time_t\n>\n> We use unsigned long internally to present time, negative value just\n> breaks thing.\n\nJunio, what do you think about this patch?\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  date.c |    8 +++++++-\n>  1 files changed, 7 insertions(+), 1 deletions(-)\n>\n> diff --git a/date.c b/date.c\n> index 353e0a5..9cbd521 100644\n> --- a/date.c\n> +++ b/date.c\n> @@ -653,8 +653,12 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)\n>        if (*timestamp == -1)\n>                return -1;\n>\n> -       if (!tm_gmt)\n> +       if (!tm_gmt) {\n> +               if ((time_t)*timestamp < (time_t)*offset * 60)\n> +                       die(\"unsupported time before Epoch\");\n>                *timestamp -= *offset * 60;\n> +       }\n> +\n>        return 0; /* success */\n>  }\n>\n> @@ -722,6 +726,8 @@ static unsigned long update_tm(struct tm *tm, struct tm *now, unsigned long sec)\n>\n>        n = mktime(tm) - sec;\n>        localtime_r(&n, tm);\n> +       if (n < 0)\n> +               die(\"unsupported time before Epoch\");\n>        return n;\n>  }\n>\n> --\n> 1.7.4.74.g639db\n> -- 8< --\n>\n\n\n\n-- \nDuy\n"},{"id":"178805","messageId":"7v39e4enar.fsf@alter.siamese.dyndns.org","threadId":"28808","inReplyTo":"CACsJy8AewxbocqQ3gvgcrbSuNyKa0BCqDn6OV31m_6-P1AxJCA@mail.gmail.com","subject":"Re: git rev-parse --since=1970-01-01 does not work reliably","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-11-04T00:36:28Z","receivedAt":"2011-11-04T00:36:28Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n> 2011/11/1 Nguyen Thai Ngoc Duy <pclouds@gmail.com>:\n>> Subject: [PATCH] Do not accept negative time_t\n>>\n>> We use unsigned long internally to present time, negative value just\n>> breaks thing.\n>\n> Junio, what do you think about this patch?\n\nAt this late point in the release cycle, the topic itself is a Meh for me,\nespecially when other discussions for next cycle occupies my attention.\n"}]}