git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Michael Haggerty" <mhagger@alum.mit.edu>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 09/10] Support "**" in .gitignore and .gitattributes patterns using wildmatch()
Date: Fri,  5 Oct 2012 11:41:08 +0700	[thread overview]
Message-ID: <1349412069-627-10-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1349412069-627-1-git-send-email-pclouds@gmail.com>

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/gitignore.txt        |  3 +++
 attr.c                             |  4 +++-
 dir.c                              |  5 ++++-
 t/t0003-attributes.sh              | 17 +++++++++++++++++
 t/t3001-ls-files-others-exclude.sh | 11 +++++++++++
 5 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index c1f692a..eb81d31 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -93,6 +93,9 @@ PATTERN FORMAT
    For example, "Documentation/{asterisk}.html" matches
    "Documentation/git.html" but not "Documentation/ppc/ppc.html"
    or "tools/perf/Documentation/perf.html".
++
+Contrary to fnmatch(3), git matches "**" to anything including
+slashes, similar to rsync(1).
 
  - A leading slash matches the beginning of the pathname.
    For example, "/{asterisk}.c" matches "cat-file.c" but not
diff --git a/attr.c b/attr.c
index 1aa058e..3103c66 100644
--- a/attr.c
+++ b/attr.c
@@ -12,6 +12,7 @@
 #include "exec_cmd.h"
 #include "attr.h"
 #include "dir.h"
+#include "wildmatch.h"
 
 const char git_attr__true[] = "(builtin)true";
 const char git_attr__false[] = "\0(builtin)false";
@@ -709,7 +710,8 @@ static int path_matches(const char *pathname, int pathlen,
 	if (!namelen || prefix > namelen)
 		return 0;
 
-	return fnmatch_icase(pattern, name, FNM_PATHNAME) == 0;
+	return (ignore_case && iwildmatch(pattern, name)) ||
+		(!ignore_case && wildmatch(pattern, name));
 }
 
 static int macroexpand_one(int attr_nr, int rem);
diff --git a/dir.c b/dir.c
index c6a0275..cb78273 100644
--- a/dir.c
+++ b/dir.c
@@ -8,6 +8,7 @@
 #include "cache.h"
 #include "dir.h"
 #include "refs.h"
+#include "wildmatch.h"
 
 struct path_simplify {
 	int len;
@@ -600,7 +601,9 @@ int excluded_from_list(const char *pathname,
 			namelen -= prefix;
 		}
 
-		if (!namelen || !fnmatch_icase(exclude, name, FNM_PATHNAME))
+		if (!namelen ||
+		    ((ignore_case && iwildmatch(exclude, name)) ||
+		     (!ignore_case && wildmatch(exclude, name))))
 			return to_exclude;
 	}
 	return -1; /* undecided */
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index febc45c..6c3c554 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -232,4 +232,21 @@ test_expect_success 'bare repository: test info/attributes' '
 	attr_check subdir/a/i unspecified
 '
 
+test_expect_success '"**" test' '
+	cd .. &&
+	echo "**/f foo=bar" >.gitattributes &&
+	cat <<\EOF >expect &&
+f: foo: unspecified
+a/f: foo: bar
+a/b/f: foo: bar
+a/b/c/f: foo: bar
+EOF
+	git check-attr foo -- "f" >actual 2>err &&
+	git check-attr foo -- "a/f" >>actual 2>>err &&
+	git check-attr foo -- "a/b/f" >>actual 2>>err &&
+	git check-attr foo -- "a/b/c/f" >>actual 2>>err &&
+	test_cmp expect actual &&
+	test_line_count = 0 err
+'
+
 test_done
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index c8fe978..67c8bcf 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -214,4 +214,15 @@ test_expect_success 'subdirectory ignore (l1)' '
 	test_cmp expect actual
 '
 
+
+test_expect_success 'ls-files with "**" patterns' '
+	cat <<\EOF >expect &&
+one/a.1
+one/two/a.1
+three/a.1
+EOF
+	git ls-files -o -i --exclude "**/a.1" >actual
+	test_cmp expect actual
+'
+
 test_done
-- 
1.7.12.1.405.gb727dc9

  parent reply	other threads:[~2012-10-05  7:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-05  4:40 [PATCH 00/10] nd/wildmatch take 2 Nguyễn Thái Ngọc Duy
2012-10-05  4:41 ` [PATCH 01/10] gitignore: make pattern parsing code a separate function Nguyễn Thái Ngọc Duy
2012-10-05  4:41 ` [PATCH 02/10] attr: avoid strlen() on every match Nguyễn Thái Ngọc Duy
2012-10-05  4:41 ` [PATCH 03/10] attr: avoid searching for basename " Nguyễn Thái Ngọc Duy
2012-10-05  4:41 ` [PATCH 04/10] attr: more matching optimizations from .gitignore Nguyễn Thái Ngọc Duy
2012-10-05 18:48   ` Junio C Hamano
2012-10-06  5:02     ` Nguyen Thai Ngoc Duy
2012-10-06  5:36       ` Junio C Hamano
2012-10-06  6:43         ` Nguyen Thai Ngoc Duy
2012-10-06  6:59           ` Junio C Hamano
2012-10-08  3:26     ` Nguyen Thai Ngoc Duy
2012-10-08 15:50       ` Junio C Hamano
2012-10-05  4:41 ` [PATCH 05/10] Import wildmatch from rsync Nguyễn Thái Ngọc Duy
2012-10-05 10:30   ` Peter Krefting
2012-10-05 11:18     ` Nguyen Thai Ngoc Duy
2012-10-05  4:41 ` [PATCH 06/10] wildmatch: remove static variable force_lower_case Nguyễn Thái Ngọc Duy
2012-10-05  4:41 ` [PATCH 07/10] wildmatch: fix case-insensitive matching Nguyễn Thái Ngọc Duy
2012-10-05  4:41 ` [PATCH 08/10] Integrate wildmatch to git Nguyễn Thái Ngọc Duy
2012-10-05 21:20   ` Thiago Farina
2012-10-06  9:25     ` Joachim Schmitz
2012-10-05  4:41 ` Nguyễn Thái Ngọc Duy [this message]
2012-10-05  4:41 ` [PATCH 10/10] gitignore: forbid "abc**def" Nguyễn Thái Ngọc 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=1349412069-627-10-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mhagger@alum.mit.edu \
    /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).