@ -1031,24 +1031,35 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data)
return ret;
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;
struct config_source top;
FILE *f = fopen(filename, "r");
ret = -1;
top.u.file = f;
if (f) {
top.name = name;
struct config_source top;
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;
return do_config_from(&top, fn, data);
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;
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);
fclose(f);
}
}
return ret;
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
* If we have a specific filename, use it. Otherwise, follow the
* regular lookup sequence.
* 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);
return git_config_from_file(fn, config_source->file, data);
else if (config_source && config_source->blob)
else if (config_source && config_source->blob)
return git_config_from_blob_ref(fn, config_source->blob, data);
return git_config_from_blob_ref(fn, config_source->blob, data);