summaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
authorLibravatar René Scharfe <l.s.r@web.de>2017-08-09 17:54:46 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-08-09 10:21:45 -0700
commit881529c84656e7ff41379c0684df0ff9a796d444 (patch)
treedfcb91dad1a4d2e1b918c83bcd02f4f76b46223b /apply.c
parentGit 2.12.3 (diff)
downloadtgif-881529c84656e7ff41379c0684df0ff9a796d444.tar.xz
apply: remove prefix_length member from apply_state
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. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/apply.c b/apply.c
index 0e2caeab9c..4f67896b65 100644
--- a/apply.c
+++ b/apply.c
@@ -79,7 +79,6 @@ int init_apply_state(struct apply_state *state,
{
memset(state, 0, sizeof(*state));
state->prefix = prefix;
- state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
state->lock_file = lock_file;
state->newfd = -1;
state->apply = 1;
@@ -795,11 +794,11 @@ static int guess_p_value(struct apply_state *state, const char *nameline)
* Does it begin with "a/$our-prefix" and such? Then this is
* very likely to apply to our directory.
*/
- if (!strncmp(name, state->prefix, state->prefix_length))
+ if (starts_with(name, state->prefix))
val = count_slashes(state->prefix);
else {
cp++;
- if (!strncmp(cp, state->prefix, state->prefix_length))
+ if (starts_with(cp, state->prefix))
val = count_slashes(state->prefix) + 1;
}
}
@@ -2078,10 +2077,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;
}