git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Olivier Marin <dkr+ml.git@free.fr>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Git Mailing List <git@vger.kernel.org>,
	Olivier Marin <dkr@freesurf.fr>
Subject: [PATCH] Fix approxidate("never") to always return 0
Date: Tue, 17 Jun 2008 18:34:57 +0200	[thread overview]
Message-ID: <1213720497-9093-1-git-send-email-dkr+ml.git@free.fr> (raw)
In-Reply-To: <4855A3CC.2090701@free.fr>

From: Olivier Marin <dkr@freesurf.fr>

Commit af66366a9feb0194ed04b1f538998021ece268a8 introduced the keyword
"never" to be used with approxidate() but defined it with a fixed date
without taking care of timezone. As a result approxidate() will return
a timestamp in the future with a negative timezone.

With this patch, approxidate("never") always return 0 whatever your
timezone is.

Also, print seconds since the Epoch in test-date.

Signed-off-by: Olivier Marin <dkr@freesurf.fr>
---

Without this patch:

	$ git --version
	git version 1.5.6.rc3.156.g1a01 (next)

	$ mkdir /tmp/repo1 && cd /tmp/repo1 && git init
	$ echo A > A && git add A && git commit -m A

	$ git config gc.reflogexpire never

	$ TZ=UTC git reflog expire --dry-run --verbose HEAD
	keep commit (initial): A

	$ TZ=UTC-2 git reflog expire --dry-run --verbose HEAD
	would prune commit (initial): A

This test does not trigger the problem with Junio's "Per-ref reflog expiry
configuration" patch because it explicitly tests for "never" without relying
on approxidate() but the bug still remains with --expire option and in date.c

This make me thinking about TZ=UTC forced into t/test-lib.sh. Should not
test cases to be independant of the timezone?

 date.c      |    6 ++----
 test-date.c |    2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/date.c b/date.c
index a74ed86..1a4eb87 100644
--- a/date.c
+++ b/date.c
@@ -682,10 +682,8 @@ static void date_am(struct tm *tm, int *num)
 
 static void date_never(struct tm *tm, int *num)
 {
-	tm->tm_mon = tm->tm_wday = tm->tm_yday
-		= tm->tm_hour = tm->tm_min = tm->tm_sec = 0;
-	tm->tm_year = 70;
-	tm->tm_mday = 1;
+	time_t n = 0;
+	localtime_r(&n, tm);
 }
 
 static const struct special {
diff --git a/test-date.c b/test-date.c
index 62e8f23..b84e000 100644
--- a/test-date.c
+++ b/test-date.c
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
 		printf("%s -> %s -> %s", argv[i], result, ctime(&t));
 
 		t = approxidate(argv[i]);
-		printf("%s -> %s\n", argv[i], ctime(&t));
+		printf("%s -> %lu -> %s\n", argv[i], t, ctime(&t));
 	}
 	return 0;
 }
-- 
1.5.6.rc3.204.gf01a.dirty

  reply	other threads:[~2008-06-17 16:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-15 23:20 Bug with approxidate("never")? Olivier Marin
2008-06-17 16:34 ` Olivier Marin [this message]
2008-06-18 15:06   ` [PATCH] Fix approxidate("never") to always return 0 Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1213720497-9093-1-git-send-email-dkr+ml.git@free.fr \
    --to=dkr+ml.git@free.fr \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=dkr@freesurf.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).