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) ...@@ -1376,6 +1376,30 @@ int git_config_parse_path(git_buf *out, const char *value)
return git_buf_sets(out, 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 */ /* Take something the user gave us and make it nice for our hash function */
int git_config__normalize_name(const char *in, char **out) int git_config__normalize_name(const char *in, char **out)
{ {
...@@ -1393,8 +1417,8 @@ 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; goto invalid;
/* Validate and downcase up to first dot and after last dot */ /* Validate and downcase up to first dot and after last dot */
if (git_config_file_normalize_section(name, fdot) < 0 || if (normalize_section(name, fdot) < 0 ||
git_config_file_normalize_section(ldot + 1, NULL) < 0) normalize_section(ldot + 1, NULL) < 0)
goto invalid; goto invalid;
/* If there is a middle range, make sure it doesn't have newlines */ /* If there is a middle range, make sure it doesn't have newlines */
...@@ -1466,8 +1490,7 @@ int git_config_rename_section( ...@@ -1466,8 +1490,7 @@ int git_config_rename_section(
goto cleanup; goto cleanup;
if (new_section_name != NULL && if (new_section_name != NULL &&
(error = git_config_file_normalize_section( (error = normalize_section(replace.ptr, strchr(replace.ptr, '.'))) < 0)
replace.ptr, strchr(replace.ptr, '.'))) < 0)
{ {
giterr_set( giterr_set(
GITERR_CONFIG, "invalid config section '%s'", new_section_name); GITERR_CONFIG, "invalid config section '%s'", new_section_name);
......
...@@ -107,29 +107,6 @@ static void config_entry_list_free(config_entry_list *list) ...@@ -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) static void config_entry_list_append(config_entry_list **list, config_entry_list *entry)
{ {
if (*list) if (*list)
......
...@@ -68,6 +68,4 @@ GIT_INLINE(int) git_config_file_unlock(git_config_backend *cfg, int success) ...@@ -68,6 +68,4 @@ GIT_INLINE(int) git_config_file_unlock(git_config_backend *cfg, int success)
return cfg->unlock(cfg, success); return cfg->unlock(cfg, success);
} }
extern int git_config_file_normalize_section(char *start, char *end);
#endif #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