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

Re: [PATCH v7 4/4] config: allow http.<url>.* any user matching

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 22, 2013, 05:28 UTC
Message-ID
<7va9lfqi3b.fsf@alter.siamese.dyndns.org>
In-Reply-To
<b8fedff6e14fded3929e2b835aac6f9@f74d39fa044aa309eaea14b9f57fe79>
"Kyle J. McKay" <mackyle@gmail.com> writes:
Show 39 quoted lines
> diff --git a/test-url-normalize.c b/test-url-normalize.c
> index d68312d..f325571 100644
> --- a/test-url-normalize.c
> +++ b/test-url-normalize.c
> @@ -9,7 +9,7 @@ int main()
>  
>  #include "http.c"
>  
> -#define url_normalize(u) http_options_url_normalize(u)
> +#define url_normalize(u,i) http_options_url_normalize(u,i)
>  
>  int main(int argc, char **argv)
>  {
> @@ -40,21 +40,22 @@ int main(int argc, char **argv)
>  		die(usage);
>  
>  	if (argc == 2) {
> -		url1 = url_normalize(argv[1]);
> +		struct url_info info;
> +		url1 = url_normalize(argv[1], &info);
>  		if (!url1)
>  			return 1;
>  		if (opt_p)
>  			printf("%s\n", url1);
>  		if (opt_l)
> -			printf("%u\n", (unsigned)strlen(url1));
> +			printf("%u\n", (unsigned)info.url_len);
>  		return 0;
>  	}
>  
>  	if (opt_p || opt_l)
>  		die(usage);
>  
> -	url1 = url_normalize(argv[1]);
> -	url2 = url_normalize(argv[2]);
> +	url1 = url_normalize(argv[1], NULL);
> +	url2 = url_normalize(argv[2], NULL);
>  	return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
>  }

It looks like that this program could also drive http_options() directly, or alternatively make a call

	git_config(http_options, &info);

in its main() to let the config parser do its work, to make sure that the machinery picks up the right values from the desired entry in the configuration file, with a bit more effort.

Show 34 quoted lines
> +static int match_is_ignored(size_t matchlen, int usermatch, enum http_option_type opt)
>  {
>  	/*
> -	 * Compare matchlen to the last matched length of option opt and
> +	 * Compare matchlen to the last matched path 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.
> +	 * not shorter) the new setting will override the previous setting
> +	 * unless the new setting did not match the user and the previous match
> +	 * did.  Otherwise return false and record matchlen as the current last
> +	 * matched path length of option opt and usermatch as the last user
> +	 * matching state for option opt.
>  	 */
>  	if (matchlen < http_option_max_matched_len[opt])
>  		return 1;
> -	http_option_max_matched_len[opt] = matchlen;
> +	if (matchlen > http_option_max_matched_len[opt]) {
> +		http_option_max_matched_len[opt] = matchlen;
> +		http_option_user_matched[opt] = usermatch;
> +		return 0;
> +	}
> +	/*
> +	 * If a previous match of the same length explicitly matched the user
> +	 * name, but the current match matched on any user, ignore it.
> +	 */
> +	if (!usermatch && http_option_user_matched[opt])
> +		return 1;
> +	http_option_user_matched[opt] = usermatch;
>  	return 0;
>  }

OK, so if there is a configuration for a generic URL that is longer, it defeats a shorter URL with a specific username, e.g. when talking to host.xz/name as kyle, with configuration for these two keys exist:

	scheme://kyle@host.xz/path
        scheme://host.xz/path/name
the value for the latter one is used.

I am not complaining; just making sure that is what we want to give users, as it was not quite clear in the Documentation/config.txt part of the patch.

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