[PATCH] Fix approxidate("never") to always return 0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Olivier Marin <dkr@xxxxxxxxxxx>

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@xxxxxxxxxxx>
---

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux