Skip to content

Commit b15667b

Browse files
committed
Merge branch 'js/larger-timestamps'
Some platforms have ulong that is smaller than time_t, and our historical use of ulong for timestamp would mean they cannot represent some timestamp that the platform allows. Invent a separate and dedicated timestamp_t (so that we can distingiuish timestamps and a vanilla ulongs, which along is already a good move), and then declare uintmax_t is the type to be used as the timestamp_t. * js/larger-timestamps: archive-tar: fix a sparse 'constant too large' warning use uintmax_t for timestamps date.c: abort if the system time cannot handle one of our timestamps timestamp_t: a new data type for timestamps PRItime: introduce a new "printf format" for timestamps parse_timestamp(): specify explicitly where we parse timestamps t0006 & t5000: skip "far in the future" test when time_t is too limited t0006 & t5000: prepare for 64-bit timestamps ref-filter: avoid using `unsigned long` for catch-all data type
2 parents afc5f2c + 3f78971 commit b15667b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+257
-220
lines changed

Documentation/technical/api-parse-options.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ There are some macros to easily define options:
183183
scale the provided value by 1024, 1024^2 or 1024^3 respectively.
184184
The scaled value is put into `unsigned_long_var`.
185185

186-
`OPT_DATE(short, long, &int_var, description)`::
186+
`OPT_DATE(short, long, &timestamp_t_var, description)`::
187187
Introduce an option with date argument, see `approxidate()`.
188-
The timestamp is put into `int_var`.
188+
The timestamp is put into `timestamp_t_var`.
189189

190-
`OPT_EXPIRY_DATE(short, long, &int_var, description)`::
190+
`OPT_EXPIRY_DATE(short, long, &timestamp_t_var, description)`::
191191
Introduce an option with expiry date argument, see `parse_expiry_date()`.
192-
The timestamp is put into `int_var`.
192+
The timestamp is put into `timestamp_t_var`.
193193

194194
`OPT_CALLBACK(short, long, &var, arg_str, description, func_ptr)`::
195195
Introduce an option with argument.

archive-tar.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ static int write_tar_filter_archive(const struct archiver *ar,
2727
*/
2828
#if ULONG_MAX == 0xFFFFFFFF
2929
#define USTAR_MAX_SIZE ULONG_MAX
30-
#define USTAR_MAX_MTIME ULONG_MAX
3130
#else
3231
#define USTAR_MAX_SIZE 077777777777UL
33-
#define USTAR_MAX_MTIME 077777777777UL
32+
#endif
33+
#if TIME_MAX == 0xFFFFFFFF
34+
#define USTAR_MAX_MTIME TIME_MAX
35+
#else
36+
#define USTAR_MAX_MTIME 077777777777ULL
3437
#endif
3538

3639
/* writes out the whole block, but only if it is full */

archive-zip.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,17 @@ static void write_zip_trailer(const unsigned char *sha1)
593593
write_or_die(1, sha1_to_hex(sha1), GIT_SHA1_HEXSZ);
594594
}
595595

