]> git.ipfire.org Git - thirdparty/git.git/commitdiff
date API: provide and use a DATE_MODE_INIT
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 16 Feb 2022 08:14:03 +0000 (09:14 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Feb 2022 17:40:00 +0000 (09:40 -0800)
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 add00ba2de9 (date: make "local"
orthogonal to date format, 2015-09-03).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
date.c
date.h
ref-filter.c
t/helper/test-date.c

diff --git a/date.c b/date.c
index 863b07e9e63fb80ec3de71b9338b3a01dcba8655..54c709e4a089acfff0f060683abad9ea4e84cf8c 100644 (file)
--- a/date.c
+++ b/date.c
@@ -206,11 +206,10 @@ void show_date_relative(timestamp_t time, struct strbuf *timebuf)
 
 struct date_mode *date_mode_from_type(enum date_mode_type type)
 {
-       static struct date_mode mode;
+       static struct date_mode mode = DATE_MODE_INIT;
        if (type == DATE_STRFTIME)
                BUG("cannot create anonymous strftime date_mode struct");
        mode.type = type;
-       mode.local = 0;
        return &mode;
 }
 
diff --git a/date.h b/date.h
index 5db9ec8dd299855ff47f9387140f63489bb983ab..c3a00d08ed63990606643e2708f90cb3d16ab8e3 100644 (file)
--- a/date.h
+++ b/date.h
@@ -20,6 +20,10 @@ struct date_mode {
        int local;
 };
 
+#define DATE_MODE_INIT { \
+       .type = DATE_NORMAL, \
+}
+
 /*
  * Convenience helper for passing a constant type, like:
  *
index f7a2f17bfd94d7073cead2cfbebf877f6ab9fb98..3399bde932f7e8c7de5acbaff95c8ed9013d37c1 100644 (file)
@@ -1251,7 +1251,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
        char *zone;
        timestamp_t timestamp;
        long tz;
-       struct date_mode date_mode = { DATE_NORMAL };
+       struct date_mode date_mode = DATE_MODE_INIT;
        const char *formatp;
 
        /*
index ded3d059f56ddc73982cee3338acc6397399bd56..111071e1dd16d0cf81dce5cbea0e2f075bdbd0bc 100644 (file)
@@ -35,7 +35,7 @@ static void show_human_dates(const char **argv)
 
 static void show_dates(const char **argv, const char *format)
 {
-       struct date_mode mode;
+       struct date_mode mode = DATE_MODE_INIT;
 
        parse_date_format(format, &mode);
        for (; *argv; argv++) {