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

Re: [PATCH v2 1/6] commit: provide a function to find a header in a buffer

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 27, 2014, 19:26 UTC
Message-ID
<xmqqsikhd98f.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20140827191414.GA7561@peff.net>
Jeff King <peff@peff.net> writes:
Show 5 quoted lines
> I think they are a direct tradeoff. If you include only the first line,
> then callers who want multiple lines have to keep parsing.  If you
> include multiple lines, then callers who care only about the first line
> will have to re-find the newline rather than just using "out_len"
> directly.
Fair enough.
Show 7 quoted lines
> I suppose you could argue that people who are only expecting one line
> (e.g., "encoding") should just assume that out_len ends at the first
> line. For correctly-formatted commits, that works the same under either
> scheme. For a broken commit where "encoding" _is_ multi-line, one case
> would ignore the continued bits and the other case would return an
> unexpected encoding value with newlines in it. The choice probably
> doesn't matter much in practice.
True.
> Mostly I just punted on it with a comment since I did not plan to add
> any multi-line callers, and I figured we could sort it out then. If you
> feel strongly, it should be pretty easy to check for continuation and
> extend out_len if necessary.

I agree that we do not want to worry too much about the minority multi-line callers.

I don't mind returning -1 in out_len and have the callers check. That way will allow callers to easily diagnose this

	tree $T
        author $GIT_AUTHOR_IDENT
	committer $GIT_COMMITTER_IDENT
	encoding encoding
         unexpected continuation line
	log message

as an error; they would just make sure that out_len is not the "this is continued; you need to parse the rest yourself" value.

Otherwise, the callers need to check value[out_len+1] to see if it is an SP (value[out_len] must be '\n') to catch the error, I would think.

Previous: Jeff KingNext: Jeff King
Message 8 of 18 in “clean up author parsing”
  1. 0/6 clean up author parsingJeff King, Aug 27, 2014
  2. 1/6 commit: provide a function to find a header in a bufferJeff King, Aug 27, 2014
  3. Junio C HamanoAug 27, 2014
  4. Jeff KingAug 27, 2014
  5. Jeff KingAug 27, 2014
  6. Junio C HamanoAug 27, 2014
  7. Jeff KingAug 27, 2014
  8. Junio C HamanoAug 27, 2014
  9. Jeff KingAug 27, 2014
  10. Junio C HamanoAug 27, 2014
  11. 2/6 record_author_info: fix memory leak on malformed commitJeff King, Aug 27, 2014
  12. 3/6 record_author_info: use find_commit_headerJeff King, Aug 27, 2014
  13. 4/6 use strbufs in date functionsJeff King, Aug 27, 2014
  14. 5/6 determine_author_info: reuse parsing functionsJeff King, Aug 27, 2014
  15. 6/6 determine_author_info: copy getenv outputJeff King, Aug 27, 2014
  16. Christian CouderAug 27, 2014
  17. Jeff KingAug 27, 2014
  18. Junio C HamanoAug 27, 2014

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.