@@ -458,35 +458,28 @@ static int auto_number = 1;
458
458
459
459
static char * default_attach = NULL ;
460
460
461
- static char * * extra_hdr ;
462
- static int extra_hdr_nr ;
463
- static int extra_hdr_alloc ;
464
-
465
- static char * * extra_to ;
466
- static int extra_to_nr ;
467
- static int extra_to_alloc ;
468
-
469
- static char * * extra_cc ;
470
- static int extra_cc_nr ;
471
- static int extra_cc_alloc ;
461
+ static struct string_list extra_hdr ;
462
+ static struct string_list extra_to ;
463
+ static struct string_list extra_cc ;
472
464
473
465
static void add_header (const char * value )
474
466
{
467
+ struct string_list_item * item ;
475
468
int len = strlen (value );
476
469
while (len && value [len - 1 ] == '\n' )
477
470
len -- ;
471
+
478
472
if (!strncasecmp (value , "to: " , 4 )) {
479
- ALLOC_GROW (extra_to , extra_to_nr + 1 , extra_to_alloc );
480
- extra_to [extra_to_nr ++ ] = xstrndup (value + 4 , len - 4 );
481
- return ;
473
+ item = string_list_append (value + 4 , & extra_to );
474
+ len -= 4 ;
475
+ } else if (!strncasecmp (value , "cc: " , 4 )) {
476
+ item = string_list_append (value + 4 , & extra_cc );
477
+ len -= 4 ;
478
+ } else {
479
+ item = string_list_append (value , & extra_hdr );
482
480
}
483
- if (!strncasecmp (value , "cc: " , 4 )) {
484
- ALLOC_GROW (extra_cc , extra_cc_nr + 1 , extra_cc_alloc );
485
- extra_cc [extra_cc_nr ++ ] = xstrndup (value + 4 , len - 4 );
486
- return ;
487
- }
488
- ALLOC_GROW (extra_hdr , extra_hdr_nr + 1 , extra_hdr_alloc );
489
- extra_hdr [extra_hdr_nr ++ ] = xstrndup (value , len );
481
+
482
+ item -> string [len ] = '\0' ;
490
483
}
491
484
492
485
#define THREAD_SHALLOW 1
@@ -507,15 +500,13 @@ static int git_format_config(const char *var, const char *value, void *cb)
507
500
if (!strcmp (var , "format.to" )) {
508
501
if (!value )
509
502
return config_error_nonbool (var );
510
- ALLOC_GROW (extra_to , extra_to_nr + 1 , extra_to_alloc );
511
- extra_to [extra_to_nr ++ ] = xstrdup (value );
503
+ string_list_append (value , & extra_to );
512
504
return 0 ;
513
505
}
514
506
if (!strcmp (var , "format.cc" )) {
515
507
if (!value )
516
508
return config_error_nonbool (var );
517
- ALLOC_GROW (extra_cc , extra_cc_nr + 1 , extra_cc_alloc );
518
- extra_cc [extra_cc_nr ++ ] = xstrdup (value );
509
+ string_list_append (value , & extra_cc );
519
510
return 0 ;
520
511
}
521
512
if (!strcmp (var , "diff.color" ) || !strcmp (var , "color.diff" )) {
@@ -884,15 +875,13 @@ static int header_callback(const struct option *opt, const char *arg, int unset)
884
875
885
876
static int to_callback (const struct option * opt , const char * arg , int unset )
886
877
{
887
- ALLOC_GROW (extra_to , extra_to_nr + 1 , extra_to_alloc );
888
- extra_to [extra_to_nr ++ ] = xstrdup (arg );
878
+ string_list_append (arg , & extra_to );
889
879
return 0 ;
890
880
}
891
881
892
882
static int cc_callback (const struct option * opt , const char * arg , int unset )
893
883
{
894
- ALLOC_GROW (extra_cc , extra_cc_nr + 1 , extra_cc_alloc );
895
- extra_cc [extra_cc_nr ++ ] = xstrdup (arg );
884
+ string_list_append (arg , & extra_cc );
896
885
return 0 ;
897
886
}
898
887
@@ -972,6 +961,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
972
961
OPT_END ()
973
962
};
974
963
964
+ extra_hdr .strdup_strings = 1 ;
965
+ extra_to .strdup_strings = 1 ;
966
+ extra_cc .strdup_strings = 1 ;
975
967
git_config (git_format_config , NULL );
976
968
init_revisions (& rev , prefix );
977
969
rev .commit_format = CMIT_FMT_EMAIL ;
@@ -1008,29 +1000,29 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1008
1000
add_signoff = xmemdupz (committer , endpos - committer + 1 );
1009
1001
}
1010
1002
1011
- for (i = 0 ; i < extra_hdr_nr ; i ++ ) {
1012
- strbuf_addstr (& buf , extra_hdr [i ]);
1003
+ for (i = 0 ; i < extra_hdr . nr ; i ++ ) {
1004
+ strbuf_addstr (& buf , extra_hdr . items [i ]. string );
1013
1005
strbuf_addch (& buf , '\n' );
1014
1006
}
1015
1007
1016
- if (extra_to_nr )
1008
+ if (extra_to . nr )
1017
1009
strbuf_addstr (& buf , "To: " );
1018
- for (i = 0 ; i < extra_to_nr ; i ++ ) {
1010
+ for (i = 0 ; i < extra_to . nr ; i ++ ) {
1019
1011
if (i )
1020
1012
strbuf_addstr (& buf , " " );
1021
- strbuf_addstr (& buf , extra_to [i ]);
1022
- if (i + 1 < extra_to_nr )
1013
+ strbuf_addstr (& buf , extra_to . items [i ]. string );
1014
+ if (i + 1 < extra_to . nr )
1023
1015
strbuf_addch (& buf , ',' );
1024
1016
strbuf_addch (& buf , '\n' );
1025
1017
}
1026
1018
1027
- if (extra_cc_nr )
1019
+ if (extra_cc . nr )
1028
1020
strbuf_addstr (& buf , "Cc: " );
1029
- for (i = 0 ; i < extra_cc_nr ; i ++ ) {
1021
+ for (i = 0 ; i < extra_cc . nr ; i ++ ) {
1030
1022
if (i )
1031
1023
strbuf_addstr (& buf , " " );
1032
- strbuf_addstr (& buf , extra_cc [i ]);
1033
- if (i + 1 < extra_cc_nr )
1024
+ strbuf_addstr (& buf , extra_cc . items [i ]. string );
1025
+ if (i + 1 < extra_cc . nr )
1034
1026
strbuf_addch (& buf , ',' );
1035
1027
strbuf_addch (& buf , '\n' );
1036
1028
}
@@ -1239,6 +1231,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1239
1231
fclose (stdout );
1240
1232
}
1241
1233
free (list );
1234
+ string_list_clear (& extra_to , 0 );
1235
+ string_list_clear (& extra_cc , 0 );
1236
+ string_list_clear (& extra_hdr , 0 );
1242
1237
if (ignore_if_in_upstream )
1243
1238
free_patch_ids (& ids );
1244
1239
return 0 ;
0 commit comments