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

Re: [PATCH 1/2] add '%d' pretty format specifier to show decoration

From
Jeff King <peff@peff.net>
Date
Sep 3, 2008, 19:12 UTC
Message-ID
<20080903191217.GA31195@coredump.intra.peff.net>
In-Reply-To
<alpine.LNX.1.10.0809032036270.32295@pollux>
On Wed, Sep 03, 2008 at 08:40:08PM +0200, Michael Dressel wrote:
> This is a variation of the patch provided by  Jeff King <peff@peff.net>:
> allow '%d' pretty format specifier to show decoration

Thank you for picking this up. I had been meaning to look at it further but hadn't gotten around to it yet.

> would calculate decorations, but not show them. You can now
> do:
>
>   git log --pretty=format:'%H (%d) %s'

I think Junio requested the enclosing parentheses be included. I am not sure I agree, but we are already mandating the comma separator. Personally, I think the right solution is more like

  %(decorate:delim=, )

but that is a much bigger change (and part of what was holding me up on just improving this patch). I think adding %d in the meantime (with or without the surrounding parentheses) is reasonable.

> The difference is that you don't need --decorate when %d has been given
> because this would be "doppeltgemoppelt" (redundant).
This is good, but I don't like the implementation:
Show 17 quoted lines
> +static int deco_in_format(int argc, const char **argv)
> +{
> +	int i;
> +	int deco=0;
> +	for (i=0;i<argc;i++)
> +	{
> +		if ((strstr(argv[i], "pretty=format:") ||
> +					strstr(argv[i], "pretty=tformat:")) &&
> +				strstr(argv[i], "%d"))
> +		{
> +			deco=1;
> +			break;
> +		}
> +
> +	}
> +	return deco;
> +}
There are two bad things about this:
  1. It looks through argv. Partly this is a bit ugly, and we should
     just hook into the part where we have already parsed --pretty=.
     Which in this case really means looking at user_format after
     calling setup_revisions (which is sadly a static global; it really
     should be cleaned up as a member of struct rev_list). But worse
     here is that you don't even look through argv correctly. You really
     want prefixcmp(argv[i], "--pretty=format:"), since otherwise this
     would trigger on something like:
         git log ':/implement %d in pretty:format'
     which is unlikely, perhaps, but I don't think it's that hard to do
     it right in this case.
  2. It just looks for '%d' rather than using the same parser as the
     rest of the code. I _think_ this is actually correct now, because
     we don't even allow simple quoting like '%%d'. But it would be much
     cleaner, I think, to have a library call next to
     format_commit_message() that fills in a struct of "used" items.
So something like:
  static void cmd_log_init(...)
  {
          struct user_format_need ufneed;
  ...
          for (i = 1; i < argc; i++) {
            ...
                  if (!stcmp(arg, "--decorate"))
                          decorate = 1;
            ...
          }
          user_format_needs(&ufneed);
          if (decorate || ufneed.decorate)
            for_each_ref(add_ref_decoration, NULL);
  }
Make sense?
-Peff
Previous: Michael DresselNext: Junio C Hamano
Message 2 of 23 in “add '%d' pretty format specifier to show decoration”
  1. 1/2 add '%d' pretty format specifier to show decorationMichael Dressel, Sep 3, 2008
  2. Jeff KingSep 3, 2008
  3. Junio C HamanoSep 3, 2008
  4. Jeff KingSep 3, 2008
  5. Junio C HamanoSep 3, 2008
  6. Jeff KingSep 3, 2008
  7. René ScharfeSep 3, 2008
  8. Jeff KingSep 4, 2008
  9. René ScharfeSep 4, 2008
  10. 1/3 log: add load_ref_decorations()René Scharfe, Sep 4, 2008
  11. 2/3 move load_ref_decorations() to log-tree.c and export itRené Scharfe, Sep 4, 2008
  12. 3/3 add '%d' pretty format specifier to show decorationRené Scharfe, Sep 4, 2008
  13. Jeff KingSep 5, 2008
  14. Junio C HamanoSep 5, 2008
  15. Jeff KingSep 5, 2008
  16. Junio C HamanoSep 5, 2008
  17. Michael DresselSep 5, 2008
  18. Michael DresselSep 9, 2008
  19. René ScharfeSep 9, 2008
  20. René ScharfeSep 5, 2008
  21. Jeff KingSep 3, 2008
  22. Michael DresselSep 3, 2008
  23. Jeff KingSep 3, 2008

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.