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

Re: [PATCH 3/3] parse_commit(): handle broken whitespace-only timestamp

From
Jeff King <peff@peff.net>
Date
Apr 25, 2023, 05:27 UTC
Message-ID
<20230425052739.GB4007491@coredump.intra.peff.net>
In-Reply-To
<xmqqy1mhdurt.fsf@gitster.g>
On Mon, Apr 24, 2023 at 11:01:26AM -0700, Junio C Hamano wrote:
Show 18 quoted lines
> > +	/*
> > +	 * trim leading whitespace; parse_timestamp() will do this itself, but
> > +	 * it will walk past the newline at eol while doing so. So we insist
> > +	 * that there is at least one digit here.
> > +	 */
> 
> "one digit" -> "one non-whitespace".
> 
> > +	while (dateptr < eol && isspace(*dateptr))
> > +		dateptr++;
> 
> This is an expected change, but
> 
> > +	if (!strchr("0123456789", *dateptr))
> > +		return 0;
> 
> this is not.  Isn't the only problematic case that dateptr being at
> eol?  That is what the proposed log message argued.

Yes, that would be sufficient. I was moving things slightly closer to what split_ident_line() does by actually checking for numbers. But that led to the final paragraph in the commit message explaining how it all ends up the same either way.

So I'll swap this out for:
  if (dateptr == eol)

which I think requires less explanation, as it leaves the function more like it was originally (and the behavior is the same either way).

Show 5 quoted lines
> >  	/* dateptr < eol && *eol == '\n', so parsing will stop at eol */
> 
> This comment is slightly stale.  dateptr < eol, *eol == '\n', and we
> know the string starting at dateptr is not a run of whitespace and
> that is what makes the parsing stop at eol.

Yeah, I hoped the extra context of the earlier comment would be enough. ;) But it is probably better to spell it out by expanding this comment. The code is certainly tricky enough.

-Peff
Previous: Junio C Hamano
Message 6 of 6 in “parse_commit(): handle broken whitespace-only timestamp”
  1. 3/3 parse_commit(): handle broken whitespace-only timestampJeff King, Apr 22, 2023
  2. René ScharfeApr 22, 2023
  3. Jeff KingApr 23, 2023
  4. Jeff KingApr 25, 2023
  5. Junio C HamanoApr 24, 2023
  6. Jeff KingApr 25, 2023

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.