Commit 1aeff5d7c97eac81965d09b0fac8e89ddb6909be

Patrick Steinhardt 2018-08-10T12:52:18

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.

diff --git a/src/config.c b/src/config.c
index 72c1c73..ebff6a2 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 26bc200..fb88818 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 72818e5..6a0984e 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