Re: [PATCH v6 6/6] config: "git config --get-urlmatch" parses section.<url>.key

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeff King <peff@xxxxxxxx> writes:

>   1. Git-config expects pre-canonicalized variable names (so http.noepsv
>      instead of "http.noEPSV"). I think the "git config --get" code path
>      does this for the caller, so we should probably do the same for
>      "--get-urlmatch". And it is even easier here, because we know that
>      "http.noEPSV" does not contain a case-sensitive middle part. :)

I'll squash these in later, but here is from my working copy.
Thanks for spotting.

 builtin/config.c       | 32 +++++++++++++++++++-------------
 t/t1300-repo-config.sh |  4 ++--
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/builtin/config.c b/builtin/config.c
index c35c5be..c046f54 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -379,9 +379,22 @@ static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
 	return 0;
 }
 
+static char *dup_downcase(const char *string)
+{
+	char *result;
+	size_t len, i;
+
+	len = strlen(string);
+	result = xmalloc(len + 1);
+	for (i = 0; i < len; i++)
+		result[i] = tolower(string[i]);
+	result[i] = '\0';
+	return result;
+}
+
 static int get_urlmatch(const char *var, const char *url)
 {
-	const char *section_tail;
+	char *section_tail;
 	struct string_list_item *item;
 	struct urlmatch_config config = { STRING_LIST_INIT_DUP };
 	struct string_list values = STRING_LIST_INIT_DUP;
@@ -393,13 +406,13 @@ static int get_urlmatch(const char *var, const char *url)
 	if (!url_normalize(url, &config.url))
 		die(config.url.err);
 
-	section_tail = strchr(var, '.');
+	config.section = dup_downcase(var);
+	section_tail = strchr(config.section, '.');
 	if (section_tail) {
-		config.section = xmemdupz(var, section_tail - var);
-		config.key = strrchr(var, '.') + 1;
+		*section_tail = '\0';
+		config.key = section_tail + 1;
 		show_keys = 0;
 	} else {
-		config.section = var;
 		config.key = NULL;
 		show_keys = 1;
 	}
@@ -425,14 +438,7 @@ static int get_urlmatch(const char *var, const char *url)
 	string_list_clear(&values, 1);
 	free(config.url.url);
 
-	/*
-	 * section name may have been copied to replace the dot, in which
-	 * case it needs to be freed.  key name is either NULL (e.g. 'http'
-	 * alone) or points into var (e.g. 'http.savecookies'), and we do
-	 * not own the storage.
-	 */
-	if (config.section != var)
-		free((void *)config.section);
+	free((void *)config.section);
 	return 0;
 }
 
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 323e880..c23f478 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -1097,7 +1097,7 @@ test_expect_success 'urlmatch' '
 	EOF
 
 	echo true >expect &&
-	git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
+	git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
 	test_cmp expect actual &&
 
 	echo false >expect &&
@@ -1108,7 +1108,7 @@ test_expect_success 'urlmatch' '
 		echo http.cookiefile /tmp/cookie.txt &&
 		echo http.sslverify false
 	} >expect &&
-	git config --get-urlmatch http https://weak.example.com >actual &&
+	git config --get-urlmatch HTTP https://weak.example.com >actual &&
 	test_cmp expect actual
 '
 
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]