From: "Kyle J. McKay" <mackyle@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH 3/3] config: --get-urlmatch
Date: Tue, 30 Jul 2013 12:14:03 -0700 [thread overview]
Message-ID: <C34D29B7-055D-4D82-B9FE-27150E51FF79@gmail.com> (raw)
In-Reply-To: <1375138150-19520-4-git-send-email-gitster@pobox.com>
On Jul 29, 2013, at 15:49, 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. In addition to $section.$variable, entries in the
> configuration file(s) that match $section.<urlpattern>.$variable are
> looked up and the one with <urlpattern> that matches the given $url
> the best is used to answer the query.
>
> This can still be further refactored to remove code from
> http_options()
> in http.c, I think.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> builtin/config.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++
> +++++++++
> 1 file changed, 141 insertions(+)
>
> diff --git a/builtin/config.c b/builtin/config.c
> index 12c5073..c1d32ae 100644
> --- a/builtin/config.c
> +++ b/builtin/config.c
[...]
> +static int get_urlmatch(const char *var, const char *url)
> +{
> + const char *section_tail;
> + struct string_list_item *item;
> + struct urlmatch_collect collect = { STRING_LIST_INIT_DUP };
> +
> + if (!url_normalize(url, &collect.url))
> + die(collect.url.err);
The value now stored in collect.url.url is never freed.
> +
> + section_tail = strchr(var, '.');
> + if (section_tail) {
> + collect.section = xmemdupz(var, section_tail - var);
> + collect.key = strrchr(var, '.') + 1;
> + show_keys = 0;
> + } else {
> + collect.section = var;
> + collect.key = NULL;
> + show_keys = 1;
> + }
> +
> + git_config_with_options(urlmatch_collect, &collect,
> + given_config_file, respect_includes);
> +
> + for_each_string_list_item(item, &collect.vars) {
> + struct urlmatch_item *matched = item->util;
> + struct strbuf key = STRBUF_INIT;
> + struct strbuf buf = STRBUF_INIT;
> +
> + strbuf_addstr(&key, collect.section);
> + strbuf_addch(&key, '.');
> + strbuf_addstr(&key, item->string);
> + format_config(&buf, key.buf,
> + matched->value_is_null ? NULL : matched->value.buf);
> + fwrite(buf.buf, 1, buf.len, stdout);
> + strbuf_release(&key);
> + strbuf_release(&buf);
> +
> + strbuf_release(&matched->value);
> + }
> + string_list_clear(&collect.vars, 1);
Needs something like this here:
+ free(collect.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 (collect.section != var)
> + free((void *)collect.section);
> + return 0;
> +}
Still needed after 4/3 except it's now config.url.url instead.
next prev parent reply other threads:[~2013-07-30 19:14 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-24 19:07 [PATCH] test-url-normalize.c: Fix gcc errors and sparse warnings Ramsay Jones
2013-07-24 19:35 ` Kyle J. McKay
2013-07-24 20:39 ` Junio C Hamano
2013-07-29 22:49 ` [PATCH 0/3] "git config --get-urlmatch $section.$key $url" Junio C Hamano
2013-07-29 22:49 ` [PATCH 1/3] url-match: split out URL matching logic out of http.c Junio C Hamano
2013-07-29 22:49 ` [PATCH 2/3] builtin/config: refactor collect_config() Junio C Hamano
2013-07-29 22:49 ` [PATCH 3/3] config: --get-urlmatch Junio C Hamano
2013-07-30 0:37 ` Jeff King
2013-07-30 1:33 ` Junio C Hamano
2013-07-30 8:14 ` Jeff King
2013-07-30 13:52 ` Junio C Hamano
2013-07-30 19:14 ` Kyle J. McKay [this message]
2013-07-30 2:03 ` [PATCH 4/3] url-match: generalize configuration collection logic Junio C Hamano
2013-07-30 2:13 ` [PATCH 5/3] revert most of the http_options() change Junio C Hamano
2013-07-30 19:14 ` Kyle J. McKay
2013-07-30 19:41 ` Kyle J. McKay
2013-07-30 21:09 ` Junio C Hamano
2013-07-31 17:59 ` [PATCH 0/3] "git config --get-urlmatch $section.$key $url" Ramsay Jones
2013-07-31 19:31 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C34D29B7-055D-4D82-B9FE-27150E51FF79@gmail.com \
--to=mackyle@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).