From: Christian Couder <christian.couder@gmail.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] apply: remove prefix_length member from apply_state
Date: Thu, 10 Aug 2017 17:58:38 +0200 [thread overview]
Message-ID: <CAP8UFD1W5DnXe8a3VUREhzdAOFCExQrudpP4z4CYNuS==rN0eQ@mail.gmail.com> (raw)
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.
> @@ -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;
next prev parent reply other threads:[~2017-08-10 15:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-09 15:54 [PATCH] apply: remove prefix_length member from apply_state René Scharfe
2017-08-10 15:58 ` Christian Couder [this message]
2017-08-10 23:41 ` Jeff King
2017-08-11 8:52 ` René Scharfe
2017-08-11 9:04 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAP8UFD1W5DnXe8a3VUREhzdAOFCExQrudpP4z4CYNuS==rN0eQ@mail.gmail.com' \
--to=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).