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

Re: [PATCH v2] wt-status: correct and simplify check for detached HEAD

From
Jeff King <peff@peff.net>
Date
Nov 28, 2015, 17:31 UTC
Message-ID
<20151128173131.GF27264@sigill.intra.peff.net>
In-Reply-To
<5655C14A.1060308@web.de>
On Wed, Nov 25, 2015 at 03:10:18PM +0100, René Scharfe wrote:
Show 12 quoted lines
> Fix that by doing the comparison using strcmp() and only after the
> branch name is extracted.  This way neither too less nor too many
> characters are checked.  While at it call strchrnul() to find the end
> of the branch name instead of open-coding it.
> 
> Helped-by: Jeff King <peff@peff.net>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
> We can be more careful when parsing -- or avoid parsing and backtrack
> if we found "HEAD" after all.  The latter is simpler, and string
> parsing is tricky enough that we better take such opportunities to
> simplify the code..

Yeah, I think this is nicer. We end up allocating either way anyway, so the only extra effort is copy the string.

-Peff
Previous: Matthieu Moy
Message 8 of 8 in “wt-status: use strncmp() for length-limited string comparison”
  1. wt-status: use strncmp() for length-limited string comparisonRené Scharfe, Nov 6, 2015
  2. Jeff KingNov 24, 2015
  3. René ScharfeNov 25, 2015
  4. Jeff KingNov 25, 2015
  5. Matthieu MoyNov 25, 2015
  6. wt-status: correct and simplify check for detached HEADRené Scharfe, Nov 25, 2015
  7. Matthieu MoyNov 25, 2015
  8. Jeff KingNov 28, 2015

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.