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

Re: [PATCH] apply: remove prefix_length member from apply_state

From
Christian Couder <christian.couder@gmail.com>
Date
Aug 10, 2017, 15:58 UTC
Message-ID
<CAP8UFD1W5DnXe8a3VUREhzdAOFCExQrudpP4z4CYNuS==rN0eQ@mail.gmail.com>
In-Reply-To
<24fb9d9c-0b1c-4aaa-7d89-12d322066cff@web.de>
On Wed, Aug 9, 2017 at 5:54 PM, René Scharfe <l.s.r@web.de> wrote:
> Use a NULL-and-NUL check to see if we have a prefix and consistently use
> C string functions on it instead of storing its length in a member of
> struct apply_state.  This avoids strlen() calls and simplifies the code.
This looks like a good idea.
Show 13 quoted lines
> @@ -2088,10 +2087,9 @@ static int use_patch(struct apply_state *state, struct patch *p)
>         int i;
>
>         /* Paths outside are not touched regardless of "--include" */
> -       if (0 < state->prefix_length) {
> -               int pathlen = strlen(pathname);
> -               if (pathlen <= state->prefix_length ||
> -                   memcmp(state->prefix, pathname, state->prefix_length))
> +       if (state->prefix && *state->prefix) {
> +               const char *rest;
> +               if (!skip_prefix(pathname, state->prefix, &rest) || !*rest)
>                         return 0;
>         }
Yeah, or maybe declare "const char *rest;" just after "int i;" and then use:
       if (state->prefix && *state->prefix &&
          (!skip_prefix(pathname, state->prefix, &rest) || !*rest))
               return 0;
Previous: René ScharfeNext: Jeff King
Message 2 of 5 in “apply: remove prefix_length member from apply_state”
  1. apply: remove prefix_length member from apply_stateRené Scharfe, Aug 9, 2017
  2. Christian CouderAug 10, 2017
  3. Jeff KingAug 10, 2017
  4. René ScharfeAug 11, 2017
  5. Jeff KingAug 11, 2017

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.