From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] rev-parse --glob
Date: Wed, 20 Jan 2010 13:08:44 +0200 [thread overview]
Message-ID: <20100120110843.GA11343@Knoppix> (raw)
In-Reply-To: <7vska13wt0.fsf@alter.siamese.dyndns.org>
On Wed, Jan 20, 2010 at 02:17:15AM -0800, Junio C Hamano wrote:
> Ilari Liusvaara <ilari.liusvaara@elisanet.fi> writes:
>
> Looks fairly competently done. Does this mean you've abandoned the --namespace
> series? I don't mind reverting them from 'next'.
Pretty much.
> > +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.
That pattern of course has been edited before (and the namespace behavoiour
is implemented 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.
Extended globs? Except that:
'git check-ref-format refs/heads/X+\(a\|b\) ; echo $?' => 0
And '+(a|b)' is wildcard in extended glob (not expressible with standard
glob operators).
Extended globbing in gitignore would be useful as some have asked if there
is way to use regular expressions there (nope). At least extended globs
are equivalent to regular expressions in power.
> > @@ -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.
'--glob=remotes/origin' and '--glob=remotes/origin*' are not the same. The
first gets DWIMed to '--glob=refs/remotes/origin/*'. The usual case for
globbing is globbing entiere namespace (name of one remote can be prefix
of another).
-Ilari
prev parent reply other threads:[~2010-01-20 11:08 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 ` [PATCH 1/2] rev-parse --glob Junio C Hamano
2010-01-20 11:08 ` Ilari Liusvaara [this message]
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=20100120110843.GA11343@Knoppix \
--to=ilari.liusvaara@elisanet.fi \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).