* [RFC/PATCH] Making ce_path_match() more useful by accepting globs
@ 2007-11-25 20:35 Junio C Hamano
2007-11-26 19:56 ` Alex Riesen
0 siblings, 1 reply; 2+ messages in thread
From: Junio C Hamano @ 2007-11-25 20:35 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
Currently, these do not work:
git diff-files 't/*.sh'
git diff-index HEAD 'xdiff/*.c'
git update-index -g 'Documentation/howto/*.txt'
This is because ce_path_match(), the underlying function that is used to
see if a cache entry matches the set of pathspecs, only understands
leading directory match.
This teaches ce_path_match() to use the match_pathspec() used in
git-ls-files, which knows about glob patterns.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
[SORRY FOR A RESEND -- I screwed up the To: field of the previous message]
* Having two different behaviours of pathspec matching has been
bothering me for quite some time. The changes here look trivially
correct and the result passes all the tests, but this is quite close
to the core part of the system, and would benefit greatly from extra
set of eyes.
This patch does not touch the tree walker, and does not affect
diff-tree nor ancestry pruning done in the revision traversal. That
however is even closer to the core and is performance critical. It
needs to be done carefully not to descend into trees that would never
match needlessly. IOW, not today.
dir.c | 5 +++--
read-cache.c | 17 ++---------------
2 files changed, 5 insertions(+), 17 deletions(-)
diff --git a/dir.c b/dir.c
index 225fdfb..be640c9 100644
--- a/dir.c
+++ b/dir.c
@@ -98,20 +98,21 @@ int match_pathspec(const char **pathspec, const char *name, int namelen, int pre
{
int retval;
const char *match;
+ int want_seen = !!seen;
name += prefix;
namelen -= prefix;
for (retval = 0; (match = *pathspec++) != NULL; seen++) {
int how;
- if (retval && *seen == MATCHED_EXACTLY)
+ if (retval && seen && want_seen && *seen == MATCHED_EXACTLY)
continue;
match += prefix;
how = match_one(match, name, namelen);
if (how) {
if (retval < how)
retval = how;
- if (*seen < how)
+ if (want_seen && *seen < how)
*seen = how;
}
}
diff --git a/read-cache.c b/read-cache.c
index 7db5588..767464e 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -472,7 +472,7 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)
int ce_path_match(const struct cache_entry *ce, const char **pathspec)
{
- const char *match, *name;
+ const char *name;
int len;
if (!pathspec)
@@ -480,20 +480,7 @@ int ce_path_match(const struct cache_entry *ce, const char **pathspec)
len = ce_namelen(ce);
name = ce->name;
- while ((match = *pathspec++) != NULL) {
- int matchlen = strlen(match);
- if (matchlen > len)
- continue;
- if (memcmp(name, match, matchlen))
- continue;
- if (matchlen && name[matchlen-1] == '/')
- return 1;
- if (name[matchlen] == '/' || !name[matchlen])
- return 1;
- if (!matchlen)
- return 1;
- }
- return 0;
+ return !!match_pathspec(pathspec, name, len, 0, NULL);
}
/*
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC/PATCH] Making ce_path_match() more useful by accepting globs
2007-11-25 20:35 [RFC/PATCH] Making ce_path_match() more useful by accepting globs Junio C Hamano
@ 2007-11-26 19:56 ` Alex Riesen
0 siblings, 0 replies; 2+ messages in thread
From: Alex Riesen @ 2007-11-26 19:56 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Linus Torvalds, git
Junio C Hamano, Sun, Nov 25, 2007 21:35:18 +0100:
> Currently, these do not work:
>
> git diff-files 't/*.sh'
> git diff-index HEAD 'xdiff/*.c'
> git update-index -g 'Documentation/howto/*.txt'
>
> This is because ce_path_match(), the underlying function that is used to
> see if a cache entry matches the set of pathspecs, only understands
> leading directory match.
>
> This teaches ce_path_match() to use the match_pathspec() used in
> git-ls-files, which knows about glob patterns.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
> [SORRY FOR A RESEND -- I screwed up the To: field of the previous message]
>
> * Having two different behaviours of pathspec matching has been
> bothering me for quite some time. The changes here look trivially
> correct and the result passes all the tests, but this is quite close
> to the core part of the system, and would benefit greatly from extra
> set of eyes.
How about doing the same what was done with recursive directory
walker (no, I'm not confusing pathname filters with paths)? Always
have the glob expansion for porcelain (git-diff, git-log, git-show),
and add a command-line option to activate for plumbing?
(Well, the oldtimers as yourself will probably find it hard to
separate git-diff-tree from git-diff).
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-11-26 19:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-25 20:35 [RFC/PATCH] Making ce_path_match() more useful by accepting globs Junio C Hamano
2007-11-26 19:56 ` Alex Riesen
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).