Use time_t
Subsystems (2)
PATCH v5 5/8 Introduce a new "printf format" for timestamps
In reply to Johannes SchindelinCurrently, 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.
--- builtin/blame.c | 6 +++--- builtin/fsck.c | 2 +- builtin/log.c | 2 +- builtin/receive-pack.c | 4 ++-- builtin/rev-list.c | 2 +- builtin/rev-parse.c | 2 +- date.c | 26 +++++++++++++------------- fetch-pack.c | 2 +- git-compat-util.h | 1 + refs/files-backend.c | 2 +- t/helper/test-date.c | 2 +- t/helper/test-parse-options.c | 2 +- t/helper/test-ref-store.c | 2 +- upload-pack.c | 2 +- vcs-svn/fast_export.c | 4 ++-- 15 files changed, 31 insertions(+), 30 deletions(-)
builtin/blame.c +3 -3
@@ -1727,11 +1727,11 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)get_commit_info (suspect->commit, &ci,1 );printf ("author %s\n" , ci.author.buf);printf ("author-mail %s\n" , ci.author_mail.buf); -printf ("author-time %lu\n" , ci.author_time); +printf ("author-time %" PRItime"\n" , ci.author_time);printf ("author-tz %s\n" , ci.author_tz.buf);printf ("committer %s\n" , ci.committer.buf);printf ("committer-mail %s\n" , ci.committer_mail.buf); -printf ("committer-time %lu\n" , ci.committer_time); +printf ("committer-time %" PRItime"\n" , ci.committer_time);printf ("committer-tz %s\n" , ci.committer_tz.buf);printf ("summary %s\n" , ci.summary.buf);if (suspect->commit->object.flags &UNINTERESTING )
@@ -1844,7 +1844,7 @@ static const char *format_time(unsigned long time, const char *tz_str,strbuf_reset (&time_buf);if (show_raw_time) { -strbuf_addf (&time_buf,"%lu %s" , time, tz_str); +strbuf_addf (&time_buf,"%" PRItime" %s" , time, tz_str); }else {const char *time_str;
builtin/fsck.c +1 -1
@@ -407,7 +407,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,if (timestamp && name_objects)add_decoration (fsck_walk_options.object_names, obj, -xstrfmt ("%s@{%ld}" , refname, timestamp)); +xstrfmt ("%s@{%" PRItime"}" , refname, timestamp)); obj->used =1 ;mark_object_reachable (obj); }else {
builtin/log.c +1 -1
@@ -910,7 +910,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)static void gen_message_id (struct rev_info *info,char *base) {struct strbuf buf =STRBUF_INIT ; -strbuf_addf (&buf,"%s.%lu.git.%s" , base, +strbuf_addf (&buf,"%s.%" PRItime".git.%s" , base, (unsigned long )time (NULL ),git_committer_info (IDENT_NO_NAME |IDENT_NO_DATE |IDENT_STRICT )); info->message_id =strbuf_detach (&buf,NULL );
builtin/receive-pack.c +2 -2
@@ -459,12 +459,12 @@ static char *prepare_push_cert_nonce(const char *path, unsigned long stamp)struct strbuf buf =STRBUF_INIT ;unsigned char sha1[20 ]; -strbuf_addf (&buf,"%s:%lu" , path, stamp); +strbuf_addf (&buf,"%s:%" PRItime, path, stamp);hmac_sha1 (sha1, buf.buf, buf.len, cert_nonce_seed,strlen (cert_nonce_seed));;strbuf_release (&buf);/* RFC 2104 5. HMAC-SHA1-80 */ -strbuf_addf (&buf,"%lu-%.*s" , stamp,20 ,sha1_to_hex (sha1)); +strbuf_addf (&buf,"%" PRItime"-%.*s" , stamp,20 ,sha1_to_hex (sha1));return strbuf_detach (&buf,NULL ); }
builtin/rev-list.c +1 -1
@@ -80,7 +80,7 @@ static void show_commit(struct commit *commit, void *data) }if (info->show_timestamp) -printf ("%lu " , commit->date); +printf ("%" PRItime" " , commit->date);if (info->header_prefix)fputs (info->header_prefix, stdout);
builtin/rev-parse.c +1 -1
@@ -218,7 +218,7 @@ static void show_datestring(const char *flag, const char *datestr)/* date handling requires both flags and revs */ if ((filter & (DO_FLAGS |DO_REVS )) != (DO_FLAGS |DO_REVS ))return ; - buffer =xstrfmt ("%s%lu" , flag,approxidate (datestr)); + buffer =xstrfmt ("%s%" PRItime, flag,approxidate (datestr));show (buffer);free (buffer); }
date.c +13 -13
@@ -100,41 +100,41 @@ void show_date_relative(unsigned long time, int tz, diff = now->tv_sec - time;if (diff <90 ) {strbuf_addf (timebuf, -Q_ ("%lu second ago" ,"%lu seconds ago" , diff), diff); +Q_ ("%" PRItime" second ago" ,"%" PRItime" seconds ago" , diff), diff);return ; }/* Turn it into minutes */ diff = (diff +30 ) /60 ;if (diff <90 ) {strbuf_addf (timebuf, -Q_ ("%lu minute ago" ,"%lu minutes ago" , diff), diff); +Q_ ("%" PRItime" minute ago" ,"%" PRItime" minutes ago" , diff), diff);return ; }/* Turn it into hours */ diff = (diff +30 ) /60 ;if (diff <36 ) {strbuf_addf (timebuf, -Q_ ("%lu hour ago" ,"%lu hours ago" , diff), diff); +Q_ ("%" PRItime" hour ago" ,"%" PRItime" hours ago" , diff), diff);return ; }/* We deal with number of days from here on */ diff = (diff +12 ) /24 ;if (diff <14 ) {strbuf_addf (timebuf, -Q_ ("%lu day ago" ,"%lu days ago" , diff), diff); +Q_ ("%" PRItime" day ago" ,"%" PRItime" days ago" , diff), diff);return ; }/* Say weeks for the past 10 weeks or so */ if (diff <70 ) {strbuf_addf (timebuf, -Q_ ("%lu week ago" ,"%lu weeks ago" , (diff +3 ) /7 ), +Q_ ("%" PRItime" week ago" ,"%" PRItime" weeks ago" , (diff +3 ) /7 ), (diff +3 ) /7 );return ; }/* Say months for the past 12 months or so */ if (diff <365 ) {strbuf_addf (timebuf, -Q_ ("%lu month ago" ,"%lu months ago" , (diff +15 ) /30 ), +Q_ ("%" PRItime" month ago" ,"%" PRItime" months ago" , (diff +15 ) /30 ), (diff +15 ) /30 );return ; }
@@ -145,20 +145,20 @@ void show_date_relative(unsigned long time, int tz,unsigned long months = totalmonths %12 ;if (months) {struct strbuf sb =STRBUF_INIT ; -strbuf_addf (&sb,Q_ ("%lu year" ,"%lu years" , years), years); +strbuf_addf (&sb,Q_ ("%" PRItime" year" ,"%" PRItime" years" , years), years);strbuf_addf (timebuf,/* TRANSLATORS: "%s" is "<n> years" */ -Q_ ("%s, %lu month ago" ,"%s, %lu months ago" , months), +Q_ ("%s, %" PRItime" month ago" ,"%s, %" PRItime" months ago" , months), sb.buf, months);strbuf_release (&sb); }else strbuf_addf (timebuf, -Q_ ("%lu year ago" ,"%lu years ago" , years), years); +Q_ ("%" PRItime" year ago" ,"%" PRItime" years ago" , years), years);return ; }/* Otherwise, just years. Centuries is probably overkill. */ strbuf_addf (timebuf, -Q_ ("%lu year ago" ,"%lu years ago" , (diff +183 ) /365 ), +Q_ ("%" PRItime" year ago" ,"%" PRItime" years ago" , (diff +183 ) /365 ), (diff +183 ) /365 ); }
@@ -179,7 +179,7 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)if (mode->type ==DATE_UNIX ) {strbuf_reset (&timebuf); -strbuf_addf (&timebuf,"%lu" , time); +strbuf_addf (&timebuf,"%" PRItime, time);return timebuf.buf; }
@@ -188,7 +188,7 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)if (mode->type ==DATE_RAW ) {strbuf_reset (&timebuf); -strbuf_addf (&timebuf,"%lu %+05d" , time, tz); +strbuf_addf (&timebuf,"%" PRItime" %+05d" , time, tz);return timebuf.buf; }
@@ -643,7 +643,7 @@ static void date_string(unsigned long date, int offset, struct strbuf *buf) offset = -offset; sign ='-' ; } -strbuf_addf (buf,"%lu %c%02d%02d" , date, sign, offset /60 , offset %60 ); +strbuf_addf (buf,"%" PRItime" %c%02d%02d" , date, sign, offset /60 , offset %60 ); }/*
fetch-pack.c +1 -1
@@ -395,7 +395,7 @@ static int find_common(struct fetch_pack_args *args,packet_buf_write (&req_buf,"deepen %d" , args->depth);if (args->deepen_since) {unsigned long max_age =approxidate (args->deepen_since); -packet_buf_write (&req_buf,"deepen-since %lu" , max_age); +packet_buf_write (&req_buf,"deepen-since %" PRItime, max_age); }if (args->deepen_not) {int i;
git-compat-util.h +1 -0
@@ -319,6 +319,7 @@ extern char *gitdirname(char *);#define PRIo32 "o"#endif +#define PRItime "lu"#define parse_timestamp strtoul#ifndef PATH_SEP
refs/files-backend.c +1 -1
@@ -4135,7 +4135,7 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,printf ("prune %s" , message); }else {if (cb->newlog) { -fprintf (cb->newlog,"%s %s %s %lu %+05d\t%s" , +fprintf (cb->newlog,"%s %s %s %" PRItime" %+05d\t%s" ,oid_to_hex (ooid),oid_to_hex (noid), email, timestamp, tz, message);oidcpy (&cb->last_kept_oid, noid);
t/helper/test-date.c +1 -1
@@ -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
t/helper/test-parse-options.c +1 -1
@@ -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);
t/helper/test-ref-store.c +1 -1
@@ -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 ;
upload-pack.c +1 -1
@@ -863,7 +863,7 @@ static void receive_needs(void)argv_array_push (&av,"rev-list" );if (deepen_since) -argv_array_pushf (&av,"--max-age=%lu" , deepen_since); +argv_array_pushf (&av,"--max-age=%" PRItime, deepen_since);if (deepen_not.nr) {argv_array_push (&av,"--not" );for (i =0 ; i < deepen_not.nr; i++) {
vcs-svn/fast_export.c +2 -2
@@ -73,7 +73,7 @@ void fast_export_begin_note(uint32_t revision, const char *author,static int firstnote =1 ;size_t loglen =strlen (log);printf ("commit %s\n" , note_ref); -printf ("committer %s <%s@%s> %lu +0000\n" , author, author,"local" , timestamp); +printf ("committer %s <%s@%s> %" PRItime" +0000\n" , author, author,"local" , timestamp);printf ("data %" PRIuMAX"\n" , (uintmax_t )loglen);fwrite (log, loglen,1 , stdout);if (firstnote) {
@@ -107,7 +107,7 @@ void fast_export_begin_commit(uint32_t revision, const char *author, }printf ("commit %s\n" , local_ref);printf ("mark :%" PRIu32"\n" , revision); -printf ("committer %s <%s@%s> %lu +0000\n" , +printf ("committer %s <%s@%s> %" PRItime" +0000\n" , *author ? author :"nobody" , *author ? author :"nobody" , *uuid ? uuid :"local" , timestamp);
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH v5 6/8 Introduce a new data type for timestamps
In reply to Johannes SchindelinGit'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.
--- Documentation/technical/api-parse-options.txt | 8 ++-- archive-tar.c | 5 +- archive-zip.c | 12 ++++- archive.h | 2 +- builtin/am.c | 2 +- builtin/blame.c | 8 ++-- builtin/fsck.c | 4 +- builtin/gc.c | 2 +- builtin/log.c | 2 +- builtin/merge-base.c | 2 +- builtin/name-rev.c | 6 +-- builtin/pack-objects.c | 4 +- builtin/prune.c | 4 +- builtin/receive-pack.c | 6 +-- builtin/reflog.c | 24 +++++----- builtin/show-branch.c | 4 +- builtin/worktree.c | 4 +- bundle.c | 2 +- cache.h | 14 +++--- commit.c | 12 ++--- commit.h | 2 +- config.c | 2 +- credential-cache--daemon.c | 12 ++--- date.c | 66 +++++++++++++-------------- fetch-pack.c | 6 +-- git-compat-util.h | 2 + http-backend.c | 4 +- parse-options-cb.c | 4 +- pretty.c | 2 +- reachable.c | 9 ++-- reachable.h | 4 +- ref-filter.c | 4 +- reflog-walk.c | 8 ++-- refs.c | 14 +++--- refs.h | 8 ++-- refs/files-backend.c | 4 +- revision.c | 6 +-- revision.h | 4 +- sha1_name.c | 6 +-- t/helper/test-date.c | 8 ++-- t/helper/test-parse-options.c | 2 +- t/helper/test-ref-store.c | 2 +- tag.c | 2 +- tag.h | 2 +- upload-pack.c | 4 +- vcs-svn/fast_export.c | 4 +- vcs-svn/fast_export.h | 4 +- vcs-svn/svndump.c | 2 +- wt-status.c | 2 +- 49 files changed, 169 insertions(+), 157 deletions(-)
Documentation/technical/api-parse-options.txt +4 -4
@@ -183,13 +183,13 @@ There are some macros to easily define options: scale the provided value by 1024, 1024^2 or 1024^3 respectively. The scaled value is put into `unsigned_long_var`. -`OPT_DATE(short, long, &int_var, description)`:: +`OPT_DATE(short, long, ×tamp_t_var, description)`:: Introduce an option with date argument, see `approxidate()`. - The timestamp is put into `int_var`. + The timestamp is put into `timestamp_t_var`. -`OPT_EXPIRY_DATE(short, long, &int_var, description)`:: +`OPT_EXPIRY_DATE(short, long, ×tamp_t_var, description)`:: Introduce an option with expiry date argument, see `parse_expiry_date()`. - The timestamp is put into `int_var`. + The timestamp is put into `timestamp_t_var`. `OPT_CALLBACK(short, long, &var, arg_str, description, func_ptr)`:: Introduce an option with argument.
archive-tar.c +4 -1
@@ -27,9 +27,12 @@ static int write_tar_filter_archive(const struct archiver *ar,*/ #if ULONG_MAX ==0xFFFFFFFF #define USTAR_MAX_SIZE ULONG_MAX -#define USTAR_MAX_MTIME ULONG_MAX#else #define USTAR_MAX_SIZE 077777777777UL +#endif +#if TIME_MAX ==0xFFFFFFFF +#define USTAR_MAX_MTIME TIME_MAX +#else #define USTAR_MAX_MTIME 077777777777UL#endif
archive-zip.c +10 -2
@@ -545,9 +545,17 @@ static void write_zip_trailer(const unsigned char *sha1)write_or_die (1 ,sha1_to_hex (sha1),GIT_SHA1_HEXSZ ); } -static void dos_time (time_t *time,int *dos_date,int *dos_time) +static void dos_time (timestamp_t *timestamp,int *dos_date,int *dos_time) { -struct tm *t =localtime (time); +time_t time; +struct tm *t; + +if (date_overflows (*timestamp)) +die ("timestamp too large for this system: %" PRItime, + *timestamp); + time = (time_t)*timestamp; + t =localtime (&time); + *timestamp = time; *dos_date = t->tm_mday + (t->tm_mon +1 ) *32 + (t->tm_year +1900 -1980 ) *512 ;
archive.h +1 -1
@@ -9,7 +9,7 @@ struct archiver_args {struct tree *tree;const unsigned char *commit_sha1;const struct commit *commit; -time_t time; +timestamp_t time;struct pathspec pathspec; unsigned int verbose : 1; unsigned int worktree_attributes : 1;
builtin/am.c +1 -1
@@ -881,7 +881,7 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)if (skip_prefix (sb.buf,"# User " , &str))fprintf (out,"From: %s\n" , str);else if (skip_prefix (sb.buf,"# Date " , &str)) { -unsigned long timestamp; +timestamp_t timestamp;long tz, tz2;char *end;
builtin/blame.c +4 -4
@@ -1561,13 +1561,13 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)struct commit_info {struct strbuf author;struct strbuf author_mail; -unsigned long author_time; +timestamp_t author_time;struct strbuf author_tz;/* filled only when asked for details */ struct strbuf committer;struct strbuf committer_mail; -unsigned long committer_time; +timestamp_t committer_time;struct strbuf committer_tz;struct strbuf summary;
@@ -1578,7 +1578,7 @@ struct commit_info {*/ static void get_ac_line (const char *inbuf,const char *what,struct strbuf *name,struct strbuf *mail, -unsigned long *time,struct strbuf *tz) +timestamp_t *time,struct strbuf *tz) {struct ident_split ident;size_t len, maillen, namelen;
@@ -1837,7 +1837,7 @@ static void assign_blame(struct scoreboard *sb, int opt)stop_progress (&pi.progress); } -static const char *format_time (unsigned long time,const char *tz_str, +static const char *format_time (timestamp_t time,const char *tz_str,int show_raw_time) {static struct strbuf time_buf =STRBUF_INIT ;
builtin/fsck.c +2 -2
@@ -397,7 +397,7 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,static int default_refs;static void fsck_handle_reflog_oid (const char *refname,struct object_id *oid, -unsigned long timestamp) +timestamp_t timestamp) {struct object *obj;
@@ -418,7 +418,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, }static int fsck_handle_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {const char *refname = cb_data;
builtin/gc.c +1 -1
@@ -33,7 +33,7 @@ static int aggressive_window = 250;static int gc_auto_threshold =6700 ;static int gc_auto_pack_limit =50 ;static int detach_auto =1 ; -static unsigned long gc_log_expire_time; +static timestamp_t gc_log_expire_time;static const char *gc_log_expire ="1.day.ago" ;static const char *prune_expire ="2.weeks.ago" ;static const char *prune_worktrees_expire ="3.months.ago" ;
builtin/log.c +1 -1
@@ -911,7 +911,7 @@ static void gen_message_id(struct rev_info *info, char *base) {struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"%s.%" PRItime".git.%s" , base, - (unsigned long )time (NULL ), + (timestamp_t )time (NULL ),git_committer_info (IDENT_NO_NAME |IDENT_NO_DATE |IDENT_STRICT )); info->message_id =strbuf_detach (&buf,NULL ); }
builtin/merge-base.c +1 -1
@@ -132,7 +132,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs) }static int collect_one_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *ident,unsigned long timestamp, +const char *ident,timestamp_t timestamp,int tz,const char *message,void *cbdata) {struct rev_collect *revs = cbdata;
builtin/name-rev.c +3 -3
@@ -10,7 +10,7 @@typedef struct rev_name {const char *tip_name; -unsigned long taggerdate; +timestamp_t taggerdate;int generation;int distance; }rev_name ;
@@ -21,7 +21,7 @@ static long cutoff = LONG_MAX;#define MERGE_TRAVERSAL_WEIGHT 65535static void name_rev (struct commit *commit, -const char *tip_name,unsigned long taggerdate, +const char *tip_name,timestamp_t taggerdate,int generation,int distance,int deref) {
@@ -146,7 +146,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vostruct name_ref_data *data = cb_data;int can_abbreviate_output = data->tags_only && data->name_only;int deref =0 ; -unsigned long taggerdate =ULONG_MAX ; +timestamp_t taggerdate =TIME_MAX ;if (data->tags_only && !starts_with (path,"refs/tags/" ))return 0 ;
builtin/pack-objects.c +2 -2
@@ -44,7 +44,7 @@ static uint32_t nr_result, nr_written;static int non_empty;static int reuse_delta =1 , reuse_object =1 ;static int keep_unreachable, unpack_unreachable, include_tag; -static unsigned long unpack_unreachable_expiration; +static timestamp_t unpack_unreachable_expiration;static int pack_loose_unreachable;static int local;static int have_non_local_packs;
@@ -2675,7 +2675,7 @@ static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)static struct oid_array recent_objects;static int loosened_object_can_be_discarded (const struct object_id *oid, -unsigned long mtime) +timestamp_t mtime) {if (!unpack_unreachable_expiration)return 0 ;
builtin/prune.c +2 -2
@@ -13,7 +13,7 @@ static const char * const prune_usage[] = { };static int show_only;static int verbose; -static unsigned long expire; +static timestamp_t expire;static int show_progress =-1 ;static int prune_tmp_file (const char *fullpath)
@@ -111,7 +111,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix) };char *s; - expire =ULONG_MAX ; + expire =TIME_MAX ; save_commit_buffer =0 ; check_replace_refs =0 ; ref_paranoia =1 ;
builtin/receive-pack.c +3 -3
@@ -78,7 +78,7 @@ static const char *NONCE_OK = "OK";static const char *NONCE_SLOP ="SLOP" ;static const char *nonce_status;static long nonce_stamp_slop; -static unsigned long nonce_stamp_slop_limit; +static timestamp_t nonce_stamp_slop_limit;static struct ref_transaction *transaction; static enum {
@@ -454,7 +454,7 @@ static void hmac_sha1(unsigned char *out,git_SHA1_Final (out, &ctx); } -static char *prepare_push_cert_nonce (const char *path,unsigned long stamp) +static char *prepare_push_cert_nonce (const char *path,timestamp_t stamp) {struct strbuf buf =STRBUF_INIT ;unsigned char sha1[20 ];
@@ -496,7 +496,7 @@ static char *find_header(const char *msg, size_t len, const char *key)static const char *check_nonce (const char *buf,size_t len) {char *nonce =find_header (buf, len,"nonce" ); -unsigned long stamp, ostamp; +timestamp_t stamp, ostamp;char *bohmac, *expect =NULL ;const char *retval =NONCE_BAD ;
builtin/reflog.c +12 -12
@@ -16,14 +16,14 @@ static const char reflog_delete_usage[] =static const char reflog_exists_usage[] ="git reflog exists <ref>" ; -static unsigned long default_reflog_expire; -static unsigned long default_reflog_expire_unreachable; +static timestamp_t default_reflog_expire; +static timestamp_t default_reflog_expire_unreachable;struct cmd_reflog_expire_cb {struct rev_info revs;int stalefix; -unsigned long expire_total; -unsigned long expire_unreachable; +timestamp_t expire_total; +timestamp_t expire_unreachable;int recno; };
@@ -219,7 +219,7 @@ static int keep_entry(struct commit **it, unsigned char *sha1)static void mark_reachable (struct expire_reflog_policy_cb *cb) {struct commit_list *pending; -unsigned long expire_limit = cb->mark_limit; +timestamp_t expire_limit = cb->mark_limit;struct commit_list *leftover =NULL ;for (pending = cb->mark_list; pending; pending = pending->next)
@@ -284,7 +284,7 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit* Return true iff the specified reflog entry should be expired. */ static int should_expire_reflog_ent (unsigned char *osha1,unsigned char *nsha1, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct expire_reflog_policy_cb *cb = cb_data;
@@ -392,8 +392,8 @@ static int collect_reflog(const char *ref, const struct object_id *oid, int unusstatic struct reflog_expire_cfg {struct reflog_expire_cfg *next; -unsigned long expire_total; -unsigned long expire_unreachable; +timestamp_t expire_total; +timestamp_t expire_unreachable;char pattern[FLEX_ARRAY ]; } *reflog_expire_cfg, **reflog_expire_cfg_tail;
@@ -415,7 +415,7 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)return ent; } -static int parse_expire_cfg_value (const char *var,const char *value,unsigned long *expire) +static int parse_expire_cfg_value (const char *var,const char *value,timestamp_t *expire) {if (!value)return config_error_nonbool (var);
@@ -433,7 +433,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb) {const char *pattern, *key;int pattern_len; -unsigned long expire; +timestamp_t expire;int slot;struct reflog_expire_cfg *ent;
@@ -515,7 +515,7 @@ static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, int slot, cstatic int cmd_reflog_expire (int argc,const char **argv,const char *prefix) {struct expire_reflog_policy_cb cb; -unsigned long now =time (NULL ); +timestamp_t now =time (NULL );int i, status, do_all;int explicit_expiry =0 ;unsigned int flags =0 ;
@@ -616,7 +616,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) }static int count_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct expire_reflog_policy_cb *cb = cb_data;
builtin/show-branch.c +2 -2
@@ -735,7 +735,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) base =strtoul (reflog_base, &ep,10 );if (*ep) {/* Ah, that is a date spec... */ -unsigned long at; +timestamp_t at; at =approxidate (reflog_base);read_ref_at (ref, flags, at,-1 , oid.hash,NULL ,NULL ,NULL , &base);
@@ -746,7 +746,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)char *logmsg;char *nth_desc;const char *msg; -unsigned long timestamp; +timestamp_t timestamp;int tz; if (read_ref_at(ref, flags, 0, base+i, oid.hash, &logmsg,
builtin/worktree.c +2 -2
@@ -30,7 +30,7 @@ struct add_opts {static int show_only;static int verbose; -static unsigned long expire; +static timestamp_t expire;static int prune_worktree (const char *id,struct strbuf *reason) {
@@ -131,7 +131,7 @@ static int prune(int ac, const char **av, const char *prefix) OPT_END() }; - expire =ULONG_MAX ; + expire =TIME_MAX ; ac =parse_options (ac, av, prefix, options, worktree_usage,0 );if (ac)usage_with_options (worktree_usage, options);
bundle.c +1 -1
@@ -211,7 +211,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)unsigned long size;enum object_type type;char *buf =NULL , *line, *lineend; -unsigned long date; +timestamp_t date;int result =1 ;if (revs->max_age ==-1 && revs->min_age ==-1 )
cache.h +7 -7
@@ -1478,18 +1478,18 @@ struct date_mode {#define DATE_MODE (t) date_mode_from_type(DATE_##t)struct date_mode *date_mode_from_type (enum date_mode_type type); -const char *show_date (unsigned long time,int timezone,const struct date_mode *mode); -void show_date_relative (unsigned long time,int tz,const struct timeval *now, +const char *show_date (timestamp_t time,int timezone,const struct date_mode *mode); +void show_date_relative (timestamp_t time,int tz,const struct timeval *now,struct strbuf *timebuf);int parse_date (const char *date,struct strbuf *out); -int parse_date_basic (const char *date,unsigned long *timestamp,int *offset); -int parse_expiry_date (const char *date,unsigned long *timestamp); +int parse_date_basic (const char *date,timestamp_t *timestamp,int *offset); +int parse_expiry_date (const char *date,timestamp_t *timestamp);void datestamp (struct strbuf *out);#define approxidate (s) approxidate_careful((s), NULL) -unsigned long approxidate_careful (const char *,int *); -unsigned long approxidate_relative (const char *date,const struct timeval *now); +timestamp_t approxidate_careful (const char *,int *); +timestamp_t approxidate_relative (const char *date,const struct timeval *now);void parse_date_format (const char *format,struct date_mode *mode); -int date_overflows (unsigned long date); +int date_overflows (timestamp_t date);#define IDENT_STRICT 1#define IDENT_NO_DATE 2
commit.c +6 -6
@@ -66,7 +66,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)return commit; } -static unsigned long parse_commit_date (const char *buf,const char *tail) +static timestamp_t parse_commit_date (const char *buf,const char *tail) {const char *dateptr;
@@ -473,8 +473,8 @@ struct commit_list * commit_list_insert_by_date(struct commit *item, struct commstatic int commit_list_compare_by_date (const void *a,const void *b) { -unsigned long a_date = ((const struct commit_list *)a)->item->date; -unsigned long b_date = ((const struct commit_list *)b)->item->date; +timestamp_t a_date = ((const struct commit_list *)a)->item->date; +timestamp_t b_date = ((const struct commit_list *)b)->item->date;if (a_date < b_date)return 1 ;if (a_date > b_date)
@@ -598,7 +598,7 @@ static void record_author_date(struct author_date_slab *author_date,const char *ident_line;size_t ident_len;char *date_end; -unsigned long date; +timestamp_t date; ident_line =find_commit_header (buffer,"author" , &ident_len);if (!ident_line)
@@ -621,8 +621,8 @@ static int compare_commits_by_author_date(const void *a_, const void *b_, {const struct commit *a = a_, *b = b_;struct author_date_slab *author_date = cb_data; -unsigned long a_date = *(author_date_slab_at (author_date, a)); -unsigned long b_date = *(author_date_slab_at (author_date, b)); +timestamp_t a_date = *(author_date_slab_at (author_date, a)); +timestamp_t b_date = *(author_date_slab_at (author_date, b));/* newer commits with larger date first */ if (a_date < b_date)
commit.h +1 -1
@@ -17,7 +17,7 @@ struct commit {struct object object;void *util;unsigned int index; -unsigned long date; +timestamp_t date;struct commit_list *parents;struct tree *tree; };
config.c +1 -1
@@ -1943,7 +1943,7 @@ int git_config_get_expiry(const char *key, const char **output)if (ret)return ret;if (strcmp (*output,"now" )) { -unsigned long now =approxidate ("now" ); +timestamp_t now =approxidate ("now" );if (approxidate (*output) >= now)git_die_config (key,_ ("Invalid %s: '%s'" ), key, *output); }
credential-cache--daemon.c +6 -6
@@ -8,7 +8,7 @@ static struct tempfile socket_file;struct credential_cache_entry {struct credential item; -unsigned long expiration; +timestamp_t expiration; };static struct credential_cache_entry *entries;static int entries_nr;
@@ -47,12 +47,12 @@ static void remove_credential(const struct credential *c) e->expiration =0 ; } -static int check_expirations (void ) +static timestamp_t check_expirations (void ) { -static unsigned long wait_for_entry_until; +static timestamp_t wait_for_entry_until;int i =0 ; -unsigned long now =time (NULL ); -unsigned long next = (unsigned long )-1 ; +timestamp_t now =time (NULL ); +timestamp_t next =TIME_MAX ;/* * Initially give the client 30 seconds to actually contact us
@@ -159,7 +159,7 @@ static void serve_one_client(FILE *in, FILE *out)static int serve_cache_loop (int fd) {struct pollfd pfd; -unsigned long wakeup; +timestamp_t wakeup; wakeup =check_expirations ();if (!wakeup)
date.c +33 -33
207 lines not on this page · raw message
fetch-pack.c +3 -3
@@ -394,7 +394,7 @@ static int find_common(struct fetch_pack_args *args,if (args->depth >0 )packet_buf_write (&req_buf,"deepen %d" , args->depth);if (args->deepen_since) { -unsigned long max_age =approxidate (args->deepen_since); +timestamp_t max_age =approxidate (args->deepen_since);packet_buf_write (&req_buf,"deepen-since %" PRItime, max_age); }if (args->deepen_not) {
@@ -583,7 +583,7 @@ static int mark_complete_oid(const char *refname, const struct object_id *oid, }static void mark_recent_complete_commits (struct fetch_pack_args *args, -unsigned long cutoff) +timestamp_t cutoff) {while (complete && cutoff <= complete->item->date) { print_verbose(args, _("Marking %s as complete"),
@@ -670,7 +670,7 @@ static int everything_local(struct fetch_pack_args *args, {struct ref *ref;int retval; -unsigned long cutoff =0 ; +timestamp_t cutoff =0 ; save_commit_buffer =0 ;
git-compat-util.h +2 -0
@@ -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 ':'
http-backend.c +2 -2
@@ -90,7 +90,7 @@ static void hdr_int(struct strbuf *hdr, const char *name, uintmax_t value)strbuf_addf (hdr,"%s: %" PRIuMAX"\r\n" , name, value); } -static void hdr_date (struct strbuf *hdr,const char *name,unsigned long when) +static void hdr_date (struct strbuf *hdr,const char *name,timestamp_t when) {const char *value =show_date (when,0 ,DATE_MODE (RFC2822 ));hdr_str (hdr, name, value);
@@ -105,7 +105,7 @@ static void hdr_nocache(struct strbuf *hdr)static void hdr_cache_forever (struct strbuf *hdr) { -unsigned long now =time (NULL ); +timestamp_t now =time (NULL );hdr_date (hdr,"Date" , now);hdr_date (hdr,"Expires" , now +31536000 );hdr_str (hdr,"Cache-Control" ,"public, max-age=31536000" );
parse-options-cb.c +2 -2
@@ -31,14 +31,14 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)int parse_opt_approxidate_cb (const struct option *opt,const char *arg,int unset) { - *(unsigned long *)(opt->value) =approxidate (arg); + *(timestamp_t *)(opt->value) =approxidate (arg);return 0 ; }int parse_opt_expiry_date_cb (const struct option *opt,const char *arg,int unset) { -return parse_expiry_date (arg, (unsigned long *)opt->value); +return parse_expiry_date (arg, (timestamp_t *)opt->value); } int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
pretty.c +1 -1
@@ -405,7 +405,7 @@ static void add_rfc2047(struct strbuf *sb, const char *line, size_t len,const char *show_ident_date (const struct ident_split *ident,const struct date_mode *mode) { -unsigned long date =0 ; +timestamp_t date =0 ;long tz =0 ;if (ident->date_begin && ident->date_end)
reachable.c +4 -5
@@ -55,11 +55,11 @@ static void mark_commit(struct commit *c, void *data)struct recent_data {struct rev_info *revs; -unsigned long timestamp; +timestamp_t timestamp; };static void add_recent_object (const struct object_id *oid, -unsigned long mtime, +timestamp_t mtime,struct recent_data *data) {struct object *obj;
@@ -139,7 +139,7 @@ static int add_recent_packed(const struct object_id *oid, }int add_unseen_recent_objects_to_traversal (struct rev_info *revs, -unsigned long timestamp) +timestamp_t timestamp) {struct recent_data data;int r;
@@ -156,8 +156,7 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs, }void mark_reachable_objects (struct rev_info *revs,int mark_reflog, -unsigned long mark_recent, -struct progress *progress) +timestamp_t mark_recent,struct progress *progress) {struct connectivity_progress cp;
reachable.h +2 -2
@@ -3,8 +3,8 @@struct progress ;extern int add_unseen_recent_objects_to_traversal (struct rev_info *revs, -unsigned long timestamp); +timestamp_t timestamp);extern void mark_reachable_objects (struct rev_info *revs,int mark_reflog, -unsigned long mark_recent,struct progress *); +timestamp_t mark_recent,struct progress *);#endif
ref-filter.c +2 -2
@@ -849,7 +849,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam {const char *eoemail =strstr (buf,"> " );char *zone; -unsigned long timestamp; +timestamp_t timestamp;long tz;struct date_mode date_mode = {DATE_NORMAL };const char *formatp;
@@ -869,7 +869,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnamif (!eoemail) goto bad; timestamp =parse_timestamp (eoemail +2 , &zone,10 ); -if (timestamp ==ULONG_MAX ) +if (timestamp ==TIME_MAX ) goto bad; tz =strtol (zone,NULL ,10 );if ((tz ==LONG_MIN || tz ==LONG_MAX ) && errno ==ERANGE )
reflog-walk.c +4 -4
@@ -12,7 +12,7 @@ struct complete_reflogs {struct reflog_info {struct object_id ooid, noid;char *email; -unsigned long timestamp; +timestamp_t timestamp;int tz;char *message; } *items;
@@ -20,7 +20,7 @@ struct complete_reflogs { };static int read_one_reflog (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct complete_reflogs *array = cb_data;
@@ -69,7 +69,7 @@ static struct complete_reflogs *read_complete_reflog(const char *ref) }static int get_reflog_recno_by_time (struct complete_reflogs *array, -unsigned long timestamp) +timestamp_t timestamp) {int i;for (i = array->nr -1 ; i >=0 ; i--)
@@ -141,7 +141,7 @@ void init_reflog_walk(struct reflog_walk_info **info)int add_reflog_for_walk (struct reflog_walk_info *info,struct commit *commit,const char *name) { -unsigned long timestamp =0 ; +timestamp_t timestamp =0 ;int recno =-1 ;struct string_list_item *item;struct complete_reflogs *reflogs;
refs.c +7 -7
@@ -712,7 +712,7 @@ int is_branch(const char *refname)struct read_ref_at_cb {const char *refname; -unsigned long at_time; +timestamp_t at_time;int cnt;int reccnt;unsigned char *sha1;
@@ -721,15 +721,15 @@ struct read_ref_at_cb {unsigned char osha1[20 ];unsigned char nsha1[20 ];int tz; -unsigned long date; +timestamp_t date;char **msg; -unsigned long *cutoff_time; +timestamp_t *cutoff_time;int *cutoff_tz;int *cutoff_cnt; };static int read_ref_at_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct read_ref_at_cb *cb = cb_data;
@@ -776,7 +776,7 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid, }static int read_ref_at_ent_oldest (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct read_ref_at_cb *cb = cb_data;
@@ -796,9 +796,9 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noidreturn 1 ; } -int read_ref_at (const char *refname,unsigned int flags,unsigned long at_time,int cnt, +int read_ref_at (const char *refname,unsigned int flags,timestamp_t at_time,int cnt,unsigned char *sha1,char **msg, -unsigned long *cutoff_time,int *cutoff_tz,int *cutoff_cnt) +timestamp_t *cutoff_time,int *cutoff_tz,int *cutoff_cnt) {struct read_ref_at_cb cb;
refs.h +4 -4
@@ -317,9 +317,9 @@ int safe_create_reflog(const char *refname, int force_create, struct strbuf *err/** Reads log for the value of ref during at_time. **/ int read_ref_at (const char *refname,unsigned int flags, -unsigned long at_time,int cnt, +timestamp_t at_time,int cnt,unsigned char *sha1,char **msg, -unsigned long *cutoff_time,int *cutoff_tz,int *cutoff_cnt); +timestamp_t *cutoff_time,int *cutoff_tz,int *cutoff_cnt);/** Check if a particular reflog exists */ int refs_reflog_exists (struct ref_store *refs,const char *refname);
@@ -356,7 +356,7 @@ int delete_reflog(const char *refname);/* iterate over reflog entries */ typedef int each_reflog_ent_fn (struct object_id *old_oid,struct object_id *new_oid, -const char *committer,unsigned long timestamp, +const char *committer,timestamp_t timestamp,int tz,const char *msg,void *cb_data); int refs_for_each_reflog_ent(struct ref_store *refs, const char *refname,
@@ -616,7 +616,7 @@ typedef void reflog_expiry_prepare_fn(const char *refname,typedef int reflog_expiry_should_prune_fn (unsigned char *osha1,unsigned char *nsha1,const char *email, -unsigned long timestamp,int tz, +timestamp_t timestamp,int tz,const char *message,void *cb_data);typedef void reflog_expiry_cleanup_fn (void *cb_data);
refs/files-backend.c +2 -2
@@ -3237,7 +3237,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c {struct object_id ooid, noid;char *email_end, *message; -unsigned long timestamp; +timestamp_t timestamp;int tz;const char *p = sb->buf;
@@ -4118,7 +4118,7 @@ struct expire_reflog_cb { };static int expire_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct expire_reflog_cb *cb = cb_data;
revision.c +3 -3
@@ -884,7 +884,7 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)/* How many extra uninteresting commits we want to see.. */ #define SLOP 5 -static int still_interesting (struct commit_list *src,unsigned long date,int slop, +static int still_interesting (struct commit_list *src,timestamp_t date,int slop,struct commit **interesting_cache) {/*
@@ -1018,7 +1018,7 @@ static void limit_left_right(struct commit_list *list, struct rev_info *revs)static int limit_list (struct rev_info *revs) {int slop =SLOP ; -unsigned long date = ~0ul ; +timestamp_t date =TIME_MAX ;struct commit_list *list = revs->commits;struct commit_list *newlist =NULL ;struct commit_list **p = &newlist;
@@ -1215,7 +1215,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data) }static int handle_one_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {handle_one_reflog_commit (ooid, cb_data);
revision.h +2 -2
@@ -181,8 +181,8 @@ struct rev_info {/* special limits */ int skip_count;int max_count; -unsigned long max_age; -unsigned long min_age; +timestamp_t max_age; +timestamp_t min_age;int min_parents;int max_parents;int (*include_check)(struct commit *,void *);
sha1_name.c +3 -3
@@ -660,8 +660,8 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,if (reflog_len) {int nth, i; -unsigned long at_time; -unsigned long co_time; +timestamp_t at_time; +timestamp_t co_time;int co_tz, co_cnt;/* Is it asking for N-th entry, or approxidate? */
@@ -1054,7 +1054,7 @@ struct grab_nth_branch_switch_cbdata { };static int grab_nth_branch_switch (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct grab_nth_branch_switch_cbdata *cb = cb_data;
t/helper/test-date.c +4 -4
@@ -27,7 +27,7 @@ static void show_dates(const char **argv, const char *format)parse_date_format (format, &mode);for (; *argv; argv++) {char *arg; -time_t t; +timestamp_t t;int tz;/*
@@ -48,7 +48,7 @@ static void parse_dates(const char **argv, struct timeval *now)struct strbuf result =STRBUF_INIT ;for (; *argv; argv++) { -unsigned long t; +timestamp_t t;int tz;strbuf_reset (&result);
@@ -65,7 +65,7 @@ static void parse_dates(const char **argv, struct timeval *now)static void parse_approxidate (const char **argv,struct timeval *now) {for (; *argv; argv++) { -time_t t; +timestamp_t t; t =approxidate_relative (*argv, now);printf ("%s -> %s\n" , *argv,show_date (t,0 ,DATE_MODE (ISO8601 ))); }
@@ -96,7 +96,7 @@ int cmd_main(int argc, const char **argv)else if (!strcmp (*argv,"approxidate" ))parse_approxidate (argv+1 , &now);else if (!strcmp (*argv,"is64bit" )) -return sizeof (unsigned long ) ==8 ?0 :1 ; +return sizeof (timestamp_t) ==8 ?0 :1 ;else if (!strcmp (*argv,"time_t-is64bit" ))return sizeof (time_t) ==8 ?0 :1 ;else
t/helper/test-parse-options.c +1 -1
@@ -5,7 +5,7 @@static int boolean =0 ;static int integer =0 ;static unsigned long magnitude =0 ; -static unsigned long timestamp; +static timestamp_t timestamp;static int abbrev =7 ;static int verbose =-1 ;/* unspecified */ static int dry_run =0 , quiet =0 ;
t/helper/test-ref-store.c +1 -1
@@ -138,7 +138,7 @@ static int cmd_for_each_reflog(struct ref_store *refs, const char **argv) }static int each_reflog (struct object_id *old_oid,struct object_id *new_oid, -const char *committer,unsigned long timestamp, +const char *committer,timestamp_t timestamp,int tz,const char *msg,void *cb_data) { printf("%s %s %s %"PRItime" %d %s\n",
tag.c +1 -1
@@ -97,7 +97,7 @@ struct tag *lookup_tag(const unsigned char *sha1)return object_as_type (obj,OBJ_TAG ,0 ); } -static unsigned long parse_tag_date (const char *buf,const char *tail) +static timestamp_t parse_tag_date (const char *buf,const char *tail) {const char *dateptr;
tag.h +1 -1
@@ -9,7 +9,7 @@ struct tag {struct object object;struct object *tagged;char *tag; -unsigned long date; +timestamp_t date; };extern struct tag *lookup_tag (const unsigned char *sha1);
upload-pack.c +2 -2
@@ -35,7 +35,7 @@ static const char * const upload_pack_usage[] = {#define CLIENT_SHALLOW (1u << 18)#define HIDDEN_REF (1u << 19) -static unsigned long oldest_have; +static timestamp_t oldest_have;static int deepen_relative;static int multi_ack;
@@ -735,7 +735,7 @@ static void receive_needs(void)struct string_list deepen_not =STRING_LIST_INIT_DUP ;int depth =0 ;int has_non_tip =0 ; -unsigned long deepen_since =0 ; +timestamp_t deepen_since =0 ;int deepen_rev_list =0 ; shallow_nr =0 ;
vcs-svn/fast_export.c +2 -2
@@ -68,7 +68,7 @@ void fast_export_modify(const char *path, uint32_t mode, const char *dataref) }void fast_export_begin_note (uint32_t revision,const char *author, -const char *log,unsigned long timestamp,const char *note_ref) +const char *log,timestamp_t timestamp,const char *note_ref) {static int firstnote =1 ;size_t loglen =strlen (log);
@@ -93,7 +93,7 @@ static char gitsvnline[MAX_GITSVN_LINE_LEN];void fast_export_begin_commit (uint32_t revision,const char *author,const struct strbuf *log,const char *uuid,const char *url, -unsigned long timestamp,const char *local_ref) +timestamp_t timestamp,const char *local_ref) {static const struct strbuf empty =STRBUF_INIT ;if (!log)
vcs-svn/fast_export.h +2 -2
@@ -11,10 +11,10 @@ void fast_export_delete(const char *path);void fast_export_modify (const char *path,uint32_t mode,const char *dataref);void fast_export_note (const char *committish,const char *dataref);void fast_export_begin_note (uint32_t revision,const char *author, -const char *log,unsigned long timestamp,const char *note_ref); +const char *log,timestamp_t timestamp,const char *note_ref);void fast_export_begin_commit (uint32_t revision,const char *author,const struct strbuf *log,const char *uuid,const char *url, -unsigned long timestamp,const char *local_ref); +timestamp_t timestamp,const char *local_ref);void fast_export_end_commit (uint32_t revision);void fast_export_data (uint32_t mode,off_t len,struct line_buffer *input);void fast_export_buf_to_data (const struct strbuf *data);
vcs-svn/svndump.c +1 -1
@@ -47,7 +47,7 @@ static struct {static struct {uint32_t revision; -unsigned long timestamp; +timestamp_t timestamp;struct strbuf log, author, note; } rev_ctx;
wt-status.c +1 -1
@@ -1387,7 +1387,7 @@ struct grab_1st_switch_cbdata { };static int grab_1st_switch (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct grab_1st_switch_cbdata *cb = cb_data;
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
Re: [PATCH v5 6/8] Introduce a new data type for timestamps
Am 24.04.2017 um 15:58 schrieb Johannes Schindelin:
archive-tar.c static int write_tar_filter_archive(const struct archiver *ar, · line 32
Quoted 12 lines
archive-tar.c +1
-1@@ -27,9 +27,12 @@ static int write_tar_filter_archive(const struct archiver *ar,*/ #if ULONG_MAX ==0xFFFFFFFF #define USTAR_MAX_SIZE ULONG_MAX -#define USTAR_MAX_MTIME ULONG_MAX#else #define USTAR_MAX_SIZE 077777777777UL +#endif
This part of the hunk is fine: if ULONG_MAX is not 2^32-1, then 2^33-1 will fit in a long.
archive-tar.c static int write_tar_filter_archive(const struct archiver *ar, · line 37
Quoted 5 lines
archive-tar.c +3
-0+#if TIME_MAX ==0xFFFFFFFF +#define USTAR_MAX_MTIME TIME_MAX +#else #define USTAR_MAX_MTIME 077777777777UL#endif
But this is not: just because TIME_MAX is not 32 bits, does not mean that long is also more than 32 bits. We need this:
archive-tar.c +1 -1
@@ -33,7 +33,7 @@ static int write_tar_filter_archive(const struct archiver *ar,#if TIME_MAX ==0xFFFFFFFF #define USTAR_MAX_MTIME TIME_MAX#else -#define USTAR_MAX_MTIME 077777777777UL +#define USTAR_MAX_MTIME 077777777777ULL#endif /* writes out the whole block, but only if it is full */
Re: [PATCH v5 6/8] Introduce a new data type for timestamps
Hi Hannes,
Quoted 31 lines · Johannes Sixt
Am 24.04.2017 um 15:58 schrieb Johannes Schindelin:
archive-tar.c static int write_tar_filter_archive(const struct archiver *ar, · line 32
Quoted 12 lines
archive-tar.c +1
-1@@ -27,9 +27,12 @@ static int write_tar_filter_archive(const struct archiver *ar,*/ #if ULONG_MAX ==0xFFFFFFFF #define USTAR_MAX_SIZE ULONG_MAX -#define USTAR_MAX_MTIME ULONG_MAX#else #define USTAR_MAX_SIZE 077777777777UL +#endif This part of the hunk is fine: if
ULONG_MAXis not 2^32-1, then 2^33-1 will fit in a long.archive-tar.c static int write_tar_filter_archive(const struct archiver *ar, · line 37
Quoted 5 lines
archive-tar.c +3
-0+#if TIME_MAX ==0xFFFFFFFF +#define USTAR_MAX_MTIME TIME_MAX +#else #define USTAR_MAX_MTIME 077777777777UL#endif But this is not: just because
TIME_MAXis not 32 bits, does not mean that long is also more than 32 bits. We need this:archive-tar.c +0
-0
archive-tar.c static int write_tar_filter_archive(const struct archiver *ar, · line 39
Quoted 8 lines
archive-tar.c +1
-1@@ -33,7 +33,7 @@ static int write_tar_filter_archive(const struct archiver *ar,#if TIME_MAX ==0xFFFFFFFF #define USTAR_MAX_MTIME TIME_MAX#else -#define USTAR_MAX_MTIME 077777777777UL +#define USTAR_MAX_MTIME 077777777777ULL#endif /* writes out the whole block, but only if it is full */
Right! Thank you, v6 coming up,
Dscho
Re: [PATCH v5 6/8] Introduce a new data type for timestamps
In reply to Johannes SchindelinAm 24.04.2017 um 15:58 schrieb Johannes Schindelin:
Quoted 47 lines
archive-tar.c +4
-1@@ -27,9 +27,12 @@ static int write_tar_filter_archive(const struct archiver *ar,*/ #if ULONG_MAX ==0xFFFFFFFF #define USTAR_MAX_SIZE ULONG_MAX -#define USTAR_MAX_MTIME ULONG_MAX#else #define USTAR_MAX_SIZE 077777777777UL +#endif +#if TIME_MAX ==0xFFFFFFFF +#define USTAR_MAX_MTIME TIME_MAX +#else #define USTAR_MAX_MTIME 077777777777UL#endif archive-zip.c +10
-2@@ -545,9 +545,17 @@ static void write_zip_trailer(const unsigned char *sha1)write_or_die (1 ,sha1_to_hex (sha1),GIT_SHA1_HEXSZ ); } -static void dos_time (time_t *time,int *dos_date,int *dos_time) +static void dos_time (timestamp_t *timestamp,int *dos_date,int *dos_time) { -struct tm *t =localtime (time); +time_t time; +struct tm *t; + +if (date_overflows (*timestamp)) +die ("timestamp too large for this system: %" PRItime, + *timestamp); + time = (time_t)*timestamp; + t =localtime (&time); + *timestamp = time; *dos_date = t->tm_mday + (t->tm_mon +1 ) *32 + (t->tm_year +1900 -1980 ) *512 ;archive.h +0
-0
archive.h struct archiver_args { · line 15
Quoted 8 lines
archive.h +1
-1@@ -9,7 +9,7 @@ struct archiver_args {struct tree *tree;const unsigned char *commit_sha1;const struct commit *commit; -time_t time; +timestamp_t time;struct pathspec pathspec; unsigned int verbose : 1; unsigned int worktree_attributes : 1;
time_t is converted to timestamp_t here. Hmm.
Truncation can already occur in archive.c::parse_treeish_arg() when assigning commit->date (of type timestamp_t) to archive_time (of type time_t). The overflow check should either be moved there or the type of the latter variable should be changed, right?
Compilation and tests are still successful on Debian x86 and MinGW64 even after removing the changes above. On the former the test "generate tar with future mtime" in t5000 writes Epoch time stamps in both cases (and doesn't notice because tar is unable to handle times after 2038, so that check is skipped), on the latter it emits the correct future dates.
So what are the benefits of these changes?
Unless I'm missing something (very possible at this time of day) I'd say drop these hunks and let me handle the fallout of the series in archive. I was planning on improving its date handling code anyway (eventually)..
René
PATCH v5 7/8 Abort if the system time cannot handle one of our timestamps
In reply to Johannes SchindelinWe are about to switch to a new data type for time stamps that is definitely not smaller or equal, but larger or equal to time_t.
So before using the system functions to process or format timestamps, let's make extra certain that they can handle what we feed them.
--- date.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
date.c +15 -2
@@ -46,7 +46,17 @@ static time_t gm_time_t(timestamp_t time, int tz) minutes = tz <0 ? -tz : tz; minutes = (minutes /100 )*60 + (minutes %100 ); minutes = tz <0 ? -minutes : minutes; -return time + minutes *60 ; + +if (minutes >0 ) { +if (unsigned_add_overflows (time, minutes *60 )) +die ("Timestamp+tz too large: %" PRItime" +%04d" , + time, tz); + }else if (time < -minutes *60 ) +die ("Timestamp before Unix epoch: %" PRItime" %04d" , time, tz); + time += minutes *60 ; +if (date_overflows (time)) +die ("Timestamp too large for this system: %" PRItime, time); +return (time_t )time; }/*
@@ -70,7 +80,10 @@ static int local_tzoffset(timestamp_t time)struct tm tm;int offset, eastwest; - t = time; +if (date_overflows (time)) +die ("Timestamp too large for this system: %" PRItime, time); + + t = (time_t )time;localtime_r (&t, &tm); t_local =tm_to_time_t (&tm);
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH v5 8/8 Use uintmax_t for timestamps
In reply to Johannes SchindelinPreviously, 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...
--- git-compat-util.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
git-compat-util.h +7 -3
@@ -319,10 +319,14 @@ extern char *gitdirname(char *);#define PRIo32 "o"#endif -typedef unsigned long timestamp_t ; -#define PRItime "lu" -#define parse_timestamp strtoul +typedef uintmax_t timestamp_t ; +#define PRItime PRIuMAX +#define parse_timestamp strtoumax +#ifdef ULLONG_MAX +#define TIME_MAX ULLONG_MAX +#else #define TIME_MAX ULONG_MAX +#endif #ifndef PATH_SEP #define PATH_SEP ':'
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
Re: [PATCH v5 8/8] Use uintmax_t for timestamps
Am 24.04.2017 um 15:58 schrieb Johannes Schindelin:
Quoted 8 lines
#define PRIo32 "o"
#endif(quoted diff) +1
-3-typedef unsigned long timestamp_t; -#define PRItime "lu" -#define parse_timestamp strtoul +typedef uintmax_t timestamp_t;
Review
Quoted 10 lines
(quoted diff) +6
-0+#define PRItime PRIuMAX +#define parse_timestamp strtoumax +#ifdef ULLONG_MAX +#define TIME_MAX ULLONG_MAX +#else #define TIME_MAX ULONG_MAX +#endif #ifndef PATH_SEP #define PATH_SEP ':'
I think you should squash in this:
git-compat-util.h +1 -5
@@ -322,11 +322,7 @@ extern char *gitdirname(char *);typedef uintmax_t timestamp_t ;#define PRItime PRIuMAX#define parse_timestamp strtoumax -#ifdef ULLONG_MAX -#define TIME_MAX ULLONG_MAX -#else -#define TIME_MAX ULONG_MAX -#endif +#define TIME_MAX UINTMAX_MAX#ifndef PATH_SEP #define PATH_SEP ':'
UINTMAX_MAX is already used git-compat-util.h
-- Hannes
Re: [PATCH v5 8/8] Use uintmax_t for timestamps
Hi Hannes,
Quoted 40 lines · Johannes Sixt
Am 24.04.2017 um 15:58 schrieb Johannes Schindelin:
Quoted 8 lines
#define PRIo32 "o"
#endif(quoted diff) +1
-3-typedef unsigned long timestamp_t; -#define PRItime "lu" -#define parse_timestamp strtoul +typedef uintmax_t timestamp_t;Review
Quoted 10 lines
(quoted diff) +6
-0+#define PRItime PRIuMAX +#define parse_timestamp strtoumax +#ifdef ULLONG_MAX +#define TIME_MAX ULLONG_MAX +#else #define TIME_MAX ULONG_MAX +#endif #ifndef PATH_SEP #define PATH_SEP ':'I think you should squash in this:
git-compat-util.h +1
-5@@ -322,11 +322,7 @@ extern char *gitdirname(char *);typedef uintmax_t timestamp_t ;#define PRItime PRIuMAX#define parse_timestamp strtoumax -#ifdef ULLONG_MAX -#define TIME_MAX ULLONG_MAX -#else -#define TIME_MAX ULONG_MAX -#endif +#define TIME_MAX UINTMAX_MAX#ifndef PATH_SEP #define PATH_SEP ':'
Quoted 1 line
UINTMAX_MAXis already usedgit-compat-util.h
Good point. I very much appreciate your fresh eyes here, as I simply overlooked this in the humongous task to convert v1 to use uintmax_t instead of time_t.
Ciao,
Dscho
Re: [PATCH v5 0/8] Introduce timestamp_t for timestamps
In reply to Johannes SchindelinAm 24.04.2017 um 15:57 schrieb Johannes Schindelin:
Quoted 11 lines
Git v2.9.2 was released in a hurry to accomodate for platforms like Windows, where the
unsigned longdata type is 32-bit even for 64-bit setups.The quick fix was to simply disable all the testing with "absurd" future dates.
However, we can do much better than that, as we already make use of 64-bit data types internally. There is no good reason why we should not use the same for timestamps. Hence, let's use
uintmax_tfor timestamps.
Quoted 8 lines
Note: while the
time_tdata type exists and is meant to be used for timestamps, on 32-bit Linux it is *still* 32-bit. An earlier iteration usedtime_tfor that reason, but it came with a few serious downsides:
astime_tcan be signed (and indeed, on Windows it is anint64_t), Git's expectation that 0 is the minimal value does no longer hold true, introducing its own set of interesting challenges. Besides, if we *can* handle far in the future timestamps (except for formatting them using the system libraries), it is more consistent to do so.
time_t is signed on Linux and BSDs as well.
Using an unsigned type gives us the ability to represent times beyond the 292 billion years in the future that int64_t would give us, but prevents recording events that occurred before the Epoch. That doesn't sound like a good deal to me -- storing historical works (e.g. law texts) with real time stamps is probably more interesting than fixing the year 292277026596 problem within this decade.
Quoted 4 lines
The upside of using
uintmax_tfor timestamps is that we do a much better job to support far in the future timestamps across all platforms, including 32-bit ones. The downside is that those platforms that use a 32-bittime_twill barf when parsing or formatting those timestamps.
IIUC this series has two aims: solving the year 2038 problem on 32-bit Linux by replacing time_t (int32_t), and solving the year 2106 problem on Windows by replacing unsigned long (uint32_t), right? The latter one sounds more interesting, because 32-bit platforms would still be unable to fully use bigger time values as you wrote above.
Can we leave time_t alone and just do the part where you replace unsigned long with timestamp_t defined as uint64_t? That should already help on Windows, correct? When/if timestamp_t is later changed to a signed type then we could easily convert the time_t cases to timestamp_t as well, or the other way around.
Quoted 7 lines
This iteration makes the
date_overflows()check more stringent again.It is arguably a bug to paper over too-large author/committer dates and to replace them with Jan 1 1970 without even telling the user that we do that, but this is the behavior that t4212 verifies, so I reinstated that behavior. The change in behavior was missed because of the missing
unsigned_add_overflows()test.
I can't think of many ways to get future time stamps (broken clock, broken CMOS battery, bit rot, time travel), so I wouldn't expect a change towards better error reporting to affect a lot of users. (Not necessarily as part of this series, of course.)
Quoted 69 lines
Changes since v4:
- in
gm_time_t(), we now test specifically that the timezone adjustment neither underflows nor overflows.- the patch introduced in v4 that tried to defer the
date_overflows()check togm_time_t()rather than replacing the ident timestamp by a 0 without any warning was dropped again: it broke t4212.Johannes Schindelin (8):
ref-filter: avoid usingunsigned longfor catch-all data type t0006 & t5000: prepare for 64-bit timestamps
t0006 & t5000: skip "far in the future" test whentime_tis too
limited
Specify explicitly where we parse timestamps Introduce a new "printf format" for timestamps Introduce a new data type for timestamps
Abort if the system time cannot handle one of our timestamps Useuintmax_tfor timestampsDocumentation/technical/api-parse-options.txt | 8 +- archive-tar.c | 5 +- archive-zip.c | 12 ++- archive.h | 2 +- builtin/am.c | 4 +- builtin/blame.c | 14 ++-- builtin/fsck.c | 6 +- builtin/gc.c | 2 +- builtin/log.c | 4 +- builtin/merge-base.c | 2 +- builtin/name-rev.c | 6 +- builtin/pack-objects.c | 4 +- builtin/prune.c | 4 +- builtin/receive-pack.c | 14 ++-- builtin/reflog.c | 24 +++--- builtin/rev-list.c | 2 +- builtin/rev-parse.c | 2 +- builtin/show-branch.c | 4 +- builtin/worktree.c | 4 +- bundle.c | 4 +- cache.h | 14 ++-- commit.c | 18 ++-- commit.h | 2 +- config.c | 2 +- credential-cache--daemon.c | 12 +-- date.c | 113 ++++++++++++++------------ fetch-pack.c | 8 +- fsck.c | 2 +- git-compat-util.h | 9 ++ http-backend.c | 4 +- parse-options-cb.c | 4 +- pretty.c | 4 +- reachable.c | 9 +- reachable.h | 4 +- ref-filter.c | 22 ++--- reflog-walk.c | 8 +- refs.c | 14 ++-- refs.h | 8 +- refs/files-backend.c | 8 +- revision.c | 6 +- revision.h | 4 +- sha1_name.c | 6 +- t/helper/test-date.c | 18 ++-- t/helper/test-parse-options.c | 4 +- t/helper/test-ref-store.c | 4 +- t/t0006-date.sh | 4 +- t/t5000-tar-tree.sh | 6 +- t/test-lib.sh | 3 +
Quoted 8 lines
tag.c | 6 +- tag.h | 2 +- upload-pack.c | 8 +- vcs-svn/fast_export.c | 8 +- vcs-svn/fast_export.h | 4 +- vcs-svn/svndump.c | 2 +- wt-status.c | 2 +- 55 files changed, 260 insertions(+), 219 deletions(-)
How did you find all the pieces of code that need to be touched? Is there a regex or something that can be used to spot new such places that sneak in, e.g. through in-flight merges?
Quoted 53 lines
base-commit:
e2cb6ab84c94f147f1259260961513b40c36108a
Published-As: https://github.com/dscho/git/releases/tag/time_t-may-be-int64-v5
Fetch-It-Via: git fetch https://github.com/dscho/git time_t-may-be-int64-v5Interdiff vs v4:
diff --git a/date.c b/date.c index 75f6335cd09..63fa99685e2 100644 --- a/date.c +++ b/date.c @@ -47,9 +47,16 @@ static time_t gm_time_t(timestamp_t time, int tz) minutes = (minutes / 100)*60 + (minutes % 100); minutes = tz < 0 ? -minutes : minutes; - if (date_overflows(time + minutes * 60)) + if (minutes > 0) { + if (unsigned_add_overflows(time, minutes * 60)) + die("Timestamp+tz too large: %"PRItime" +%04d", + time, tz); + } else if (time < -minutes * 60) + die("Timestamp before Unix epoch: %"PRItime" %04d", time, tz); + time += minutes * 60; + if (date_overflows(time)) die("Timestamp too large for this system: %"PRItime, time); - return (time_t)time + minutes * 60; + return (time_t)time; }/*diff --git
a/pretty.cb/pretty.c
index35fd290096a..587d48371b0100644
---a/pretty.c
+++b/pretty.c
@@ -410,10 +410,14 @@ const char *show_ident_date(const structident_split*ident,if (ident->date_begin && ident->date_end) date = parse_timestamp(ident->date_begin, NULL, 10); - if (ident->tz_begin && ident->tz_end) - tz = strtol(ident->tz_begin, NULL, 10); - if (tz >= INT_MAX || tz <= INT_MIN) - tz = 0; + if (date_overflows(date)) + date = 0; + else { + if (ident->tz_begin && ident->tz_end) + tz = strtol(ident->tz_begin, NULL, 10); + if (tz >= INT_MAX || tz <= INT_MIN) + tz = 0; + } return show_date(date, tz, mode); }
Re: [PATCH v5 0/8] Introduce timestamp_t for timestamps
Hi René,
Quoted 22 lines · René Scharfe
Am 24.04.2017 um 15:57 schrieb Johannes Schindelin:
Quoted 12 lines
Git v2.9.2 was released in a hurry to accomodate for platforms like Windows, where the
unsigned longdata type is 32-bit even for 64-bit setups.The quick fix was to simply disable all the testing with "absurd" future dates.
However, we can do much better than that, as we already make use of 64-bit data types internally. There is no good reason why we should not use the same for timestamps. Hence, let's use
uintmax_tfor timestamps.Quoted 8 lines
Note: while the
time_tdata type exists and is meant to be used for timestamps, on 32-bit Linux it is *still* 32-bit. An earlier iteration usedtime_tfor that reason, but it came with a few serious
downsides: astime_tcan be signed (and indeed, on Windows it is anint64_t), Git's expectation that 0 is the minimal value does no longer hold true, introducing its own set of interesting challenges. Besides, if we *can* handle far in the future timestamps (except for formatting them using the system libraries), it is more consistent to do so.
Quoted 1 line
time_tis signed on Linux and BSDs as well.
s/is/happens to be/.
The point is: we must not rely on time_t to be signed just because it *happens* to be the case on the setups to which we have access. We want Git to be portable, not only "portable to our own setups".
Quoted 6 lines
Using an unsigned type gives us the ability to represent times beyond the 292 billion years in the future that
int64_twould give us, but prevents recording events that occurred before the Epoch. That doesn't sound like a good deal to me -- storing historical works (e.g. law texts) with real time stamps is probably more interesting than fixing the year 292277026596 problem within this decade.
It sounds like a good deal to me, if the alternative is that *I* have to patch Git's source code to support signed timestamps, when *I* am probably the only one in this entire thread who does not even want them.
So could y'all please just stop talking about signed timestamps to me? I feel that they are really, really start to irritate the hell out of me.
Quoted 9 lines
Quoted 5 lines
The upside of using
uintmax_tfor timestamps is that we do a much better job to support far in the future timestamps across all platforms, including 32-bit ones. The downside is that those platforms that use a 32-bittime_twill barf when parsing or formatting those timestamps.IIUC this series has two aims: solving the year 2038 problem on 32-bit Linux by replacing
time_t(int32_t), and solving the year 2106 problem on Windows by replacing unsigned long (uint32_t), right?
No. The series has one aim: to stop using unsigned long (which is ill-defined to begin with) for timestamps.
Quoted 8 lines
The latter one sounds more interesting, because 32-bit platforms would still be unable to fully use bigger time values as you wrote above.
Can we leave
time_talone and just do the part where you replace unsigned long withtimestamp_tdefined asuint64_t? That should already help on Windows, correct? When/iftimestamp_tis later changed to a signed type then we could easily convert thetime_tcases totimestamp_tas well, or the other way around.
This patch series leaves time_t alone already, so your wish has been fulfilled preemptively.
Quoted 8 lines
Quoted 7 lines
This iteration makes the
date_overflows()check more stringent again.It is arguably a bug to paper over too-large author/committer dates and to replace them with Jan 1 1970 without even telling the user that we do that, but this is the behavior that t4212 verifies, so I reinstated that behavior. The change in behavior was missed because of the missing
unsigned_add_overflows()test.
Quoted 4 lines
I can't think of many ways to get future time stamps (broken clock, broken CMOS battery, bit rot, time travel), so I wouldn't expect a change towards better error reporting to affect a lot of users. (Not necessarily as part of this series, of course.)
If you want to suggest that we should stop verifying overflows when a complex reasoning can prove that the overflow is not happening in a billion years, I disagree. Not only is it unnecessarily time-consuming to ask readers to perform the complex reasoning, and not only is there enough room for bugs to hide in plain sight (because of the complexity), it also makes the same code harder to reuse in other software where a different timestamp data type was chosen (or inherited from previous Git versions).
I'd much rather have easy-to-reason code that does not cause head scratching (like the "why do we ignore a too large timestamp?" triggering if (date_overflows(date)) date = 0;) than pretending to be smart and clever and make everybody else feel stupid by forcing them through hoops of thinking bubbles until they also reached the conclusion that this actually won't happen. Unless there is a bug in the code.
Quoted 58 lines
Quoted 49 lines
Documentation/technical/api-parse-options.txt | 8 +- archive-tar.c | 5 +- archive-zip.c | 12 ++- archive.h | 2 +- builtin/am.c | 4 +- builtin/blame.c | 14 ++-- builtin/fsck.c | 6 +- builtin/gc.c | 2 +- builtin/log.c | 4 +- builtin/merge-base.c | 2 +- builtin/name-rev.c | 6 +- builtin/pack-objects.c | 4 +- builtin/prune.c | 4 +- builtin/receive-pack.c | 14 ++-- builtin/reflog.c | 24 +++--- builtin/rev-list.c | 2 +- builtin/rev-parse.c | 2 +- builtin/show-branch.c | 4 +- builtin/worktree.c | 4 +- bundle.c | 4 +- cache.h | 14 ++-- commit.c | 18 ++-- commit.h | 2 +- config.c | 2 +- credential-cache--daemon.c | 12 +-- date.c | 113 ++++++++++++++------------ fetch-pack.c | 8 +- fsck.c | 2 +- git-compat-util.h | 9 ++ http-backend.c | 4 +- parse-options-cb.c | 4 +- pretty.c | 4 +- reachable.c | 9 +- reachable.h | 4 +- ref-filter.c | 22 ++--- reflog-walk.c | 8 +- refs.c | 14 ++-- refs.h | 8 +- refs/files-backend.c | 8 +- revision.c | 6 +- revision.h | 4 +- sha1_name.c | 6 +- t/helper/test-date.c | 18 ++-- t/helper/test-parse-options.c | 4 +- t/helper/test-ref-store.c | 4 +- t/t0006-date.sh | 4 +- t/t5000-tar-tree.sh | 6 +- t/test-lib.sh | 3 +Quoted 8 lines
tag.c | 6 +- tag.h | 2 +- upload-pack.c | 8 +- vcs-svn/fast_export.c | 8 +- vcs-svn/fast_export.h | 4 +- vcs-svn/svndump.c | 2 +- wt-status.c | 2 +- 55 files changed, 260 insertions(+), 219 deletions(-)
Quoted 1 line
How did you find all the pieces of code that need to be touched?
Pain and suffering.
Seriosly, for v1 of this patch series, I went painstakingly through git grep -Ovi "unsigned long". I determined for every single use of unsigned long whether it referred to a timestamp and changed it accordingly.
In subsequent iterations, I went the cheaper route of compiling with DEVELOPER=1 on Windows and once I even went through replacing the 64-bit libraries and compiler/linker in my Linux VM with 32-bit ones to imitate the 32-bit Linux Travis coordinate (because I failed to get the Docker setup to run in the VM). These build runs identified new callers of functions whose signature I had to change to avoid unsigned long for timestamps.
This was no fun.
Quoted 2 lines
Is there a regex or something that can be used to spot new such places that sneak in, e.g. through in-flight merges?
No, a regex would only work if we already had converted all unsigned long uses to semantically meaningful data types.
Ciao,
Dscho
P.S.: Please remove the quoted interdiff when there is no reason to keep it around.
Re: [PATCH v5 0/8] Introduce timestamp_t for timestamps
Hi Dscho,
Am 26.04.2017 um 00:22 schrieb Johannes Schindelin:
Quoted 10 lines · René Scharfe
Quoted 6 lines
Am 24.04.2017 um 15:57 schrieb Johannes Schindelin:
Can we leavetime_talone and just do the part where you replace unsigned long withtimestamp_tdefined asuint64_t? That should already help on Windows, correct? When/iftimestamp_tis later changed to a signed type then we could easily convert thetime_tcases totimestamp_tas well, or the other way around.This patch series leaves
time_talone already, so your wish has been fulfilled preemptively.
Sounds good! It does contain conversions from time_t to timestamp_t in archive-zip.c, though. I'll comment in reply to the relevant patch.
Quoted 19 lines
Quoted 10 lines
Quoted 5 lines
It is arguably a bug to paper over too-large author/committer dates and to replace them with Jan 1 1970 without even telling the user that we do that, but this is the behavior that t4212 verifies, so I reinstated that behavior. The change in behavior was missed because of the missing
unsigned_add_overflows()test.I can't think of many ways to get future time stamps (broken clock, broken CMOS battery, bit rot, time travel), so I wouldn't expect a change towards better error reporting to affect a lot of users. (Not necessarily as part of this series, of course.)
If you want to suggest that we should stop verifying overflows when a complex reasoning can prove that the overflow is not happening in a billion years, I disagree. Not only is it unnecessarily time-consuming to ask readers to perform the complex reasoning, and not only is there enough room for bugs to hide in plain sight (because of the complexity), it also makes the same code harder to reuse in other software where a different timestamp data type was chosen (or inherited from previous Git versions).
Quoted 6 lines
I'd much rather have easy-to-reason code that does not cause head scratching (like the "why do we ignore a too large timestamp?" triggering
if (date_overflows(date)) date = 0;) than pretending to be smart and clever and make everybody else feel stupid by forcing them through hoops of thinking bubbles until they also reached the conclusion that this actually won't happen. Unless there is a bug in the code.
No, I meant that the presence of tests does not necessarily cast an undesirable behavior into stone, especially if it's hard to trigger in real life. And that improvements thereof can be done later. In other words: It's OK to maintain the same behavior in this series, but cheer up, we may be able to fix the issue eventually.
René
Re: [PATCH v5 0/8] Introduce timestamp_t for timestamps
In reply to René ScharfeQuoted 4 lines · René Scharfe
I can't think of many ways to get future time stamps (broken clock, broken CMOS battery, bit rot, time travel), so I wouldn't expect a change towards better error reporting to affect a lot of users. (Not necessarily as part of this series, of course.)
Better error reporting is one thing, but we do not want to kill "git log" in the middle by calling die().
Dropping the patch v4 9/9 that caused us to call die() was a good thing to do within the scope of this series, I would think.
v6 cover Introduce timestamp_t for timestamps
In reply to Johannes SchindelinGit v2.9.2 was released in a hurry to accomodate for platforms like Windows, where the unsigned long data type is 32-bit even for 64-bit setups.
The quick fix was to simply disable all the testing with "absurd" future dates.
However, we can do much better than that, as we already make use of 64-bit data types internally. There is no good reason why we should not use the same for timestamps. Hence, let's use uintmax_t for timestamps.
Note: while the time_t data type exists and is meant to be used for timestamps, on 32-bit Linux it is *still* 32-bit. An earlier iteration used time_t for that reason, but it came with a few serious downsides:
as time_t can be signed (and indeed, on Windows it is an int64_t), Git's expectation that 0 is the minimal value would no longer hold true, introducing its own set of interesting challenges. Besides, if we *can* handle far in the future timestamps (except for formatting them using the system libraries), it is more consistent to do so.
The upside of using uintmax_t for timestamps is that we do a much better job to support far in the future timestamps across all platforms, including 32-bit ones. The downside is that those platforms that use a 32-bit time_t will barf when parsing or formatting those timestamps.
Hannes Sixt found two more improvements which I incorporated into this iteration.
Changes since v5:
- use UINTMAX_MAX as TIME_MAX instead of rolling funny ULLONG_MAX games (thanks Hannes Sixt)
- mark the large constant in archive-tar.c as unsigned long long, as we cannot know that unsigned long is large enough (again, thanks Hannes Sixt)
Johannes Schindelin (8):
ref-filter: avoid using unsigned long for catch-all data type t0006 & t5000: prepare for 64-bit timestamps
t0006 & t5000: skip "far in the future" test when time_t is too
limited
Specify explicitly where we parse timestamps Introduce a new "printf format" for timestamps Introduce a new data type for timestamps
Abort if the system time cannot handle one of our timestamps Use uintmax_t for timestamps
Documentation/technical/api-parse-options.txt | 8 +- archive-tar.c | 7 +- archive-zip.c | 12 ++- archive.h | 2 +- builtin/am.c | 4 +- builtin/blame.c | 14 ++-- builtin/fsck.c | 6 +- builtin/gc.c | 2 +- builtin/log.c | 4 +- builtin/merge-base.c | 2 +- builtin/name-rev.c | 6 +- builtin/pack-objects.c | 4 +- builtin/prune.c | 4 +- builtin/receive-pack.c | 14 ++-- builtin/reflog.c | 24 +++--- builtin/rev-list.c | 2 +- builtin/rev-parse.c | 2 +- builtin/show-branch.c | 4 +- builtin/worktree.c | 4 +- bundle.c | 4 +- cache.h | 14 ++-- commit.c | 18 ++-- commit.h | 2 +- config.c | 2 +- credential-cache--daemon.c | 12 +-- date.c | 113 ++++++++++++++------------ fetch-pack.c | 8 +- fsck.c | 2 +- git-compat-util.h | 5 ++ http-backend.c | 4 +- parse-options-cb.c | 4 +- pretty.c | 4 +- reachable.c | 9 +- reachable.h | 4 +- ref-filter.c | 22 ++--- reflog-walk.c | 8 +- refs.c | 14 ++-- refs.h | 8 +- refs/files-backend.c | 8 +- revision.c | 6 +- revision.h | 4 +- sha1_name.c | 6 +- t/helper/test-date.c | 18 ++-- t/helper/test-parse-options.c | 4 +- t/helper/test-ref-store.c | 4 +- t/t0006-date.sh | 4 +- t/t5000-tar-tree.sh | 6 +- t/test-lib.sh | 3 + tag.c | 6 +- tag.h | 2 +- upload-pack.c | 8 +- vcs-svn/fast_export.c | 8 +- vcs-svn/fast_export.h | 4 +- vcs-svn/svndump.c | 2 +- wt-status.c | 2 +- 55 files changed, 257 insertions(+), 220 deletions(-)
base-commit: e2cb6ab84c94f147f1259260961513b40c36108a
Published-As: https://github.com/dscho/git/releases/tag/time_t-may-be-int64-v6
Fetch-It-Via: git fetch https://github.com/dscho/git time_t-may-be-int64-v6
Interdiff vs v5:
diff --git a/archive-tar.c b/archive-tar.c
index 695339a2369..319a5b1c7cd 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -28,7 +28,7 @@ static int write_tar_filter_archive(const struct archiver *ar,
#if ULONG_MAX == 0xFFFFFFFF
#define USTAR_MAX_SIZE ULONG_MAX
#else
-#define USTAR_MAX_SIZE 077777777777UL
+#define USTAR_MAX_SIZE 077777777777ULL
#endif
#if TIME_MAX == 0xFFFFFFFF
#define USTAR_MAX_MTIME TIME_MAX
diff --git a/git-compat-util.h b/git-compat-util.h
index b66995685af..f366180f4b9 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -322,11 +322,7 @@ extern char *gitdirname(char *);
typedef uintmax_t timestamp_t;
#define PRItime PRIuMAX
#define parse_timestamp strtoumax
-#ifdef ULLONG_MAX
-#define TIME_MAX ULLONG_MAX
-#else
-#define TIME_MAX ULONG_MAX
-#endif
+#define TIME_MAX UINTMAX_MAX
#ifndef PATH_SEP #define PATH_SEP ':'
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH v6 1/8 ref-filter: avoid using `unsigned long` for catch-all data type
In its atom_value struct, the ref-filter source code wants to store different values in a field called ul (for unsigned long), e.g. timestamps.
However, as we are about to switch the data type of timestamps away from unsigned long (because it may be 32-bit even when time_t is 64-bit), that data type is not large enough.
Simply change that field to use uintmax_t instead.
This patch is a bit larger than the mere change of the data type because the field's name was tied to its data type, which has been fixed at the same time.
--- ref-filter.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
ref-filter.c +8 -8
@@ -351,7 +351,7 @@ struct ref_formatting_state {struct atom_value {const char *s;void (*handler)(struct atom_value *atomv,struct ref_formatting_state *state); -unsigned long ul;/* used for sorting when not FIELD_STR */ +uintmax_t value;/* used for sorting when not FIELD_STR */ struct used_atom *atom; };
@@ -723,7 +723,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct objectif (!strcmp (name,"objecttype" )) v->s =typename (obj->type);else if (!strcmp (name,"objectsize" )) { - v->ul = sz; + v->value = sz; v->s =xstrfmt ("%lu" , sz); }else if (deref)
@@ -770,8 +770,8 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object v->s =xstrdup (oid_to_hex (&commit->tree->object.oid)); }else if (!strcmp (name,"numparent" )) { - v->ul =commit_list_count (commit->parents); - v->s =xstrfmt ("%lu" , v->ul); + v->value =commit_list_count (commit->parents); + v->s =xstrfmt ("%lu" , (unsigned long )v->value); }else if (!strcmp (name,"parent" )) {struct commit_list *parents;
@@ -875,11 +875,11 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnamif ((tz ==LONG_MIN || tz ==LONG_MAX ) && errno ==ERANGE ) goto bad; v->s =xstrdup (show_date (timestamp, tz, &date_mode)); - v->ul = timestamp; + v->value = timestamp;return ; bad: v->s ="" ; - v->ul =0 ; + v->value =0 ; }/* See grab_values */
@@ -1941,9 +1941,9 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, struelse if (cmp_type ==FIELD_STR ) cmp =cmp_fn (va->s, vb->s);else { -if (va->ul < vb->ul) +if (va->value < vb->value) cmp =-1 ; -else if (va->ul == vb->ul) +else if (va->value == vb->value) cmp =cmp_fn (a->refname, b->refname);else cmp =1 ;
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH v6 2/8 t0006 & t5000: prepare for 64-bit timestamps
In reply to Johannes SchindelinGit's source code refers to timestamps as unsigned longs. On 32-bit platforms, as well as on Windows, unsigned long is not large enough to capture dates that are "absurdly far in the future".
It is perfectly valid by the C standard, of course, for the long data type to refer to 32-bit integers. That is why the time_t data type
exists: so that it can be 64-bit even if long is 32-bit. Git's source code simply uses an incorrect data type for timestamps, is all.
The earlier quick fix 6b9c38e14cd (t0006: skip "far in the future" test when unsigned long is not long enough, 2016-07-11) papered over this issue simply by skipping the respective test cases on platforms where they would fail due to the data type in use.
This quick fix, however, tests for *long* to be 64-bit or not. What we need, though, is a test that says whether *whatever data type we use for timestamps* is 64-bit or not.
The same quick fix was used to handle the similar problem where Git's source code uses unsigned long to represent size, instead of size_t, conflating the two issues.
So let's just add another prerequisite to test specifically whether timestamps are represented by a 64-bit data type or not. Later, after we switch to a larger data type, we can flip that prerequisite to test time_t instead of long.
--- t/helper/test-date.c | 5 ++++- t/t0006-date.sh | 4 ++-- t/t5000-tar-tree.sh | 6 +++--- t/test-lib.sh | 2 ++ 4 files changed, 11 insertions(+), 6 deletions(-)
t/helper/test-date.c +4 -1
@@ -4,7 +4,8 @@ static const char *usage_msg = "\n"" test-date relative [time_t]...\n" " test-date show:<format> [time_t]...\n" " test-date parse [date]...\n" -" test-date approxidate [date]...\n" ; +" test-date approxidate [date]...\n" +" test-date is64bit\n" ;static void show_relative_dates (const char **argv,struct timeval *now) {
@@ -93,6 +94,8 @@ int cmd_main(int argc, const char **argv)parse_dates (argv+1 , &now); else if (!strcmp(*argv, "approxidate"))parse_approxidate (argv+1 , &now); + else if (!strcmp(*argv, "is64bit")) +return sizeof (unsigned long ) ==8 ?0 :1 ; elseusage (usage_msg );return 0 ;
t/t0006-date.sh +2 -2
@@ -53,8 +53,8 @@ check_show unix-local "$TIME" '1466000000' # arbitrary time absurdly far in the future FUTURE="5758122296 -0400" -check_show iso "$FUTURE" "2152-06-19 18:24:56 -0400" LONG_IS_64BIT -check_show iso-local "$FUTURE" "2152-06-19 22:24:56 +0000" LONG_IS_64BIT +check_show iso "$FUTURE" "2152-06-19 18:24:56 -0400" TIME_IS_64BIT +check_show iso-local "$FUTURE" "2152-06-19 22:24:56 +0000" TIME_IS_64BIT check_parse() { echo "$1 -> $2" >expect
t/t5000-tar-tree.sh +3 -3
@@ -390,7 +390,7 @@ test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our huge size' ' test_cmp expect actual ' -test_expect_success LONG_IS_64BIT 'set up repository with far-future commit' ' +test_expect_success TIME_IS_64BIT 'set up repository with far-future commit' ' rm -f .git/index && echo content >file && git add file &&
@@ -398,11 +398,11 @@ test_expect_success LONG_IS_64BIT 'set up repository with far-future commit' ' git commit -m "tempori parendum" ' -test_expect_success LONG_IS_64BIT 'generate tar with future mtime' ' +test_expect_success TIME_IS_64BIT 'generate tar with future mtime' ' git archive HEAD >future.tar ' -test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our future mtime' ' +test_expect_success TAR_HUGE,TIME_IS_64BIT 'system tar can read our future mtime' ' echo 4147 >expect && tar_info future.tar | cut -d" " -f2 >actual && test_cmp expect actual
t/test-lib.sh +2 -0
@@ -1164,3 +1164,5 @@ build_option () { test_lazy_prereq LONG_IS_64BIT ' test 8 -le "$(build_option sizeof-long)" ' + +test_lazy_prereq TIME_IS_64BIT 'test-date is64bit'
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH v6 3/8 t0006 & t5000: skip "far in the future" test when time_t is too limited
In reply to Johannes SchindelinGit's source code refers to timestamps as unsigned long, which is ill-defined, as there is no guarantee about the number of bits that data type has.
In preparation of switching to another data type that is large enough to hold "far in the future" dates, we need to prepare the t0006-date.sh script for the case where we *still* cannot format those dates if the system library uses 32-bit time_t.
--- t/helper/test-date.c | 5 ++++- t/t0006-date.sh | 4 ++-- t/t5000-tar-tree.sh | 2 +- t/test-lib.sh | 1 + 4 files changed, 8 insertions(+), 4 deletions(-)
t/helper/test-date.c +4 -1
@@ -5,7 +5,8 @@ static const char *usage_msg = "\n"" test-date show:<format> [time_t]...\n" " test-date parse [date]...\n" " test-date approxidate [date]...\n" -" test-date is64bit\n" ; +" test-date is64bit\n" +" test-date time_t-is64bit\n" ;static void show_relative_dates (const char **argv,struct timeval *now) {
@@ -96,6 +97,8 @@ int cmd_main(int argc, const char **argv)parse_approxidate (argv+1 , &now); else if (!strcmp(*argv, "is64bit"))return sizeof (unsigned long ) ==8 ?0 :1 ; + else if (!strcmp(*argv, "time_t-is64bit")) +return sizeof (time_t) ==8 ?0 :1 ; elseusage (usage_msg );return 0 ;
t/t0006-date.sh +2 -2
@@ -53,8 +53,8 @@ check_show unix-local "$TIME" '1466000000' # arbitrary time absurdly far in the future FUTURE="5758122296 -0400" -check_show iso "$FUTURE" "2152-06-19 18:24:56 -0400" TIME_IS_64BIT -check_show iso-local "$FUTURE" "2152-06-19 22:24:56 +0000" TIME_IS_64BIT +check_show iso "$FUTURE" "2152-06-19 18:24:56 -0400" TIME_IS_64BIT,TIME_T_IS_64BIT +check_show iso-local "$FUTURE" "2152-06-19 22:24:56 +0000" TIME_IS_64BIT,TIME_T_IS_64BIT check_parse() { echo "$1 -> $2" >expect
t/t5000-tar-tree.sh +1 -1
@@ -402,7 +402,7 @@ test_expect_success TIME_IS_64BIT 'generate tar with future mtime' ' git archive HEAD >future.tar ' -test_expect_success TAR_HUGE,TIME_IS_64BIT 'system tar can read our future mtime' ' +test_expect_success TAR_HUGE,TIME_IS_64BIT,TIME_T_IS_64BIT 'system tar can read our future mtime' ' echo 4147 >expect && tar_info future.tar | cut -d" " -f2 >actual && test_cmp expect actual
t/test-lib.sh +1 -0
@@ -1166,3 +1166,4 @@ test_lazy_prereq LONG_IS_64BIT ' ' test_lazy_prereq TIME_IS_64BIT 'test-date is64bit' +test_lazy_prereq TIME_T_IS_64BIT 'test-date time_t-is64bit'
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH v6 4/8 Specify explicitly where we parse timestamps
In reply to Johannes SchindelinCurrently, 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.
--- builtin/am.c | 2 +- builtin/receive-pack.c | 4 ++-- bundle.c | 2 +- commit.c | 6 +++--- date.c | 6 +++--- fsck.c | 2 +- git-compat-util.h | 2 ++ pretty.c | 2 +- ref-filter.c | 2 +- refs/files-backend.c | 2 +- t/helper/test-date.c | 2 +- tag.c | 4 ++-- upload-pack.c | 2 +- 13 files changed, 20 insertions(+), 18 deletions(-)
builtin/am.c +1 -1
@@ -886,7 +886,7 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)char *end; errno =0 ; - timestamp =strtoul (str, &end,10 ); + timestamp =parse_timestamp (str, &end,10 );if (errno)return error (_ ("invalid timestamp" ));
builtin/receive-pack.c +2 -2
@@ -534,7 +534,7 @@ static const char *check_nonce(const char *buf, size_t len) retval =NONCE_BAD ; goto leave; } - stamp =strtoul (nonce, &bohmac,10 ); + stamp =parse_timestamp (nonce, &bohmac,10 );if (bohmac == nonce || bohmac[0 ] !='-' ) { retval =NONCE_BAD ; goto leave;
@@ -552,7 +552,7 @@ static const char *check_nonce(const char *buf, size_t len)* would mean it was issued by another server with its clock * skewed in the future. */ - ostamp =strtoul (push_cert_nonce,NULL ,10 ); + ostamp =parse_timestamp (push_cert_nonce,NULL ,10 ); nonce_stamp_slop = (long )ostamp - (long )stamp; if (nonce_stamp_slop_limit &&
bundle.c +1 -1
@@ -227,7 +227,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs) line =memchr (line,'>' , lineend ? lineend - line : buf + size - line);if (!line++) goto out; - date =strtoul (line,NULL ,10 ); + date =parse_timestamp (line,NULL ,10 ); result = (revs->max_age ==-1 || revs->max_age < date) && (revs->min_age ==-1 || revs->min_age > date); out:
commit.c +3 -3
@@ -89,8 +89,8 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)/* nada */ ;if (buf >= tail)return 0 ; -/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */ -return strtoul (dateptr,NULL ,10 ); +/* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */ +return parse_timestamp (dateptr,NULL ,10 ); }static struct commit_graft **commit_graft;
@@ -607,7 +607,7 @@ static void record_author_date(struct author_date_slab *author_date, !ident.date_begin || !ident.date_end) goto fail_exit;/* malformed "author" line */ - date =strtoul (ident.date_begin, &date_end,10 ); + date =parse_timestamp (ident.date_begin, &date_end,10 );if (date_end != ident.date_end) goto fail_exit;/* malformed date */ *(author_date_slab_at (author_date, commit)) = date;
date.c +3 -3
@@ -510,7 +510,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmtchar *end;unsigned long num; - num =strtoul (date, &end,10 ); + num =parse_timestamp (date, &end,10 );/* * Seconds since 1970? We trigger on that for any numbers with
@@ -658,7 +658,7 @@ static int match_object_header_date(const char *date, unsigned long *timestamp,if (*date <'0' ||'9' < *date)return -1 ; - stamp =strtoul (date, &end,10 ); + stamp =parse_timestamp (date, &end,10 );if (*end !=' ' || stamp ==ULONG_MAX || (end[1 ] !='+' && end[1 ] !='-' ))return -1 ; date = end +2 ;
@@ -1066,7 +1066,7 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num, time_t now) {char *end; -unsigned long number =strtoul (date, &end,10 ); +unsigned long number =parse_timestamp (date, &end,10 );switch (*end) {case ':' :
fsck.c +1 -1
@@ -691,7 +691,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option p++;if (*p =='0' && p[1 ] !=' ' )return report (options, obj,FSCK_MSG_ZERO_PADDED_DATE ,"invalid author/committer line - zero-padded date" ); -if (date_overflows (strtoul (p, &end,10 ))) +if (date_overflows (parse_timestamp (p, &end,10 )))return report (options, obj,FSCK_MSG_BAD_DATE_OVERFLOW ,"invalid author/committer line - date causes integer overflow" );if ((end == p || *end !=' ' ))return report (options, obj,FSCK_MSG_BAD_DATE ,"invalid author/committer line - bad date" );
git-compat-util.h +2 -0
@@ -319,6 +319,8 @@ extern char *gitdirname(char *);#define PRIo32 "o"#endif +#define parse_timestamp strtoul +#ifndef PATH_SEP #define PATH_SEP ':'#endif
pretty.c +1 -1
@@ -409,7 +409,7 @@ const char *show_ident_date(const struct ident_split *ident,long tz =0 ;if (ident->date_begin && ident->date_end) - date =strtoul (ident->date_begin,NULL ,10 ); + date =parse_timestamp (ident->date_begin,NULL ,10 );if (date_overflows (date)) date =0 ;else {
ref-filter.c +1 -1
@@ -868,7 +868,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnamif (!eoemail) goto bad; - timestamp =strtoul (eoemail +2 , &zone,10 ); + timestamp =parse_timestamp (eoemail +2 , &zone,10 );if (timestamp ==ULONG_MAX ) goto bad; tz =strtol (zone,NULL ,10 );
refs/files-backend.c +1 -1
@@ -3247,7 +3247,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cparse_oid_hex (p, &noid, &p) || *p++ !=' ' || !(email_end =strchr (p,'>' )) || email_end[1 ] !=' ' || - !(timestamp =strtoul (email_end +2 , &message,10 )) || + !(timestamp =parse_timestamp (email_end +2 , &message,10 )) || !message || message[0 ] !=' ' || (message[1 ] !='+' && message[1 ] !='-' ) || !isdigit(message[2]) || !isdigit(message[3]) ||
t/helper/test-date.c +1 -1
@@ -34,7 +34,7 @@ static void show_dates(const char **argv, const char *format)* Do not use our normal timestamp parsing here, as the point * is to test the formatting code in isolation. */ - t =strtol (*argv, &arg,10 ); + t =parse_timestamp (*argv, &arg,10 );while (*arg ==' ' ) arg++; tz =atoi (arg);
tag.c +2 -2
@@ -110,8 +110,8 @@ static unsigned long parse_tag_date(const char *buf, const char *tail)/* nada */ ;if (buf >= tail)return 0 ; -/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */ -return strtoul (dateptr,NULL ,10 ); +/* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */ +return parse_timestamp (dateptr,NULL ,10 ); }int parse_tag_buffer (struct tag *item,const void *data,unsigned long size)
upload-pack.c +1 -1
@@ -775,7 +775,7 @@ static void receive_needs(void) }if (skip_prefix (line,"deepen-since " , &arg)) {char *end =NULL ; - deepen_since =strtoul (arg, &end,0 ); + deepen_since =parse_timestamp (arg, &end,0 );if (!end || *end || !deepen_since ||/* revisions.c's max_age -1 is special */ deepen_since ==-1 )
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH v6 5/8 Introduce a new "printf format" for timestamps
In reply to Johannes SchindelinCurrently, 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.
--- builtin/blame.c | 6 +++--- builtin/fsck.c | 2 +- builtin/log.c | 2 +- builtin/receive-pack.c | 4 ++-- builtin/rev-list.c | 2 +- builtin/rev-parse.c | 2 +- date.c | 26 +++++++++++++------------- fetch-pack.c | 2 +- git-compat-util.h | 1 + refs/files-backend.c | 2 +- t/helper/test-date.c | 2 +- t/helper/test-parse-options.c | 2 +- t/helper/test-ref-store.c | 2 +- upload-pack.c | 2 +- vcs-svn/fast_export.c | 4 ++-- 15 files changed, 31 insertions(+), 30 deletions(-)
builtin/blame.c +3 -3
@@ -1727,11 +1727,11 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)get_commit_info (suspect->commit, &ci,1 );printf ("author %s\n" , ci.author.buf);printf ("author-mail %s\n" , ci.author_mail.buf); -printf ("author-time %lu\n" , ci.author_time); +printf ("author-time %" PRItime"\n" , ci.author_time);printf ("author-tz %s\n" , ci.author_tz.buf);printf ("committer %s\n" , ci.committer.buf);printf ("committer-mail %s\n" , ci.committer_mail.buf); -printf ("committer-time %lu\n" , ci.committer_time); +printf ("committer-time %" PRItime"\n" , ci.committer_time);printf ("committer-tz %s\n" , ci.committer_tz.buf);printf ("summary %s\n" , ci.summary.buf);if (suspect->commit->object.flags &UNINTERESTING )
@@ -1844,7 +1844,7 @@ static const char *format_time(unsigned long time, const char *tz_str,strbuf_reset (&time_buf);if (show_raw_time) { -strbuf_addf (&time_buf,"%lu %s" , time, tz_str); +strbuf_addf (&time_buf,"%" PRItime" %s" , time, tz_str); }else {const char *time_str;
builtin/fsck.c +1 -1
@@ -407,7 +407,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,if (timestamp && name_objects)add_decoration (fsck_walk_options.object_names, obj, -xstrfmt ("%s@{%ld}" , refname, timestamp)); +xstrfmt ("%s@{%" PRItime"}" , refname, timestamp)); obj->used =1 ;mark_object_reachable (obj); }else {
builtin/log.c +1 -1
@@ -910,7 +910,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)static void gen_message_id (struct rev_info *info,char *base) {struct strbuf buf =STRBUF_INIT ; -strbuf_addf (&buf,"%s.%lu.git.%s" , base, +strbuf_addf (&buf,"%s.%" PRItime".git.%s" , base, (unsigned long )time (NULL ),git_committer_info (IDENT_NO_NAME |IDENT_NO_DATE |IDENT_STRICT )); info->message_id =strbuf_detach (&buf,NULL );
builtin/receive-pack.c +2 -2
@@ -459,12 +459,12 @@ static char *prepare_push_cert_nonce(const char *path, unsigned long stamp)struct strbuf buf =STRBUF_INIT ;unsigned char sha1[20 ]; -strbuf_addf (&buf,"%s:%lu" , path, stamp); +strbuf_addf (&buf,"%s:%" PRItime, path, stamp);hmac_sha1 (sha1, buf.buf, buf.len, cert_nonce_seed,strlen (cert_nonce_seed));;strbuf_release (&buf);/* RFC 2104 5. HMAC-SHA1-80 */ -strbuf_addf (&buf,"%lu-%.*s" , stamp,20 ,sha1_to_hex (sha1)); +strbuf_addf (&buf,"%" PRItime"-%.*s" , stamp,20 ,sha1_to_hex (sha1));return strbuf_detach (&buf,NULL ); }
builtin/rev-list.c +1 -1
@@ -80,7 +80,7 @@ static void show_commit(struct commit *commit, void *data) }if (info->show_timestamp) -printf ("%lu " , commit->date); +printf ("%" PRItime" " , commit->date);if (info->header_prefix)fputs (info->header_prefix, stdout);
builtin/rev-parse.c +1 -1
@@ -218,7 +218,7 @@ static void show_datestring(const char *flag, const char *datestr)/* date handling requires both flags and revs */ if ((filter & (DO_FLAGS |DO_REVS )) != (DO_FLAGS |DO_REVS ))return ; - buffer =xstrfmt ("%s%lu" , flag,approxidate (datestr)); + buffer =xstrfmt ("%s%" PRItime, flag,approxidate (datestr));show (buffer);free (buffer); }
date.c +13 -13
@@ -100,41 +100,41 @@ void show_date_relative(unsigned long time, int tz, diff = now->tv_sec - time;if (diff <90 ) {strbuf_addf (timebuf, -Q_ ("%lu second ago" ,"%lu seconds ago" , diff), diff); +Q_ ("%" PRItime" second ago" ,"%" PRItime" seconds ago" , diff), diff);return ; }/* Turn it into minutes */ diff = (diff +30 ) /60 ;if (diff <90 ) {strbuf_addf (timebuf, -Q_ ("%lu minute ago" ,"%lu minutes ago" , diff), diff); +Q_ ("%" PRItime" minute ago" ,"%" PRItime" minutes ago" , diff), diff);return ; }/* Turn it into hours */ diff = (diff +30 ) /60 ;if (diff <36 ) {strbuf_addf (timebuf, -Q_ ("%lu hour ago" ,"%lu hours ago" , diff), diff); +Q_ ("%" PRItime" hour ago" ,"%" PRItime" hours ago" , diff), diff);return ; }/* We deal with number of days from here on */ diff = (diff +12 ) /24 ;if (diff <14 ) {strbuf_addf (timebuf, -Q_ ("%lu day ago" ,"%lu days ago" , diff), diff); +Q_ ("%" PRItime" day ago" ,"%" PRItime" days ago" , diff), diff);return ; }/* Say weeks for the past 10 weeks or so */ if (diff <70 ) {strbuf_addf (timebuf, -Q_ ("%lu week ago" ,"%lu weeks ago" , (diff +3 ) /7 ), +Q_ ("%" PRItime" week ago" ,"%" PRItime" weeks ago" , (diff +3 ) /7 ), (diff +3 ) /7 );return ; }/* Say months for the past 12 months or so */ if (diff <365 ) {strbuf_addf (timebuf, -Q_ ("%lu month ago" ,"%lu months ago" , (diff +15 ) /30 ), +Q_ ("%" PRItime" month ago" ,"%" PRItime" months ago" , (diff +15 ) /30 ), (diff +15 ) /30 );return ; }
@@ -145,20 +145,20 @@ void show_date_relative(unsigned long time, int tz,unsigned long months = totalmonths %12 ;if (months) {struct strbuf sb =STRBUF_INIT ; -strbuf_addf (&sb,Q_ ("%lu year" ,"%lu years" , years), years); +strbuf_addf (&sb,Q_ ("%" PRItime" year" ,"%" PRItime" years" , years), years);strbuf_addf (timebuf,/* TRANSLATORS: "%s" is "<n> years" */ -Q_ ("%s, %lu month ago" ,"%s, %lu months ago" , months), +Q_ ("%s, %" PRItime" month ago" ,"%s, %" PRItime" months ago" , months), sb.buf, months);strbuf_release (&sb); }else strbuf_addf (timebuf, -Q_ ("%lu year ago" ,"%lu years ago" , years), years); +Q_ ("%" PRItime" year ago" ,"%" PRItime" years ago" , years), years);return ; }/* Otherwise, just years. Centuries is probably overkill. */ strbuf_addf (timebuf, -Q_ ("%lu year ago" ,"%lu years ago" , (diff +183 ) /365 ), +Q_ ("%" PRItime" year ago" ,"%" PRItime" years ago" , (diff +183 ) /365 ), (diff +183 ) /365 ); }
@@ -179,7 +179,7 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)if (mode->type ==DATE_UNIX ) {strbuf_reset (&timebuf); -strbuf_addf (&timebuf,"%lu" , time); +strbuf_addf (&timebuf,"%" PRItime, time);return timebuf.buf; }
@@ -188,7 +188,7 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)if (mode->type ==DATE_RAW ) {strbuf_reset (&timebuf); -strbuf_addf (&timebuf,"%lu %+05d" , time, tz); +strbuf_addf (&timebuf,"%" PRItime" %+05d" , time, tz);return timebuf.buf; }
@@ -643,7 +643,7 @@ static void date_string(unsigned long date, int offset, struct strbuf *buf) offset = -offset; sign ='-' ; } -strbuf_addf (buf,"%lu %c%02d%02d" , date, sign, offset /60 , offset %60 ); +strbuf_addf (buf,"%" PRItime" %c%02d%02d" , date, sign, offset /60 , offset %60 ); }/*
fetch-pack.c +1 -1
@@ -395,7 +395,7 @@ static int find_common(struct fetch_pack_args *args,packet_buf_write (&req_buf,"deepen %d" , args->depth);if (args->deepen_since) {unsigned long max_age =approxidate (args->deepen_since); -packet_buf_write (&req_buf,"deepen-since %lu" , max_age); +packet_buf_write (&req_buf,"deepen-since %" PRItime, max_age); }if (args->deepen_not) {int i;
git-compat-util.h +1 -0
@@ -319,6 +319,7 @@ extern char *gitdirname(char *);#define PRIo32 "o"#endif +#define PRItime "lu"#define parse_timestamp strtoul#ifndef PATH_SEP
refs/files-backend.c +1 -1
@@ -4135,7 +4135,7 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,printf ("prune %s" , message); }else {if (cb->newlog) { -fprintf (cb->newlog,"%s %s %s %lu %+05d\t%s" , +fprintf (cb->newlog,"%s %s %s %" PRItime" %+05d\t%s" ,oid_to_hex (ooid),oid_to_hex (noid), email, timestamp, tz, message);oidcpy (&cb->last_kept_oid, noid);
t/helper/test-date.c +1 -1
@@ -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
t/helper/test-parse-options.c +1 -1
@@ -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);
t/helper/test-ref-store.c +1 -1
@@ -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 ;
upload-pack.c +1 -1
@@ -863,7 +863,7 @@ static void receive_needs(void)argv_array_push (&av,"rev-list" );if (deepen_since) -argv_array_pushf (&av,"--max-age=%lu" , deepen_since); +argv_array_pushf (&av,"--max-age=%" PRItime, deepen_since);if (deepen_not.nr) {argv_array_push (&av,"--not" );for (i =0 ; i < deepen_not.nr; i++) {
vcs-svn/fast_export.c +2 -2
@@ -73,7 +73,7 @@ void fast_export_begin_note(uint32_t revision, const char *author,static int firstnote =1 ;size_t loglen =strlen (log);printf ("commit %s\n" , note_ref); -printf ("committer %s <%s@%s> %lu +0000\n" , author, author,"local" , timestamp); +printf ("committer %s <%s@%s> %" PRItime" +0000\n" , author, author,"local" , timestamp);printf ("data %" PRIuMAX"\n" , (uintmax_t )loglen);fwrite (log, loglen,1 , stdout);if (firstnote) {
@@ -107,7 +107,7 @@ void fast_export_begin_commit(uint32_t revision, const char *author, }printf ("commit %s\n" , local_ref);printf ("mark :%" PRIu32"\n" , revision); -printf ("committer %s <%s@%s> %lu +0000\n" , +printf ("committer %s <%s@%s> %" PRItime" +0000\n" , *author ? author :"nobody" , *author ? author :"nobody" , *uuid ? uuid :"local" , timestamp);
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH v6 6/8 Introduce a new data type for timestamps
In reply to Johannes SchindelinGit'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.
--- Documentation/technical/api-parse-options.txt | 8 ++-- archive-tar.c | 7 ++- archive-zip.c | 12 ++++- archive.h | 2 +- builtin/am.c | 2 +- builtin/blame.c | 8 ++-- builtin/fsck.c | 4 +- builtin/gc.c | 2 +- builtin/log.c | 2 +- builtin/merge-base.c | 2 +- builtin/name-rev.c | 6 +-- builtin/pack-objects.c | 4 +- builtin/prune.c | 4 +- builtin/receive-pack.c | 6 +-- builtin/reflog.c | 24 +++++----- builtin/show-branch.c | 4 +- builtin/worktree.c | 4 +- bundle.c | 2 +- cache.h | 14 +++--- commit.c | 12 ++--- commit.h | 2 +- config.c | 2 +- credential-cache--daemon.c | 12 ++--- date.c | 66 +++++++++++++-------------- fetch-pack.c | 6 +-- git-compat-util.h | 2 + http-backend.c | 4 +- parse-options-cb.c | 4 +- pretty.c | 2 +- reachable.c | 9 ++-- reachable.h | 4 +- ref-filter.c | 4 +- reflog-walk.c | 8 ++-- refs.c | 14 +++--- refs.h | 8 ++-- refs/files-backend.c | 4 +- revision.c | 6 +-- revision.h | 4 +- sha1_name.c | 6 +-- t/helper/test-date.c | 8 ++-- t/helper/test-parse-options.c | 2 +- t/helper/test-ref-store.c | 2 +- tag.c | 2 +- tag.h | 2 +- upload-pack.c | 4 +- vcs-svn/fast_export.c | 4 +- vcs-svn/fast_export.h | 4 +- vcs-svn/svndump.c | 2 +- wt-status.c | 2 +- 49 files changed, 170 insertions(+), 158 deletions(-)
Documentation/technical/api-parse-options.txt +4 -4
@@ -183,13 +183,13 @@ There are some macros to easily define options: scale the provided value by 1024, 1024^2 or 1024^3 respectively. The scaled value is put into `unsigned_long_var`. -`OPT_DATE(short, long, &int_var, description)`:: +`OPT_DATE(short, long, ×tamp_t_var, description)`:: Introduce an option with date argument, see `approxidate()`. - The timestamp is put into `int_var`. + The timestamp is put into `timestamp_t_var`. -`OPT_EXPIRY_DATE(short, long, &int_var, description)`:: +`OPT_EXPIRY_DATE(short, long, ×tamp_t_var, description)`:: Introduce an option with expiry date argument, see `parse_expiry_date()`. - The timestamp is put into `int_var`. + The timestamp is put into `timestamp_t_var`. `OPT_CALLBACK(short, long, &var, arg_str, description, func_ptr)`:: Introduce an option with argument.
archive-tar.c +5 -2
@@ -27,9 +27,12 @@ static int write_tar_filter_archive(const struct archiver *ar,*/ #if ULONG_MAX ==0xFFFFFFFF #define USTAR_MAX_SIZE ULONG_MAX -#define USTAR_MAX_MTIME ULONG_MAX#else -#define USTAR_MAX_SIZE 077777777777UL +#define USTAR_MAX_SIZE 077777777777ULL +#endif +#if TIME_MAX ==0xFFFFFFFF +#define USTAR_MAX_MTIME TIME_MAX +#else #define USTAR_MAX_MTIME 077777777777UL#endif
archive-zip.c +10 -2
@@ -545,9 +545,17 @@ static void write_zip_trailer(const unsigned char *sha1)write_or_die (1 ,sha1_to_hex (sha1),GIT_SHA1_HEXSZ ); } -static void dos_time (time_t *time,int *dos_date,int *dos_time) +static void dos_time (timestamp_t *timestamp,int *dos_date,int *dos_time) { -struct tm *t =localtime (time); +time_t time; +struct tm *t; + +if (date_overflows (*timestamp)) +die ("timestamp too large for this system: %" PRItime, + *timestamp); + time = (time_t)*timestamp; + t =localtime (&time); + *timestamp = time; *dos_date = t->tm_mday + (t->tm_mon +1 ) *32 + (t->tm_year +1900 -1980 ) *512 ;
archive.h +1 -1
@@ -9,7 +9,7 @@ struct archiver_args {struct tree *tree;const unsigned char *commit_sha1;const struct commit *commit; -time_t time; +timestamp_t time;struct pathspec pathspec; unsigned int verbose : 1; unsigned int worktree_attributes : 1;
builtin/am.c +1 -1
@@ -881,7 +881,7 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)if (skip_prefix (sb.buf,"# User " , &str))fprintf (out,"From: %s\n" , str);else if (skip_prefix (sb.buf,"# Date " , &str)) { -unsigned long timestamp; +timestamp_t timestamp;long tz, tz2;char *end;
builtin/blame.c +4 -4
@@ -1561,13 +1561,13 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)struct commit_info {struct strbuf author;struct strbuf author_mail; -unsigned long author_time; +timestamp_t author_time;struct strbuf author_tz;/* filled only when asked for details */ struct strbuf committer;struct strbuf committer_mail; -unsigned long committer_time; +timestamp_t committer_time;struct strbuf committer_tz;struct strbuf summary;
@@ -1578,7 +1578,7 @@ struct commit_info {*/ static void get_ac_line (const char *inbuf,const char *what,struct strbuf *name,struct strbuf *mail, -unsigned long *time,struct strbuf *tz) +timestamp_t *time,struct strbuf *tz) {struct ident_split ident;size_t len, maillen, namelen;
@@ -1837,7 +1837,7 @@ static void assign_blame(struct scoreboard *sb, int opt)stop_progress (&pi.progress); } -static const char *format_time (unsigned long time,const char *tz_str, +static const char *format_time (timestamp_t time,const char *tz_str,int show_raw_time) {static struct strbuf time_buf =STRBUF_INIT ;
builtin/fsck.c +2 -2
@@ -397,7 +397,7 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,static int default_refs;static void fsck_handle_reflog_oid (const char *refname,struct object_id *oid, -unsigned long timestamp) +timestamp_t timestamp) {struct object *obj;
@@ -418,7 +418,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, }static int fsck_handle_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {const char *refname = cb_data;
builtin/gc.c +1 -1
@@ -33,7 +33,7 @@ static int aggressive_window = 250;static int gc_auto_threshold =6700 ;static int gc_auto_pack_limit =50 ;static int detach_auto =1 ; -static unsigned long gc_log_expire_time; +static timestamp_t gc_log_expire_time;static const char *gc_log_expire ="1.day.ago" ;static const char *prune_expire ="2.weeks.ago" ;static const char *prune_worktrees_expire ="3.months.ago" ;
builtin/log.c +1 -1
@@ -911,7 +911,7 @@ static void gen_message_id(struct rev_info *info, char *base) {struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"%s.%" PRItime".git.%s" , base, - (unsigned long )time (NULL ), + (timestamp_t )time (NULL ),git_committer_info (IDENT_NO_NAME |IDENT_NO_DATE |IDENT_STRICT )); info->message_id =strbuf_detach (&buf,NULL ); }
builtin/merge-base.c +1 -1
@@ -132,7 +132,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs) }static int collect_one_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *ident,unsigned long timestamp, +const char *ident,timestamp_t timestamp,int tz,const char *message,void *cbdata) {struct rev_collect *revs = cbdata;
builtin/name-rev.c +3 -3
@@ -10,7 +10,7 @@typedef struct rev_name {const char *tip_name; -unsigned long taggerdate; +timestamp_t taggerdate;int generation;int distance; }rev_name ;
@@ -21,7 +21,7 @@ static long cutoff = LONG_MAX;#define MERGE_TRAVERSAL_WEIGHT 65535static void name_rev (struct commit *commit, -const char *tip_name,unsigned long taggerdate, +const char *tip_name,timestamp_t taggerdate,int generation,int distance,int deref) {
@@ -146,7 +146,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vostruct name_ref_data *data = cb_data;int can_abbreviate_output = data->tags_only && data->name_only;int deref =0 ; -unsigned long taggerdate =ULONG_MAX ; +timestamp_t taggerdate =TIME_MAX ;if (data->tags_only && !starts_with (path,"refs/tags/" ))return 0 ;
builtin/pack-objects.c +2 -2
@@ -44,7 +44,7 @@ static uint32_t nr_result, nr_written;static int non_empty;static int reuse_delta =1 , reuse_object =1 ;static int keep_unreachable, unpack_unreachable, include_tag; -static unsigned long unpack_unreachable_expiration; +static timestamp_t unpack_unreachable_expiration;static int pack_loose_unreachable;static int local;static int have_non_local_packs;
@@ -2675,7 +2675,7 @@ static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)static struct oid_array recent_objects;static int loosened_object_can_be_discarded (const struct object_id *oid, -unsigned long mtime) +timestamp_t mtime) {if (!unpack_unreachable_expiration)return 0 ;
builtin/prune.c +2 -2
@@ -13,7 +13,7 @@ static const char * const prune_usage[] = { };static int show_only;static int verbose; -static unsigned long expire; +static timestamp_t expire;static int show_progress =-1 ;static int prune_tmp_file (const char *fullpath)
@@ -111,7 +111,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix) };char *s; - expire =ULONG_MAX ; + expire =TIME_MAX ; save_commit_buffer =0 ; check_replace_refs =0 ; ref_paranoia =1 ;
builtin/receive-pack.c +3 -3
@@ -78,7 +78,7 @@ static const char *NONCE_OK = "OK";static const char *NONCE_SLOP ="SLOP" ;static const char *nonce_status;static long nonce_stamp_slop; -static unsigned long nonce_stamp_slop_limit; +static timestamp_t nonce_stamp_slop_limit;static struct ref_transaction *transaction; static enum {
@@ -454,7 +454,7 @@ static void hmac_sha1(unsigned char *out,git_SHA1_Final (out, &ctx); } -static char *prepare_push_cert_nonce (const char *path,unsigned long stamp) +static char *prepare_push_cert_nonce (const char *path,timestamp_t stamp) {struct strbuf buf =STRBUF_INIT ;unsigned char sha1[20 ];
@@ -496,7 +496,7 @@ static char *find_header(const char *msg, size_t len, const char *key)static const char *check_nonce (const char *buf,size_t len) {char *nonce =find_header (buf, len,"nonce" ); -unsigned long stamp, ostamp; +timestamp_t stamp, ostamp;char *bohmac, *expect =NULL ;const char *retval =NONCE_BAD ;
builtin/reflog.c +12 -12
@@ -16,14 +16,14 @@ static const char reflog_delete_usage[] =static const char reflog_exists_usage[] ="git reflog exists <ref>" ; -static unsigned long default_reflog_expire; -static unsigned long default_reflog_expire_unreachable; +static timestamp_t default_reflog_expire; +static timestamp_t default_reflog_expire_unreachable;struct cmd_reflog_expire_cb {struct rev_info revs;int stalefix; -unsigned long expire_total; -unsigned long expire_unreachable; +timestamp_t expire_total; +timestamp_t expire_unreachable;int recno; };
@@ -219,7 +219,7 @@ static int keep_entry(struct commit **it, unsigned char *sha1)static void mark_reachable (struct expire_reflog_policy_cb *cb) {struct commit_list *pending; -unsigned long expire_limit = cb->mark_limit; +timestamp_t expire_limit = cb->mark_limit;struct commit_list *leftover =NULL ;for (pending = cb->mark_list; pending; pending = pending->next)
@@ -284,7 +284,7 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit* Return true iff the specified reflog entry should be expired. */ static int should_expire_reflog_ent (unsigned char *osha1,unsigned char *nsha1, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct expire_reflog_policy_cb *cb = cb_data;
@@ -392,8 +392,8 @@ static int collect_reflog(const char *ref, const struct object_id *oid, int unusstatic struct reflog_expire_cfg {struct reflog_expire_cfg *next; -unsigned long expire_total; -unsigned long expire_unreachable; +timestamp_t expire_total; +timestamp_t expire_unreachable;char pattern[FLEX_ARRAY ]; } *reflog_expire_cfg, **reflog_expire_cfg_tail;
@@ -415,7 +415,7 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)return ent; } -static int parse_expire_cfg_value (const char *var,const char *value,unsigned long *expire) +static int parse_expire_cfg_value (const char *var,const char *value,timestamp_t *expire) {if (!value)return config_error_nonbool (var);
@@ -433,7 +433,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb) {const char *pattern, *key;int pattern_len; -unsigned long expire; +timestamp_t expire;int slot;struct reflog_expire_cfg *ent;
@@ -515,7 +515,7 @@ static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, int slot, cstatic int cmd_reflog_expire (int argc,const char **argv,const char *prefix) {struct expire_reflog_policy_cb cb; -unsigned long now =time (NULL ); +timestamp_t now =time (NULL );int i, status, do_all;int explicit_expiry =0 ;unsigned int flags =0 ;
@@ -616,7 +616,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) }static int count_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct expire_reflog_policy_cb *cb = cb_data;
builtin/show-branch.c +2 -2
@@ -735,7 +735,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) base =strtoul (reflog_base, &ep,10 );if (*ep) {/* Ah, that is a date spec... */ -unsigned long at; +timestamp_t at; at =approxidate (reflog_base);read_ref_at (ref, flags, at,-1 , oid.hash,NULL ,NULL ,NULL , &base);
@@ -746,7 +746,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)char *logmsg;char *nth_desc;const char *msg; -unsigned long timestamp; +timestamp_t timestamp;int tz; if (read_ref_at(ref, flags, 0, base+i, oid.hash, &logmsg,
builtin/worktree.c +2 -2
@@ -30,7 +30,7 @@ struct add_opts {static int show_only;static int verbose; -static unsigned long expire; +static timestamp_t expire;static int prune_worktree (const char *id,struct strbuf *reason) {
@@ -131,7 +131,7 @@ static int prune(int ac, const char **av, const char *prefix) OPT_END() }; - expire =ULONG_MAX ; + expire =TIME_MAX ; ac =parse_options (ac, av, prefix, options, worktree_usage,0 );if (ac)usage_with_options (worktree_usage, options);
bundle.c +1 -1
@@ -211,7 +211,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)unsigned long size;enum object_type type;char *buf =NULL , *line, *lineend; -unsigned long date; +timestamp_t date;int result =1 ;if (revs->max_age ==-1 && revs->min_age ==-1 )
cache.h +7 -7
@@ -1478,18 +1478,18 @@ struct date_mode {#define DATE_MODE (t) date_mode_from_type(DATE_##t)struct date_mode *date_mode_from_type (enum date_mode_type type); -const char *show_date (unsigned long time,int timezone,const struct date_mode *mode); -void show_date_relative (unsigned long time,int tz,const struct timeval *now, +const char *show_date (timestamp_t time,int timezone,const struct date_mode *mode); +void show_date_relative (timestamp_t time,int tz,const struct timeval *now,struct strbuf *timebuf);int parse_date (const char *date,struct strbuf *out); -int parse_date_basic (const char *date,unsigned long *timestamp,int *offset); -int parse_expiry_date (const char *date,unsigned long *timestamp); +int parse_date_basic (const char *date,timestamp_t *timestamp,int *offset); +int parse_expiry_date (const char *date,timestamp_t *timestamp);void datestamp (struct strbuf *out);#define approxidate (s) approxidate_careful((s), NULL) -unsigned long approxidate_careful (const char *,int *); -unsigned long approxidate_relative (const char *date,const struct timeval *now); +timestamp_t approxidate_careful (const char *,int *); +timestamp_t approxidate_relative (const char *date,const struct timeval *now);void parse_date_format (const char *format,struct date_mode *mode); -int date_overflows (unsigned long date); +int date_overflows (timestamp_t date);#define IDENT_STRICT 1#define IDENT_NO_DATE 2
commit.c +6 -6
@@ -66,7 +66,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)return commit; } -static unsigned long parse_commit_date (const char *buf,const char *tail) +static timestamp_t parse_commit_date (const char *buf,const char *tail) {const char *dateptr;
@@ -473,8 +473,8 @@ struct commit_list * commit_list_insert_by_date(struct commit *item, struct commstatic int commit_list_compare_by_date (const void *a,const void *b) { -unsigned long a_date = ((const struct commit_list *)a)->item->date; -unsigned long b_date = ((const struct commit_list *)b)->item->date; +timestamp_t a_date = ((const struct commit_list *)a)->item->date; +timestamp_t b_date = ((const struct commit_list *)b)->item->date;if (a_date < b_date)return 1 ;if (a_date > b_date)
@@ -598,7 +598,7 @@ static void record_author_date(struct author_date_slab *author_date,const char *ident_line;size_t ident_len;char *date_end; -unsigned long date; +timestamp_t date; ident_line =find_commit_header (buffer,"author" , &ident_len);if (!ident_line)
@@ -621,8 +621,8 @@ static int compare_commits_by_author_date(const void *a_, const void *b_, {const struct commit *a = a_, *b = b_;struct author_date_slab *author_date = cb_data; -unsigned long a_date = *(author_date_slab_at (author_date, a)); -unsigned long b_date = *(author_date_slab_at (author_date, b)); +timestamp_t a_date = *(author_date_slab_at (author_date, a)); +timestamp_t b_date = *(author_date_slab_at (author_date, b));/* newer commits with larger date first */ if (a_date < b_date)
commit.h +1 -1
@@ -17,7 +17,7 @@ struct commit {struct object object;void *util;unsigned int index; -unsigned long date; +timestamp_t date;struct commit_list *parents;struct tree *tree; };
config.c +1 -1
@@ -1943,7 +1943,7 @@ int git_config_get_expiry(const char *key, const char **output)if (ret)return ret;if (strcmp (*output,"now" )) { -unsigned long now =approxidate ("now" ); +timestamp_t now =approxidate ("now" );if (approxidate (*output) >= now)git_die_config (key,_ ("Invalid %s: '%s'" ), key, *output); }
credential-cache--daemon.c +6 -6
@@ -8,7 +8,7 @@ static struct tempfile socket_file;struct credential_cache_entry {struct credential item; -unsigned long expiration; +timestamp_t expiration; };static struct credential_cache_entry *entries;static int entries_nr;
@@ -47,12 +47,12 @@ static void remove_credential(const struct credential *c) e->expiration =0 ; } -static int check_expirations (void ) +static timestamp_t check_expirations (void ) { -static unsigned long wait_for_entry_until; +static timestamp_t wait_for_entry_until;int i =0 ; -unsigned long now =time (NULL ); -unsigned long next = (unsigned long )-1 ; +timestamp_t now =time (NULL ); +timestamp_t next =TIME_MAX ;/* * Initially give the client 30 seconds to actually contact us
@@ -159,7 +159,7 @@ static void serve_one_client(FILE *in, FILE *out)static int serve_cache_loop (int fd) {struct pollfd pfd; -unsigned long wakeup; +timestamp_t wakeup; wakeup =check_expirations ();if (!wakeup)
date.c +33 -33
207 lines not on this page · raw message
fetch-pack.c +3 -3
@@ -394,7 +394,7 @@ static int find_common(struct fetch_pack_args *args,if (args->depth >0 )packet_buf_write (&req_buf,"deepen %d" , args->depth);if (args->deepen_since) { -unsigned long max_age =approxidate (args->deepen_since); +timestamp_t max_age =approxidate (args->deepen_since);packet_buf_write (&req_buf,"deepen-since %" PRItime, max_age); }if (args->deepen_not) {
@@ -583,7 +583,7 @@ static int mark_complete_oid(const char *refname, const struct object_id *oid, }static void mark_recent_complete_commits (struct fetch_pack_args *args, -unsigned long cutoff) +timestamp_t cutoff) {while (complete && cutoff <= complete->item->date) { print_verbose(args, _("Marking %s as complete"),
@@ -670,7 +670,7 @@ static int everything_local(struct fetch_pack_args *args, {struct ref *ref;int retval; -unsigned long cutoff =0 ; +timestamp_t cutoff =0 ; save_commit_buffer =0 ;
git-compat-util.h +2 -0
@@ -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 ':'
http-backend.c +2 -2
@@ -90,7 +90,7 @@ static void hdr_int(struct strbuf *hdr, const char *name, uintmax_t value)strbuf_addf (hdr,"%s: %" PRIuMAX"\r\n" , name, value); } -static void hdr_date (struct strbuf *hdr,const char *name,unsigned long when) +static void hdr_date (struct strbuf *hdr,const char *name,timestamp_t when) {const char *value =show_date (when,0 ,DATE_MODE (RFC2822 ));hdr_str (hdr, name, value);
@@ -105,7 +105,7 @@ static void hdr_nocache(struct strbuf *hdr)static void hdr_cache_forever (struct strbuf *hdr) { -unsigned long now =time (NULL ); +timestamp_t now =time (NULL );hdr_date (hdr,"Date" , now);hdr_date (hdr,"Expires" , now +31536000 );hdr_str (hdr,"Cache-Control" ,"public, max-age=31536000" );
parse-options-cb.c +2 -2
@@ -31,14 +31,14 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)int parse_opt_approxidate_cb (const struct option *opt,const char *arg,int unset) { - *(unsigned long *)(opt->value) =approxidate (arg); + *(timestamp_t *)(opt->value) =approxidate (arg);return 0 ; }int parse_opt_expiry_date_cb (const struct option *opt,const char *arg,int unset) { -return parse_expiry_date (arg, (unsigned long *)opt->value); +return parse_expiry_date (arg, (timestamp_t *)opt->value); } int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
pretty.c +1 -1
@@ -405,7 +405,7 @@ static void add_rfc2047(struct strbuf *sb, const char *line, size_t len,const char *show_ident_date (const struct ident_split *ident,const struct date_mode *mode) { -unsigned long date =0 ; +timestamp_t date =0 ;long tz =0 ;if (ident->date_begin && ident->date_end)
reachable.c +4 -5
@@ -55,11 +55,11 @@ static void mark_commit(struct commit *c, void *data)struct recent_data {struct rev_info *revs; -unsigned long timestamp; +timestamp_t timestamp; };static void add_recent_object (const struct object_id *oid, -unsigned long mtime, +timestamp_t mtime,struct recent_data *data) {struct object *obj;
@@ -139,7 +139,7 @@ static int add_recent_packed(const struct object_id *oid, }int add_unseen_recent_objects_to_traversal (struct rev_info *revs, -unsigned long timestamp) +timestamp_t timestamp) {struct recent_data data;int r;
@@ -156,8 +156,7 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs, }void mark_reachable_objects (struct rev_info *revs,int mark_reflog, -unsigned long mark_recent, -struct progress *progress) +timestamp_t mark_recent,struct progress *progress) {struct connectivity_progress cp;
reachable.h +2 -2
@@ -3,8 +3,8 @@struct progress ;extern int add_unseen_recent_objects_to_traversal (struct rev_info *revs, -unsigned long timestamp); +timestamp_t timestamp);extern void mark_reachable_objects (struct rev_info *revs,int mark_reflog, -unsigned long mark_recent,struct progress *); +timestamp_t mark_recent,struct progress *);#endif
ref-filter.c +2 -2
@@ -849,7 +849,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam {const char *eoemail =strstr (buf,"> " );char *zone; -unsigned long timestamp; +timestamp_t timestamp;long tz;struct date_mode date_mode = {DATE_NORMAL };const char *formatp;
@@ -869,7 +869,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnamif (!eoemail) goto bad; timestamp =parse_timestamp (eoemail +2 , &zone,10 ); -if (timestamp ==ULONG_MAX ) +if (timestamp ==TIME_MAX ) goto bad; tz =strtol (zone,NULL ,10 );if ((tz ==LONG_MIN || tz ==LONG_MAX ) && errno ==ERANGE )
reflog-walk.c +4 -4
@@ -12,7 +12,7 @@ struct complete_reflogs {struct reflog_info {struct object_id ooid, noid;char *email; -unsigned long timestamp; +timestamp_t timestamp;int tz;char *message; } *items;
@@ -20,7 +20,7 @@ struct complete_reflogs { };static int read_one_reflog (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct complete_reflogs *array = cb_data;
@@ -69,7 +69,7 @@ static struct complete_reflogs *read_complete_reflog(const char *ref) }static int get_reflog_recno_by_time (struct complete_reflogs *array, -unsigned long timestamp) +timestamp_t timestamp) {int i;for (i = array->nr -1 ; i >=0 ; i--)
@@ -141,7 +141,7 @@ void init_reflog_walk(struct reflog_walk_info **info)int add_reflog_for_walk (struct reflog_walk_info *info,struct commit *commit,const char *name) { -unsigned long timestamp =0 ; +timestamp_t timestamp =0 ;int recno =-1 ;struct string_list_item *item;struct complete_reflogs *reflogs;
refs.c +7 -7
@@ -712,7 +712,7 @@ int is_branch(const char *refname)struct read_ref_at_cb {const char *refname; -unsigned long at_time; +timestamp_t at_time;int cnt;int reccnt;unsigned char *sha1;
@@ -721,15 +721,15 @@ struct read_ref_at_cb {unsigned char osha1[20 ];unsigned char nsha1[20 ];int tz; -unsigned long date; +timestamp_t date;char **msg; -unsigned long *cutoff_time; +timestamp_t *cutoff_time;int *cutoff_tz;int *cutoff_cnt; };static int read_ref_at_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct read_ref_at_cb *cb = cb_data;
@@ -776,7 +776,7 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid, }static int read_ref_at_ent_oldest (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct read_ref_at_cb *cb = cb_data;
@@ -796,9 +796,9 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noidreturn 1 ; } -int read_ref_at (const char *refname,unsigned int flags,unsigned long at_time,int cnt, +int read_ref_at (const char *refname,unsigned int flags,timestamp_t at_time,int cnt,unsigned char *sha1,char **msg, -unsigned long *cutoff_time,int *cutoff_tz,int *cutoff_cnt) +timestamp_t *cutoff_time,int *cutoff_tz,int *cutoff_cnt) {struct read_ref_at_cb cb;
refs.h +4 -4
@@ -317,9 +317,9 @@ int safe_create_reflog(const char *refname, int force_create, struct strbuf *err/** Reads log for the value of ref during at_time. **/ int read_ref_at (const char *refname,unsigned int flags, -unsigned long at_time,int cnt, +timestamp_t at_time,int cnt,unsigned char *sha1,char **msg, -unsigned long *cutoff_time,int *cutoff_tz,int *cutoff_cnt); +timestamp_t *cutoff_time,int *cutoff_tz,int *cutoff_cnt);/** Check if a particular reflog exists */ int refs_reflog_exists (struct ref_store *refs,const char *refname);
@@ -356,7 +356,7 @@ int delete_reflog(const char *refname);/* iterate over reflog entries */ typedef int each_reflog_ent_fn (struct object_id *old_oid,struct object_id *new_oid, -const char *committer,unsigned long timestamp, +const char *committer,timestamp_t timestamp,int tz,const char *msg,void *cb_data); int refs_for_each_reflog_ent(struct ref_store *refs, const char *refname,
@@ -616,7 +616,7 @@ typedef void reflog_expiry_prepare_fn(const char *refname,typedef int reflog_expiry_should_prune_fn (unsigned char *osha1,unsigned char *nsha1,const char *email, -unsigned long timestamp,int tz, +timestamp_t timestamp,int tz,const char *message,void *cb_data);typedef void reflog_expiry_cleanup_fn (void *cb_data);
refs/files-backend.c +2 -2
@@ -3237,7 +3237,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c {struct object_id ooid, noid;char *email_end, *message; -unsigned long timestamp; +timestamp_t timestamp;int tz;const char *p = sb->buf;
@@ -4118,7 +4118,7 @@ struct expire_reflog_cb { };static int expire_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct expire_reflog_cb *cb = cb_data;
revision.c +3 -3
@@ -884,7 +884,7 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)/* How many extra uninteresting commits we want to see.. */ #define SLOP 5 -static int still_interesting (struct commit_list *src,unsigned long date,int slop, +static int still_interesting (struct commit_list *src,timestamp_t date,int slop,struct commit **interesting_cache) {/*
@@ -1018,7 +1018,7 @@ static void limit_left_right(struct commit_list *list, struct rev_info *revs)static int limit_list (struct rev_info *revs) {int slop =SLOP ; -unsigned long date = ~0ul ; +timestamp_t date =TIME_MAX ;struct commit_list *list = revs->commits;struct commit_list *newlist =NULL ;struct commit_list **p = &newlist;
@@ -1215,7 +1215,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data) }static int handle_one_reflog_ent (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {handle_one_reflog_commit (ooid, cb_data);
revision.h +2 -2
@@ -181,8 +181,8 @@ struct rev_info {/* special limits */ int skip_count;int max_count; -unsigned long max_age; -unsigned long min_age; +timestamp_t max_age; +timestamp_t min_age;int min_parents;int max_parents;int (*include_check)(struct commit *,void *);
sha1_name.c +3 -3
@@ -660,8 +660,8 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,if (reflog_len) {int nth, i; -unsigned long at_time; -unsigned long co_time; +timestamp_t at_time; +timestamp_t co_time;int co_tz, co_cnt;/* Is it asking for N-th entry, or approxidate? */
@@ -1054,7 +1054,7 @@ struct grab_nth_branch_switch_cbdata { };static int grab_nth_branch_switch (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct grab_nth_branch_switch_cbdata *cb = cb_data;
t/helper/test-date.c +4 -4
@@ -27,7 +27,7 @@ static void show_dates(const char **argv, const char *format)parse_date_format (format, &mode);for (; *argv; argv++) {char *arg; -time_t t; +timestamp_t t;int tz;/*
@@ -48,7 +48,7 @@ static void parse_dates(const char **argv, struct timeval *now)struct strbuf result =STRBUF_INIT ;for (; *argv; argv++) { -unsigned long t; +timestamp_t t;int tz;strbuf_reset (&result);
@@ -65,7 +65,7 @@ static void parse_dates(const char **argv, struct timeval *now)static void parse_approxidate (const char **argv,struct timeval *now) {for (; *argv; argv++) { -time_t t; +timestamp_t t; t =approxidate_relative (*argv, now);printf ("%s -> %s\n" , *argv,show_date (t,0 ,DATE_MODE (ISO8601 ))); }
@@ -96,7 +96,7 @@ int cmd_main(int argc, const char **argv)else if (!strcmp (*argv,"approxidate" ))parse_approxidate (argv+1 , &now);else if (!strcmp (*argv,"is64bit" )) -return sizeof (unsigned long ) ==8 ?0 :1 ; +return sizeof (timestamp_t) ==8 ?0 :1 ;else if (!strcmp (*argv,"time_t-is64bit" ))return sizeof (time_t) ==8 ?0 :1 ;else
t/helper/test-parse-options.c +1 -1
@@ -5,7 +5,7 @@static int boolean =0 ;static int integer =0 ;static unsigned long magnitude =0 ; -static unsigned long timestamp; +static timestamp_t timestamp;static int abbrev =7 ;static int verbose =-1 ;/* unspecified */ static int dry_run =0 , quiet =0 ;
t/helper/test-ref-store.c +1 -1
@@ -138,7 +138,7 @@ static int cmd_for_each_reflog(struct ref_store *refs, const char **argv) }static int each_reflog (struct object_id *old_oid,struct object_id *new_oid, -const char *committer,unsigned long timestamp, +const char *committer,timestamp_t timestamp,int tz,const char *msg,void *cb_data) { printf("%s %s %s %"PRItime" %d %s\n",
tag.c +1 -1
@@ -97,7 +97,7 @@ struct tag *lookup_tag(const unsigned char *sha1)return object_as_type (obj,OBJ_TAG ,0 ); } -static unsigned long parse_tag_date (const char *buf,const char *tail) +static timestamp_t parse_tag_date (const char *buf,const char *tail) {const char *dateptr;
tag.h +1 -1
@@ -9,7 +9,7 @@ struct tag {struct object object;struct object *tagged;char *tag; -unsigned long date; +timestamp_t date; };extern struct tag *lookup_tag (const unsigned char *sha1);
upload-pack.c +2 -2
@@ -35,7 +35,7 @@ static const char * const upload_pack_usage[] = {#define CLIENT_SHALLOW (1u << 18)#define HIDDEN_REF (1u << 19) -static unsigned long oldest_have; +static timestamp_t oldest_have;static int deepen_relative;static int multi_ack;
@@ -735,7 +735,7 @@ static void receive_needs(void)struct string_list deepen_not =STRING_LIST_INIT_DUP ;int depth =0 ;int has_non_tip =0 ; -unsigned long deepen_since =0 ; +timestamp_t deepen_since =0 ;int deepen_rev_list =0 ; shallow_nr =0 ;
vcs-svn/fast_export.c +2 -2
@@ -68,7 +68,7 @@ void fast_export_modify(const char *path, uint32_t mode, const char *dataref) }void fast_export_begin_note (uint32_t revision,const char *author, -const char *log,unsigned long timestamp,const char *note_ref) +const char *log,timestamp_t timestamp,const char *note_ref) {static int firstnote =1 ;size_t loglen =strlen (log);
@@ -93,7 +93,7 @@ static char gitsvnline[MAX_GITSVN_LINE_LEN];void fast_export_begin_commit (uint32_t revision,const char *author,const struct strbuf *log,const char *uuid,const char *url, -unsigned long timestamp,const char *local_ref) +timestamp_t timestamp,const char *local_ref) {static const struct strbuf empty =STRBUF_INIT ;if (!log)
vcs-svn/fast_export.h +2 -2
@@ -11,10 +11,10 @@ void fast_export_delete(const char *path);void fast_export_modify (const char *path,uint32_t mode,const char *dataref);void fast_export_note (const char *committish,const char *dataref);void fast_export_begin_note (uint32_t revision,const char *author, -const char *log,unsigned long timestamp,const char *note_ref); +const char *log,timestamp_t timestamp,const char *note_ref);void fast_export_begin_commit (uint32_t revision,const char *author,const struct strbuf *log,const char *uuid,const char *url, -unsigned long timestamp,const char *local_ref); +timestamp_t timestamp,const char *local_ref);void fast_export_end_commit (uint32_t revision);void fast_export_data (uint32_t mode,off_t len,struct line_buffer *input);void fast_export_buf_to_data (const struct strbuf *data);
vcs-svn/svndump.c +1 -1
@@ -47,7 +47,7 @@ static struct {static struct {uint32_t revision; -unsigned long timestamp; +timestamp_t timestamp;struct strbuf log, author, note; } rev_ctx;
wt-status.c +1 -1
@@ -1387,7 +1387,7 @@ struct grab_1st_switch_cbdata { };static int grab_1st_switch (struct object_id *ooid,struct object_id *noid, -const char *email,unsigned long timestamp,int tz, +const char *email,timestamp_t timestamp,int tz,const char *message,void *cb_data) {struct grab_1st_switch_cbdata *cb = cb_data;
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH 1/1 name-rev: change a "long" variable to timestamp_t
Earlier dddbad72 ("timestamp_t: a new data type for timestamps", 2017-04-26) updated all in-core variables, fields and function return values that are used to store "seconds since epoch" to a new type timestamp_t. Unfortunately one variable "cutoff", which is used to keep track of the oldest timestamp of commit we saw on the command line, was "long", and left behind.
Update it to timestamp_t as well.
---
* Noticed while merging the topic 'mg/name-rev-debug' to 'pu'.
builtin/name-rev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/name-rev.c +1 -1
@@ -15,7 +15,7 @@ typedef struct rev_name {int distance; } rev_name; -static long cutoff =LONG_MAX ; +static timestamp_t cutoff =TIME_MAX ;/* How many generations are maximally preferred over _one_ merge traversal? */ #define MERGE_TRAVERSAL_WEIGHT 65535
Signature · 1 line
2.13.0-439-gd4feae47b3
Re: [PATCH] name-rev: change a "long" variable to timestamp_t
Hi Junio,
Quoted 10 lines · Junio C Hamano
Earlier
dddbad72("timestamp_t: a new data type for timestamps", 2017-04-26) updated all in-core variables, fields and function return values that are used to store "seconds since epoch" to a new typetimestamp_t. Unfortunately one variable "cutoff", which is used to keep track of the oldest timestamp of commit we saw on the command line, was "long", and left behind.Update it to
timestamp_tas well.Signed-off-by Junio C Hamano <[email protected]>
Obviously correct. Thanks.
Ciao,
Dscho
PATCH v6 7/8 Abort if the system time cannot handle one of our timestamps
In reply to Johannes SchindelinWe are about to switch to a new data type for time stamps that is definitely not smaller or equal, but larger or equal to time_t.
So before using the system functions to process or format timestamps, let's make extra certain that they can handle what we feed them.
--- date.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
date.c +15 -2
@@ -46,7 +46,17 @@ static time_t gm_time_t(timestamp_t time, int tz) minutes = tz <0 ? -tz : tz; minutes = (minutes /100 )*60 + (minutes %100 ); minutes = tz <0 ? -minutes : minutes; -return time + minutes *60 ; + +if (minutes >0 ) { +if (unsigned_add_overflows (time, minutes *60 )) +die ("Timestamp+tz too large: %" PRItime" +%04d" , + time, tz); + }else if (time < -minutes *60 ) +die ("Timestamp before Unix epoch: %" PRItime" %04d" , time, tz); + time += minutes *60 ; +if (date_overflows (time)) +die ("Timestamp too large for this system: %" PRItime, time); +return (time_t )time; }/*
@@ -70,7 +80,10 @@ static int local_tzoffset(timestamp_t time)struct tm tm;int offset, eastwest; - t = time; +if (date_overflows (time)) +die ("Timestamp too large for this system: %" PRItime, time); + + t = (time_t )time;localtime_r (&t, &tm); t_local =tm_to_time_t (&tm);
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f
PATCH v6 8/8 Use uintmax_t for timestamps
In reply to Johannes SchindelinPreviously, 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...
--- git-compat-util.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
git-compat-util.h +4 -4
@@ -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 ':'
Signature · 1 line
2.12.2.windows.2.406.gd14a8f8640f