Skip to content

Commit c7759cd

Browse files
committed
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
2 parents 70def2c + 881529c commit c7759cd

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

apply.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ int init_apply_state(struct apply_state *state,
8080
{
8181
memset(state, 0, sizeof(*state));
8282
state->prefix = prefix;
83-
state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
8483
state->lock_file = lock_file;
8584
state->newfd = -1;
8685
state->apply = 1;
@@ -787,11 +786,11 @@ static int guess_p_value(struct apply_state *state, const char *nameline)
787786
* Does it begin with "a/$our-prefix" and such? Then this is
788787
* very likely to apply to our directory.
789788
*/
790-
if (!strncmp(name, state->prefix, state->prefix_length))
789+
if (starts_with(name, state->prefix))
791790
val = count_slashes(state->prefix);
792791
else {
793792
cp++;
794-
if (!strncmp(cp, state->prefix, state->prefix_length))
793+
if (starts_with(cp, state->prefix))
795794
val = count_slashes(state->prefix) + 1;
796795
}
797796
}
@@ -2108,10 +2107,9 @@ static int use_patch(struct apply_state *state, struct patch *p)
21082107
int i;
21092108

21102109
/* Paths outside are not touched regardless of "--include" */
2111-
if (0 < state->prefix_length) {
2112-
int pathlen = strlen(pathname);
2113-
if (pathlen <= state->prefix_length ||
2114-
memcmp(state->prefix, pathname, state->prefix_length))
2110+
if (state->prefix && *state->prefix) {
2111+
const char *rest;
2112+
if (!skip_prefix(pathname, state->prefix, &rest) || !*rest)
21152113
return 0;
21162114
}
21172115

apply.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ enum apply_verbosity {
3535

3636
struct apply_state {
3737
const char *prefix;
38-
int prefix_length;
3938

4039
/* These are lock_file related */
4140
struct lock_file *lock_file;

0 commit comments

Comments
 (0)