git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: git@vger.kernel.org
Cc: "Kirill A. Shutemov" <kirill@shutemov.name>
Subject: [PATCH] config: git_config_from_file(): handle "-" filename as stdin
Date: Fri, 14 Feb 2014 15:34:38 +0200	[thread overview]
Message-ID: <1392384878-7080-1-git-send-email-kirill@shutemov.name> (raw)

The patch extends git config --file interface to allow read config from
stdin.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 config.c               | 10 ++++++----
 t/t1300-repo-config.sh |  4 ++++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/config.c b/config.c
index d969a5aefc2b..f80cc7e657e8 100644
--- a/config.c
+++ b/config.c
@@ -1032,10 +1032,11 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data)
 
 int git_config_from_file(config_fn_t fn, const char *filename, void *data)
 {
-	int ret;
-	FILE *f = fopen(filename, "r");
+	int from_stdin = !strcmp(filename, "-");
+	int ret = -1;
+	FILE *f;
 
-	ret = -1;
+	f = from_stdin ? stdin : fopen(filename, "r");
 	if (f) {
 		struct config_source top;
 
@@ -1048,7 +1049,8 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
 
 		ret = do_config_from(&top, fn, data);
 
-		fclose(f);
+		if (!from_stdin)
+			fclose(f);
 	}
 	return ret;
 }
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 967359344dab..f1a63075e34f 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -484,6 +484,10 @@ test_expect_success 'alternative GIT_CONFIG (--file)' '
 	test_cmp expect output
 '
 
+test_expect_success 'alternative GIT_CONFIG (--file=-)' '
+	git config --file - -l < other-config > output &&
+	test_cmp expect output
+'
 test_expect_success 'refer config from subdirectory' '
 	mkdir x &&
 	(
-- 
1.8.5.2

             reply	other threads:[~2014-02-14 13:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14 13:34 Kirill A. Shutemov [this message]
2014-02-14 18:27 ` [PATCH] config: git_config_from_file(): handle "-" filename as stdin Junio C Hamano
2014-02-14 20:04   ` Kirill A. Shutemov
2014-02-14 20:35     ` Junio C Hamano

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=1392384878-7080-1-git-send-email-kirill@shutemov.name \
    --to=kirill@shutemov.name \
    --cc=git@vger.kernel.org \
    /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).