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

Re: [PATCH v6 1/4] config: add support for http.<url>.* settings

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 19, 2013, 20:08 UTC
Message-ID
<7va9liuxbv.fsf@alter.siamese.dyndns.org>
In-Reply-To
<296e6ff588bb131a7e8274738d4378c@f74d39fa044aa309eaea14b9f57fe79>
"Kyle J. McKay" <mackyle@gmail.com> writes:
Show 25 quoted lines
> +static size_t http_option_max_matched_len[OPT_MAX];
>  ...
> +static int new_match_is_shorter(size_t matchlen, enum http_option_type opt)
> +{
> +	/*
> +	 * Compare matchlen to the last matched length of option opt and
> +	 * return true if matchlen is shorter than the last matched length
> +	 * (meaning the config setting should be ignored).  Upon seeing the
> +	 * _same_ key (i.e. new key has the same match length which is therefore
> +	 * not shorter) the new setting will override the previous setting.
> +	 * Otherwise return false and record matchlen as the current last
> +	 * matched length of option opt.
> +	 */
> +	if (matchlen < http_option_max_matched_len[opt])
> +		return 1;
> +	http_option_max_matched_len[opt] = matchlen;
> +	return 0;
> +}
> + ...
> @@ -337,7 +472,7 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
>  
>  	http_is_verbose = 0;
>  
> -	git_config(http_options, NULL);
> +	git_config(http_options, (void *)url);

Can http_init() be called more than once? max-matched-len (and leter user-matched as well) is initialized to zero at the link time, and never reset after it is used for matching the configuration file entries with a single URL.

If this function is called more than once, the code needs to memset(0) the array(s), don't it?

Another possibility, which might be better, is to package that array and the url into a structure, have it on the stackframe of this function, i.e.

	struct match_url_state {
        	const char *url;
		size_t http_option_max_matched_len[OPT_MAX];
		int http_option_user_matched[OPT_MAX];
	} match_url_state = {NULL};
	git_config(http_options, &match_url_state);

or something. In any case, you no longer have to cast the second parameter of git_config to (void *) only to defeat constness ;-)

>  	curl_global_init(CURL_GLOBAL_ALL);
Previous: Kyle J. McKayNext: Kyle J. McKay
Message 3 of 10 in “config: add support for http.<url>.* settings”
  1. 0/4 config: add support for http.<url>.* settingsKyle J. McKay, Jul 19, 2013
  2. 1/4 config: add support for http.<url>.* settingsKyle J. McKay, Jul 19, 2013
  3. Junio C HamanoJul 19, 2013
  4. Kyle J. McKayJul 19, 2013
  5. 2/4 config: improve support for http.<url>.* settingsKyle J. McKay, Jul 19, 2013
  6. Junio C HamanoJul 19, 2013
  7. Kyle J. McKayJul 19, 2013
  8. Junio C HamanoJul 20, 2013
  9. 3/4 tests: add new test for the url_normalize functionKyle J. McKay, Jul 19, 2013
  10. 4/4 config: allow http.<url>.* any user matchingKyle J. McKay, Jul 19, 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.