Commit ac16bd0a94e1f7254112c7585b843bdc2d0659c1

Russell Belfer 2014-04-18T15:45:59

Minor fixes Only apply LEADING_DIR pattern munging to patterns in ignore and attribute files, not to pathspecs used to select files to operate on. Also, allow internal macro definitions to be evaluated before loading all external ones (important so that external ones can make use of internal `binary` definition).

diff --git a/src/attr.c b/src/attr.c
index 6b9a3d6..05b0c1b 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -294,7 +294,7 @@ int git_attr_add_macro(
 	git_attr_rule *macro = NULL;
 	git_pool *pool;
 
-	if ((error = attr_setup(repo)) < 0)
+	if ((error = git_attr_cache__init(repo)) < 0)
 		return error;
 
 	macro = git__calloc(1, sizeof(git_attr_rule));
diff --git a/src/attr_file.c b/src/attr_file.c
index 57b4da7..d107b5a 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -545,7 +545,8 @@ int git_attr_fnmatch__parse(
 		if (--slash_count <= 0)
 			spec->flags = spec->flags & ~GIT_ATTR_FNMATCH_FULLPATH;
 	}
-	if (spec->length >= 2 &&
+	if ((spec->flags & GIT_ATTR_FNMATCH_NOLEADINGDIR) == 0 &&
+		spec->length >= 2 &&
 		pattern[spec->length - 1] == '*' &&
 		pattern[spec->length - 2] == '/') {
 		spec->length -= 2;
diff --git a/src/attr_file.h b/src/attr_file.h
index 09afa5b..e50aec0 100644
--- a/src/attr_file.h
+++ b/src/attr_file.h
@@ -31,10 +31,11 @@
 #define GIT_ATTR_FNMATCH_ALLOWNEG   (1U << 9)
 #define GIT_ATTR_FNMATCH_ALLOWMACRO (1U << 10)
 #define GIT_ATTR_FNMATCH_LEADINGDIR (1U << 11)
+#define GIT_ATTR_FNMATCH_NOLEADINGDIR (1U << 12)
 
 #define GIT_ATTR_FNMATCH__INCOMING \
-	(GIT_ATTR_FNMATCH_ALLOWSPACE | \
-	 GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO)
+	(GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | \
+	 GIT_ATTR_FNMATCH_ALLOWMACRO | GIT_ATTR_FNMATCH_NOLEADINGDIR)
 
 typedef enum {
 	GIT_ATTR_FILE__IN_MEMORY  = 0,
diff --git a/src/pathspec.c b/src/pathspec.c
index 09650de..a01d74f 100644
--- a/src/pathspec.c
+++ b/src/pathspec.c
@@ -83,7 +83,8 @@ int git_pathspec__vinit(
 		if (!match)
 			return -1;
 
-		match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG;
+		match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE |
+			GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_NOLEADINGDIR;
 
 		ret = git_attr_fnmatch__parse(match, strpool, NULL, &pattern);
 		if (ret == GIT_ENOTFOUND) {