@@ -207,40 +207,6 @@ struct fragment {
207207#define BINARY_DELTA_DEFLATED 1
208208#define BINARY_LITERAL_DEFLATED 2
209209
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-
244210static void free_fragment_list (struct fragment * list )
245211{
246212 while (list ) {
@@ -1320,12 +1286,13 @@ static int check_header_line(int linenr, struct patch *patch)
13201286 return 0 ;
13211287}
13221288
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 )
13291296{
13301297 unsigned long offset ;
13311298 struct gitdiff_data parse_hdr_state ;
@@ -1340,21 +1307,21 @@ static int parse_git_header(struct apply_state *state,
13401307 * or removing or adding empty files), so we get
13411308 * the default name from the header.
13421309 */
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 );
13461313 free (patch -> def_name );
13471314 patch -> def_name = s ;
13481315 }
13491316
13501317 line += len ;
13511318 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 ;
13561323
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 ) ++ ) {
13581325 static const struct opentry {
13591326 const char * str ;
13601327 int (* fn )(struct gitdiff_data * , const char * , struct patch * );
@@ -1391,7 +1358,7 @@ static int parse_git_header(struct apply_state *state,
13911358 res = p -> fn (& parse_hdr_state , line + oplen , patch );
13921359 if (res < 0 )
13931360 return -1 ;
1394- if (check_header_line (state -> linenr , patch ))
1361+ if (check_header_line (* linenr , patch ))
13951362 return -1 ;
13961363 if (res > 0 )
13971364 return offset ;
@@ -1572,7 +1539,9 @@ static int find_header(struct apply_state *state,
15721539 * or mode change, so we handle that specially
15731540 */
15741541 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 );
15761545 if (git_hdr_len < 0 )
15771546 return -128 ;
15781547 if (git_hdr_len <= len )
0 commit comments