Commit 1aeff5d7 by Patrick Steinhardt

config: move function normalizing section names into "config.c"

The function `git_config_file_normalize_section` is never being used in
any file different than "config.c", but it is implemented in
"config_file.c". Move it over and make the symbol static.
parent a5562692
......@@ -1376,6 +1376,30 @@ int git_config_parse_path(git_buf *out, const char *value)
return git_buf_sets(out, value);
}
static int normalize_section(char *start, char *end)
{
char *scan;
if (start == end)
return GIT_EINVALIDSPEC;
/* Validate and downcase range */
for (scan = start; *scan; ++scan) {
if (end && scan >= end)
break;
if (isalnum(*scan))
*scan = (char)git__tolower(*scan);
else if (*scan != '-' || scan == start)
return GIT_EINVALIDSPEC;
}
if (scan == start)
return GIT_EINVALIDSPEC;
return 0;
}
/* Take something the user gave us and make it nice for our hash function */
int git_config__normalize_name(const char *in, char **out)
{
......@@ -1393,8 +1417,8 @@ int git_config__normalize_name(const char *in, char **out)
goto invalid;
/* Validate and downcase up to first dot and after last dot */
if (git_config_file_normalize_section(name, fdot) < 0 ||
git_config_file_normalize_section(ldot + 1, NULL) < 0)
if (normalize_section(name, fdot) < 0 ||
normalize_section(ldot + 1, NULL) < 0)
goto invalid;
/* If there is a middle range, make sure it doesn't have newlines */
......@@ -1466,8 +1490,7 @@ int git_config_rename_section(
goto cleanup;
if (new_section_name != NULL &&
(error = git_config_file_normalize_section(
replace.ptr, strchr(replace.ptr, '.'))) < 0)
(error = normalize_section(replace.ptr, strchr(replace.ptr, '.'))) < 0)
{
giterr_set(
GITERR_CONFIG, "invalid config section '%s'", new_section_name);
......
......@@ -107,29 +107,6 @@ static void config_entry_list_free(config_entry_list *list)
};
}
int git_config_file_normalize_section(char *start, char *end)
{
char *scan;
if (start == end)
return GIT_EINVALIDSPEC;
/* Validate and downcase range */
for (scan = start; *scan; ++scan) {
if (end && scan >= end)
break;
if (isalnum(*scan))
*scan = (char)git__tolower(*scan);
else if (*scan != '-' || scan == start)
return GIT_EINVALIDSPEC;
}
if (scan == start)
return GIT_EINVALIDSPEC;
return 0;
}
static void config_entry_list_append(config_entry_list **list, config_entry_list *entry)
{
if (*list)
......
......@@ -68,6 +68,4 @@ GIT_INLINE(int) git_config_file_unlock(git_config_backend *cfg, int success)
return cfg->unlock(cfg, success);
}
extern int git_config_file_normalize_section(char *start, char *end);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment