Skip to content

Commit f184289

Browse files
avargitster
authored andcommitted
date API: provide and use a DATE_MODE_INIT
Provide and use a DATE_MODE_INIT macro. Most of the users of struct date_mode" use it via pretty.h's "struct pretty_print_context" which doesn't have an initialization macro, so we're still bound to being initialized to "{ 0 }" by default. But we can change the couple of callers that directly declared a variable on the stack to instead use the initializer, and thus do away with the "mode.local = 0" added in add00ba (date: make "local" orthogonal to date format, 2015-09-03). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88c7b4c commit f184289

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

date.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,10 @@ void show_date_relative(timestamp_t time, struct strbuf *timebuf)
206206

207207
struct date_mode *date_mode_from_type(enum date_mode_type type)
208208
{
209-
static struct date_mode mode;
209+
static struct date_mode mode = DATE_MODE_INIT;
210210
if (type == DATE_STRFTIME)
211211
BUG("cannot create anonymous strftime date_mode struct");
212212
mode.type = type;
213-
mode.local = 0;
214213
return &mode;
215214
}
216215

date.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ struct date_mode {
2020
int local;
2121
};
2222

23+
#define DATE_MODE_INIT { \
24+
.type = DATE_NORMAL, \
25+
}
26+
2327
/*
2428
* Convenience helper for passing a constant type, like:
2529
*

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
12511251
char *zone;
12521252
timestamp_t timestamp;
12531253
long tz;
1254-
struct date_mode date_mode = { DATE_NORMAL };
1254+
struct date_mode date_mode = DATE_MODE_INIT;
12551255
const char *formatp;
12561256

12571257
/*

t/helper/test-date.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void show_human_dates(const char **argv)
3535

3636
static void show_dates(const char **argv, const char *format)
3737
{
38-
struct date_mode mode;
38+
struct date_mode mode = DATE_MODE_INIT;
3939

4040
parse_date_format(format, &mode);
4141
for (; *argv; argv++) {

0 commit comments

Comments
 (0)