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