strbuf: change an always NULL/"" strbuf_addftime() param to bool
strbuf_addftime() allows callers to pass a time zone name for expanding %Z. The only current caller either passes the empty string or NULL, in which case %Z is handed over verbatim to strftime(3). Replace that string parameter with a flag controlling whether to remove %Z from the format specification. This simplifies the code. Commit-message-by: René Scharfe <l.s.r@web.de> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Jul 1, 2017 at 13:15 UTC
3b702239d6399685aa69539b83be5f744cfa10e3
3 files changed
+6
-6
date.c
+1
-1
@@ -243,7 +243,7 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
243
tm->tm_hour, tm->tm_min, tm->tm_sec, tz);
244
else if (mode->type == DATE_STRFTIME)
245
strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz,
246
- mode->local ? NULL : "");
246
+ !mode->local);
247
else
248
strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
249
weekday_names[tm->tm_wday],
strbuf.c
+2
-3
@@ -786,7 +786,7 @@ char *xstrfmt(const char *fmt, ...)
786
}
787
788
void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
789
- int tz_offset, const char *tz_name)
789
+ int tz_offset, int suppress_tz_name)
790
{
791
struct strbuf munged_fmt = STRBUF_INIT;
792
size_t hint = 128;
@@ -815,8 +815,7 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
815
fmt++;
816
break;
817
case 'Z':
818
- if (tz_name) {
819
- strbuf_addstr(&munged_fmt, tz_name);
818
+ if (suppress_tz_name) {
819
fmt++;
820
break;
821
}
strbuf.h
+3
-2
@@ -343,11 +343,12 @@ extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
343
* `tz_offset` is in decimal hhmm format, e.g. -600 means six hours west
344
* of Greenwich, and it's used to expand %z internally. However, tokens
345
* with modifiers (e.g. %Ez) are passed to `strftime`.
346
- * `tz_name` is used to expand %Z internally unless it's NULL.
346
+ * `suppress_tz_name`, when set, expands %Z internally to the empty
347
+ * string rather than passing it to `strftime`.
348
*/
349
extern void strbuf_addftime(struct strbuf *sb, const char *fmt,
350
const struct tm *tm, int tz_offset,
350
- const char *tz_name);
351
+ int suppress_tz_name);
352
353
/**
354
* Read a given size of data from a FILE* pointer to the buffer.