diff options
| author | Patrick Steinhardt <ps@pks.im> | 2018-08-10 12:52:18 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2018-09-28 11:14:13 +0200 |
| commit | 1aeff5d7c97eac81965d09b0fac8e89ddb6909be (patch) | |
| tree | ed8da1d3d5eede9d65eeb130b5e5bda075334f63 /src | |
| parent | a55626924fe9a59936b6ff4a75cd69560e4c9f3e (diff) | |
| download | libgit2-1aeff5d7c97eac81965d09b0fac8e89ddb6909be.tar.gz | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.c | 31 | ||||
| -rw-r--r-- | src/config_file.c | 23 | ||||
| -rw-r--r-- | src/config_file.h | 2 |
3 files changed, 27 insertions, 29 deletions
diff --git a/src/config.c b/src/config.c index 72c1c7302..ebff6a280 100644 --- a/src/config.c +++ b/src/config.c @@ -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); diff --git a/src/config_file.c b/src/config_file.c index 26bc200df..fb88818b5 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -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) diff --git a/src/config_file.h b/src/config_file.h index 72818e58c..6a0984ec2 100644 --- a/src/config_file.h +++ b/src/config_file.h @@ -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 |
