@@ -19,6 +19,9 @@ struct mailinfo {
19
19
struct strbuf email ;
20
20
int keep_subject ;
21
21
int keep_non_patch_brackets_in_subject ;
22
+
23
+ int filter_stage ; /* still reading log or are we copying patch? */
24
+ int header_stage ; /* still checking in-body headers? */
22
25
};
23
26
static char * message_id ;
24
27
@@ -648,25 +651,25 @@ static int is_scissors_line(const struct strbuf *line)
648
651
gap * 2 < perforation );
649
652
}
650
653
651
- static int handle_commit_msg (struct strbuf * line , int * still_looking )
654
+ static int handle_commit_msg (struct mailinfo * mi , struct strbuf * line )
652
655
{
653
656
if (!cmitmsg )
654
657
return 0 ;
655
658
656
- if (* still_looking ) {
659
+ if (mi -> header_stage ) {
657
660
if (!line -> len || (line -> len == 1 && line -> buf [0 ] == '\n' ))
658
661
return 0 ;
659
662
}
660
663
661
- if (use_inbody_headers && * still_looking ) {
662
- * still_looking = check_header (line , s_hdr_data , 0 );
663
- if (* still_looking )
664
+ if (use_inbody_headers && mi -> header_stage ) {
665
+ mi -> header_stage = check_header (line , s_hdr_data , 0 );
666
+ if (mi -> header_stage )
664
667
return 0 ;
665
668
} else
666
669
/* Only trim the first (blank) line of the commit message
667
670
* when ignoring in-body headers.
668
671
*/
669
- * still_looking = 0 ;
672
+ mi -> header_stage = 0 ;
670
673
671
674
/* normalize the log message to UTF-8. */
672
675
if (metainfo_charset )
@@ -678,7 +681,7 @@ static int handle_commit_msg(struct strbuf *line, int *still_looking)
678
681
die_errno ("Could not rewind output message file" );
679
682
if (ftruncate (fileno (cmitmsg ), 0 ))
680
683
die_errno ("Could not truncate output message file at scissors" );
681
- * still_looking = 1 ;
684
+ mi -> header_stage = 1 ;
682
685
683
686
/*
684
687
* We may have already read "secondary headers"; purge
@@ -710,13 +713,13 @@ static void handle_patch(const struct strbuf *line)
710
713
patch_lines ++ ;
711
714
}
712
715
713
- static void handle_filter (struct strbuf * line , int * filter_stage , int * header_stage )
716
+ static void handle_filter (struct mailinfo * mi , struct strbuf * line )
714
717
{
715
- switch (* filter_stage ) {
718
+ switch (mi -> filter_stage ) {
716
719
case 0 :
717
- if (!handle_commit_msg (line , header_stage ))
720
+ if (!handle_commit_msg (mi , line ))
718
721
break ;
719
- ( * filter_stage ) ++ ;
722
+ mi -> filter_stage ++ ;
720
723
case 1 :
721
724
handle_patch (line );
722
725
break ;
@@ -800,8 +803,7 @@ static int find_boundary(struct mailinfo *mi, struct strbuf *line)
800
803
return 0 ;
801
804
}
802
805
803
- static int handle_boundary (struct mailinfo * mi , struct strbuf * line ,
804
- int * filter_stage , int * header_stage )
806
+ static int handle_boundary (struct mailinfo * mi , struct strbuf * line )
805
807
{
806
808
struct strbuf newline = STRBUF_INIT ;
807
809
@@ -823,7 +825,7 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line,
823
825
"can't recover\n" );
824
826
exit (1 );
825
827
}
826
- handle_filter (& newline , filter_stage , header_stage );
828
+ handle_filter (mi , & newline );
827
829
strbuf_release (& newline );
828
830
829
831
/* skip to the next boundary */
@@ -851,8 +853,6 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line,
851
853
static void handle_body (struct mailinfo * mi , struct strbuf * line )
852
854
{
853
855
struct strbuf prev = STRBUF_INIT ;
854
- int filter_stage = 0 ;
855
- int header_stage = 1 ;
856
856
857
857
/* Skip up to the first boundary */
858
858
if (* content_top ) {
@@ -865,10 +865,10 @@ static void handle_body(struct mailinfo *mi, struct strbuf *line)
865
865
if (* content_top && is_multipart_boundary (line )) {
866
866
/* flush any leftover */
867
867
if (prev .len ) {
868
- handle_filter (& prev , & filter_stage , & header_stage );
868
+ handle_filter (mi , & prev );
869
869
strbuf_reset (& prev );
870
870
}
871
- if (!handle_boundary (mi , line , & filter_stage , & header_stage ))
871
+ if (!handle_boundary (mi , line ))
872
872
goto handle_body_out ;
873
873
}
874
874
@@ -898,7 +898,7 @@ static void handle_body(struct mailinfo *mi, struct strbuf *line)
898
898
strbuf_addbuf (& prev , sb );
899
899
break ;
900
900
}
901
- handle_filter (sb , & filter_stage , & header_stage );
901
+ handle_filter (mi , sb );
902
902
}
903
903
/*
904
904
* The partial chunk is saved in "prev" and will be
@@ -908,7 +908,7 @@ static void handle_body(struct mailinfo *mi, struct strbuf *line)
908
908
break ;
909
909
}
910
910
default :
911
- handle_filter (line , & filter_stage , & header_stage );
911
+ handle_filter (mi , line );
912
912
}
913
913
914
914
} while (!strbuf_getwholeline (line , mi -> input , '\n' ));
@@ -1021,6 +1021,7 @@ static void setup_mailinfo(struct mailinfo *mi)
1021
1021
memset (mi , 0 , sizeof (* mi ));
1022
1022
strbuf_init (& mi -> name , 0 );
1023
1023
strbuf_init (& mi -> email , 0 );
1024
+ mi -> header_stage = 1 ;
1024
1025
git_config (git_mailinfo_config , & mi );
1025
1026
}
1026
1027
0 commit comments