@@ -469,7 +469,7 @@ static char *squash_slash(char *name)
469469 return name ;
470470}
471471
472- static char * find_name_gnu (struct apply_state * state ,
472+ static char * find_name_gnu (struct strbuf * root ,
473473 const char * line ,
474474 int p_value )
475475{
@@ -495,8 +495,8 @@ static char *find_name_gnu(struct apply_state *state,
495495 }
496496
497497 strbuf_remove (& name , 0 , cp - name .buf );
498- if (state -> root . len )
499- strbuf_insert (& name , 0 , state -> root . buf , state -> root . len );
498+ if (root -> len )
499+ strbuf_insert (& name , 0 , root -> buf , root -> len );
500500 return squash_slash (strbuf_detach (& name , NULL ));
501501}
502502
@@ -659,7 +659,7 @@ static size_t diff_timestamp_len(const char *line, size_t len)
659659 return line + len - end ;
660660}
661661
662- static char * find_name_common (struct apply_state * state ,
662+ static char * find_name_common (struct strbuf * root ,
663663 const char * line ,
664664 const char * def ,
665665 int p_value ,
@@ -702,30 +702,30 @@ static char *find_name_common(struct apply_state *state,
702702 return squash_slash (xstrdup (def ));
703703 }
704704
705- if (state -> root . len ) {
706- char * ret = xstrfmt ("%s%.*s" , state -> root . buf , len , start );
705+ if (root -> len ) {
706+ char * ret = xstrfmt ("%s%.*s" , root -> buf , len , start );
707707 return squash_slash (ret );
708708 }
709709
710710 return squash_slash (xmemdupz (start , len ));
711711}
712712
713- static char * find_name (struct apply_state * state ,
713+ static char * find_name (struct strbuf * root ,
714714 const char * line ,
715715 char * def ,
716716 int p_value ,
717717 int terminate )
718718{
719719 if (* line == '"' ) {
720- char * name = find_name_gnu (state , line , p_value );
720+ char * name = find_name_gnu (root , line , p_value );
721721 if (name )
722722 return name ;
723723 }
724724
725- return find_name_common (state , line , def , p_value , NULL , terminate );
725+ return find_name_common (root , line , def , p_value , NULL , terminate );
726726}
727727
728- static char * find_name_traditional (struct apply_state * state ,
728+ static char * find_name_traditional (struct strbuf * root ,
729729 const char * line ,
730730 char * def ,
731731 int p_value )
@@ -734,18 +734,18 @@ static char *find_name_traditional(struct apply_state *state,
734734 size_t date_len ;
735735
736736 if (* line == '"' ) {
737- char * name = find_name_gnu (state , line , p_value );
737+ char * name = find_name_gnu (root , line , p_value );
738738 if (name )
739739 return name ;
740740 }
741741
742742 len = strchrnul (line , '\n' ) - line ;
743743 date_len = diff_timestamp_len (line , len );
744744 if (!date_len )
745- return find_name_common (state , line , def , p_value , NULL , TERM_TAB );
745+ return find_name_common (root , line , def , p_value , NULL , TERM_TAB );
746746 len -= date_len ;
747747
748- return find_name_common (state , line , def , p_value , line + len , 0 );
748+ return find_name_common (root , line , def , p_value , line + len , 0 );
749749}
750750
751751/*
@@ -759,7 +759,7 @@ static int guess_p_value(struct apply_state *state, const char *nameline)
759759
760760 if (is_dev_null (nameline ))
761761 return -1 ;
762- name = find_name_traditional (state , nameline , NULL , 0 );
762+ name = find_name_traditional (& state -> root , nameline , NULL , 0 );
763763 if (!name )
764764 return -1 ;
765765 cp = strchr (name , '/' );
@@ -883,17 +883,17 @@ static int parse_traditional_patch(struct apply_state *state,
883883 if (is_dev_null (first )) {
884884 patch -> is_new = 1 ;
885885 patch -> is_delete = 0 ;
886- name = find_name_traditional (state , second , NULL , state -> p_value );
886+ name = find_name_traditional (& state -> root , second , NULL , state -> p_value );
887887 patch -> new_name = name ;
888888 } else if (is_dev_null (second )) {
889889 patch -> is_new = 0 ;
890890 patch -> is_delete = 1 ;
891- name = find_name_traditional (state , first , NULL , state -> p_value );
891+ name = find_name_traditional (& state -> root , first , NULL , state -> p_value );
892892 patch -> old_name = name ;
893893 } else {
894894 char * first_name ;
895- first_name = find_name_traditional (state , first , NULL , state -> p_value );
896- name = find_name_traditional (state , second , first_name , state -> p_value );
895+ first_name = find_name_traditional (& state -> root , first , NULL , state -> p_value );
896+ name = find_name_traditional (& state -> root , second , first_name , state -> p_value );
897897 free (first_name );
898898 if (has_epoch_timestamp (first )) {
899899 patch -> is_new = 1 ;
@@ -940,7 +940,7 @@ static int gitdiff_verify_name(struct apply_state *state,
940940 int side )
941941{
942942 if (!* name && !isnull ) {
943- * name = find_name (state , line , NULL , state -> p_value , TERM_TAB );
943+ * name = find_name (& state -> root , line , NULL , state -> p_value , TERM_TAB );
944944 return 0 ;
945945 }
946946
@@ -949,7 +949,7 @@ static int gitdiff_verify_name(struct apply_state *state,
949949 if (isnull )
950950 return error (_ ("git apply: bad git-diff - expected /dev/null, got %s on line %d" ),
951951 * name , state -> linenr );
952- another = find_name (state , line , NULL , state -> p_value , TERM_TAB );
952+ another = find_name (& state -> root , line , NULL , state -> p_value , TERM_TAB );
953953 if (!another || strcmp (another , * name )) {
954954 free (another );
955955 return error ((side == DIFF_NEW_NAME ) ?
@@ -1032,7 +1032,7 @@ static int gitdiff_copysrc(struct apply_state *state,
10321032{
10331033 patch -> is_copy = 1 ;
10341034 free (patch -> old_name );
1035- patch -> old_name = find_name (state , line , NULL , state -> p_value ? state -> p_value - 1 : 0 , 0 );
1035+ patch -> old_name = find_name (& state -> root , line , NULL , state -> p_value ? state -> p_value - 1 : 0 , 0 );
10361036 return 0 ;
10371037}
10381038
@@ -1042,7 +1042,7 @@ static int gitdiff_copydst(struct apply_state *state,
10421042{
10431043 patch -> is_copy = 1 ;
10441044 free (patch -> new_name );
1045- patch -> new_name = find_name (state , line , NULL , state -> p_value ? state -> p_value - 1 : 0 , 0 );
1045+ patch -> new_name = find_name (& state -> root , line , NULL , state -> p_value ? state -> p_value - 1 : 0 , 0 );
10461046 return 0 ;
10471047}
10481048
@@ -1052,7 +1052,7 @@ static int gitdiff_renamesrc(struct apply_state *state,
10521052{
10531053 patch -> is_rename = 1 ;
10541054 free (patch -> old_name );
1055- patch -> old_name = find_name (state , line , NULL , state -> p_value ? state -> p_value - 1 : 0 , 0 );
1055+ patch -> old_name = find_name (& state -> root , line , NULL , state -> p_value ? state -> p_value - 1 : 0 , 0 );
10561056 return 0 ;
10571057}
10581058
@@ -1062,7 +1062,7 @@ static int gitdiff_renamedst(struct apply_state *state,
10621062{
10631063 patch -> is_rename = 1 ;
10641064 free (patch -> new_name );
1065- patch -> new_name = find_name (state , line , NULL , state -> p_value ? state -> p_value - 1 : 0 , 0 );
1065+ patch -> new_name = find_name (& state -> root , line , NULL , state -> p_value ? state -> p_value - 1 : 0 , 0 );
10661066 return 0 ;
10671067}
10681068
0 commit comments