aboutsummaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-08-22 10:29:10 -0700
committerJunio C Hamano <gitster@pobox.com>2017-08-22 10:29:11 -0700
commit1168df9a9c1134b3041c0ffb1f8019a88f51cdb5 (patch)
tree98f882c9e4530a743f8df03b462995835b3d20a2 /apply.c
parenta75ef3ff99a5a916e5211f38134e3f5a78c08a5e (diff)
parent881529c84656e7ff41379c0684df0ff9a796d444 (diff)
downloadgit-1168df9a9c1134b3041c0ffb1f8019a88f51cdb5.tar.gz
git-1168df9a9c1134b3041c0ffb1f8019a88f51cdb5.tar.xz
Merge branch 'rs/apply-lose-prefix-length'
Code clean-up. * rs/apply-lose-prefix-length: apply: remove prefix_length member from apply_state
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 41ee63e1d..956f56a92 100644
--- a/apply.c
+++ b/apply.c
@@ -80,7 +80,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;
@@ -786,11 +785,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;
}
}
@@ -2089,10 +2088,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;
}