apply: only pass required data to skip_tree_prefix

Currently the 'skip_tree_prefix()' function takes 'struct apply_state' as parameter, even though it only needs the p_value from that struct. This function is in the callchain of 'parse_git_header()', which we want to make more generally useful in a subsequent commit. To make that happen we only want to pass in the required data to 'parse_git_header()', and not the whole 'struct apply_state', and thus we want functions in the callchain of 'parse_git_header()' to only take arguments they really need. Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Gummerer committed Jul 8, 2019 at 17:33 UTC d6c88c4fdc1ce189e4abad56f9e3b16d2f831867
1 file changed +9 -9
apply.c
+9 -9
@@ -1137,17 +1137,17 @@ static int gitdiff_unrecognized(struct apply_state *state,
1137 * Skip p_value leading components from "line"; as we do not accept
1138 * absolute paths, return NULL in that case.
1139 */
1140 -static const char *skip_tree_prefix(struct apply_state *state,
1140 +static const char *skip_tree_prefix(int p_value,
1141 const char *line,
1142 int llen)
1143 {
1144 int nslash;
1145 int i;
1146
1147 - if (!state->p_value)
1147 + if (!p_value)
1148 return (llen && line[0] == '/') ? NULL : line;
1149
1150 - nslash = state->p_value;
1150 + nslash = p_value;
1151 for (i = 0; i < llen; i++) {
1152 int ch = line[i];
1153 if (ch == '/' && --nslash <= 0)
@@ -1184,7 +1184,7 @@ static char *git_header_name(struct apply_state *state,
1184 goto free_and_fail1;
1185
1186 /* strip the a/b prefix including trailing slash */
1187 - cp = skip_tree_prefix(state, first.buf, first.len);
1187 + cp = skip_tree_prefix(state->p_value, first.buf, first.len);
1188 if (!cp)
1189 goto free_and_fail1;
1190 strbuf_remove(&first, 0, cp - first.buf);
@@ -1201,7 +1201,7 @@ static char *git_header_name(struct apply_state *state,
1201 if (*second == '"') {
1202 if (unquote_c_style(&sp, second, NULL))
1203 goto free_and_fail1;
1204 - cp = skip_tree_prefix(state, sp.buf, sp.len);
1204 + cp = skip_tree_prefix(state->p_value, sp.buf, sp.len);
1205 if (!cp)
1206 goto free_and_fail1;
1207 /* They must match, otherwise ignore */
@@ -1212,7 +1212,7 @@ static char *git_header_name(struct apply_state *state,
1212 }
1213
1214 /* unquoted second */
1215 - cp = skip_tree_prefix(state, second, line + llen - second);
1215 + cp = skip_tree_prefix(state->p_value, second, line + llen - second);
1216 if (!cp)
1217 goto free_and_fail1;
1218 if (line + llen - cp != first.len ||
@@ -1227,7 +1227,7 @@ static char *git_header_name(struct apply_state *state,
1227 }
1228
1229 /* unquoted first name */
1230 - name = skip_tree_prefix(state, line, llen);
1230 + name = skip_tree_prefix(state->p_value, line, llen);
1231 if (!name)
1232 return NULL;
1233
@@ -1243,7 +1243,7 @@ static char *git_header_name(struct apply_state *state,
1243 if (unquote_c_style(&sp, second, NULL))
1244 goto free_and_fail2;
1245
1246 - np = skip_tree_prefix(state, sp.buf, sp.len);
1246 + np = skip_tree_prefix(state->p_value, sp.buf, sp.len);
1247 if (!np)
1248 goto free_and_fail2;
1249
@@ -1287,7 +1287,7 @@ static char *git_header_name(struct apply_state *state,
1287 */
1288 if (!name[len + 1])
1289 return NULL; /* no postimage name */
1290 - second = skip_tree_prefix(state, name + len + 1,
1290 + second = skip_tree_prefix(state->p_value, name + len + 1,
1291 line_len - (len + 1));
1292 if (!second)
1293 return NULL;