config.c: rename "struct config_source cf"
The "cf" name is a holdover from before 4d8dd1494e
(config: make parsing
stack struct independent from actual data source, 2013-07-12), when the
struct was named config_file. Since that acronym no longer makes sense,
rename "cf" to "cs". In some places, we have "struct config_set cs", so
to avoid conflict, rename those "cs" to "set" ("config_set" would be
more descriptive, but it's much longer and would require us to rewrap
several lines).
Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e2016508e7
commit
9b4a655302
262
config.c
262
config.c
@ -202,7 +202,7 @@ static const char include_depth_advice[] = N_(
|
|||||||
"from\n"
|
"from\n"
|
||||||
" %s\n"
|
" %s\n"
|
||||||
"This might be due to circular includes.");
|
"This might be due to circular includes.");
|
||||||
static int handle_path_include(struct config_source *cf, const char *path,
|
static int handle_path_include(struct config_source *cs, const char *path,
|
||||||
struct config_include_data *inc)
|
struct config_include_data *inc)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -224,14 +224,14 @@ static int handle_path_include(struct config_source *cf, const char *path,
|
|||||||
if (!is_absolute_path(path)) {
|
if (!is_absolute_path(path)) {
|
||||||
char *slash;
|
char *slash;
|
||||||
|
|
||||||
if (!cf || !cf->path) {
|
if (!cs || !cs->path) {
|
||||||
ret = error(_("relative config includes must come from files"));
|
ret = error(_("relative config includes must come from files"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
slash = find_last_dir_sep(cf->path);
|
slash = find_last_dir_sep(cs->path);
|
||||||
if (slash)
|
if (slash)
|
||||||
strbuf_add(&buf, cf->path, slash - cf->path + 1);
|
strbuf_add(&buf, cs->path, slash - cs->path + 1);
|
||||||
strbuf_addstr(&buf, path);
|
strbuf_addstr(&buf, path);
|
||||||
path = buf.buf;
|
path = buf.buf;
|
||||||
}
|
}
|
||||||
@ -239,8 +239,8 @@ static int handle_path_include(struct config_source *cf, const char *path,
|
|||||||
if (!access_or_die(path, R_OK, 0)) {
|
if (!access_or_die(path, R_OK, 0)) {
|
||||||
if (++inc->depth > MAX_INCLUDE_DEPTH)
|
if (++inc->depth > MAX_INCLUDE_DEPTH)
|
||||||
die(_(include_depth_advice), MAX_INCLUDE_DEPTH, path,
|
die(_(include_depth_advice), MAX_INCLUDE_DEPTH, path,
|
||||||
!cf ? "<unknown>" :
|
!cs ? "<unknown>" :
|
||||||
cf->name ? cf->name :
|
cs->name ? cs->name :
|
||||||
"the command line");
|
"the command line");
|
||||||
ret = git_config_from_file(git_config_include, path, inc);
|
ret = git_config_from_file(git_config_include, path, inc);
|
||||||
inc->depth--;
|
inc->depth--;
|
||||||
@ -257,7 +257,7 @@ static void add_trailing_starstar_for_dir(struct strbuf *pat)
|
|||||||
strbuf_addstr(pat, "**");
|
strbuf_addstr(pat, "**");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int prepare_include_condition_pattern(struct config_source *cf,
|
static int prepare_include_condition_pattern(struct config_source *cs,
|
||||||
struct strbuf *pat)
|
struct strbuf *pat)
|
||||||
{
|
{
|
||||||
struct strbuf path = STRBUF_INIT;
|
struct strbuf path = STRBUF_INIT;
|
||||||
@ -274,11 +274,11 @@ static int prepare_include_condition_pattern(struct config_source *cf,
|
|||||||
if (pat->buf[0] == '.' && is_dir_sep(pat->buf[1])) {
|
if (pat->buf[0] == '.' && is_dir_sep(pat->buf[1])) {
|
||||||
const char *slash;
|
const char *slash;
|
||||||
|
|
||||||
if (!cf || !cf->path)
|
if (!cs || !cs->path)
|
||||||
return error(_("relative config include "
|
return error(_("relative config include "
|
||||||
"conditionals must come from files"));
|
"conditionals must come from files"));
|
||||||
|
|
||||||
strbuf_realpath(&path, cf->path, 1);
|
strbuf_realpath(&path, cs->path, 1);
|
||||||
slash = find_last_dir_sep(path.buf);
|
slash = find_last_dir_sep(path.buf);
|
||||||
if (!slash)
|
if (!slash)
|
||||||
BUG("how is this possible?");
|
BUG("how is this possible?");
|
||||||
@ -293,7 +293,7 @@ static int prepare_include_condition_pattern(struct config_source *cf,
|
|||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int include_by_gitdir(struct config_source *cf,
|
static int include_by_gitdir(struct config_source *cs,
|
||||||
const struct config_options *opts,
|
const struct config_options *opts,
|
||||||
const char *cond, size_t cond_len, int icase)
|
const char *cond, size_t cond_len, int icase)
|
||||||
{
|
{
|
||||||
@ -310,7 +310,7 @@ static int include_by_gitdir(struct config_source *cf,
|
|||||||
|
|
||||||
strbuf_realpath(&text, git_dir, 1);
|
strbuf_realpath(&text, git_dir, 1);
|
||||||
strbuf_add(&pattern, cond, cond_len);
|
strbuf_add(&pattern, cond, cond_len);
|
||||||
prefix = prepare_include_condition_pattern(cf, &pattern);
|
prefix = prepare_include_condition_pattern(cs, &pattern);
|
||||||
|
|
||||||
again:
|
again:
|
||||||
if (prefix < 0)
|
if (prefix < 0)
|
||||||
@ -449,16 +449,16 @@ static int include_by_remote_url(struct config_include_data *inc,
|
|||||||
inc->remote_urls);
|
inc->remote_urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int include_condition_is_true(struct config_source *cf,
|
static int include_condition_is_true(struct config_source *cs,
|
||||||
struct config_include_data *inc,
|
struct config_include_data *inc,
|
||||||
const char *cond, size_t cond_len)
|
const char *cond, size_t cond_len)
|
||||||
{
|
{
|
||||||
const struct config_options *opts = inc->opts;
|
const struct config_options *opts = inc->opts;
|
||||||
|
|
||||||
if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
|
if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
|
||||||
return include_by_gitdir(cf, opts, cond, cond_len, 0);
|
return include_by_gitdir(cs, opts, cond, cond_len, 0);
|
||||||
else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
|
else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
|
||||||
return include_by_gitdir(cf, opts, cond, cond_len, 1);
|
return include_by_gitdir(cs, opts, cond, cond_len, 1);
|
||||||
else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
|
else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
|
||||||
return include_by_branch(cond, cond_len);
|
return include_by_branch(cond, cond_len);
|
||||||
else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,
|
else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,
|
||||||
@ -472,7 +472,7 @@ static int include_condition_is_true(struct config_source *cf,
|
|||||||
static int git_config_include(const char *var, const char *value, void *data)
|
static int git_config_include(const char *var, const char *value, void *data)
|
||||||
{
|
{
|
||||||
struct config_include_data *inc = data;
|
struct config_include_data *inc = data;
|
||||||
struct config_source *cf = inc->config_reader->source;
|
struct config_source *cs = inc->config_reader->source;
|
||||||
const char *cond, *key;
|
const char *cond, *key;
|
||||||
size_t cond_len;
|
size_t cond_len;
|
||||||
int ret;
|
int ret;
|
||||||
@ -486,16 +486,16 @@ static int git_config_include(const char *var, const char *value, void *data)
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (!strcmp(var, "include.path"))
|
if (!strcmp(var, "include.path"))
|
||||||
ret = handle_path_include(cf, value, inc);
|
ret = handle_path_include(cs, value, inc);
|
||||||
|
|
||||||
if (!parse_config_key(var, "includeif", &cond, &cond_len, &key) &&
|
if (!parse_config_key(var, "includeif", &cond, &cond_len, &key) &&
|
||||||
cond && include_condition_is_true(cf, inc, cond, cond_len) &&
|
cond && include_condition_is_true(cs, inc, cond, cond_len) &&
|
||||||
!strcmp(key, "path")) {
|
!strcmp(key, "path")) {
|
||||||
config_fn_t old_fn = inc->fn;
|
config_fn_t old_fn = inc->fn;
|
||||||
|
|
||||||
if (inc->opts->unconditional_remote_url)
|
if (inc->opts->unconditional_remote_url)
|
||||||
inc->fn = forbid_remote_url;
|
inc->fn = forbid_remote_url;
|
||||||
ret = handle_path_include(cf, value, inc);
|
ret = handle_path_include(cs, value, inc);
|
||||||
inc->fn = old_fn;
|
inc->fn = old_fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,21 +820,21 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_next_char(struct config_source *cf)
|
static int get_next_char(struct config_source *cs)
|
||||||
{
|
{
|
||||||
int c = cf->do_fgetc(cf);
|
int c = cs->do_fgetc(cs);
|
||||||
|
|
||||||
if (c == '\r') {
|
if (c == '\r') {
|
||||||
/* DOS like systems */
|
/* DOS like systems */
|
||||||
c = cf->do_fgetc(cf);
|
c = cs->do_fgetc(cs);
|
||||||
if (c != '\n') {
|
if (c != '\n') {
|
||||||
if (c != EOF)
|
if (c != EOF)
|
||||||
cf->do_ungetc(c, cf);
|
cs->do_ungetc(c, cs);
|
||||||
c = '\r';
|
c = '\r';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c != EOF && ++cf->total_len > INT_MAX) {
|
if (c != EOF && ++cs->total_len > INT_MAX) {
|
||||||
/*
|
/*
|
||||||
* This is an absurdly long config file; refuse to parse
|
* This is an absurdly long config file; refuse to parse
|
||||||
* further in order to protect downstream code from integer
|
* further in order to protect downstream code from integer
|
||||||
@ -842,38 +842,38 @@ static int get_next_char(struct config_source *cf)
|
|||||||
* but we can mark EOF and put trash in the return value,
|
* but we can mark EOF and put trash in the return value,
|
||||||
* which will trigger a parse error.
|
* which will trigger a parse error.
|
||||||
*/
|
*/
|
||||||
cf->eof = 1;
|
cs->eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
cf->linenr++;
|
cs->linenr++;
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
cf->eof = 1;
|
cs->eof = 1;
|
||||||
cf->linenr++;
|
cs->linenr++;
|
||||||
c = '\n';
|
c = '\n';
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *parse_value(struct config_source *cf)
|
static char *parse_value(struct config_source *cs)
|
||||||
{
|
{
|
||||||
int quote = 0, comment = 0, space = 0;
|
int quote = 0, comment = 0, space = 0;
|
||||||
|
|
||||||
strbuf_reset(&cf->value);
|
strbuf_reset(&cs->value);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c = get_next_char(cf);
|
int c = get_next_char(cs);
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
if (quote) {
|
if (quote) {
|
||||||
cf->linenr--;
|
cs->linenr--;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return cf->value.buf;
|
return cs->value.buf;
|
||||||
}
|
}
|
||||||
if (comment)
|
if (comment)
|
||||||
continue;
|
continue;
|
||||||
if (isspace(c) && !quote) {
|
if (isspace(c) && !quote) {
|
||||||
if (cf->value.len)
|
if (cs->value.len)
|
||||||
space++;
|
space++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -884,9 +884,9 @@ static char *parse_value(struct config_source *cf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (; space; space--)
|
for (; space; space--)
|
||||||
strbuf_addch(&cf->value, ' ');
|
strbuf_addch(&cs->value, ' ');
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
c = get_next_char(cf);
|
c = get_next_char(cs);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\n':
|
case '\n':
|
||||||
continue;
|
continue;
|
||||||
@ -906,18 +906,18 @@ static char *parse_value(struct config_source *cf)
|
|||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strbuf_addch(&cf->value, c);
|
strbuf_addch(&cs->value, c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == '"') {
|
if (c == '"') {
|
||||||
quote = 1-quote;
|
quote = 1-quote;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
strbuf_addch(&cf->value, c);
|
strbuf_addch(&cs->value, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_value(struct config_source *cf, config_fn_t fn, void *data,
|
static int get_value(struct config_source *cs, config_fn_t fn, void *data,
|
||||||
struct strbuf *name)
|
struct strbuf *name)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
@ -926,8 +926,8 @@ static int get_value(struct config_source *cf, config_fn_t fn, void *data,
|
|||||||
|
|
||||||
/* Get the full name */
|
/* Get the full name */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = get_next_char(cf);
|
c = get_next_char(cs);
|
||||||
if (cf->eof)
|
if (cs->eof)
|
||||||
break;
|
break;
|
||||||
if (!iskeychar(c))
|
if (!iskeychar(c))
|
||||||
break;
|
break;
|
||||||
@ -935,13 +935,13 @@ static int get_value(struct config_source *cf, config_fn_t fn, void *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (c == ' ' || c == '\t')
|
while (c == ' ' || c == '\t')
|
||||||
c = get_next_char(cf);
|
c = get_next_char(cs);
|
||||||
|
|
||||||
value = NULL;
|
value = NULL;
|
||||||
if (c != '\n') {
|
if (c != '\n') {
|
||||||
if (c != '=')
|
if (c != '=')
|
||||||
return -1;
|
return -1;
|
||||||
value = parse_value(cf);
|
value = parse_value(cs);
|
||||||
if (!value)
|
if (!value)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -950,21 +950,21 @@ static int get_value(struct config_source *cf, config_fn_t fn, void *data,
|
|||||||
* the line we just parsed during the call to fn to get
|
* the line we just parsed during the call to fn to get
|
||||||
* accurate line number in error messages.
|
* accurate line number in error messages.
|
||||||
*/
|
*/
|
||||||
cf->linenr--;
|
cs->linenr--;
|
||||||
ret = fn(name->buf, value, data);
|
ret = fn(name->buf, value, data);
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
cf->linenr++;
|
cs->linenr++;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_extended_base_var(struct config_source *cf, struct strbuf *name,
|
static int get_extended_base_var(struct config_source *cs, struct strbuf *name,
|
||||||
int c)
|
int c)
|
||||||
{
|
{
|
||||||
cf->subsection_case_sensitive = 0;
|
cs->subsection_case_sensitive = 0;
|
||||||
do {
|
do {
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
goto error_incomplete_line;
|
goto error_incomplete_line;
|
||||||
c = get_next_char(cf);
|
c = get_next_char(cs);
|
||||||
} while (isspace(c));
|
} while (isspace(c));
|
||||||
|
|
||||||
/* We require the format to be '[base "extension"]' */
|
/* We require the format to be '[base "extension"]' */
|
||||||
@ -973,13 +973,13 @@ static int get_extended_base_var(struct config_source *cf, struct strbuf *name,
|
|||||||
strbuf_addch(name, '.');
|
strbuf_addch(name, '.');
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c = get_next_char(cf);
|
int c = get_next_char(cs);
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
goto error_incomplete_line;
|
goto error_incomplete_line;
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
break;
|
break;
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
c = get_next_char(cf);
|
c = get_next_char(cs);
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
goto error_incomplete_line;
|
goto error_incomplete_line;
|
||||||
}
|
}
|
||||||
@ -987,25 +987,25 @@ static int get_extended_base_var(struct config_source *cf, struct strbuf *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Final ']' */
|
/* Final ']' */
|
||||||
if (get_next_char(cf) != ']')
|
if (get_next_char(cs) != ']')
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
error_incomplete_line:
|
error_incomplete_line:
|
||||||
cf->linenr--;
|
cs->linenr--;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_base_var(struct config_source *cf, struct strbuf *name)
|
static int get_base_var(struct config_source *cs, struct strbuf *name)
|
||||||
{
|
{
|
||||||
cf->subsection_case_sensitive = 1;
|
cs->subsection_case_sensitive = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c = get_next_char(cf);
|
int c = get_next_char(cs);
|
||||||
if (cf->eof)
|
if (cs->eof)
|
||||||
return -1;
|
return -1;
|
||||||
if (c == ']')
|
if (c == ']')
|
||||||
return 0;
|
return 0;
|
||||||
if (isspace(c))
|
if (isspace(c))
|
||||||
return get_extended_base_var(cf, name, c);
|
return get_extended_base_var(cs, name, c);
|
||||||
if (!iskeychar(c) && c != '.')
|
if (!iskeychar(c) && c != '.')
|
||||||
return -1;
|
return -1;
|
||||||
strbuf_addch(name, tolower(c));
|
strbuf_addch(name, tolower(c));
|
||||||
@ -1018,7 +1018,7 @@ struct parse_event_data {
|
|||||||
const struct config_options *opts;
|
const struct config_options *opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int do_event(struct config_source *cf, enum config_event_t type,
|
static int do_event(struct config_source *cs, enum config_event_t type,
|
||||||
struct parse_event_data *data)
|
struct parse_event_data *data)
|
||||||
{
|
{
|
||||||
size_t offset;
|
size_t offset;
|
||||||
@ -1030,7 +1030,7 @@ static int do_event(struct config_source *cf, enum config_event_t type,
|
|||||||
data->previous_type == type)
|
data->previous_type == type)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
offset = cf->do_ftell(cf);
|
offset = cs->do_ftell(cs);
|
||||||
/*
|
/*
|
||||||
* At EOF, the parser always "inserts" an extra '\n', therefore
|
* At EOF, the parser always "inserts" an extra '\n', therefore
|
||||||
* the end offset of the event is the current file position, otherwise
|
* the end offset of the event is the current file position, otherwise
|
||||||
@ -1050,12 +1050,12 @@ static int do_event(struct config_source *cf, enum config_event_t type,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int git_parse_source(struct config_source *cf, config_fn_t fn,
|
static int git_parse_source(struct config_source *cs, config_fn_t fn,
|
||||||
void *data, const struct config_options *opts)
|
void *data, const struct config_options *opts)
|
||||||
{
|
{
|
||||||
int comment = 0;
|
int comment = 0;
|
||||||
size_t baselen = 0;
|
size_t baselen = 0;
|
||||||
struct strbuf *var = &cf->var;
|
struct strbuf *var = &cs->var;
|
||||||
int error_return = 0;
|
int error_return = 0;
|
||||||
char *error_msg = NULL;
|
char *error_msg = NULL;
|
||||||
|
|
||||||
@ -1070,7 +1070,7 @@ static int git_parse_source(struct config_source *cf, config_fn_t fn,
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
c = get_next_char(cf);
|
c = get_next_char(cs);
|
||||||
if (bomptr && *bomptr) {
|
if (bomptr && *bomptr) {
|
||||||
/* We are at the file beginning; skip UTF8-encoded BOM
|
/* We are at the file beginning; skip UTF8-encoded BOM
|
||||||
* if present. Sane editors won't put this in on their
|
* if present. Sane editors won't put this in on their
|
||||||
@ -1087,12 +1087,12 @@ static int git_parse_source(struct config_source *cf, config_fn_t fn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
if (cf->eof) {
|
if (cs->eof) {
|
||||||
if (do_event(cf, CONFIG_EVENT_EOF, &event_data) < 0)
|
if (do_event(cs, CONFIG_EVENT_EOF, &event_data) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (do_event(cf, CONFIG_EVENT_WHITESPACE, &event_data) < 0)
|
if (do_event(cs, CONFIG_EVENT_WHITESPACE, &event_data) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
comment = 0;
|
comment = 0;
|
||||||
continue;
|
continue;
|
||||||
@ -1100,23 +1100,23 @@ static int git_parse_source(struct config_source *cf, config_fn_t fn,
|
|||||||
if (comment)
|
if (comment)
|
||||||
continue;
|
continue;
|
||||||
if (isspace(c)) {
|
if (isspace(c)) {
|
||||||
if (do_event(cf, CONFIG_EVENT_WHITESPACE, &event_data) < 0)
|
if (do_event(cs, CONFIG_EVENT_WHITESPACE, &event_data) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == '#' || c == ';') {
|
if (c == '#' || c == ';') {
|
||||||
if (do_event(cf, CONFIG_EVENT_COMMENT, &event_data) < 0)
|
if (do_event(cs, CONFIG_EVENT_COMMENT, &event_data) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
comment = 1;
|
comment = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == '[') {
|
if (c == '[') {
|
||||||
if (do_event(cf, CONFIG_EVENT_SECTION, &event_data) < 0)
|
if (do_event(cs, CONFIG_EVENT_SECTION, &event_data) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Reset prior to determining a new stem */
|
/* Reset prior to determining a new stem */
|
||||||
strbuf_reset(var);
|
strbuf_reset(var);
|
||||||
if (get_base_var(cf, var) < 0 || var->len < 1)
|
if (get_base_var(cs, var) < 0 || var->len < 1)
|
||||||
break;
|
break;
|
||||||
strbuf_addch(var, '.');
|
strbuf_addch(var, '.');
|
||||||
baselen = var->len;
|
baselen = var->len;
|
||||||
@ -1125,7 +1125,7 @@ static int git_parse_source(struct config_source *cf, config_fn_t fn,
|
|||||||
if (!isalpha(c))
|
if (!isalpha(c))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (do_event(cf, CONFIG_EVENT_ENTRY, &event_data) < 0)
|
if (do_event(cs, CONFIG_EVENT_ENTRY, &event_data) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1135,42 +1135,42 @@ static int git_parse_source(struct config_source *cf, config_fn_t fn,
|
|||||||
*/
|
*/
|
||||||
strbuf_setlen(var, baselen);
|
strbuf_setlen(var, baselen);
|
||||||
strbuf_addch(var, tolower(c));
|
strbuf_addch(var, tolower(c));
|
||||||
if (get_value(cf, fn, data, var) < 0)
|
if (get_value(cs, fn, data, var) < 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_event(cf, CONFIG_EVENT_ERROR, &event_data) < 0)
|
if (do_event(cs, CONFIG_EVENT_ERROR, &event_data) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
switch (cf->origin_type) {
|
switch (cs->origin_type) {
|
||||||
case CONFIG_ORIGIN_BLOB:
|
case CONFIG_ORIGIN_BLOB:
|
||||||
error_msg = xstrfmt(_("bad config line %d in blob %s"),
|
error_msg = xstrfmt(_("bad config line %d in blob %s"),
|
||||||
cf->linenr, cf->name);
|
cs->linenr, cs->name);
|
||||||
break;
|
break;
|
||||||
case CONFIG_ORIGIN_FILE:
|
case CONFIG_ORIGIN_FILE:
|
||||||
error_msg = xstrfmt(_("bad config line %d in file %s"),
|
error_msg = xstrfmt(_("bad config line %d in file %s"),
|
||||||
cf->linenr, cf->name);
|
cs->linenr, cs->name);
|
||||||
break;
|
break;
|
||||||
case CONFIG_ORIGIN_STDIN:
|
case CONFIG_ORIGIN_STDIN:
|
||||||
error_msg = xstrfmt(_("bad config line %d in standard input"),
|
error_msg = xstrfmt(_("bad config line %d in standard input"),
|
||||||
cf->linenr);
|
cs->linenr);
|
||||||
break;
|
break;
|
||||||
case CONFIG_ORIGIN_SUBMODULE_BLOB:
|
case CONFIG_ORIGIN_SUBMODULE_BLOB:
|
||||||
error_msg = xstrfmt(_("bad config line %d in submodule-blob %s"),
|
error_msg = xstrfmt(_("bad config line %d in submodule-blob %s"),
|
||||||
cf->linenr, cf->name);
|
cs->linenr, cs->name);
|
||||||
break;
|
break;
|
||||||
case CONFIG_ORIGIN_CMDLINE:
|
case CONFIG_ORIGIN_CMDLINE:
|
||||||
error_msg = xstrfmt(_("bad config line %d in command line %s"),
|
error_msg = xstrfmt(_("bad config line %d in command line %s"),
|
||||||
cf->linenr, cf->name);
|
cs->linenr, cs->name);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error_msg = xstrfmt(_("bad config line %d in %s"),
|
error_msg = xstrfmt(_("bad config line %d in %s"),
|
||||||
cf->linenr, cf->name);
|
cs->linenr, cs->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (opts && opts->error_action ?
|
switch (opts && opts->error_action ?
|
||||||
opts->error_action :
|
opts->error_action :
|
||||||
cf->default_error_action) {
|
cs->default_error_action) {
|
||||||
case CONFIG_ERROR_DIE:
|
case CONFIG_ERROR_DIE:
|
||||||
die("%s", error_msg);
|
die("%s", error_msg);
|
||||||
break;
|
break;
|
||||||
@ -2280,13 +2280,13 @@ int config_with_options(config_fn_t fn, void *data,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void configset_iter(struct config_reader *reader, struct config_set *cs,
|
static void configset_iter(struct config_reader *reader, struct config_set *set,
|
||||||
config_fn_t fn, void *data)
|
config_fn_t fn, void *data)
|
||||||
{
|
{
|
||||||
int i, value_index;
|
int i, value_index;
|
||||||
struct string_list *values;
|
struct string_list *values;
|
||||||
struct config_set_element *entry;
|
struct config_set_element *entry;
|
||||||
struct configset_list *list = &cs->list;
|
struct configset_list *list = &set->list;
|
||||||
|
|
||||||
for (i = 0; i < list->nr; i++) {
|
for (i = 0; i < list->nr; i++) {
|
||||||
entry = list->items[i].e;
|
entry = list->items[i].e;
|
||||||
@ -2351,7 +2351,7 @@ void read_very_early_config(config_fn_t cb, void *data)
|
|||||||
config_with_options(cb, data, NULL, &opts);
|
config_with_options(cb, data, NULL, &opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)
|
static struct config_set_element *configset_find_element(struct config_set *set, const char *key)
|
||||||
{
|
{
|
||||||
struct config_set_element k;
|
struct config_set_element k;
|
||||||
struct config_set_element *found_entry;
|
struct config_set_element *found_entry;
|
||||||
@ -2365,13 +2365,13 @@ static struct config_set_element *configset_find_element(struct config_set *cs,
|
|||||||
|
|
||||||
hashmap_entry_init(&k.ent, strhash(normalized_key));
|
hashmap_entry_init(&k.ent, strhash(normalized_key));
|
||||||
k.key = normalized_key;
|
k.key = normalized_key;
|
||||||
found_entry = hashmap_get_entry(&cs->config_hash, &k, ent, NULL);
|
found_entry = hashmap_get_entry(&set->config_hash, &k, ent, NULL);
|
||||||
free(normalized_key);
|
free(normalized_key);
|
||||||
return found_entry;
|
return found_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int configset_add_value(struct config_reader *reader,
|
static int configset_add_value(struct config_reader *reader,
|
||||||
struct config_set *cs, const char *key,
|
struct config_set *set, const char *key,
|
||||||
const char *value)
|
const char *value)
|
||||||
{
|
{
|
||||||
struct config_set_element *e;
|
struct config_set_element *e;
|
||||||
@ -2379,7 +2379,7 @@ static int configset_add_value(struct config_reader *reader,
|
|||||||
struct configset_list_item *l_item;
|
struct configset_list_item *l_item;
|
||||||
struct key_value_info *kv_info = xmalloc(sizeof(*kv_info));
|
struct key_value_info *kv_info = xmalloc(sizeof(*kv_info));
|
||||||
|
|
||||||
e = configset_find_element(cs, key);
|
e = configset_find_element(set, key);
|
||||||
/*
|
/*
|
||||||
* Since the keys are being fed by git_config*() callback mechanism, they
|
* Since the keys are being fed by git_config*() callback mechanism, they
|
||||||
* are already normalized. So simply add them without any further munging.
|
* are already normalized. So simply add them without any further munging.
|
||||||
@ -2389,12 +2389,12 @@ static int configset_add_value(struct config_reader *reader,
|
|||||||
hashmap_entry_init(&e->ent, strhash(key));
|
hashmap_entry_init(&e->ent, strhash(key));
|
||||||
e->key = xstrdup(key);
|
e->key = xstrdup(key);
|
||||||
string_list_init_dup(&e->value_list);
|
string_list_init_dup(&e->value_list);
|
||||||
hashmap_add(&cs->config_hash, &e->ent);
|
hashmap_add(&set->config_hash, &e->ent);
|
||||||
}
|
}
|
||||||
si = string_list_append_nodup(&e->value_list, xstrdup_or_null(value));
|
si = string_list_append_nodup(&e->value_list, xstrdup_or_null(value));
|
||||||
|
|
||||||
ALLOC_GROW(cs->list.items, cs->list.nr + 1, cs->list.alloc);
|
ALLOC_GROW(set->list.items, set->list.nr + 1, set->list.alloc);
|
||||||
l_item = &cs->list.items[cs->list.nr++];
|
l_item = &set->list.items[set->list.nr++];
|
||||||
l_item->e = e;
|
l_item->e = e;
|
||||||
l_item->value_index = e->value_list.nr - 1;
|
l_item->value_index = e->value_list.nr - 1;
|
||||||
|
|
||||||
@ -2429,33 +2429,33 @@ static int config_set_element_cmp(const void *cmp_data UNUSED,
|
|||||||
return strcmp(e1->key, e2->key);
|
return strcmp(e1->key, e2->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_configset_init(struct config_set *cs)
|
void git_configset_init(struct config_set *set)
|
||||||
{
|
{
|
||||||
hashmap_init(&cs->config_hash, config_set_element_cmp, NULL, 0);
|
hashmap_init(&set->config_hash, config_set_element_cmp, NULL, 0);
|
||||||
cs->hash_initialized = 1;
|
set->hash_initialized = 1;
|
||||||
cs->list.nr = 0;
|
set->list.nr = 0;
|
||||||
cs->list.alloc = 0;
|
set->list.alloc = 0;
|
||||||
cs->list.items = NULL;
|
set->list.items = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_configset_clear(struct config_set *cs)
|
void git_configset_clear(struct config_set *set)
|
||||||
{
|
{
|
||||||
struct config_set_element *entry;
|
struct config_set_element *entry;
|
||||||
struct hashmap_iter iter;
|
struct hashmap_iter iter;
|
||||||
if (!cs->hash_initialized)
|
if (!set->hash_initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hashmap_for_each_entry(&cs->config_hash, &iter, entry,
|
hashmap_for_each_entry(&set->config_hash, &iter, entry,
|
||||||
ent /* member name */) {
|
ent /* member name */) {
|
||||||
free(entry->key);
|
free(entry->key);
|
||||||
string_list_clear(&entry->value_list, 1);
|
string_list_clear(&entry->value_list, 1);
|
||||||
}
|
}
|
||||||
hashmap_clear_and_free(&cs->config_hash, struct config_set_element, ent);
|
hashmap_clear_and_free(&set->config_hash, struct config_set_element, ent);
|
||||||
cs->hash_initialized = 0;
|
set->hash_initialized = 0;
|
||||||
free(cs->list.items);
|
free(set->list.items);
|
||||||
cs->list.nr = 0;
|
set->list.nr = 0;
|
||||||
cs->list.alloc = 0;
|
set->list.alloc = 0;
|
||||||
cs->list.items = NULL;
|
set->list.items = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct configset_add_data {
|
struct configset_add_data {
|
||||||
@ -2471,15 +2471,15 @@ static int config_set_callback(const char *key, const char *value, void *cb)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_configset_add_file(struct config_set *cs, const char *filename)
|
int git_configset_add_file(struct config_set *set, const char *filename)
|
||||||
{
|
{
|
||||||
struct configset_add_data data = CONFIGSET_ADD_INIT;
|
struct configset_add_data data = CONFIGSET_ADD_INIT;
|
||||||
data.config_reader = &the_reader;
|
data.config_reader = &the_reader;
|
||||||
data.config_set = cs;
|
data.config_set = set;
|
||||||
return git_config_from_file(config_set_callback, filename, &data);
|
return git_config_from_file(config_set_callback, filename, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_configset_get_value(struct config_set *cs, const char *key, const char **value)
|
int git_configset_get_value(struct config_set *set, const char *key, const char **value)
|
||||||
{
|
{
|
||||||
const struct string_list *values = NULL;
|
const struct string_list *values = NULL;
|
||||||
/*
|
/*
|
||||||
@ -2487,7 +2487,7 @@ int git_configset_get_value(struct config_set *cs, const char *key, const char *
|
|||||||
* queried key in the files of the configset, the value returned will be the last
|
* queried key in the files of the configset, the value returned will be the last
|
||||||
* value in the value list for that key.
|
* value in the value list for that key.
|
||||||
*/
|
*/
|
||||||
values = git_configset_get_value_multi(cs, key);
|
values = git_configset_get_value_multi(set, key);
|
||||||
|
|
||||||
if (!values)
|
if (!values)
|
||||||
return 1;
|
return 1;
|
||||||
@ -2496,26 +2496,26 @@ int git_configset_get_value(struct config_set *cs, const char *key, const char *
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key)
|
const struct string_list *git_configset_get_value_multi(struct config_set *set, const char *key)
|
||||||
{
|
{
|
||||||
struct config_set_element *e = configset_find_element(cs, key);
|
struct config_set_element *e = configset_find_element(set, key);
|
||||||
return e ? &e->value_list : NULL;
|
return e ? &e->value_list : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_configset_get_string(struct config_set *cs, const char *key, char **dest)
|
int git_configset_get_string(struct config_set *set, const char *key, char **dest)
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
if (!git_configset_get_value(cs, key, &value))
|
if (!git_configset_get_value(set, key, &value))
|
||||||
return git_config_string((const char **)dest, key, value);
|
return git_config_string((const char **)dest, key, value);
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int git_configset_get_string_tmp(struct config_set *cs, const char *key,
|
static int git_configset_get_string_tmp(struct config_set *set, const char *key,
|
||||||
const char **dest)
|
const char **dest)
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
if (!git_configset_get_value(cs, key, &value)) {
|
if (!git_configset_get_value(set, key, &value)) {
|
||||||
if (!value)
|
if (!value)
|
||||||
return config_error_nonbool(key);
|
return config_error_nonbool(key);
|
||||||
*dest = value;
|
*dest = value;
|
||||||
@ -2525,51 +2525,51 @@ static int git_configset_get_string_tmp(struct config_set *cs, const char *key,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_configset_get_int(struct config_set *cs, const char *key, int *dest)
|
int git_configset_get_int(struct config_set *set, const char *key, int *dest)
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
if (!git_configset_get_value(cs, key, &value)) {
|
if (!git_configset_get_value(set, key, &value)) {
|
||||||
*dest = git_config_int(key, value);
|
*dest = git_config_int(key, value);
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest)
|
int git_configset_get_ulong(struct config_set *set, const char *key, unsigned long *dest)
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
if (!git_configset_get_value(cs, key, &value)) {
|
if (!git_configset_get_value(set, key, &value)) {
|
||||||
*dest = git_config_ulong(key, value);
|
*dest = git_config_ulong(key, value);
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_configset_get_bool(struct config_set *cs, const char *key, int *dest)
|
int git_configset_get_bool(struct config_set *set, const char *key, int *dest)
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
if (!git_configset_get_value(cs, key, &value)) {
|
if (!git_configset_get_value(set, key, &value)) {
|
||||||
*dest = git_config_bool(key, value);
|
*dest = git_config_bool(key, value);
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_configset_get_bool_or_int(struct config_set *cs, const char *key,
|
int git_configset_get_bool_or_int(struct config_set *set, const char *key,
|
||||||
int *is_bool, int *dest)
|
int *is_bool, int *dest)
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
if (!git_configset_get_value(cs, key, &value)) {
|
if (!git_configset_get_value(set, key, &value)) {
|
||||||
*dest = git_config_bool_or_int(key, value, is_bool);
|
*dest = git_config_bool_or_int(key, value, is_bool);
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest)
|
int git_configset_get_maybe_bool(struct config_set *set, const char *key, int *dest)
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
if (!git_configset_get_value(cs, key, &value)) {
|
if (!git_configset_get_value(set, key, &value)) {
|
||||||
*dest = git_parse_maybe_bool(value);
|
*dest = git_parse_maybe_bool(value);
|
||||||
if (*dest == -1)
|
if (*dest == -1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -2578,10 +2578,10 @@ int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *de
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest)
|
int git_configset_get_pathname(struct config_set *set, const char *key, const char **dest)
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
if (!git_configset_get_value(cs, key, &value))
|
if (!git_configset_get_value(set, key, &value))
|
||||||
return git_config_pathname(dest, key, value);
|
return git_config_pathname(dest, key, value);
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
@ -2972,7 +2972,7 @@ static int store_aux_event(enum config_event_t type,
|
|||||||
size_t begin, size_t end, void *data)
|
size_t begin, size_t end, void *data)
|
||||||
{
|
{
|
||||||
struct config_store_data *store = data;
|
struct config_store_data *store = data;
|
||||||
struct config_source *cf = store->config_reader->source;
|
struct config_source *cs = store->config_reader->source;
|
||||||
|
|
||||||
ALLOC_GROW(store->parsed, store->parsed_nr + 1, store->parsed_alloc);
|
ALLOC_GROW(store->parsed, store->parsed_nr + 1, store->parsed_alloc);
|
||||||
store->parsed[store->parsed_nr].begin = begin;
|
store->parsed[store->parsed_nr].begin = begin;
|
||||||
@ -2982,10 +2982,10 @@ static int store_aux_event(enum config_event_t type,
|
|||||||
if (type == CONFIG_EVENT_SECTION) {
|
if (type == CONFIG_EVENT_SECTION) {
|
||||||
int (*cmpfn)(const char *, const char *, size_t);
|
int (*cmpfn)(const char *, const char *, size_t);
|
||||||
|
|
||||||
if (cf->var.len < 2 || cf->var.buf[cf->var.len - 1] != '.')
|
if (cs->var.len < 2 || cs->var.buf[cs->var.len - 1] != '.')
|
||||||
return error(_("invalid section name '%s'"), cf->var.buf);
|
return error(_("invalid section name '%s'"), cs->var.buf);
|
||||||
|
|
||||||
if (cf->subsection_case_sensitive)
|
if (cs->subsection_case_sensitive)
|
||||||
cmpfn = strncasecmp;
|
cmpfn = strncasecmp;
|
||||||
else
|
else
|
||||||
cmpfn = strncmp;
|
cmpfn = strncmp;
|
||||||
@ -2993,8 +2993,8 @@ static int store_aux_event(enum config_event_t type,
|
|||||||
/* Is this the section we were looking for? */
|
/* Is this the section we were looking for? */
|
||||||
store->is_keys_section =
|
store->is_keys_section =
|
||||||
store->parsed[store->parsed_nr].is_keys_section =
|
store->parsed[store->parsed_nr].is_keys_section =
|
||||||
cf->var.len - 1 == store->baselen &&
|
cs->var.len - 1 == store->baselen &&
|
||||||
!cmpfn(cf->var.buf, store->key, store->baselen);
|
!cmpfn(cs->var.buf, store->key, store->baselen);
|
||||||
if (store->is_keys_section) {
|
if (store->is_keys_section) {
|
||||||
store->section_seen = 1;
|
store->section_seen = 1;
|
||||||
ALLOC_GROW(store->seen, store->seen_nr + 1,
|
ALLOC_GROW(store->seen, store->seen_nr + 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user