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
Jeff King <peff@peff.net>
Date
Aug 27, 2014, 18:00 UTC
Message-ID
<20140827180016.GA6269@peff.net>
In-Reply-To
<xmqqioldet75.fsf@gitster.dls.corp.google.com>
On Wed, Aug 27, 2014 at 10:30:22AM -0700, Junio C Hamano wrote:
Show 9 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > +const char *find_commit_header(const char *msg, const char *key, size_t *out_len)
> [...]
> 
> Hmph.  Does this have to worry about continuation lines in the
> header part e.g. mergetag?  If the original in pretty.c was only
> about the encoding, it may not have mattered, but now because it is
> made public, it may matter more.

If you mean parsing past continuation lines, then no, we do not need to worry. We go line by line and look for the key at the beginning of a line, so we would skip past any continuation lines.

If you mean including continuation lines in the output, I don't think that's a good idea here. It would mean the function would have to copy the value out (to get rid of the continuation whitespace) rather than point directly into the msg buffer.

That may be something some callers want, but they should build it separately around this find_commit_header, so that callers that want a single line (like "encoding" or "author") do not have to pay the price. I didn't bother building it out here since there are no callers which want it yet (though I did not look at the mergetag code, which could possibly be converted).

In the meantime, I hoped this comment would suffice for any callers to know whether it was suitable:

+/*
+ * Search the commit object contents given by "msg" for the header "key".
+ * Returns a pointer to the start of the header contents, or NULL. The length
+ * of the header, up to the first newline, is returned via out_len.
+ *
+ * Note that some headers (like mergetag) may be multi-line. It is the caller's
+ * responsibility to parse further in this case!
+ */
+extern const char *find_commit_header(const char *msg, const char *key,
+                                     size_t *out_len);
-Peff
Previous: Junio C HamanoNext: Jeff King
Message 4 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.