3737
3838#define MAIL_DEFAULT_WRAP 72
3939#define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100
40+ #define FORMAT_PATCH_NAME_MAX_DEFAULT 64
4041
4142/* Set a default date-time format for git log ("log.date" config variable) */
4243static const char * default_date_mode = NULL ;
@@ -50,6 +51,7 @@ static int decoration_style;
5051static int decoration_given ;
5152static int use_mailmap_config = 1 ;
5253static const char * fmt_patch_subject_prefix = "PATCH" ;
54+ static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT ;
5355static const char * fmt_pretty ;
5456
5557static const char * const builtin_log_usage [] = {
@@ -150,6 +152,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
150152 rev -> abbrev_commit = default_abbrev_commit ;
151153 rev -> show_root_diff = default_show_root ;
152154 rev -> subject_prefix = fmt_patch_subject_prefix ;
155+ rev -> patch_name_max = fmt_patch_name_max ;
153156 rev -> show_signature = default_show_signature ;
154157 rev -> encode_email_headers = default_encode_email_headers ;
155158 rev -> diffopt .flags .allow_textconv = 1 ;
@@ -457,6 +460,10 @@ static int git_log_config(const char *var, const char *value, void *cb)
457460 return git_config_string (& fmt_pretty , var , value );
458461 if (!strcmp (var , "format.subjectprefix" ))
459462 return git_config_string (& fmt_patch_subject_prefix , var , value );
463+ if (!strcmp (var , "format.filenamemaxlength" )) {
464+ fmt_patch_name_max = git_config_int (var , value );
465+ return 0 ;
466+ }
460467 if (!strcmp (var , "format.encodeemailheaders" )) {
461468 default_encode_email_headers = git_config_bool (var , value );
462469 return 0 ;
@@ -958,15 +965,9 @@ static int open_next_file(struct commit *commit, const char *subject,
958965 struct rev_info * rev , int quiet )
959966{
960967 struct strbuf filename = STRBUF_INIT ;
961- int suffix_len = strlen (rev -> patch_suffix ) + 1 ;
962968
963969 if (output_directory ) {
964970 strbuf_addstr (& filename , output_directory );
965- if (filename .len >=
966- PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len ) {
967- strbuf_release (& filename );
968- return error (_ ("name of output directory is too long" ));
969- }
970971 strbuf_complete (& filename , '/' );
971972 }
972973
@@ -1754,6 +1755,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
17541755 N_ ("start numbering patches at <n> instead of 1" )),
17551756 OPT_INTEGER ('v' , "reroll-count" , & reroll_count ,
17561757 N_ ("mark the series as Nth re-roll" )),
1758+ OPT_INTEGER (0 , "filename-max-length" , & fmt_patch_name_max ,
1759+ N_ ("max length of output filename" )),
17571760 OPT_CALLBACK_F (0 , "rfc" , & rev , NULL ,
17581761 N_ ("Use [RFC PATCH] instead of [PATCH]" ),
17591762 PARSE_OPT_NOARG | PARSE_OPT_NONEG , rfc_callback ),
@@ -1854,6 +1857,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
18541857 PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
18551858 PARSE_OPT_KEEP_DASHDASH );
18561859
1860+ /* Make sure "0000-$sub.patch" gives non-negative length for $sub */
1861+ if (fmt_patch_name_max <= strlen ("0000-" ) + strlen (fmt_patch_suffix ))
1862+ fmt_patch_name_max = strlen ("0000-" ) + strlen (fmt_patch_suffix );
1863+
18571864 if (cover_from_description_arg )
18581865 cover_from_description_mode = parse_cover_from_description (cover_from_description_arg );
18591866
@@ -1938,6 +1945,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19381945 rev .diffopt .output_format |= DIFF_FORMAT_PATCH ;
19391946
19401947 rev .zero_commit = zero_commit ;
1948+ rev .patch_name_max = fmt_patch_name_max ;
19411949
19421950 if (!rev .diffopt .flags .text && !no_binary_diff )
19431951 rev .diffopt .flags .binary = 1 ;
0 commit comments