Skip to content

Commit 88c7b4c

Browse files
avargitster
authored andcommitted
date API: create a date.h, split from cache.h
Move the declaration of the date.c functions from cache.h, and adjust the relevant users to include the new date.h header. The show_ident_date() function belonged in pretty.h (it's defined in pretty.c), its two users outside of pretty.c didn't strictly need to include pretty.h, as they get it indirectly, but let's add it to them anyway. Similarly, the change to "builtin/{fast-import,show-branch,tag}.c" isn't needed as far as the compiler is concerned, but since they all use the "DATE_MODE()" macro we now define in date.h, let's have them include it. We could simply include this new header in "cache.h", but as this change shows these functions weren't common enough to warrant including in it in the first place. By moving them out of cache.h changes to this API will no longer cause a (mostly) full re-build of the project when "make" is run. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f6c71f8 commit 88c7b4c

18 files changed

+68
-48
lines changed

archive-zip.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "object-store.h"
1010
#include "userdiff.h"
1111
#include "xdiff-interface.h"
12+
#include "date.h"
1213

1314
static int zip_date;
1415
static int zip_time;

builtin/am.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "string-list.h"
3535
#include "packfile.h"
3636
#include "repository.h"
37+
#include "pretty.h"
3738

3839
/**
3940
* Returns the length of the first line of msg.

builtin/commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "help.h"
3838
#include "commit-reach.h"
3939
#include "commit-graph.h"
40+
#include "pretty.h"
4041

4142
static const char * const builtin_commit_usage[] = {
4243
N_("git commit [<options>] [--] <pathspec>..."),

builtin/fast-import.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "mem-pool.h"
2020
#include "commit-reach.h"
2121
#include "khash.h"
22+
#include "date.h"
2223

2324
#define PACK_ID_BITS 16
2425
#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)

builtin/show-branch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "parse-options.h"
99
#include "dir.h"
1010
#include "commit-slab.h"
11+
#include "date.h"
1112

1213
static const char* show_branch_usage[] = {
1314
N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"

builtin/tag.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "oid-array.h"
2121
#include "column.h"
2222
#include "ref-filter.h"
23+
#include "date.h"
2324

2425
static const char * const git_tag_usage[] = {
2526
N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>]\n"

cache.h

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,46 +1559,6 @@ struct object *repo_peel_to_type(struct repository *r,
15591559
#define peel_to_type(name, namelen, obj, type) \
15601560
repo_peel_to_type(the_repository, name, namelen, obj, type)
15611561

1562-
enum date_mode_type {
1563-
DATE_NORMAL = 0,
1564-
DATE_HUMAN,
1565-
DATE_RELATIVE,
1566-
DATE_SHORT,
1567-
DATE_ISO8601,
1568-
DATE_ISO8601_STRICT,
1569-
DATE_RFC2822,
1570-
DATE_STRFTIME,
1571-
DATE_RAW,
1572-
DATE_UNIX
1573-
};
1574-
1575-
struct date_mode {
1576-
enum date_mode_type type;
1577-
const char *strftime_fmt;
1578-
int local;
1579-
};
1580-
1581-
/*
1582-
* Convenience helper for passing a constant type, like:
1583-
*
1584-
* show_date(t, tz, DATE_MODE(NORMAL));
1585-
*/
1586-
#define DATE_MODE(t) date_mode_from_type(DATE_##t)
1587-
struct date_mode *date_mode_from_type(enum date_mode_type type);
1588-
1589-
const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode);
1590-
void show_date_relative(timestamp_t time, struct strbuf *timebuf);
1591-
int parse_date(const char *date, struct strbuf *out);
1592-
int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset);
1593-
int parse_expiry_date(const char *date, timestamp_t *timestamp);
1594-
void datestamp(struct strbuf *out);
1595-
#define approxidate(s) approxidate_careful((s), NULL)
1596-
timestamp_t approxidate_careful(const char *, int *);
1597-
timestamp_t approxidate_relative(const char *date);
1598-
void parse_date_format(const char *format, struct date_mode *mode);
1599-
int date_overflows(timestamp_t date);
1600-
time_t tm_to_time_t(const struct tm *tm);
1601-
16021562
#define IDENT_STRICT 1
16031563
#define IDENT_NO_DATE 2
16041564
#define IDENT_NO_NAME 4
@@ -1644,14 +1604,6 @@ struct ident_split {
16441604
*/
16451605
int split_ident_line(struct ident_split *, const char *, int);
16461606

1647-
/*
1648-
* Like show_date, but pull the timestamp and tz parameters from
1649-
* the ident_split. It will also sanity-check the values and produce
1650-
* a well-known sentinel date if they appear bogus.
1651-
*/
1652-
const char *show_ident_date(const struct ident_split *id,
1653-
const struct date_mode *mode);
1654-
16551607
/*
16561608
* Compare split idents for equality or strict ordering. Note that we
16571609
* compare only the ident part of the line, ignoring any timestamp.

config.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
*/
88
#include "cache.h"
9+
#include "date.h"
910
#include "branch.h"
1011
#include "config.h"
1112
#include "environment.h"

date.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "cache.h"
8+
#include "date.h"
89

910
/*
1011
* This is like mktime, but without normalization of tm_wday and tm_yday.

date.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef DATE_H
2+
#define DATE_H
3+
4+
enum date_mode_type {
5+
DATE_NORMAL = 0,
6+
DATE_HUMAN,
7+
DATE_RELATIVE,
8+
DATE_SHORT,
9+
DATE_ISO8601,
10+
DATE_ISO8601_STRICT,
11+
DATE_RFC2822,
12+
DATE_STRFTIME,
13+
DATE_RAW,
14+
DATE_UNIX
15+
};
16+
17+
struct date_mode {
18+
enum date_mode_type type;
19+
const char *strftime_fmt;
20+
int local;
21+
};
22+
23+
/*
24+
* Convenience helper for passing a constant type, like:
25+
*
26+
* show_date(t, tz, DATE_MODE(NORMAL));
27+
*/
28+
#define DATE_MODE(t) date_mode_from_type(DATE_##t)
29+
struct date_mode *date_mode_from_type(enum date_mode_type type);
30+
31+
const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode);
32+
void show_date_relative(timestamp_t time, struct strbuf *timebuf);
33+
int parse_date(const char *date, struct strbuf *out);
34+
int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset);
35+
int parse_expiry_date(const char *date, timestamp_t *timestamp);
36+
void datestamp(struct strbuf *out);
37+
#define approxidate(s) approxidate_careful((s), NULL)
38+
timestamp_t approxidate_careful(const char *, int *);
39+
timestamp_t approxidate_relative(const char *date);
40+
void parse_date_format(const char *format, struct date_mode *mode);
41+
int date_overflows(timestamp_t date);
42+
time_t tm_to_time_t(const struct tm *tm);
43+
#endif

0 commit comments

Comments
 (0)