22
#include "rerere.h"
23
#include "apply.h"
24
25
+struct gitdiff_data {
26
+ struct strbuf *root;
27
+ int linenr;
28
+ int p_value;
29
+};
30
+
31
static void git_apply_config(void)
32
{
33
git_config_get_string_const("apply.whitespace", &apply_default_whitespace);
920
return 0;
921
}
922
917
-static int gitdiff_hdrend(struct apply_state *state,
923
+static int gitdiff_hdrend(struct gitdiff_data *state,
924
const char *line,
925
struct patch *patch)
926
{
939
#define DIFF_OLD_NAME 0
940
#define DIFF_NEW_NAME 1
941
936
-static int gitdiff_verify_name(struct apply_state *state,
942
+static int gitdiff_verify_name(struct gitdiff_data *state,
943
const char *line,
944
int isnull,
945
char **name,
946
int side)
947
{
948
if (!*name && !isnull) {
943
- *name = find_name(&state->root, line, NULL, state->p_value, TERM_TAB);
949
+ *name = find_name(state->root, line, NULL, state->p_value, TERM_TAB);
950
return 0;
951
}
952
955
if (isnull)
956
return error(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
957
*name, state->linenr);
952
- another = find_name(&state->root, line, NULL, state->p_value, TERM_TAB);
958
+ another = find_name(state->root, line, NULL, state->p_value, TERM_TAB);
959
if (!another || strcmp(another, *name)) {
960
free(another);
961
return error((side == DIFF_NEW_NAME) ?
971
return 0;
972
}
973
968
-static int gitdiff_oldname(struct apply_state *state,
974
+static int gitdiff_oldname(struct gitdiff_data *state,
975
const char *line,
976
struct patch *patch)
977
{
980
DIFF_OLD_NAME);
981
}
982
977
-static int gitdiff_newname(struct apply_state *state,
983
+static int gitdiff_newname(struct gitdiff_data *state,
984
const char *line,
985
struct patch *patch)
986
{
998
return 0;
999
}
1000
995
-static int gitdiff_oldmode(struct apply_state *state,
1001
+static int gitdiff_oldmode(struct gitdiff_data *state,
1002
const char *line,
1003
struct patch *patch)
1004
{
1005
return parse_mode_line(line, state->linenr, &patch->old_mode);
1006
}
1007
1002
-static int gitdiff_newmode(struct apply_state *state,
1008
+static int gitdiff_newmode(struct gitdiff_data *state,
1009
const char *line,
1010
struct patch *patch)
1011
{
1012
return parse_mode_line(line, state->linenr, &patch->new_mode);
1013
}
1014
1009
-static int gitdiff_delete(struct apply_state *state,
1015
+static int gitdiff_delete(struct gitdiff_data *state,
1016
const char *line,
1017
struct patch *patch)
1018
{
1022
return gitdiff_oldmode(state, line, patch);
1023
}
1024
1019
-static int gitdiff_newfile(struct apply_state *state,
1025
+static int gitdiff_newfile(struct gitdiff_data *state,
1026
const char *line,
1027
struct patch *patch)
1028
{
1032
return gitdiff_newmode(state, line, patch);
1033
}
1034
1029
-static int gitdiff_copysrc(struct apply_state *state,
1035
+static int gitdiff_copysrc(struct gitdiff_data *state,
1036
const char *line,
1037
struct patch *patch)
1038
{
1039
patch->is_copy = 1;
1040
free(patch->old_name);
1035
- patch->old_name = find_name(&state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1041
+ patch->old_name = find_name(state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1042
return 0;
1043
}
1044
1039
-static int gitdiff_copydst(struct apply_state *state,
1045
+static int gitdiff_copydst(struct gitdiff_data *state,
1046
const char *line,
1047
struct patch *patch)
1048
{
1049
patch->is_copy = 1;
1050
free(patch->new_name);
1045
- patch->new_name = find_name(&state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1051
+ patch->new_name = find_name(state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1052
return 0;
1053
}
1054
1049
-static int gitdiff_renamesrc(struct apply_state *state,
1055
+static int gitdiff_renamesrc(struct gitdiff_data *state,
1056
const char *line,
1057
struct patch *patch)
1058
{
1059
patch->is_rename = 1;
1060
free(patch->old_name);
1055
- patch->old_name = find_name(&state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1061
+ patch->old_name = find_name(state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1062
return 0;
1063
}
1064
1059
-static int gitdiff_renamedst(struct apply_state *state,
1065
+static int gitdiff_renamedst(struct gitdiff_data *state,
1066
const char *line,
1067
struct patch *patch)
1068
{
1069
patch->is_rename = 1;
1070
free(patch->new_name);
1065
- patch->new_name = find_name(&state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1071
+ patch->new_name = find_name(state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1072
return 0;
1073
}
1074
1069
-static int gitdiff_similarity(struct apply_state *state,
1075
+static int gitdiff_similarity(struct gitdiff_data *state,
1076
const char *line,
1077
struct patch *patch)
1078
{
1082
return 0;
1083
}
1084
1079
-static int gitdiff_dissimilarity(struct apply_state *state,
1085
+static int gitdiff_dissimilarity(struct gitdiff_data *state,
1086
const char *line,
1087
struct patch *patch)
1088
{
1092
return 0;
1093
}
1094
1089
-static int gitdiff_index(struct apply_state *state,
1095
+static int gitdiff_index(struct gitdiff_data *state,
1096
const char *line,
1097
struct patch *patch)
1098
{
1132
* This is normal for a diff that doesn't change anything: we'll fall through
1133
* into the next diff. Tell the parser to break out.
1134
*/
1129
-static int gitdiff_unrecognized(struct apply_state *state,
1135
+static int gitdiff_unrecognized(struct gitdiff_data *state,
1136
const char *line,
1137
struct patch *patch)
1138
{
1328
struct patch *patch)
1329
{
1330
unsigned long offset;
1331
+ struct gitdiff_data parse_hdr_state;
1332
1333
/* A git diff has explicit new/delete information, so we don't guess */
1334
patch->is_new = 0;
1350
line += len;
1351
size -= len;
1352
state->linenr++;
1353
+ parse_hdr_state.root = &state->root;
1354
+ parse_hdr_state.linenr = state->linenr;
1355
+ parse_hdr_state.p_value = state->p_value;
1356
+
1357
for (offset = len ; size > 0 ; offset += len, size -= len, line += len, state->linenr++) {
1358
static const struct opentry {
1359
const char *str;
1349
- int (*fn)(struct apply_state *, const char *, struct patch *);
1360
+ int (*fn)(struct gitdiff_data *, const char *, struct patch *);
1361
} optable[] = {
1362
{ "@@ -", gitdiff_hdrend },
1363
{ "--- ", gitdiff_oldname },
1388
int res;
1389
if (len < oplen || memcmp(p->str, line, oplen))
1390
continue;
1380
- res = p->fn(state, line + oplen, patch);
1391
+ res = p->fn(&parse_hdr_state, line + oplen, patch);
1392
if (res < 0)
1393
return -1;
1394
if (check_header_line(state->linenr, patch))