Mercurial > jhg
diff src/org/tmatesoft/hg/internal/PathGlobMatcher.java @ 229:1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 31 May 2011 05:23:07 +0200 |
parents | 4a948ec83980 |
children | 981f9f50bb6c |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/PathGlobMatcher.java Fri May 27 03:01:26 2011 +0200 +++ b/src/org/tmatesoft/hg/internal/PathGlobMatcher.java Tue May 31 05:23:07 2011 +0200 @@ -39,7 +39,7 @@ String[] regexp = new String[globPatterns.length]; //deliberately let fail with NPE int i = 0; for (String s : globPatterns) { - regexp[i] = glob2regexp(s); + regexp[i++] = glob2regexp(s); } try { delegate = new PathRegexpMatcher(regexp); @@ -53,21 +53,28 @@ // HgIgnore.glob2regex is similar, but IsIgnore solves slightly different task // (need to match partial paths, e.g. for glob 'bin' shall match not only 'bin' folder, but also any path below it, // which is not generally the case - private static String glob2regexp(String glob) { + private static String glob2regexp(String glob) { // FIXME TESTS NEEDED!!! int end = glob.length() - 1; - boolean needLineEndMatch = glob.charAt(end) != '*'; - while (end > 0 && glob.charAt(end) == '*') end--; // remove trailing * that are useless for Pattern.find() + if (glob.length() > 2 && glob.charAt(end) == '*' && glob.charAt(end - 1) == '.') { + end-=2; + } + boolean needLineEndMatch = true;//glob.charAt(end) != '*'; +// while (end > 0 && glob.charAt(end) == '*') end--; // remove trailing * that are useless for Pattern.find() StringBuilder sb = new StringBuilder(end*2); - if (glob.charAt(0) != '*') { +// if (glob.charAt(0) != '*') { sb.append('^'); - } +// } for (int i = 0; i <= end; i++) { char ch = glob.charAt(i); if (ch == '*') { - if (glob.charAt(i+1) == '*') { // i < end because we've stripped any trailing * earlier + if (i < end && glob.charAt(i+1) == '*') { // any char, including path segment separator sb.append(".*?"); i++; + if (i < end && glob.charAt(i+1) == '/') { + sb.append("/?"); + i++; + } } else { // just path segments sb.append("[^/]*?");