git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/3] format-patch: tie file-opening logic to output_directory

From
Jeff King <peff@peff.net>
Date
Nov 4, 2020, 19:28 UTC
Message-ID
<20201104192834.GB3060275@coredump.intra.peff.net>
In-Reply-To
<20201104192645.GA3059114@coredump.intra.peff.net>

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>
---
 builtin/log.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index fbff5493d2..927156fb85 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1153,7 +1153,7 @@ static void get_notes_args(struct strvec *arg, struct rev_info *rev)
 	}
 }
 
-static void make_cover_letter(struct rev_info *rev, int use_stdout,
+static void make_cover_letter(struct rev_info *rev, int use_separate_file,
 			      struct commit *origin,
 			      int nr, struct commit **list,
 			      const char *branch_name,
@@ -1173,7 +1173,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
 
 	committer = git_committer_info(0);
 
-	if (!use_stdout &&
+	if (use_separate_file &&
 	    open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
 		die(_("failed to create cover-letter file"));
 
@@ -2117,7 +2117,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	if (cover_letter) {
 		if (thread)
 			gen_message_id(&rev, "cover");
-		make_cover_letter(&rev, use_stdout,
+		make_cover_letter(&rev, !!output_directory,
 				  origin, nr, list, branch_name, quiet);
 		print_bases(&bases, rev.diffopt.file);
 		print_signature(rev.diffopt.file);
@@ -2172,7 +2172,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			gen_message_id(&rev, oid_to_hex(&commit->object.oid));
 		}
 
-		if (!use_stdout &&
+		if (output_directory &&
 		    open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
 			die(_("failed to create output files"));
 		shown = log_tree_commit(&rev, commit);
@@ -2185,7 +2185,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		 * the log; when using one file per patch, we do
 		 * not want the extra blank line.
 		 */
-		if (!use_stdout)
+		if (output_directory)
 			rev.shown_one = 0;
 		if (shown) {
 			print_bases(&bases, rev.diffopt.file);
@@ -2196,7 +2196,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			else
 				print_signature(rev.diffopt.file);
 		}
-		if (!use_stdout)
+		if (output_directory)
 			fclose(rev.diffopt.file);
 	}
 	stop_progress(&progress);
-- 
2.29.2.559.g8ec94df761
Previous: Jeff KingNext: Jeff King
Message 15 of 17 in “[Bug report] Crash when creating patch”
  1. Johannes PostlerNov 4, 2020
  2. Jeff KingNov 4, 2020
  3. 1/3 format-patch: refactor output selectionJeff King, Nov 4, 2020
  4. Eric SunshineNov 4, 2020
  5. Jeff KingNov 4, 2020
  6. 2/3 format-patch: tie file-opening logic to output_directoryJeff King, Nov 4, 2020
  7. Eric SunshineNov 4, 2020
  8. 3/3 format-patch: support --output optionJeff King, Nov 4, 2020
  9. Eric SunshineNov 4, 2020
  10. Jeff KingNov 4, 2020
  11. Eric SunshineNov 4, 2020
  12. Junio C HamanoNov 4, 2020
  13. format-patch --outputJeff King, Nov 4, 2020
  14. 1/3 format-patch: refactor output selectionJeff King, Nov 4, 2020
  15. 2/3 format-patch: tie file-opening logic to output_directoryJeff King, Nov 4, 2020
  16. 3/3 format-patch: support --output optionJeff King, Nov 4, 2020
  17. Johannes PostlerNov 5, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.