Mercurial > jhg
diff src/org/tmatesoft/hg/repo/HgIgnore.java @ 342:516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 18 Nov 2011 05:10:33 +0100 |
parents | 863356c2847e |
children | 58016b1b8554 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgIgnore.java Thu Nov 17 07:04:58 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgIgnore.java Fri Nov 18 05:10:33 2011 +0100 @@ -90,6 +90,10 @@ // hence no special treatment of Windows path // however, own attempts make me think '\' on Windows are not treated as escapes line = glob2regex(line); + } else { + assert "regexp".equals(syntax); + // regular expression patterns need not match start of the line unless demanded explicitly + line = line.charAt(0) == '^' ? line : ".*" + line; } try { result.add(Pattern.compile(line)); // case-sensitive @@ -119,6 +123,7 @@ assert line.length() > 0; StringBuilder sb = new StringBuilder(line.length() + 10); int start = 0, end = line.length() - 1; + sb.append("(?:|.*/)"); // glob patterns shall match file in any directory int inCurly = 0; for (int i = start; i <= end; i++) { @@ -163,17 +168,18 @@ * @return <code>true</code> if matches repository configuration of ignored files. */ public boolean isIgnored(Path path) { - boolean isDeep = path.toString().indexOf('/') != -1; + String ps = path.toString(); for (Pattern p : entries) { - if (p.matcher(path).matches()) { + int x = ps.indexOf('/'); // reset for each pattern + if (p.matcher(ps).find()) { return true; } - if (isDeep) { - for (String segment : path.segments()) { - if (p.matcher(segment).matches()) { - return true; - } + while (x != -1 && x+1 != ps.length() /*skip very last segment not to check complete string twice*/) { + String fragment = ps.substring(0, x); + if (p.matcher(fragment).matches()) { + return true; } + x = ps.indexOf('/', x+1); } } return false;