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

Re: [PATCH 06/14] shortlog: replace hand-parsing of author with pretty-printer

From
Jeff King <peff@peff.net>
Date
Jan 4, 2016, 10:17 UTC
Message-ID
<20160104101712.GA32086@sigill.intra.peff.net>
In-Reply-To
<CAPig+cRxBHp9hRBbFPYtEdytnmGdVYVMfJLKzjT6qoQ8EOSxQw@mail.gmail.com>
On Mon, Jan 04, 2016 at 04:43:23AM -0500, Eric Sunshine wrote:
> > +       format_commit_message(commit, "%an <%ae>", &author, &ctx);
> > +       if (author.len <= 3) {
> 
> I suppose magic number 3 is the space, '<', and '>'...
Yeah. That's worthy of a comment, I think (see below).

I don't think we will detect a case with just a missing name _or_ email, but neither did the original.

Show 5 quoted lines
> >                 warning(_("Missing author: %s"),
> >                     oid_to_hex(&commit->object.oid));
> >                 return;
> 
> Is this leaking strbuf 'author'?
Yes. Looks like the original leaked "buf" in the same way.

Rather than repeat the strbuf_release, I think we can introduce a goto, like:

diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 10c92fa..4180a2d 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -124,10 +124,11 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 	ctx.output_encoding = get_log_output_encoding();
 
 	format_commit_message(commit, "%an <%ae>", &author, &ctx);
+	/* we can detect a total failure only by seeing " <>" in the output */
 	if (author.len <= 3) {
 		warning(_("Missing author: %s"),
 		    oid_to_hex(&commit->object.oid));
-		return;
+		goto out;
 	}
 
 	if (log->user_format)
@@ -136,6 +137,8 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		format_commit_message(commit, "%s", &oneline, &ctx);
 
 	insert_one_record(log, author.buf, oneline.len ? oneline.buf : "<none>");
+
+out:
 	strbuf_release(&author);
 	strbuf_release(&oneline);
 }

That should make it easier to handle the cases added later in the
series, too.

-Peff
Previous: Eric SunshineNext: Jeff King
Message 16 of 29 in “counting trailers with shortlogs”
  1. 0/14 counting trailers with shortlogsJeff King, Dec 29, 2015
  2. 01/14 move string functions out of git-compat-utilJeff King, Dec 29, 2015
  3. 02/14 log: refactor add_header to drop some magic numbersJeff King, Dec 29, 2015
  4. Eric SunshineDec 31, 2015
  5. Jeff KingJan 1, 2016
  6. Jeff KingJan 1, 2016
  7. 03/14 strutil: add skip_prefix_icaseJeff King, Dec 29, 2015
  8. Eric SunshineDec 31, 2015
  9. Jeff KingJan 1, 2016
  10. 04/14 shortlog: use skip_prefix_icase to parse "Author" linesJeff King, Dec 29, 2015
  11. Eric SunshineDec 31, 2015
  12. Jeff KingJan 1, 2016
  13. 05/14 shortlog: use strbufs to read from stdinJeff King, Dec 29, 2015
  14. 06/14 shortlog: replace hand-parsing of author with pretty-printerJeff King, Dec 29, 2015
  15. Eric SunshineJan 4, 2016
  16. Jeff KingJan 4, 2016
  17. 07/14 shortlog: optimize "--summary" modeJeff King, Dec 29, 2015
  18. 08/14 shortlog: optimize out useless "<none>" normalizationJeff King, Dec 29, 2015
  19. 09/14 shortlog: optimize out useless string listJeff King, Dec 29, 2015
  20. 10/14 shortlog: change "author" variables to "ident"Jeff King, Dec 29, 2015
  21. 11/14 shortlog: allow grouping by committer identJeff King, Dec 29, 2015
  22. Eric SunshineJan 4, 2016
  23. Jeff KingJan 4, 2016
  24. 12/14 trailer: factor out config readingJeff King, Dec 29, 2015
  25. 13/14 trailer: add interface for parsing commit trailersJeff King, Dec 29, 2015
  26. 14/14 shortlog: match commit trailers with --identJeff King, Dec 29, 2015
  27. Jeff KingDec 29, 2015
  28. Eric SunshineJan 4, 2016
  29. Jeff KingJan 4, 2016

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.