format-patch: tie file-opening logic to output_directory

In format-patch we're either outputting to stdout or to individual files in an output directory (which may be just "./"). Our logic for whether to open a new file for each patch is checked with "!use_stdout", but it is equally correct to check for a non-NULL output_directory. The distinction will matter when we add a new single-stream output in a future patch, when only one of the three methods will want individual files. Let's swap the logic here in preparation. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Nov 4, 2020 at 14:28 UTC 1e1693b2bbaa9613f3a39a35196fc219c25f7677
1 file changed +6 -6
builtin/log.c
+6 -6
@@ -1153,7 +1153,7 @@ static void get_notes_args(struct strvec *arg, struct rev_info *rev)
1153 }
1154 }
1155
1156 -static void make_cover_letter(struct rev_info *rev, int use_stdout,
1156 +static void make_cover_letter(struct rev_info *rev, int use_separate_file,
1157 struct commit *origin,
1158 int nr, struct commit **list,
1159 const char *branch_name,
@@ -1173,7 +1173,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
1173
1174 committer = git_committer_info(0);
1175
1176 - if (!use_stdout &&
1176 + if (use_separate_file &&
1177 open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
1178 die(_("failed to create cover-letter file"));
1179
@@ -2117,7 +2117,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
2117 if (cover_letter) {
2118 if (thread)
2119 gen_message_id(&rev, "cover");
2120 - make_cover_letter(&rev, use_stdout,
2120 + make_cover_letter(&rev, !!output_directory,
2121 origin, nr, list, branch_name, quiet);
2122 print_bases(&bases, rev.diffopt.file);
2123 print_signature(rev.diffopt.file);
@@ -2172,7 +2172,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
2172 gen_message_id(&rev, oid_to_hex(&commit->object.oid));
2173 }
2174
2175 - if (!use_stdout &&
2175 + if (output_directory &&
2176 open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
2177 die(_("failed to create output files"));
2178 shown = log_tree_commit(&rev, commit);
@@ -2185,7 +2185,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
2185 * the log; when using one file per patch, we do
2186 * not want the extra blank line.
2187 */
2188 - if (!use_stdout)
2188 + if (output_directory)
2189 rev.shown_one = 0;
2190 if (shown) {
2191 print_bases(&bases, rev.diffopt.file);
@@ -2196,7 +2196,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
2196 else
2197 print_signature(rev.diffopt.file);
2198 }
2199 - if (!use_stdout)
2199 + if (output_directory)
2200 fclose(rev.diffopt.file);
2201 }
2202 stop_progress(&progress);