[PATCH] config: git_config_from_file(): handle "-" filename as stdin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Kirill A. Shutemov <kirill@xxxxxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]