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

Re: [PATCH 1/1] general style: replaces memcmp() with starts_with()

From
Jeff King <peff@peff.net>
Date
Mar 18, 2014, 02:41 UTC
Message-ID
<20140318024134.GA644@sigill.intra.peff.net>
In-Reply-To
<xmqqd2hka0h7.fsf@gitster.dls.corp.google.com>
On Mon, Mar 17, 2014 at 04:07:00PM -0700, Junio C Hamano wrote:
Show 6 quoted lines
> >> > -		if (!memcmp(used_atom[at], "color:", 6))
> >> > +		if (starts_with(used_atom[at], "color:"))
> >> >  			need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
> [...]
> What if used_atom[at] is not related to color at all?  We do not
> want to touch the variable.

Thanks, that is what I was missing. It is not "did we find a reset" but "toggle on for a non-reset color, toggle off for a reset".

It could be written with skip_prefix as:
  if (skip_prefix(used_atom[at], "color:", &c))
          need_color_reset_at_eol = !!strcmp(c, "reset");

but I do not think it is particularly important to do so. Sorry for the noise.

-Peff
Previous: Junio C HamanoNext: Quint Guvernator
Message 6 of 12 in “general style: replaces memcmp() with starts_with()”
  1. 0/1 general style: replaces memcmp() with starts_with()Quint Guvernator, Mar 17, 2014
  2. 1/1 general style: replaces memcmp() with starts_with()Quint Guvernator, Mar 17, 2014
  3. Junio C HamanoMar 17, 2014
  4. Jeff KingMar 17, 2014
  5. Junio C HamanoMar 17, 2014
  6. Jeff KingMar 18, 2014
  7. Quint GuvernatorMar 17, 2014
  8. Eric SunshineMar 18, 2014
  9. Quint GuvernatorMar 18, 2014
  10. Eric SunshineMar 18, 2014
  11. Junio C HamanoMar 18, 2014
  12. Quint GuvernatorMar 17, 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.