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

Re: [PATCHv3] pretty: Initialize notes if %N is used

From
Jeff King <peff@peff.net>
Date
Apr 13, 2010, 11:07 UTC
Message-ID
<20100413110723.GA2910@coredump.intra.peff.net>
In-Reply-To
<1271156465-7302-1-git-send-email-heipei@hackvalue.de>
On Tue, Apr 13, 2010 at 01:01:05PM +0200, Johannes Gilger wrote:
> Introduced space when calling userformat_find_requirements and dealt
> with %+N and %-N during the strbuf_expand phase. I hope strncmp is the
> right way to do it here. strbuf is NUL-terminated so there should not
> be a problem.

Ugh. I didn't even know we had such a thing. Those look like the only ones that should be a problem, though. I'm glad to have factored out the "want" code, now. At least it will all be in one spot.

Show 14 quoted lines
> +static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
> +				   void *context)
> +{
> +	struct userformat_want *w = context;
> +
> +	switch (*placeholder) {
> +		case '-':
> +		case '+':
> +			if (!strncmp(placeholder+1, "N", 1))
> +				w->notes = 1;
> +		case 'N': w->notes = 1;
> +	}
> +	return 0;
> +}
Should this perhaps be:
  if (*placeholder == '+' || *placeholder == '-')
    placeholder++;
  switch (*placeholder) {
    case 'N': w->notes = 1; break;
  }

so that it will extend naturally if other placeholder lookups are needed (since those ones also could have + or - markers).

Also, I just noticed that your case is missing a 'break'. Not a bug yet, but it will be if somebody adds a new case. This is almost certainly my fault from the original version I posted. :)

-Peff
Previous: Johannes GilgerNext: Johannes Gilger
Message 22 of 26 in “Initialize notes trees if %N is used and no --show-notes given”
  1. Initialize notes trees if %N is used and no --show-notes givenJohannes Gilger, Apr 5, 2010
  2. Jeff KingApr 6, 2010
  3. Thomas RastApr 6, 2010
  4. Johannes GilgerApr 6, 2010
  5. Thomas RastApr 6, 2010
  6. Jeff KingApr 6, 2010
  7. Junio C HamanoApr 7, 2010
  8. Jeff KingApr 7, 2010
  9. pretty.c: Don't expand %N without --show-notesJohannes Gilger, Apr 10, 2010
  10. Junio C HamanoApr 10, 2010
  11. Notes: Connect the %N flag to --{show,no}-notesJohannes Gilger, Apr 10, 2010
  12. Junio C HamanoApr 10, 2010
  13. Jeff KingApr 10, 2010
  14. pretty: Initialize notes if %N is usedJohannes Gilger, Apr 11, 2010
  15. Jeff KingApr 12, 2010
  16. [PATCHv2] pretty: Initialize notes if %N is usedJohannes Gilger, Apr 13, 2010
  17. Jeff KingApr 13, 2010
  18. Johannes GilgerApr 13, 2010
  19. [PATCHv3] pretty: Initialize notes if %N is usedy@vger.kernel.org, Apr 13, 2010
  20. [PATCHv3] pretty: Initialize notes if %N is usedy@vger.kernel.org, Apr 13, 2010
  21. [PATCHv3] pretty: Initialize notes if %N is usedJohannes Gilger, Apr 13, 2010
  22. Jeff KingApr 13, 2010
  23. [PATCHv4] pretty: Initialize notes if %N is usedJohannes Gilger, Apr 13, 2010
  24. Junio C HamanoApr 13, 2010
  25. [PATCHv5] pretty: Initialize notes if %N is usedJohannes Gilger, Apr 13, 2010
  26. Johannes GilgerApr 10, 2010

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.