@@ -207,40 +207,6 @@ struct fragment {
207
207
#define BINARY_DELTA_DEFLATED 1
208
208
#define BINARY_LITERAL_DEFLATED 2
209
209
210
- /*
211
- * This represents a "patch" to a file, both metainfo changes
212
- * such as creation/deletion, filemode and content changes represented
213
- * as a series of fragments.
214
- */
215
- struct patch {
216
- char * new_name , * old_name , * def_name ;
217
- unsigned int old_mode , new_mode ;
218
- int is_new , is_delete ; /* -1 = unknown, 0 = false, 1 = true */
219
- int rejected ;
220
- unsigned ws_rule ;
221
- int lines_added , lines_deleted ;
222
- int score ;
223
- int extension_linenr ; /* first line specifying delete/new/rename/copy */
224
- unsigned int is_toplevel_relative :1 ;
225
- unsigned int inaccurate_eof :1 ;
226
- unsigned int is_binary :1 ;
227
- unsigned int is_copy :1 ;
228
- unsigned int is_rename :1 ;
229
- unsigned int recount :1 ;
230
- unsigned int conflicted_threeway :1 ;
231
- unsigned int direct_to_threeway :1 ;
232
- unsigned int crlf_in_old :1 ;
233
- struct fragment * fragments ;
234
- char * result ;
235
- size_t resultsize ;
236
- char old_oid_prefix [GIT_MAX_HEXSZ + 1 ];
237
- char new_oid_prefix [GIT_MAX_HEXSZ + 1 ];
238
- struct patch * next ;
239
-
240
- /* three-way fallback result */
241
- struct object_id threeway_stage [3 ];
242
- };
243
-
244
210
static void free_fragment_list (struct fragment * list )
245
211
{
246
212
while (list ) {
@@ -1320,12 +1286,13 @@ static int check_header_line(int linenr, struct patch *patch)
1320
1286
return 0 ;
1321
1287
}
1322
1288
1323
- /* Verify that we recognize the lines following a git header */
1324
- static int parse_git_header (struct apply_state * state ,
1325
- const char * line ,
1326
- int len ,
1327
- unsigned int size ,
1328
- struct patch * patch )
1289
+ int parse_git_diff_header (struct strbuf * root ,
1290
+ int * linenr ,
1291
+ int p_value ,
1292
+ const char * line ,
1293
+ int len ,
1294
+ unsigned int size ,
1295
+ struct patch * patch )
1329
1296
{
1330
1297
unsigned long offset ;
1331
1298
struct gitdiff_data parse_hdr_state ;
@@ -1340,21 +1307,21 @@ static int parse_git_header(struct apply_state *state,
1340
1307
* or removing or adding empty files), so we get
1341
1308
* the default name from the header.
1342
1309
*/
1343
- patch -> def_name = git_header_name (state -> p_value , line , len );
1344
- if (patch -> def_name && state -> root . len ) {
1345
- char * s = xstrfmt ("%s%s" , state -> root . buf , patch -> def_name );
1310
+ patch -> def_name = git_header_name (p_value , line , len );
1311
+ if (patch -> def_name && root -> len ) {
1312
+ char * s = xstrfmt ("%s%s" , root -> buf , patch -> def_name );
1346
1313
free (patch -> def_name );
1347
1314
patch -> def_name = s ;
1348
1315
}
1349
1316
1350
1317
line += len ;
1351
1318
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 ;
1319
+ ( * linenr ) ++ ;
1320
+ parse_hdr_state .root = root ;
1321
+ parse_hdr_state .linenr = * linenr ;
1322
+ parse_hdr_state .p_value = p_value ;
1356
1323
1357
- for (offset = len ; size > 0 ; offset += len , size -= len , line += len , state -> linenr ++ ) {
1324
+ for (offset = len ; size > 0 ; offset += len , size -= len , line += len , ( * linenr ) ++ ) {
1358
1325
static const struct opentry {
1359
1326
const char * str ;
1360
1327
int (* fn )(struct gitdiff_data * , const char * , struct patch * );
@@ -1391,7 +1358,7 @@ static int parse_git_header(struct apply_state *state,
1391
1358
res = p -> fn (& parse_hdr_state , line + oplen , patch );
1392
1359
if (res < 0 )
1393
1360
return -1 ;
1394
- if (check_header_line (state -> linenr , patch ))
1361
+ if (check_header_line (* linenr , patch ))
1395
1362
return -1 ;
1396
1363
if (res > 0 )
1397
1364
return offset ;
@@ -1572,7 +1539,9 @@ static int find_header(struct apply_state *state,
1572
1539
* or mode change, so we handle that specially
1573
1540
*/
1574
1541
if (!memcmp ("diff --git " , line , 11 )) {
1575
- int git_hdr_len = parse_git_header (state , line , len , size , patch );
1542
+ int git_hdr_len = parse_git_diff_header (& state -> root , & state -> linenr ,
1543
+ state -> p_value , line , len ,
1544
+ size , patch );
1576
1545
if (git_hdr_len < 0 )
1577
1546
return -128 ;
1578
1547
if (git_hdr_len <= len )
0 commit comments