git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 31, 2013, 23:47 UTC
Message-ID
<7vzjt2s35v.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20130731224511.GA25882@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 5 quoted lines
>   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
 '
 
Previous: Kyle J. McKay
Message 23 of 23 in “http.<url>.<key> and friends”
  1. 0/6 http.<url>.<key> and friendsJunio C Hamano, Jul 31, 2013
  2. 1/6 http.c: fix parsing of http.sslCertPasswordProtected variableJunio C Hamano, Jul 31, 2013
  3. 2/6 config: add helper to normalize and match URLsJunio C Hamano, Jul 31, 2013
  4. Kyle J. McKayJul 31, 2013
  5. 0/2 http.<url>.<key> and friendsKyle J. McKay, Jul 31, 2013
  6. 2/4 config: add helper to normalize and match URLsKyle J. McKay, Jul 31, 2013
  7. 4/4 config: parse http.<url>.<variable> using urlmatchKyle J. McKay, Jul 31, 2013
  8. Junio C HamanoJul 31, 2013
  9. 4/6 config: parse http.<url>.<variable> using urlmatchKyle J. McKay, Jul 31, 2013
  10. 3/6 config: add generic callback wrapper to parse section.<url>.keyJunio C Hamano, Jul 31, 2013
  11. 4/6 config: parse http.<url>.<variable> using urlmatchJunio C Hamano, Jul 31, 2013
  12. Kyle J. McKayJul 31, 2013
  13. 5/6 builtin/config: refactor collect_config()Junio C Hamano, Jul 31, 2013
  14. 6/6 config: "git config --get-urlmatch" parses section.<url>.keyJunio C Hamano, Jul 31, 2013
  15. Jeff KingJul 31, 2013
  16. Kyle J. McKayJul 31, 2013
  17. Jeff KingJul 31, 2013
  18. Junio C HamanoAug 1, 2013
  19. Jeff KingAug 1, 2013
  20. 4/6 config: parse http.<url>.<variable> using urlmatchKyle J. McKay, Aug 5, 2013
  21. Junio C HamanoAug 5, 2013
  22. Kyle J. McKayAug 5, 2013
  23. Junio C HamanoJul 31, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.