git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] strbuf_addftime(): handle "%s" manually

From
Jeff King <peff@peff.net>
Date
Nov 2, 2021, 15:43 UTC
Message-ID
<YYFcj0Y9ApBU9j+V@coredump.intra.peff.net>
In-Reply-To
<YYEihoLbEGi44dDb@coredump.intra.peff.net>
On Tue, Nov 02, 2021 at 07:35:35AM -0400, Jeff King wrote:
Show 11 quoted lines
> @@ -1019,6 +1024,13 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
>  			strbuf_addstr(&munged_fmt, "%%");
>  			fmt++;
>  			break;
> +		case 's':
> +			strbuf_addf(&munged_fmt, "%"PRItime,
> +				    tm_to_time_t(tm) -
> +				    3600 * (tz_offset / 100) -
> +				    60 * (tz_offset % 100));
> +			fmt++;
> +			break;
Looks like we may need something like this squashed in:
diff --git a/strbuf.c b/strbuf.c
index 33015b33df..995394f38e 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1026,7 +1026,7 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
 			break;
 		case 's':
 			strbuf_addf(&munged_fmt, "%"PRItime,
-				    tm_to_time_t(tm) -
+				    (timestamp_t)tm_to_time_t(tm) -
 				    3600 * (tz_offset / 100) -
 				    60 * (tz_offset % 100));
 			fmt++;

because tm_to_time_t() returns an actual time_t, which will vary in
size. The 32-bit CI job complains:

  strbuf.c:1028:29: error: format '%lld' expects argument of type 'long long int', but argument 3 has type 'long int' [-Werror=format=]

-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 10 of 12 in “timezone related bug of git”
  1. Dongsheng SongOct 31, 2021
  2. Jeff KingOct 31, 2021
  3. Dongsheng SongOct 31, 2021
  4. Junio C HamanoOct 31, 2021
  5. Jeff KingNov 1, 2021
  6. Dongsheng SongNov 1, 2021
  7. Junio C HamanoNov 1, 2021
  8. Jeff KingNov 2, 2021
  9. strbuf_addftime(): handle "%s" manuallyJeff King, Nov 2, 2021
  10. Jeff KingNov 2, 2021
  11. Junio C HamanoNov 3, 2021
  12. Jeff KingNov 4, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.