summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-09-10 08:03:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-09-10 08:03:01 (GMT)
commitc7759cd60ab0213024c3fbe9a163dcd49b2bb838 (patch)
tree1ecc8399c65a2990f15e05d2de080e12a8336e7a
parent70def2c47fd541b6c62629a23054c317428ea43e (diff)
parent881529c84656e7ff41379c0684df0ff9a796d444 (diff)
downloadgit-c7759cd60ab0213024c3fbe9a163dcd49b2bb838.zip
git-c7759cd60ab0213024c3fbe9a163dcd49b2bb838.tar.gz
git-c7759cd60ab0213024c3fbe9a163dcd49b2bb838.tar.bz2
Merge branch 'rs/apply-lose-prefix-length' into maint
Code clean-up. * rs/apply-lose-prefix-length: apply: remove prefix_length member from apply_state
-rw-r--r--apply.c12
-rw-r--r--apply.h1
2 files changed, 5 insertions, 8 deletions
diff --git a/apply.c b/apply.c
index 36c37b5..0c7b259 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;
@@ -787,11 +786,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;
}
}
@@ -2108,10 +2107,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;
}
diff --git a/apply.h b/apply.h
index b3d6783..d9b3957 100644
--- a/apply.h
+++ b/apply.h
@@ -35,7 +35,6 @@ enum apply_verbosity {
struct apply_state {
const char *prefix;
- int prefix_length;
/* These are lock_file related */
struct lock_file *lock_file;