diff options
author | Kirill A. Shutemov <kirill@shutemov.name> | 2014-02-19 00:58:55 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-02-18 16:12:14 -0800 |
commit | 3caec73b5568341c5d8f303692423a8e9fb0cb39 (patch) | |
tree | 469a2cb5f3e8bdaf95832eaf846ba76926b8751c /config.c | |
parent | c8985ce05360857733738561dd6cdf964470cbdf (diff) | |
download | git-3caec73b5568341c5d8f303692423a8e9fb0cb39.tar.gz |
config: teach "git config --file -" to read from the standard inputks/config-file-stdin
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.c | 41 |
1 files changed, 27 insertions, 14 deletions
@@ -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); |