596-
static void dos_time(time_t *time, int *dos_date, int *dos_time)
596+
static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
597597
{
598-
struct tm *t = localtime(time);
598+
time_t time;
599+
struct tm *t;
600+
601+
if (date_overflows(*timestamp))
602+
die("timestamp too large for this system: %"PRItime,
603+
*timestamp);
604+
time = (time_t)*timestamp;
605+
t = localtime(&time);
606+
*timestamp = time;
599607

600608
*dos_date = t->tm_mday + (t->tm_mon + 1) * 32 +
601609
(t->tm_year + 1900 - 1980) * 512;

archive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct archiver_args {
99
struct tree *tree;
1010
const unsigned char *commit_sha1;
1111
const struct commit *commit;
12-
time_t time;
12+
timestamp_t time;
1313
struct pathspec pathspec;
1414
unsigned int verbose : 1;
1515
unsigned int worktree_attributes : 1;

builtin/am.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,12 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
879879
if (skip_prefix(sb.buf, "# User ", &str))
880880
fprintf(out, "From: %s\n", str);
881881
else if (skip_prefix(sb.buf, "# Date ", &str)) {
882-
unsigned long timestamp;
882+
timestamp_t timestamp;
883883
long tz, tz2;
884884
char *end;
885885

886886
errno = 0;
887-
timestamp = strtoul(str, &end, 10);
887+
timestamp = parse_timestamp(str, &end, 10);
888888
if (errno)
889889
return error(_("invalid timestamp"));
890890

builtin/blame.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,13 +1561,13 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
15611561
struct commit_info {
15621562
struct strbuf author;
15631563
struct strbuf author_mail;
1564-
unsigned long author_time;
1564+
timestamp_t author_time;
15651565
struct strbuf author_tz;
15661566

15671567
/* filled only when asked for details */
15681568
struct strbuf committer;
15691569
struct strbuf committer_mail;
1570-
unsigned long committer_time;
1570+
timestamp_t committer_time;
15711571
struct strbuf committer_tz;
15721572

15731573
struct strbuf summary;
@@ -1578,7 +1578,7 @@ struct commit_info {
15781578
*/
15791579
static void get_ac_line(const char *inbuf, const char *what,
15801580
struct strbuf *name, struct strbuf *mail,
1581-
unsigned long *time, struct strbuf *tz)
1581+
timestamp_t *time, struct strbuf *tz)
15821582
{
15831583
struct ident_split ident;
15841584
size_t len, maillen, namelen;
@@ -1727,11 +1727,11 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)
17271727
get_commit_info(suspect->commit, &ci, 1);
17281728
printf("author %s\n", ci.author.buf);
17291729
printf("author-mail %s\n", ci.author_mail.buf);
1730-
printf("author-time %lu\n", ci.author_time);
1730+
printf("author-time %"PRItime"\n", ci.author_time);
17311731
printf("author-tz %s\n", ci.author_tz.buf);
17321732
printf("committer %s\n", ci.committer.buf);
17331733
printf("committer-mail %s\n", ci.committer_mail.buf);
1734-
printf("committer-time %lu\n", ci.committer_time);
1734+
printf("committer-time %"PRItime"\n", ci.committer_time);
17351735
printf("committer-tz %s\n", ci.committer_tz.buf);
17361736
printf("summary %s\n", ci.summary.buf);
17371737
if (suspect->commit->object.flags & UNINTERESTING)
@@ -1837,14 +1837,14 @@ static void assign_blame(struct scoreboard *sb, int opt)
18371837
stop_progress(&pi.progress);
18381838
}
18391839

1840-
static const char *format_time(unsigned long time, const char *tz_str,
1840+
static const char *format_time(timestamp_t time, const char *tz_str,
18411841
int show_raw_time)
18421842
{
18431843
static struct strbuf time_buf = STRBUF_INIT;
18441844

18451845
strbuf_reset(&time_buf);
18461846
if (show_raw_time) {
1847-
strbuf_addf(&time_buf, "%lu %s", time, tz_str);
1847+
strbuf_addf(&time_buf, "%"PRItime" %s", time, tz_str);
18481848
}
18491849
else {
18501850
const char *time_str;

builtin/fsck.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
397397
static int default_refs;
398398

399399
static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
400-
unsigned long timestamp)
400+
timestamp_t timestamp)
401401
{
402402
struct object *obj;
403403

@@ -407,7 +407,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
407407
if (timestamp && name_objects)
408408
add_decoration(fsck_walk_options.object_names,
409409
obj,
410-
xstrfmt("%s@{%ld}", refname, timestamp));
410+
xstrfmt("%s@{%"PRItime"}", refname, timestamp));
411411
obj->used = 1;
412412
mark_object_reachable(obj);
413413
} else {
@@ -418,7 +418,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
418418
}
419419

420420
static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid,
421-
const char *email, unsigned long timestamp, int tz,
421+
const char *email, timestamp_t timestamp, int tz,
422422
const char *message, void *cb_data)
423423
{
424424
const char *refname = cb_data;

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int aggressive_window = 250;
3333
static int gc_auto_threshold = 6700;
3434
static int gc_auto_pack_limit = 50;
3535
static int detach_auto = 1;
36-
static unsigned long gc_log_expire_time;
36+
static timestamp_t gc_log_expire_time;
3737
static const char *gc_log_expire = "1.day.ago";
3838
static const char *prune_expire = "2.weeks.ago";
3939
static const char *prune_worktrees_expire = "3.months.ago";

builtin/log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
910910
static void gen_message_id(struct rev_info *info, char *base)
911911
{
912912
struct strbuf buf = STRBUF_INIT;
913-
strbuf_addf(&buf, "%s.%lu.git.%s", base,
914-
(unsigned long) time(NULL),
913+
strbuf_addf(&buf, "%s.%"PRItime".git.%s", base,
914+
(timestamp_t) time(NULL),
915915
git_committer_info(IDENT_NO_NAME|IDENT_NO_DATE|IDENT_STRICT));
916916
info->message_id = strbuf_detach(&buf, NULL);
917917
}

builtin/merge-base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
132132
}
133133

134134
static int collect_one_reflog_ent(struct object_id *ooid, struct object_id *noid,
135-
const char *ident, unsigned long timestamp,
135+
const char *ident, timestamp_t timestamp,
136136
int tz, const char *message, void *cbdata)
137137
{
138138
struct rev_collect *revs = cbdata;

0 commit comments

Comments
 (0)