@@ -116,6 +116,7 @@ struct am_state {
116116 int keep ; /* enum keep_type */
117117 int message_id ;
118118 int scissors ; /* enum scissors_type */
119+ int quoted_cr ; /* enum quoted_cr_action */
119120 struct strvec git_apply_opts ;
120121 const char * resolvemsg ;
121122 int committer_date_is_author_date ;
@@ -145,6 +146,7 @@ static void am_state_init(struct am_state *state)
145146 git_config_get_bool ("am.messageid" , & state -> message_id );
146147
147148 state -> scissors = SCISSORS_UNSET ;
149+ state -> quoted_cr = quoted_cr_unset ;
148150
149151 strvec_init (& state -> git_apply_opts );
150152
@@ -165,6 +167,16 @@ static void am_state_release(struct am_state *state)
165167 strvec_clear (& state -> git_apply_opts );
166168}
167169
170+ static int am_option_parse_quoted_cr (const struct option * opt ,
171+ const char * arg , int unset )
172+ {
173+ BUG_ON_OPT_NEG (unset );
174+
175+ if (mailinfo_parse_quoted_cr_action (arg , opt -> value ) != 0 )
176+ return error (_ ("bad action '%s' for '%s'" ), arg , "--quoted-cr" );
177+ return 0 ;
178+ }
179+
168180/**
169181 * Returns path relative to the am_state directory.
170182 */
@@ -397,6 +409,12 @@ static void am_load(struct am_state *state)
397409 else
398410 state -> scissors = SCISSORS_UNSET ;
399411
412+ read_state_file (& sb , state , "quoted-cr" , 1 );
413+ if (!* sb .buf )
414+ state -> quoted_cr = quoted_cr_unset ;
415+ else if (mailinfo_parse_quoted_cr_action (sb .buf , & state -> quoted_cr ) != 0 )
416+ die (_ ("could not parse %s" ), am_path (state , "quoted-cr" ));
417+
400418 read_state_file (& sb , state , "apply-opt" , 1 );
401419 strvec_clear (& state -> git_apply_opts );
402420 if (sq_dequote_to_strvec (sb .buf , & state -> git_apply_opts ) < 0 )
@@ -1002,6 +1020,24 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10021020 }
10031021 write_state_text (state , "scissors" , str );
10041022
1023+ switch (state -> quoted_cr ) {
1024+ case quoted_cr_unset :
1025+ str = "" ;
1026+ break ;
1027+ case quoted_cr_nowarn :
1028+ str = "nowarn" ;
1029+ break ;
1030+ case quoted_cr_warn :
1031+ str = "warn" ;
1032+ break ;
1033+ case quoted_cr_strip :
1034+ str = "strip" ;
1035+ break ;
1036+ default :
1037+ BUG ("invalid value for state->quoted_cr" );
1038+ }
1039+ write_state_text (state , "quoted-cr" , str );
1040+
10051041 sq_quote_argv (& sb , state -> git_apply_opts .v );
10061042 write_state_text (state , "apply-opt" , sb .buf );
10071043
@@ -1162,6 +1198,18 @@ static int parse_mail(struct am_state *state, const char *mail)
11621198 BUG ("invalid value for state->scissors" );
11631199 }
11641200
1201+ switch (state -> quoted_cr ) {
1202+ case quoted_cr_unset :
1203+ break ;
1204+ case quoted_cr_nowarn :
1205+ case quoted_cr_warn :
1206+ case quoted_cr_strip :
1207+ mi .quoted_cr = state -> quoted_cr ;
1208+ break ;
1209+ default :
1210+ BUG ("invalid value for state->quoted_cr" );
1211+ }
1212+
11651213 mi .input = xfopen (mail , "r" );
11661214 mi .output = xfopen (am_path (state , "info" ), "w" );
11671215 if (mailinfo (& mi , am_path (state , "msg" ), am_path (state , "patch" )))
@@ -2242,6 +2290,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
22422290 0 , PARSE_OPT_NONEG ),
22432291 OPT_BOOL ('c' , "scissors" , & state .scissors ,
22442292 N_ ("strip everything before a scissors line" )),
2293+ OPT_CALLBACK_F (0 , "quoted-cr" , & state .quoted_cr , N_ ("action" ),
2294+ N_ ("pass it through git-mailinfo" ),
2295+ PARSE_OPT_NONEG , am_option_parse_quoted_cr ),
22452296 OPT_PASSTHRU_ARGV (0 , "whitespace" , & state .git_apply_opts , N_ ("action" ),
22462297 N_ ("pass it through git-apply" ),
22472298 0 ),
0 commit comments