From 1aeb7e756c82d31e46712ec7557c4cbae37dccd9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Apr 2017 12:45:44 +0200 Subject: parse_timestamp(): specify explicitly where we parse timestamps Currently, Git's source code represents all timestamps as `unsigned long`. In preparation for using a more appropriate data type, let's introduce a symbol `parse_timestamp` (currently being defined to `strtoul`) where appropriate, so that we can later easily switch to, say, use `strtoull()` instead. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-compat-util.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index 8a4a3f85e..fc1b5fe1a 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -319,6 +319,8 @@ extern char *gitdirname(char *); #define PRIo32 "o" #endif +#define parse_timestamp strtoul + #ifndef PATH_SEP #define PATH_SEP ':' #endif -- cgit v1.2.1 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 --- git-compat-util.h | 1 + 1 file changed, 1 insertion(+) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index fc1b5fe1a..cd522903e 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -319,6 +319,7 @@ extern char *gitdirname(char *); #define PRIo32 "o" #endif +#define PRItime "lu" #define parse_timestamp strtoul #ifndef PATH_SEP -- cgit v1.2.1 From dddbad728c93280fe54ef86699b6d70e2aab44d1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Apr 2017 21:29:31 +0200 Subject: timestamp_t: a new data type for timestamps Git's source code assumes that unsigned long is at least as precise as time_t. Which is incorrect, and causes a lot of problems, in particular where unsigned long is only 32-bit (notably on Windows, even in 64-bit versions). So let's just use a more appropriate data type instead. In preparation for this, we introduce the new `timestamp_t` data type. By necessity, this is a very, very large patch, as it has to replace all timestamps' data type in one go. As we will use a data type that is not necessarily identical to `time_t`, we need to be very careful to use `time_t` whenever we interact with the system functions, and `timestamp_t` everywhere else. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-compat-util.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index cd522903e..72c12173a 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -319,8 +319,10 @@ extern char *gitdirname(char *); #define PRIo32 "o" #endif +typedef unsigned long timestamp_t; #define PRItime "lu" #define parse_timestamp strtoul +#define TIME_MAX ULONG_MAX #ifndef PATH_SEP #define PATH_SEP ':' -- cgit v1.2.1 From 28f4aee3fb1a45ebcda8ff84f94d6d2d0053f887 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Apr 2017 21:29:42 +0200 Subject: use uintmax_t for timestamps Previously, we used `unsigned long` for timestamps. This was only a good choice on Linux, where we know implicitly that `unsigned long` is what is used for `time_t`. However, we want to use a different data type for timestamps for two reasons: - there is nothing that says that `unsigned long` should be the same data type as `time_t`, and indeed, on 64-bit Windows for example, it is not: `unsigned long` is 32-bit but `time_t` is 64-bit. - even on 32-bit Linux, where `unsigned long` (and thereby `time_t`) is 32-bit, we *want* to be able to encode timestamps in Git that are currently absurdly far in the future, *even if* the system library is not able to format those timestamps into date strings. So let's just switch to the maximal integer type available, which should be at least 64-bit for all practical purposes these days. It certainly cannot be worse than `unsigned long`, so... Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-compat-util.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index 72c12173a..f8349a03b 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -319,10 +319,10 @@ extern char *gitdirname(char *); #define PRIo32 "o" #endif -typedef unsigned long timestamp_t; -#define PRItime "lu" -#define parse_timestamp strtoul -#define TIME_MAX ULONG_MAX +typedef uintmax_t timestamp_t; +#define PRItime PRIuMAX +#define parse_timestamp strtoumax +#define TIME_MAX UINTMAX_MAX #ifndef PATH_SEP #define PATH_SEP ':' -- cgit v1.2.1