@@ -502,7 +502,7 @@ static int detect_patch_format(const char **paths)
502
502
* Splits out individual email patches from `paths`, where each path is either
503
503
* a mbox file or a Maildir. Returns 0 on success, -1 on failure.
504
504
*/
505
- static int split_mail_mbox (struct am_state * state , const char * * paths )
505
+ static int split_mail_mbox (struct am_state * state , const char * * paths , int keep_cr )
506
506
{
507
507
struct child_process cp = CHILD_PROCESS_INIT ;
508
508
struct strbuf last = STRBUF_INIT ;
@@ -512,6 +512,8 @@ static int split_mail_mbox(struct am_state *state, const char **paths)
512
512
argv_array_pushf (& cp .args , "-d%d" , state -> prec );
513
513
argv_array_pushf (& cp .args , "-o%s" , state -> dir );
514
514
argv_array_push (& cp .args , "-b" );
515
+ if (keep_cr )
516
+ argv_array_push (& cp .args , "--keep-cr" );
515
517
argv_array_push (& cp .args , "--" );
516
518
argv_array_pushv (& cp .args , paths );
517
519
@@ -536,14 +538,22 @@ static int split_mail_mbox(struct am_state *state, const char **paths)
536
538
* state->cur will be set to the index of the first mail, and state->last will
537
539
* be set to the index of the last mail.
538
540
*
541
+ * Set keep_cr to 0 to convert all lines ending with \r\n to end with \n, 1
542
+ * to disable this behavior, -1 to use the default configured setting.
543
+ *
539
544
* Returns 0 on success, -1 on failure.
540
545
*/
541
546
static int split_mail (struct am_state * state , enum patch_format patch_format ,
542
- const char * * paths )
547
+ const char * * paths , int keep_cr )
543
548
{
549
+ if (keep_cr < 0 ) {
550
+ keep_cr = 0 ;
551
+ git_config_get_bool ("am.keepcr" , & keep_cr );
552
+ }
553
+
544
554
switch (patch_format ) {
545
555
case PATCH_FORMAT_MBOX :
546
- return split_mail_mbox (state , paths );
556
+ return split_mail_mbox (state , paths , keep_cr );
547
557
default :
548
558
die ("BUG: invalid patch_format" );
549
559
}
@@ -554,7 +564,7 @@ static int split_mail(struct am_state *state, enum patch_format patch_format,
554
564
* Setup a new am session for applying patches
555
565
*/
556
566
static void am_setup (struct am_state * state , enum patch_format patch_format ,
557
- const char * * paths )
567
+ const char * * paths , int keep_cr )
558
568
{
559
569
unsigned char curr_head [GIT_SHA1_RAWSZ ];
560
570
const char * str ;
@@ -570,7 +580,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
570
580
if (mkdir (state -> dir , 0777 ) < 0 && errno != EEXIST )
571
581
die_errno (_ ("failed to create directory '%s'" ), state -> dir );
572
582
573
- if (split_mail (state , patch_format , paths ) < 0 ) {
583
+ if (split_mail (state , patch_format , paths , keep_cr ) < 0 ) {
574
584
am_destroy (state );
575
585
die (_ ("Failed to split patches." ));
576
586
}
@@ -1511,6 +1521,7 @@ enum resume_mode {
1511
1521
int cmd_am (int argc , const char * * argv , const char * prefix )
1512
1522
{
1513
1523
struct am_state state ;
1524
+ int keep_cr = -1 ;
1514
1525
int patch_format = PATCH_FORMAT_UNKNOWN ;
1515
1526
enum resume_mode resume = RESUME_FALSE ;
1516
1527
@@ -1534,6 +1545,12 @@ int cmd_am(int argc, const char **argv, const char *prefix)
1534
1545
N_ ("pass -b flag to git-mailinfo" ), KEEP_NON_PATCH ),
1535
1546
OPT_BOOL ('m' , "message-id" , & state .message_id ,
1536
1547
N_ ("pass -m flag to git-mailinfo" )),
1548
+ { OPTION_SET_INT , 0 , "keep-cr" , & keep_cr , NULL ,
1549
+ N_ ("pass --keep-cr flag to git-mailsplit for mbox format" ),
1550
+ PARSE_OPT_NOARG | PARSE_OPT_NONEG , NULL , 1 },
1551
+ { OPTION_SET_INT , 0 , "no-keep-cr" , & keep_cr , NULL ,
1552
+ N_ ("do not pass --keep-cr flag to git-mailsplit independent of am.keepcr" ),
1553
+ PARSE_OPT_NOARG | PARSE_OPT_NONEG , NULL , 0 },
1537
1554
OPT_CALLBACK (0 , "patch-format" , & patch_format , N_ ("format" ),
1538
1555
N_ ("format the patch(es) are in" ),
1539
1556
parse_opt_patchformat ),
@@ -1631,7 +1648,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
1631
1648
argv_array_push (& paths , mkpath ("%s/%s" , prefix , argv [i ]));
1632
1649
}
1633
1650
1634
- am_setup (& state , patch_format , paths .argv );
1651
+ am_setup (& state , patch_format , paths .argv , keep_cr );
1635
1652
1636
1653
argv_array_clear (& paths );
1637
1654
}
0 commit comments