@@ -1156,7 +1156,7 @@ static void get_notes_args(struct strvec *arg, struct rev_info *rev)
11561156 }
11571157}
11581158
1159- static void make_cover_letter (struct rev_info * rev , int use_stdout ,
1159+ static void make_cover_letter (struct rev_info * rev , int use_separate_file ,
11601160 struct commit * origin ,
11611161 int nr , struct commit * * list ,
11621162 const char * branch_name ,
@@ -1176,7 +1176,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
11761176
11771177 committer = git_committer_info (0 );
11781178
1179- if (! use_stdout &&
1179+ if (use_separate_file &&
11801180 open_next_file (NULL , rev -> numbered_files ? NULL : "cover-letter" , rev , quiet ))
11811181 die (_ ("failed to create cover-letter file" ));
11821182
@@ -1945,20 +1945,27 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19451945 if (rev .show_notes )
19461946 load_display_notes (& rev .notes_opt );
19471947
1948- if (! output_directory && ! use_stdout )
1949- output_directory = config_output_directory ;
1948+ if (use_stdout + rev . diffopt . close_file + !! output_directory > 1 )
1949+ die ( _ ( "--stdout, --output, and --output-directory are mutually exclusive" )) ;
19501950
1951- if (!use_stdout )
1952- output_directory = set_outdir (prefix , output_directory );
1953- else
1951+ if (use_stdout ) {
19541952 setup_pager ();
1955-
1956- if (output_directory ) {
1953+ } else if (rev .diffopt .close_file ) {
1954+ /*
1955+ * The diff code parsed --output; it has already opened the
1956+ * file, but but we must instruct it not to close after each
1957+ * diff.
1958+ */
1959+ rev .diffopt .close_file = 0 ;
1960+ } else {
19571961 int saved ;
1962+
1963+ if (!output_directory )
1964+ output_directory = config_output_directory ;
1965+ output_directory = set_outdir (prefix , output_directory );
1966+
19581967 if (rev .diffopt .use_color != GIT_COLOR_ALWAYS )
19591968 rev .diffopt .use_color = GIT_COLOR_NEVER ;
1960- if (use_stdout )
1961- die (_ ("standard output, or directory, which one?" ));
19621969 /*
19631970 * We consider <outdir> as 'outside of gitdir', therefore avoid
19641971 * applying adjust_shared_perm in s-c-l-d.
@@ -2120,7 +2127,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
21202127 if (cover_letter ) {
21212128 if (thread )
21222129 gen_message_id (& rev , "cover" );
2123- make_cover_letter (& rev , use_stdout ,
2130+ make_cover_letter (& rev , !! output_directory ,
21242131 origin , nr , list , branch_name , quiet );
21252132 print_bases (& bases , rev .diffopt .file );
21262133 print_signature (rev .diffopt .file );
@@ -2175,7 +2182,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
21752182 gen_message_id (& rev , oid_to_hex (& commit -> object .oid ));
21762183 }
21772184
2178- if (! use_stdout &&
2185+ if (output_directory &&
21792186 open_next_file (rev .numbered_files ? NULL : commit , NULL , & rev , quiet ))
21802187 die (_ ("failed to create output files" ));
21812188 shown = log_tree_commit (& rev , commit );
@@ -2188,7 +2195,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
21882195 * the log; when using one file per patch, we do
21892196 * not want the extra blank line.
21902197 */
2191- if (! use_stdout )
2198+ if (output_directory )
21922199 rev .shown_one = 0 ;
21932200 if (shown ) {
21942201 print_bases (& bases , rev .diffopt .file );
@@ -2199,7 +2206,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
21992206 else
22002207 print_signature (rev .diffopt .file );
22012208 }
2202- if (! use_stdout )
2209+ if (output_directory )
22032210 fclose (rev .diffopt .file );
22042211 }
22052212 stop_progress (& progress );
0 commit comments