From: Junio C Hamano <gitster@pobox.com>
To: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] rev-parse --glob
Date: Wed, 20 Jan 2010 02:17:15 -0800 [thread overview]
Message-ID: <7vska13wt0.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1263980906-11058-1-git-send-email-ilari.liusvaara@elisanet.fi> (Ilari Liusvaara's message of "Wed\, 20 Jan 2010 11\:48\:25 +0200")
Ilari Liusvaara <ilari.liusvaara@elisanet.fi> writes:
> Add --glob=<glob-pattern> option to rev-parse and everything that
> accepts its options. This option matches all refs that match given
> shell glob pattern (complete with some DWIM logic).
>
> Example:
>
> 'git log --branches --not --glob=remotes/origin'
>
> To show what you have that origin doesn't.
>
> Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
> ---
Looks fairly competently done. Does this mean you've abandoned the --namespace
series? I don't mind reverting them from 'next'.
> +static int filter_refs(const char* ref, const unsigned char *sha, int flags,
> + void* data)
> +{
> + struct ref_filter *filter = (struct ref_filter*)data;
> + if (fnmatch(filter->pattern, ref, 0))
> + return 0;
In many places (not just refs) we use "If leading path component matches,
or fnmatch() says Ok" (e.g. builtin-for-each-ref.c, builtin_grep.c), and
in some other places we only use fnmatch(). I think it is better to pick
one convention, and adjust the other one to match, and my gut feeling is
that "leading path or fnmatch()", while theologically might be messier,
would be more useful in practice. And that was why I did my "like this"
patch http://article.gmane.org/gmane.comp.version-control.git/137492 that way.
My longer term desire is to consolidate these fnmatch() users to call a
single helper function, and then perhaps replace fnmatch() in that helper
function with something more powerful. Although I do not personally care
too much, people often wanted to have "path/**/leaf-that-is-deep" matcher.
I don't want you to go there just yet with this series, but at least
following the same style everywhere would pave the way to consolidating
them.
> @@ -674,6 +691,35 @@ int for_each_replace_ref(each_ref_fn fn, void *cb_data)
> return do_for_each_ref("refs/replace/", fn, 13, 0, cb_data);
> }
>
> +int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
> +{
> + struct strbuf real_pattern = STRBUF_INIT;
> + struct ref_filter filter;
> + const char *has_glob_specials;
> + int ret;
> +
> + if (prefixcmp(pattern, "refs/"))
> + strbuf_addstr(&real_pattern, "refs/");
> + strbuf_addstr(&real_pattern, pattern);
> +
> + has_glob_specials = strpbrk(pattern, "?*[");
Would the need for this code hopefully disappear if we take the "leading
path or fnmatch()" check? If we still need this, we probably would want
to add a has_glob_special() helper function not as a hardcoded srpbrk(),
but in terms of is_glob_special() in git-compat-util.h.
Thanks.
next prev parent reply other threads:[~2010-01-20 10:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-20 9:48 [PATCH 1/2] rev-parse --glob Ilari Liusvaara
2010-01-20 9:48 ` [PATCH 2/2] rev-parse --branches/--tags/--remotes=pattern Ilari Liusvaara
2010-01-20 10:18 ` Junio C Hamano
2010-01-21 12:51 ` Johannes Sixt
2010-01-21 13:51 ` Michael J Gruber
2010-01-21 17:27 ` Thomas Rast
2010-01-21 20:09 ` Junio C Hamano
2010-01-22 0:21 ` [PATCH] Documentation: improve description of --glob=pattern and friends Thomas Rast
2010-01-22 0:51 ` Junio C Hamano
2010-01-21 17:58 ` [PATCH 2/2] rev-parse --branches/--tags/--remotes=pattern Junio C Hamano
2010-01-20 10:17 ` Junio C Hamano [this message]
2010-01-20 11:08 ` [PATCH 1/2] rev-parse --glob Ilari Liusvaara
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vska13wt0.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=ilari.liusvaara@elisanet.fi \
/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.
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 NNTP newsgroup(s).