From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 6/8] wildmatch: adjust "**" behavior
Date: Tue, 9 Oct 2012 10:09:05 +0700 [thread overview]
Message-ID: <1349752147-13314-7-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1349752147-13314-1-git-send-email-pclouds@gmail.com>
Standard wildmatch() sees consecutive asterisks as "*" that can also
match slashes. But that may be hard to explain to users as
"abc/**/def" can match "abcdef", "abcxyzdef", "abc/def", "abc/x/def",
"abc/x/y/def"...
This patch changes wildmatch so that users can do
- "**/def" -> all paths ending with file/directory 'def'
- "abc/**" - equivalent to "/abc/"
- "abc/**/def" -> "abc/x/def", "abc/x/y/def"...
- other "**" cases are downgraded to normal "*"
Basically the magic of "**" only remains if it's wrapped around by
slashes.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
t/t3070-wildmatch.sh | 2 +-
wildmatch.c | 8 +++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/t/t3070-wildmatch.sh b/t/t3070-wildmatch.sh
index bb92f8d..d320f84 100755
--- a/t/t3070-wildmatch.sh
+++ b/t/t3070-wildmatch.sh
@@ -51,7 +51,7 @@ match 1 1 ']' ']'
# Extended slash-matching features
match 0 0 'foo/baz/bar' 'foo*bar'
-match 1 0 'foo/baz/bar' 'foo**bar'
+match 0 0 'foo/baz/bar' 'foo**bar'
match 0 0 'foo/bar' 'foo?bar'
match 0 0 'foo/bar' 'foo[/]bar'
match 0 0 'foo/bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
diff --git a/wildmatch.c b/wildmatch.c
index fdb8cb1..1b39346 100644
--- a/wildmatch.c
+++ b/wildmatch.c
@@ -91,8 +91,14 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
continue;
case '*':
if (*++p == '*') {
+ const uchar *prev_p = p - 2;
while (*++p == '*') {}
- special = TRUE;
+ if ((prev_p == text || *prev_p == '/') ||
+ (*p == '\0' || *p == '/' ||
+ (p[0] == '\\' && p[1] == '/'))) {
+ special = TRUE;
+ } else
+ special = FALSE;
} else
special = FALSE;
if (*p == '\0') {
--
1.8.0.rc0.29.g1fdd78f
next prev parent reply other threads:[~2012-10-09 3:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-09 3:08 [PATCH 0/8] wildmatch take 3 Nguyễn Thái Ngọc Duy
2012-10-09 3:09 ` [PATCH 1/8] Import wildmatch from rsync Nguyễn Thái Ngọc Duy
2012-10-09 3:09 ` [PATCH 2/8] wildmatch: remove unnecessary functions Nguyễn Thái Ngọc Duy
2012-10-09 3:09 ` [PATCH 3/8] Integrate wildmatch to git Nguyễn Thái Ngọc Duy
2012-10-09 3:09 ` [PATCH 4/8] wildmatch: remove static variable force_lower_case Nguyễn Thái Ngọc Duy
2012-10-09 20:47 ` Junio C Hamano
2012-10-10 5:14 ` Nguyen Thai Ngoc Duy
2012-10-10 5:31 ` Junio C Hamano
2012-10-10 5:47 ` Nguyen Thai Ngoc Duy
2012-10-09 3:09 ` [PATCH 5/8] wildmatch: fix case-insensitive matching Nguyễn Thái Ngọc Duy
2012-10-09 3:09 ` Nguyễn Thái Ngọc Duy [this message]
2012-10-09 3:09 ` [PATCH 7/8] wildmatch: make /**/ match zero or more directories Nguyễn Thái Ngọc Duy
2012-10-09 3:09 ` [PATCH 8/8] Support "**" wildcard in .gitignore and .gitattributes Nguyễn Thái Ngọc Duy
2012-10-09 7:57 ` Michael Haggerty
2012-10-10 5:40 ` Nguyen Thai Ngoc Duy
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=1349752147-13314-7-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/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).