From 4904cbc9e195f1de2cb6ff3c5b3d5b756343ef44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sat, 24 Jun 2017 12:14:51 +0000 Subject: strbuf.h comment: discuss strbuf_addftime() arguments in order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the comment documenting the strbuf_addftime() function to discuss the parameters in the order in which they appear, which makes this easier to read than discussing them out of order. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano diff --git a/strbuf.h b/strbuf.h index 4559035..6708cef 100644 --- a/strbuf.h +++ b/strbuf.h @@ -340,10 +340,10 @@ extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); /** * Add the time specified by `tm`, as formatted by `strftime`. - * `tz_name` is used to expand %Z internally unless it's NULL. * `tz_offset` is in decimal hhmm format, e.g. -600 means six hours west * of Greenwich, and it's used to expand %z internally. However, tokens * with modifiers (e.g. %Ez) are passed to `strftime`. + * `tz_name` is used to expand %Z internally unless it's NULL. */ extern void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm, int tz_offset, -- cgit v0.10.2-6-g49f6 From 3b702239d6399685aa69539b83be5f744cfa10e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sat, 1 Jul 2017 13:15:47 +0000 Subject: strbuf: change an always NULL/"" strbuf_addftime() param to bool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano diff --git a/date.c b/date.c index 5580c40..8aca136 100644 --- a/date.c +++ b/date.c @@ -243,7 +243,7 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode) tm->tm_hour, tm->tm_min, tm->tm_sec, tz); else if (mode->type == DATE_STRFTIME) strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz, - mode->local ? NULL : ""); + !mode->local); else strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d", weekday_names[tm->tm_wday], diff --git a/strbuf.c b/strbuf.c index be3b9e3..89e40bb 100644 --- a/strbuf.c +++ b/strbuf.c @@ -786,7 +786,7 @@ char *xstrfmt(const char *fmt, ...) } void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm, - int tz_offset, const char *tz_name) + int tz_offset, int suppress_tz_name) { struct strbuf munged_fmt = STRBUF_INIT; size_t hint = 128; @@ -815,8 +815,7 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm, fmt++; break; case 'Z': - if (tz_name) { - strbuf_addstr(&munged_fmt, tz_name); + if (suppress_tz_name) { fmt++; break; } diff --git a/strbuf.h b/strbuf.h index 6708cef..9262615 100644 --- a/strbuf.h +++ b/strbuf.h @@ -343,11 +343,12 @@ extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); * `tz_offset` is in decimal hhmm format, e.g. -600 means six hours west * of Greenwich, and it's used to expand %z internally. However, tokens * with modifiers (e.g. %Ez) are passed to `strftime`. - * `tz_name` is used to expand %Z internally unless it's NULL. + * `suppress_tz_name`, when set, expands %Z internally to the empty + * string rather than passing it to `strftime`. */ extern void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm, int tz_offset, - const char *tz_name); + int suppress_tz_name); /** * Read a given size of data from a FILE* pointer to the buffer. -- cgit v0.10.2-6-g49f6