diff src/org/tmatesoft/hg/repo/HgIgnore.java @ 339:863356c2847e

Issue 16: respect glob patterns in HgIgnore for sub-directories
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 16 Nov 2011 22:42:21 +0100
parents 3d41dc148d14
children 516b817415ba
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgIgnore.java	Tue Nov 15 04:47:03 2011 +0100
+++ b/src/org/tmatesoft/hg/repo/HgIgnore.java	Wed Nov 16 22:42:21 2011 +0100
@@ -118,14 +118,7 @@
 	private static String glob2regex(String line) {
 		assert line.length() > 0;
 		StringBuilder sb = new StringBuilder(line.length() + 10);
-		if (line.charAt(0) != '*') {
-			sb.append('^'); // help avoid matcher.find() to match 'bin' pattern in the middle of the filename
-		}
 		int start = 0, end = line.length() - 1;
-		// '*' at the beginning and end of a line are useless for Pattern
-		// XXX although how about **.txt - such globs can be seen in a config, are they valid for HgIgnore?
-		while (start <= end && line.charAt(start) == '*') start++;
-		while (end > start && line.charAt(end) == '*') end--;
 
 		int inCurly = 0;
 		for (int i = start; i <= end; i++) {
@@ -170,10 +163,18 @@
 	 * @return <code>true</code> if matches repository configuration of ignored files.
 	 */
 	public boolean isIgnored(Path path) {
+		boolean isDeep = path.toString().indexOf('/') != -1;
 		for (Pattern p : entries) {
-			if (p.matcher(path).find()) {
+			if (p.matcher(path).matches()) {
 				return true;
 			}
+			if (isDeep) {
+				for (String segment : path.segments()) {
+					if (p.matcher(segment).matches()) {
+						return true;
+					}
+				}
+			}
 		}
 		return false;
 	}