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

Re: [PATCH 2/2] convert trivial uses of strncmp() to skip_prefix()

From
Jeff King <peff@peff.net>
Date
Jan 7, 2023, 13:33 UTC
Message-ID
<Y7l0mq6khtlgxGca@coredump.intra.peff.net>
In-Reply-To
<Y7lzFG9gyDrOE4Xt@coredump.intra.peff.net>
On Sat, Jan 07, 2023 at 08:26:45AM -0500, Jeff King wrote:
> Note in the case in ws.c that to get rid of the magic number "9"
> completely, we also switch out "len" for recomputing the pointer
> difference. These are equivalent because "len" is always "ep - string".

By the way, one thing I noticed about this parse_whitespace_rule() function is that it's very loose about its matching. It does:

        for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++) {
                if (strncmp(whitespace_rule_names[i].rule_name,
                            string, len))
                        continue;
		...we matched...
		break;
	}

So it will prefix-match any of the options, even if there are ambiguities. E.g.:

  git -c core.whitespace=-t show

will turn off "trailing-space", even though it would also match "tab-in-indent". It would be easy enough to fix it to require the whole name, but I wasn't sure if this prefix-matching was supposed to be a feature (it doesn't seem to be documented anywhere, though).

-Peff
Previous: Jeff KingNext: René Scharfe
Message 4 of 6 in “some minor starts_with()/skip_prefix() cleanups”
  1. 0/2 some minor starts_with()/skip_prefix() cleanupsJeff King, Jan 7, 2023
  2. 1/2 convert trivial uses of strncmp() to starts_with()Jeff King, Jan 7, 2023
  3. 2/2 convert trivial uses of strncmp() to skip_prefix()Jeff King, Jan 7, 2023
  4. Jeff KingJan 7, 2023
  5. René ScharfeJan 7, 2023
  6. Jeff KingJan 11, 2023

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.