git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Kuleshov <kuleshovmail@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Alexander Kuleshov <kuleshovmail@gmail.com>
Subject: [PATCH] format-patch: introduce format.outputDirectory configuration
Date: Thu, 18 Jun 2015 17:18:00 +0600	[thread overview]
Message-ID: <1434626280-4610-1-git-send-email-kuleshovmail@gmail.com> (raw)

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 <kuleshovmail@gmail.com>
---
 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

             reply	other threads:[~2015-06-18 11:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-18 11:18 Alexander Kuleshov [this message]
2015-06-18 17:13 ` [PATCH] format-patch: introduce format.outputDirectory configuration Junio C Hamano
2015-06-18 19:57   ` Jeff King
2015-06-18 20:05     ` Junio C Hamano
2015-06-18 20:06       ` Junio C Hamano
2015-06-18 20:13         ` Jeff King
2015-06-18 20:22           ` Jeff King
2015-06-18 21:46             ` Junio C Hamano
2015-06-19  4:14               ` Jeff King
2015-06-19  7:06                 ` Alexander Kuleshov
2015-06-19 13:33               ` Alexander Kuleshov
2015-06-19 15:59                 ` Junio C Hamano
2015-06-19 17:19                   ` Alexander Kuleshov
2015-06-19 17:27                     ` Alexander Kuleshov
2015-06-19 17:49                       ` Alexander Kuleshov
2015-06-19 18:14                       ` Junio C Hamano
2015-06-19 11:34 ` Remi Galan Alfonso
2015-06-19 11:34   ` Alexander Kuleshov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434626280-4610-1-git-send-email-kuleshovmail@gmail.com \
    --to=kuleshovmail@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).