@@ -298,7 +298,8 @@ static int git_format_config(const char *var, const char *value)
298
298
static FILE * realstdout = NULL ;
299
299
static const char * output_directory = NULL ;
300
300
301
- static int reopen_stdout (struct commit * commit , int nr , int keep_subject )
301
+ static int reopen_stdout (struct commit * commit , int nr , int keep_subject ,
302
+ int numbered_files )
302
303
{
303
304
char filename [PATH_MAX ];
304
305
char * sol ;
@@ -315,53 +316,61 @@ static int reopen_stdout(struct commit *commit, int nr, int keep_subject)
315
316
filename [len ++ ] = '/' ;
316
317
}
317
318
318
- sprintf (filename + len , "%04d" , nr );
319
- len = strlen (filename );
320
-
321
- sol = strstr (commit -> buffer , "\n\n" );
322
- if (sol ) {
323
- int j , space = 1 ;
324
-
325
- sol += 2 ;
326
- /* strip [PATCH] or [PATCH blabla] */
327
- if (!keep_subject && !prefixcmp (sol , "[PATCH" )) {
328
- char * eos = strchr (sol + 6 , ']' );
329
- if (eos ) {
330
- while (isspace (* eos ))
331
- eos ++ ;
332
- sol = eos ;
333
- }
334
- }
319
+ if (numbered_files ) {
320
+ sprintf (filename + len , "%d" , nr );
321
+ len = strlen (filename );
335
322
336
- for (j = 0 ;
337
- j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 &&
338
- len < sizeof (filename ) - suffix_len &&
339
- sol [j ] && sol [j ] != '\n' ;
340
- j ++ ) {
341
- if (istitlechar (sol [j ])) {
342
- if (space ) {
343
- filename [len ++ ] = '-' ;
344
- space = 0 ;
323
+ } else {
324
+ sprintf (filename + len , "%04d" , nr );
325
+ len = strlen (filename );
326
+
327
+ sol = strstr (commit -> buffer , "\n\n" );
328
+ if (sol ) {
329
+ int j , space = 1 ;
330
+
331
+ sol += 2 ;
332
+ /* strip [PATCH] or [PATCH blabla] */
333
+ if (!keep_subject && !prefixcmp (sol , "[PATCH" )) {
334
+ char * eos = strchr (sol + 6 , ']' );
335
+ if (eos ) {
336
+ while (isspace (* eos ))
337
+ eos ++ ;
338
+ sol = eos ;
345
339
}
346
- filename [len ++ ] = sol [j ];
347
- if (sol [j ] == '.' )
348
- while (sol [j + 1 ] == '.' )
349
- j ++ ;
350
- } else
351
- space = 1 ;
340
+ }
341
+
342
+ for (j = 0 ;
343
+ j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 &&
344
+ len < sizeof (filename ) - suffix_len &&
345
+ sol [j ] && sol [j ] != '\n' ;
346
+ j ++ ) {
347
+ if (istitlechar (sol [j ])) {
348
+ if (space ) {
349
+ filename [len ++ ] = '-' ;
350
+ space = 0 ;
351
+ }
352
+ filename [len ++ ] = sol [j ];
353
+ if (sol [j ] == '.' )
354
+ while (sol [j + 1 ] == '.' )
355
+ j ++ ;
356
+ } else
357
+ space = 1 ;
358
+ }
359
+ while (filename [len - 1 ] == '.'
360
+ || filename [len - 1 ] == '-' )
361
+ len -- ;
362
+ filename [len ] = 0 ;
352
363
}
353
- while ( filename [ len - 1 ] == '.' || filename [ len - 1 ] == '-' )
354
- len -- ;
355
- filename [ len ] = 0 ;
364
+ if ( len + suffix_len >= sizeof ( filename ) )
365
+ return error ( "Patch pathname too long" ) ;
366
+ strcpy ( filename + len , fmt_patch_suffix ) ;
356
367
}
357
- if (len + suffix_len >= sizeof (filename ))
358
- return error ("Patch pathname too long" );
359
- strcpy (filename + len , fmt_patch_suffix );
368
+
360
369
fprintf (realstdout , "%s\n" , filename );
361
370
if (freopen (filename , "w" , stdout ) == NULL )
362
371
return error ("Cannot open patch file %s" ,filename );
363
- return 0 ;
364
372
373
+ return 0 ;
365
374
}
366
375
367
376
static void get_patch_ids (struct rev_info * rev , struct patch_ids * ids , const char * prefix )
@@ -431,6 +440,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
431
440
int numbered = 0 ;
432
441
int start_number = -1 ;
433
442
int keep_subject = 0 ;
443
+ int numbered_files = 0 ; /* _just_ numbers */
434
444
int subject_prefix = 0 ;
435
445
int ignore_if_in_upstream = 0 ;
436
446
int thread = 0 ;
@@ -465,6 +475,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
465
475
numbered = 1 ;
466
476
else if (!prefixcmp (argv [i ], "--start-number=" ))
467
477
start_number = strtol (argv [i ] + 15 , NULL , 10 );
478
+ else if (!strcmp (argv [i ], "--numbered-files" ))
479
+ numbered_files = 1 ;
468
480
else if (!strcmp (argv [i ], "--start-number" )) {
469
481
i ++ ;
470
482
if (i == argc )
@@ -540,6 +552,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
540
552
die ("-n and -k are mutually exclusive." );
541
553
if (keep_subject && subject_prefix )
542
554
die ("--subject-prefix and -k are mutually exclusive." );
555
+ if (numbered_files && use_stdout )
556
+ die ("--numbered-files and --stdout are mutually exclusive." );
543
557
544
558
argc = setup_revisions (argc , argv , & rev , "HEAD" );
545
559
if (argc > 1 )
@@ -614,7 +628,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
614
628
rev .message_id = message_id ;
615
629
}
616
630
if (!use_stdout )
617
- if (reopen_stdout (commit , rev .nr , keep_subject ))
631
+ if (reopen_stdout (commit , rev .nr , keep_subject ,
632
+ numbered_files ))
618
633
die ("Failed to create output files" );
619
634
shown = log_tree_commit (& rev , commit );
620
635
free (commit -> buffer );
0 commit comments