From cb71f8bdb5a105cd5b66142b887989d9addc82d0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Apr 2017 12:45:48 +0200 Subject: PRItime: introduce a new "printf format" for timestamps Currently, Git's source code treats all timestamps as if they were unsigned longs. Therefore, it is okay to write "%lu" when printing them. There is a substantial problem with that, though: at least on Windows, time_t is *larger* than unsigned long, and hence we will want to switch away from the ill-specified `unsigned long` data type. So let's introduce the pseudo format "PRItime" (currently simply being defined to "lu") to make it easier to change the data type used for timestamps. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/helper/test-date.c | 2 +- t/helper/test-parse-options.c | 2 +- t/helper/test-ref-store.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 't/helper') diff --git a/t/helper/test-date.c b/t/helper/test-date.c index 52d1fc3445..269040f028 100644 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@ -53,7 +53,7 @@ static void parse_dates(const char **argv, struct timeval *now) strbuf_reset(&result); parse_date(*argv, &result); - if (sscanf(result.buf, "%lu %d", &t, &tz) == 2) + if (sscanf(result.buf, "%"PRItime" %d", &t, &tz) == 2) printf("%s -> %s\n", *argv, show_date(t, tz, DATE_MODE(ISO8601))); else diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index a01430c24b..7d93627e45 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -161,7 +161,7 @@ int cmd_main(int argc, const char **argv) show(&expect, &ret, "boolean: %d", boolean); show(&expect, &ret, "integer: %d", integer); show(&expect, &ret, "magnitude: %lu", magnitude); - show(&expect, &ret, "timestamp: %lu", timestamp); + show(&expect, &ret, "timestamp: %"PRItime, timestamp); show(&expect, &ret, "string: %s", string ? string : "(not set)"); show(&expect, &ret, "abbrev: %d", abbrev); show(&expect, &ret, "verbose: %d", verbose); diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 2d84c45ffe..a436bfdb05 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -141,7 +141,7 @@ static int each_reflog(struct object_id *old_oid, struct object_id *new_oid, const char *committer, unsigned long timestamp, int tz, const char *msg, void *cb_data) { - printf("%s %s %s %lu %d %s\n", + printf("%s %s %s %"PRItime" %d %s\n", oid_to_hex(old_oid), oid_to_hex(new_oid), committer, timestamp, tz, msg); return 0; -- cgit v1.2.1