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

Re: [PATCH 3/3] config: --get-urlmatch

From
Jeff King <peff@peff.net>
Date
Jul 30, 2013, 00:37 UTC
Message-ID
<20130730003716.GA13114@sigill.intra.peff.net>
In-Reply-To
<1375138150-19520-4-git-send-email-gitster@pobox.com>
On Mon, Jul 29, 2013 at 03:49:10PM -0700, Junio C Hamano wrote:
> "git config --get-urlmatch $section[.$variable] $url" is a way to
> learn what the configured value for $section.$variable is for the
> given URL, using the logic introduced by the http.<url>.config
> topic.

That interface looks good to me. It matches the --get-all/--get-regexp options of git-config. It does not quite match --get-color, which is really a type (like --bool or --int), but I think --get-color is the odd one out there.

> This can still be further refactored to remove code from http_options()
> in http.c, I think.

Yeah, that would be the ultimate goal. I think you would just need to keep the same string_list there, with one urlmatch_item per key that we care about.

> ---
>  builtin/config.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++

It seems like some of the logic here should be reusable for http.c. Should it be in config.c instead?

Show 13 quoted lines
> +struct urlmatch_collect {
> +	struct string_list vars;
> +	struct url_info url;
> +	const char *section;
> +	const char *key;
> +};
> +
> +struct urlmatch_item {
> +	size_t max_matched_len;
> +	char user_matched;
> +	char value_is_null;
> +	struct strbuf value;
> +};

I think you ultimately want such a string_list for matching arbitrary numbers of keys, but do you need it for the git-config case?

You will always be matching collect->key, so you will only ever insert a single item into the collect->vars list. IOW, this could be:

  struct urlmatch_collect {
    struct url_info url;
    const char *section;
    const char *key;
    struct urlmatch_item match;
  };

I don't mind if it is more complicated than this single-case needs to be if the code is also being used to http.c, but I haven't seen that yet (and this code would not used as-is, as you would want to call the function with many potential collect->key values, but without re-normalizing the URL over and over).

And of course, it needs docs and tests. :) The latter can probably come by converting some of the test-url-normalize tests to just use git-config instead.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 19 in “test-url-normalize.c: Fix gcc errors and sparse warnings”
  1. test-url-normalize.c: Fix gcc errors and sparse warningsRamsay Jones, Jul 24, 2013
  2. Kyle J. McKayJul 24, 2013
  3. Junio C HamanoJul 24, 2013
  4. 0/3 "git config --get-urlmatch $section.$key $url"Junio C Hamano, Jul 29, 2013
  5. 1/3 url-match: split out URL matching logic out of http.cJunio C Hamano, Jul 29, 2013
  6. 2/3 builtin/config: refactor collect_config()Junio C Hamano, Jul 29, 2013
  7. 3/3 config: --get-urlmatchJunio C Hamano, Jul 29, 2013
  8. Jeff KingJul 30, 2013
  9. Junio C HamanoJul 30, 2013
  10. Jeff KingJul 30, 2013
  11. Junio C HamanoJul 30, 2013
  12. Kyle J. McKayJul 30, 2013
  13. 4/3 url-match: generalize configuration collection logicJunio C Hamano, Jul 30, 2013
  14. 5/3 revert most of the http_options() changeJunio C Hamano, Jul 30, 2013
  15. Kyle J. McKayJul 30, 2013
  16. Kyle J. McKayJul 30, 2013
  17. Junio C HamanoJul 30, 2013
  18. Ramsay JonesJul 31, 2013
  19. 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.