comparison 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
comparison
equal deleted inserted replaced
338:3cfa4d908fc9 339:863356c2847e
116 // 116 //
117 // TODO consider refactoring to reuse in PathGlobMatcher#glob2regexp 117 // TODO consider refactoring to reuse in PathGlobMatcher#glob2regexp
118 private static String glob2regex(String line) { 118 private static String glob2regex(String line) {
119 assert line.length() > 0; 119 assert line.length() > 0;
120 StringBuilder sb = new StringBuilder(line.length() + 10); 120 StringBuilder sb = new StringBuilder(line.length() + 10);
121 if (line.charAt(0) != '*') {
122 sb.append('^'); // help avoid matcher.find() to match 'bin' pattern in the middle of the filename
123 }
124 int start = 0, end = line.length() - 1; 121 int start = 0, end = line.length() - 1;
125 // '*' at the beginning and end of a line are useless for Pattern
126 // XXX although how about **.txt - such globs can be seen in a config, are they valid for HgIgnore?
127 while (start <= end && line.charAt(start) == '*') start++;
128 while (end > start && line.charAt(end) == '*') end--;
129 122
130 int inCurly = 0; 123 int inCurly = 0;
131 for (int i = start; i <= end; i++) { 124 for (int i = start; i <= end; i++) {
132 char ch = line.charAt(i); 125 char ch = line.charAt(i);
133 if (ch == '.' || ch == '\\') { 126 if (ch == '.' || ch == '\\') {
168 /** 161 /**
169 * @param path file or directory name in question 162 * @param path file or directory name in question
170 * @return <code>true</code> if matches repository configuration of ignored files. 163 * @return <code>true</code> if matches repository configuration of ignored files.
171 */ 164 */
172 public boolean isIgnored(Path path) { 165 public boolean isIgnored(Path path) {
166 boolean isDeep = path.toString().indexOf('/') != -1;
173 for (Pattern p : entries) { 167 for (Pattern p : entries) {
174 if (p.matcher(path).find()) { 168 if (p.matcher(path).matches()) {
175 return true; 169 return true;
170 }
171 if (isDeep) {
172 for (String segment : path.segments()) {
173 if (p.matcher(segment).matches()) {
174 return true;
175 }
176 }
176 } 177 }
177 } 178 }
178 return false; 179 return false;
179 } 180 }
180 181