summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill@shutemov.name>2014-02-18 22:58:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-02-19 00:12:14 (GMT)
commit3caec73b5568341c5d8f303692423a8e9fb0cb39 (patch)
tree469a2cb5f3e8bdaf95832eaf846ba76926b8751c /config.c
parentc8985ce05360857733738561dd6cdf964470cbdf (diff)
downloadgit-3caec73b5568341c5d8f303692423a8e9fb0cb39.zip
git-3caec73b5568341c5d8f303692423a8e9fb0cb39.tar.gz
git-3caec73b5568341c5d8f303692423a8e9fb0cb39.tar.bz2
config: teach "git config --file -" to read from the standard input
The patch extends git config --file interface to allow read config from stdin. Editing stdin or setting value in stdin is an error. Include by absolute path is allowed in stdin config, but not by relative path. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/config.c b/config.c
index a21b0dd..7b1febd 100644
--- a/config.c
+++ b/config.c
@@ -1031,24 +1031,35 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data)
return ret;
}
-int git_config_from_file(config_fn_t fn, const char *filename, void *data)
+static int do_config_from_file(config_fn_t fn,
+ const char *name, const char *path, FILE *f, void *data)
{
- int ret;
- FILE *f = fopen(filename, "r");
+ struct config_source top;
- ret = -1;
- if (f) {
- struct config_source top;
+ top.u.file = f;
+ top.name = name;
+ top.path = path;
+ top.die_on_error = 1;
+ top.do_fgetc = config_file_fgetc;
+ top.do_ungetc = config_file_ungetc;
+ top.do_ftell = config_file_ftell;
- top.u.file = f;
- top.name = top.path = filename;
- top.die_on_error = 1;
- top.do_fgetc = config_file_fgetc;
- top.do_ungetc = config_file_ungetc;
- top.do_ftell = config_file_ftell;
+ return do_config_from(&top, fn, data);
+}
- ret = do_config_from(&top, fn, data);
+static int git_config_from_stdin(config_fn_t fn, void *data)
+{
+ return do_config_from_file(fn, "<stdin>", NULL, stdin, data);
+}
+
+int git_config_from_file(config_fn_t fn, const char *filename, void *data)
+{
+ int ret = -1;
+ FILE *f;
+ f = fopen(filename, "r");
+ if (f) {
+ ret = do_config_from_file(fn, filename, filename, f, data);
fclose(f);
}
return ret;
@@ -1190,7 +1201,9 @@ int git_config_with_options(config_fn_t fn, void *data,
* If we have a specific filename, use it. Otherwise, follow the
* regular lookup sequence.
*/
- if (config_source && config_source->file)
+ if (config_source && config_source->use_stdin)
+ return git_config_from_stdin(fn, data);
+ else if (config_source && config_source->file)
return git_config_from_file(fn, config_source->file, data);
else if (config_source && config_source->blob)
return git_config_from_blob_ref(fn, config_source->blob, data);