@@ -517,7 +517,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
517
517
if (get_oid_with_context (the_repository , obj_name ,
518
518
GET_OID_RECORD_PATH ,
519
519
& oidc , & obj_context ))
520
- die (_ ("Not a valid object name %s" ), obj_name );
520
+ die (_ ("not a valid object name %s" ), obj_name );
521
521
if (!obj_context .path ||
522
522
!textconv_object (the_repository , obj_context .path ,
523
523
obj_context .mode , & oidc , 1 , & buf , & size )) {
@@ -541,7 +541,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
541
541
int offset = 0 ;
542
542
543
543
if (!buf )
544
- return error (_ ("Could not read object %s" ), oid_to_hex (oid ));
544
+ return error (_ ("could not read object %s" ), oid_to_hex (oid ));
545
545
546
546
assert (type == OBJ_TAG );
547
547
while (offset < size && buf [offset ] != '\n' ) {
@@ -635,7 +635,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
635
635
break ;
636
636
o = parse_object (the_repository , & t -> tagged -> oid );
637
637
if (!o )
638
- ret = error (_ ("Could not read object %s" ),
638
+ ret = error (_ ("could not read object %s" ),
639
639
oid_to_hex (& t -> tagged -> oid ));
640
640
objects [i ].item = o ;
641
641
i -- ;
@@ -660,7 +660,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
660
660
ret = cmd_log_walk (& rev );
661
661
break ;
662
662
default :
663
- ret = error (_ ("Unknown type: %d" ), o -> type );
663
+ ret = error (_ ("unknown type: %d" ), o -> type );
664
664
}
665
665
}
666
666
free (objects );
@@ -871,8 +871,16 @@ static int git_format_config(const char *var, const char *value, void *cb)
871
871
static const char * output_directory = NULL ;
872
872
static int outdir_offset ;
873
873
874
+ static FILE * fopen_excl (const char * filename )
875
+ {
876
+ int fd = open (filename , O_CREAT | O_EXCL | O_WRONLY , 0666 );
877
+ if (fd < 0 )
878
+ return NULL ;
879
+ return fdopen (fd , "w" );
880
+ }
881
+
874
882
static int open_next_file (struct commit * commit , const char * subject ,
875
- struct rev_info * rev , int quiet )
883
+ struct rev_info * rev , int quiet , int clobber )
876
884
{
877
885
struct strbuf filename = STRBUF_INIT ;
878
886
int suffix_len = strlen (rev -> patch_suffix ) + 1 ;
@@ -897,8 +905,13 @@ static int open_next_file(struct commit *commit, const char *subject,
897
905
if (!quiet )
898
906
printf ("%s\n" , filename .buf + outdir_offset );
899
907
900
- if ((rev -> diffopt .file = fopen (filename .buf , "w" )) == NULL ) {
901
- error_errno (_ ("Cannot open patch file %s" ), filename .buf );
908
+ if (clobber )
909
+ rev -> diffopt .file = fopen (filename .buf , "w" );
910
+ else
911
+ rev -> diffopt .file = fopen_excl (filename .buf );
912
+
913
+ if (!rev -> diffopt .file ) {
914
+ error_errno (_ ("cannot open patch file %s" ), filename .buf );
902
915
strbuf_release (& filename );
903
916
return -1 ;
904
917
}
@@ -915,7 +928,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
915
928
unsigned flags1 , flags2 ;
916
929
917
930
if (rev -> pending .nr != 2 )
918
- die (_ ("Need exactly one range. " ));
931
+ die (_ ("need exactly one range" ));
919
932
920
933
o1 = rev -> pending .objects [0 ].item ;
921
934
o2 = rev -> pending .objects [1 ].item ;
@@ -925,7 +938,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
925
938
c2 = lookup_commit_reference (the_repository , & o2 -> oid );
926
939
927
940
if ((flags1 & UNINTERESTING ) == (flags2 & UNINTERESTING ))
928
- die (_ ("Not a range. " ));
941
+ die (_ ("not a range" ));
929
942
930
943
init_patch_ids (the_repository , ids );
931
944
@@ -1034,7 +1047,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
1034
1047
struct commit * origin ,
1035
1048
int nr , struct commit * * list ,
1036
1049
const char * branch_name ,
1037
- int quiet )
1050
+ int quiet ,
1051
+ int clobber )
1038
1052
{
1039
1053
const char * committer ;
1040
1054
const char * body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n" ;
@@ -1048,13 +1062,14 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
1048
1062
struct commit * head = list [0 ];
1049
1063
1050
1064
if (!cmit_fmt_is_mail (rev -> commit_format ))
1051
- die (_ ("Cover letter needs email format" ));
1065
+ die (_ ("cover letter needs email format" ));
1052
1066
1053
1067
committer = git_committer_info (0 );
1054
1068
1055
1069
if (!use_stdout &&
1056
- open_next_file (NULL , rev -> numbered_files ? NULL : "cover-letter" , rev , quiet ))
1057
- return ;
1070
+ open_next_file (NULL , rev -> numbered_files ? NULL : "cover-letter" ,
1071
+ rev , quiet , clobber ))
1072
+ die (_ ("failed to create cover-letter file" ));
1058
1073
1059
1074
log_write_email_headers (rev , head , & pp .after_subject , & need_8bit_cte , 0 );
1060
1075
@@ -1218,7 +1233,7 @@ static int output_directory_callback(const struct option *opt, const char *arg,
1218
1233
const char * * dir = (const char * * )opt -> value ;
1219
1234
BUG_ON_OPT_NEG (unset );
1220
1235
if (* dir )
1221
- die (_ ("Two output directories?" ));
1236
+ die (_ ("two output directories?" ));
1222
1237
* dir = arg ;
1223
1238
return 0 ;
1224
1239
}
@@ -1329,7 +1344,7 @@ static struct commit *get_base_commit(const char *base_commit,
1329
1344
if (base_commit && strcmp (base_commit , "auto" )) {
1330
1345
base = lookup_commit_reference_by_name (base_commit );
1331
1346
if (!base )
1332
- die (_ ("Unknown commit %s" ), base_commit );
1347
+ die (_ ("unknown commit %s" ), base_commit );
1333
1348
} else if ((base_commit && !strcmp (base_commit , "auto" )) || base_auto ) {
1334
1349
struct branch * curr_branch = branch_get (NULL );
1335
1350
const char * upstream = branch_get_upstream (curr_branch , NULL );
@@ -1339,18 +1354,18 @@ static struct commit *get_base_commit(const char *base_commit,
1339
1354
struct object_id oid ;
1340
1355
1341
1356
if (get_oid (upstream , & oid ))
1342
- die (_ ("Failed to resolve '%s' as a valid ref. " ), upstream );
1357
+ die (_ ("failed to resolve '%s' as a valid ref" ), upstream );
1343
1358
commit = lookup_commit_or_die (& oid , "upstream base" );
1344
1359
base_list = get_merge_bases_many (commit , total , list );
1345
1360
/* There should be one and only one merge base. */
1346
1361
if (!base_list || base_list -> next )
1347
- die (_ ("Could not find exact merge base. " ));
1362
+ die (_ ("could not find exact merge base" ));
1348
1363
base = base_list -> item ;
1349
1364
free_commit_list (base_list );
1350
1365
} else {
1351
- die (_ ("Failed to get upstream, if you want to record base commit automatically,\n"
1366
+ die (_ ("failed to get upstream, if you want to record base commit automatically,\n"
1352
1367
"please use git branch --set-upstream-to to track a remote branch.\n"
1353
- "Or you could specify base commit by --base=<base-commit-id> manually. " ));
1368
+ "Or you could specify base commit by --base=<base-commit-id> manually" ));
1354
1369
}
1355
1370
}
1356
1371
@@ -1368,7 +1383,7 @@ static struct commit *get_base_commit(const char *base_commit,
1368
1383
struct commit_list * merge_base ;
1369
1384
merge_base = get_merge_bases (rev [2 * i ], rev [2 * i + 1 ]);
1370
1385
if (!merge_base || merge_base -> next )
1371
- die (_ ("Failed to find exact merge base" ));
1386
+ die (_ ("failed to find exact merge base" ));
1372
1387
1373
1388
rev [i ] = merge_base -> item ;
1374
1389
}
@@ -1517,6 +1532,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1517
1532
struct strbuf buf = STRBUF_INIT ;
1518
1533
int use_patch_format = 0 ;
1519
1534
int quiet = 0 ;
1535
+ int clobber = 1 ;
1520
1536
int reroll_count = -1 ;
1521
1537
char * branch_name = NULL ;
1522
1538
char * base_commit = NULL ;
@@ -1603,6 +1619,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1603
1619
OPT__QUIET (& quiet , N_ ("don't print the patch filenames" )),
1604
1620
OPT_BOOL (0 , "progress" , & show_progress ,
1605
1621
N_ ("show progress while generating patches" )),
1622
+ OPT_BOOL (0 , "clobber" , & clobber ,
1623
+ N_ ("allow overwriting output files" )),
1606
1624
OPT_CALLBACK (0 , "interdiff" , & idiff_prev , N_ ("rev" ),
1607
1625
N_ ("show changes against <rev> in cover letter or single patch" ),
1608
1626
parse_opt_object_name ),
@@ -1747,7 +1765,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1747
1765
if (use_stdout )
1748
1766
die (_ ("standard output, or directory, which one?" ));
1749
1767
if (mkdir (output_directory , 0777 ) < 0 && errno != EEXIST )
1750
- die_errno (_ ("Could not create directory '%s'" ),
1768
+ die_errno (_ ("could not create directory '%s'" ),
1751
1769
output_directory );
1752
1770
}
1753
1771
@@ -1893,7 +1911,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1893
1911
if (thread )
1894
1912
gen_message_id (& rev , "cover" );
1895
1913
make_cover_letter (& rev , use_stdout ,
1896
- origin , nr , list , branch_name , quiet );
1914
+ origin , nr , list , branch_name ,
1915
+ quiet , clobber );
1897
1916
print_bases (& bases , rev .diffopt .file );
1898
1917
print_signature (rev .diffopt .file );
1899
1918
total ++ ;
@@ -1948,8 +1967,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1948
1967
}
1949
1968
1950
1969
if (!use_stdout &&
1951
- open_next_file (rev .numbered_files ? NULL : commit , NULL , & rev , quiet ))
1952
- die (_ ("Failed to create output files" ));
1970
+ open_next_file (rev .numbered_files ? NULL : commit , NULL ,
1971
+ & rev , quiet , clobber ))
1972
+ die (_ ("failed to create output files" ));
1953
1973
shown = log_tree_commit (& rev , commit );
1954
1974
free_commit_buffer (the_repository -> parsed_objects ,
1955
1975
commit );
@@ -2073,9 +2093,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
2073
2093
revs .max_parents = 1 ;
2074
2094
2075
2095
if (add_pending_commit (head , & revs , 0 ))
2076
- die (_ ("Unknown commit %s" ), head );
2096
+ die (_ ("unknown commit %s" ), head );
2077
2097
if (add_pending_commit (upstream , & revs , UNINTERESTING ))
2078
- die (_ ("Unknown commit %s" ), upstream );
2098
+ die (_ ("unknown commit %s" ), upstream );
2079
2099
2080
2100
/* Don't say anything if head and upstream are the same. */
2081
2101
if (revs .pending .nr == 2 ) {
@@ -2087,7 +2107,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
2087
2107
get_patch_ids (& revs , & ids );
2088
2108
2089
2109
if (limit && add_pending_commit (limit , & revs , UNINTERESTING ))
2090
- die (_ ("Unknown commit %s" ), limit );
2110
+ die (_ ("unknown commit %s" ), limit );
2091
2111
2092
2112
/* reverse the list of commits */
2093
2113
if (prepare_revision_walk (& revs ))
0 commit comments