{"thread":{"id":"13971","subject":"Bug with approxidate(\"never\")?","startedAt":"2008-06-15T23:20:44Z","lastAt":"2008-06-18T15:06:57Z","messageCount":3,"participants":["Olivier Marin","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"79992","messageId":"4855A3CC.2090701@free.fr","threadId":"13971","inReplyTo":null,"subject":"Bug with approxidate(\"never\")?","fromName":"Olivier Marin","fromEmail":"dkr+ml.git@free.fr","sentAt":"2008-06-15T23:20:44Z","receivedAt":"2008-06-15T23:20:44Z","isPatch":false,"sender":{"key":"dkr+ml.git@free.fr","avatar":null},"body":"Hi,\n\nWhile I was playing in the stash area and with \"reflog expire\" I was\nsurprised by the fact that \"never\" is not always never. For example,\napproxidate(\"never\") returns 4294960096 for my timezone (CET-2), it\nloops with all negative timezones.\n\nI fixed it by replacing date_never() with this one:\n\nstatic void date_never(struct tm *tm, int *num)\n{\n        time_t n = 0;\n        localtime_r(&n, tm);\n}\n\nbut I not sure this is the right fix. Better idea?\n\nIf you want to try yourself, the following test case should trigger\nthe problem.\n\ndiff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh\nindex 73f830d..b07d7bd 100755\n--- a/t/t1410-reflog.sh\n+++ b/t/t1410-reflog.sh\n@@ -158,6 +158,17 @@ test_expect_success 'reflog expire' '\n        check_fsck \"dangling commit $K\"\n '\n \n+test_expect_success 'reflog expire --expire=never' '\n+\n+       TZ=CET-2 &&\n+       git reflog expire --expire=never \\\n+               --stale-fix \\\n+               --all &&\n+\n+       loglen=$(wc -l <.git/logs/refs/heads/master) &&\n+       test $loglen = 2\n+'\n+\n test_expect_success 'prune and fsck' '\n \n        git prune &&\n"},{"id":"80151","messageId":"1213720497-9093-1-git-send-email-dkr+ml.git@free.fr","threadId":"13971","inReplyTo":"4855A3CC.2090701@free.fr","subject":"[PATCH] Fix approxidate(\"never\") to always return 0","fromName":"Olivier Marin","fromEmail":"dkr+ml.git@free.fr","sentAt":"2008-06-17T16:34:57Z","receivedAt":"2008-06-17T16:34:57Z","isPatch":true,"sender":{"key":"dkr+ml.git@free.fr","avatar":null},"body":"From: Olivier Marin <dkr@freesurf.fr>\n\nCommit af66366a9feb0194ed04b1f538998021ece268a8 introduced the keyword\n\"never\" to be used with approxidate() but defined it with a fixed date\nwithout taking care of timezone. As a result approxidate() will return\na timestamp in the future with a negative timezone.\n\nWith this patch, approxidate(\"never\") always return 0 whatever your\ntimezone is.\n\nAlso, print seconds since the Epoch in test-date.\n\nSigned-off-by: Olivier Marin <dkr@freesurf.fr>\n---\n\nWithout this patch:\n\n\t$ git --version\n\tgit version 1.5.6.rc3.156.g1a01 (next)\n\n\t$ mkdir /tmp/repo1 && cd /tmp/repo1 && git init\n\t$ echo A > A && git add A && git commit -m A\n\n\t$ git config gc.reflogexpire never\n\n\t$ TZ=UTC git reflog expire --dry-run --verbose HEAD\n\tkeep commit (initial): A\n\n\t$ TZ=UTC-2 git reflog expire --dry-run --verbose HEAD\n\twould prune commit (initial): A\n\nThis test does not trigger the problem with Junio's \"Per-ref reflog expiry\nconfiguration\" patch because it explicitly tests for \"never\" without relying\non approxidate() but the bug still remains with --expire option and in date.c\n\nThis make me thinking about TZ=UTC forced into t/test-lib.sh. Should not\ntest cases to be independant of the timezone?\n\n date.c      |    6 ++----\n test-date.c |    2 +-\n 2 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/date.c b/date.c\nindex a74ed86..1a4eb87 100644\n--- a/date.c\n+++ b/date.c\n@@ -682,10 +682,8 @@ static void date_am(struct tm *tm, int *num)\n \n static void date_never(struct tm *tm, int *num)\n {\n-\ttm->tm_mon = tm->tm_wday = tm->tm_yday\n-\t\t= tm->tm_hour = tm->tm_min = tm->tm_sec = 0;\n-\ttm->tm_year = 70;\n-\ttm->tm_mday = 1;\n+\ttime_t n = 0;\n+\tlocaltime_r(&n, tm);\n }\n \n static const struct special {\ndiff --git a/test-date.c b/test-date.c\nindex 62e8f23..b84e000 100644\n--- a/test-date.c\n+++ b/test-date.c\n@@ -14,7 +14,7 @@ int main(int argc, char **argv)\n \t\tprintf(\"%s -> %s -> %s\", argv[i], result, ctime(&t));\n \n \t\tt = approxidate(argv[i]);\n-\t\tprintf(\"%s -> %s\\n\", argv[i], ctime(&t));\n+\t\tprintf(\"%s -> %lu -> %s\\n\", argv[i], t, ctime(&t));\n \t}\n \treturn 0;\n }\n-- \n1.5.6.rc3.204.gf01a.dirty\n"},{"id":"80222","messageId":"alpine.DEB.1.00.0806181550190.6439@racer","threadId":"13971","inReplyTo":"1213720497-9093-1-git-send-email-dkr+ml.git@free.fr","subject":"Re: [PATCH] Fix approxidate(\"never\") to always return 0","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-06-18T15:06:57Z","receivedAt":"2008-06-18T15:06:57Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 17 Jun 2008, Olivier Marin wrote:\n\n> diff --git a/date.c b/date.c\n> index a74ed86..1a4eb87 100644\n> --- a/date.c\n> +++ b/date.c\n> @@ -682,10 +682,8 @@ static void date_am(struct tm *tm, int *num)\n>  \n>  static void date_never(struct tm *tm, int *num)\n>  {\n> -\ttm->tm_mon = tm->tm_wday = tm->tm_yday\n> -\t\t= tm->tm_hour = tm->tm_min = tm->tm_sec = 0;\n> -\ttm->tm_year = 70;\n> -\ttm->tm_mday = 1;\n> +\ttime_t n = 0;\n> +\tlocaltime_r(&n, tm);\n\nI would have reused local_tzoffset() and been explicit about the used \ndate, but your version is shorter.\n\nCiao,\nDscho\n"}]}