Thread (3 messages) flat view 3 messages, 2 authors, 2016-06-15
STALE3751d

[PATCH] format-patch: introduce format.outputDirectory configuration

From: Alexander Kuleshov <hidden>
Date: 2016-06-15 23:05:22
Subsystem: documentation, the rest · Maintainers: Jonathan Corbet, Linus Torvalds

We can pass -o/--output-directory to the format-patch command to
store patches not in the working directory. This patch introduces
format.outputDirectory configuration option for same purpose.

The case of usage of this configuration option can be convinience
to not pass everytime -o/--output-directory if an user has pattern
to store all patches in the /patches directory for example.

The format.outputDirectory has lower priority than command line
option, so if user will set format.outputDirectory and pass the
command line option, a result will be stored in a directory that
passed to command line option.

Signed-off-by: Alexander Kuleshov <redacted>
---
 Documentation/config.txt |  4 ++++
 builtin/log.c            | 14 ++++++++++++--
 t/t4014-format-patch.sh  |  9 +++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index fd2036c..8f6f7ed 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1247,6 +1247,10 @@ format.coverLetter::
 	format-patch is invoked, but in addition can be set to "auto", to
 	generate a cover-letter only when there's more than one patch.
 
+format.outputDirectory::
+	Set a custom directory to store the resulting files instead of the
+	current working directory.
+
 filter.<driver>.clean::
 	The command which is used to convert the content of a worktree
 	file to a blob upon checkin.  See linkgit:gitattributes[5] for
diff --git a/builtin/log.c b/builtin/log.c
index dfb351e..22c1e46 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -687,6 +687,8 @@ enum {
 	COVER_AUTO
 };
 
+static const char *config_output_directory = NULL;
+
 static int git_format_config(const char *var, const char *value, void *cb)
 {
 	if (!strcmp(var, "format.headers")) {
@@ -757,6 +759,9 @@ static int git_format_config(const char *var, const char *value, void *cb)
 		config_cover_letter = git_config_bool(var, value) ? COVER_ON : COVER_OFF;
 		return 0;
 	}
+	if (!strcmp(var, "format.outputdirectory")) {
+		return git_config_string(&config_output_directory, var, value);
+	}
 
 	return git_log_config(var, value, cb);
 }
@@ -1006,7 +1011,8 @@ static const char *clean_message_id(const char *msg_id)
 	return xmemdupz(a, z - a);
 }
 
-static const char *set_outdir(const char *prefix, const char *output_directory)
+static const char *set_outdir(const char *prefix, const char *output_directory,
+			      const char *config_output_directory)
 {
 	if (output_directory && is_absolute_path(output_directory))
 		return output_directory;
@@ -1014,6 +1020,9 @@ static const char *set_outdir(const char *prefix, const char *output_directory)
 	if (!prefix || !*prefix) {
 		if (output_directory)
 			return output_directory;
+
+		if (config_output_directory)
+			return config_output_directory;
 		/* The user did not explicitly ask for "./" */
 		outdir_offset = 2;
 		return "./";
@@ -1368,7 +1377,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		init_display_notes(&rev.notes_opt);
 
 	if (!use_stdout)
-		output_directory = set_outdir(prefix, output_directory);
+		output_directory = set_outdir(prefix, output_directory,
+					      config_output_directory);
 	else
 		setup_pager();
 
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index c39e500..a4b18b5 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -40,6 +40,15 @@ test_expect_success setup '
 
 '
 
+test_expect_success "format-patch format.outputDirectory option" '
+	git config format.outputDirectory "patches/" &&
+	git format-patch master..side &&
+	cnt=$(ls | wc -l) &&
+	echo $cnt &&
+	test $cnt = 3 &&
+	git config --unset format.outputDirectory
+'
+
 test_expect_success "format-patch --ignore-if-in-upstream" '
 
 	git format-patch --stdout master..side >patch0 &&
-- 
2.4.0.383.gded6615.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help