comparison src/org/tmatesoft/hg/repo/HgIgnore.java @ 114:46291ec605a0

Filters to read and initialize according to configuration files
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 03 Feb 2011 22:13:55 +0100
parents a3a2e5deb320
children 8248aae33f7d
comparison
equal deleted inserted replaced
113:67ae317408c9 114:46291ec605a0
91 assert line.length() > 0; 91 assert line.length() > 0;
92 StringBuilder sb = new StringBuilder(line.length() + 10); 92 StringBuilder sb = new StringBuilder(line.length() + 10);
93 sb.append('^'); // help avoid matcher.find() to match 'bin' pattern in the middle of the filename 93 sb.append('^'); // help avoid matcher.find() to match 'bin' pattern in the middle of the filename
94 int start = 0, end = line.length() - 1; 94 int start = 0, end = line.length() - 1;
95 // '*' at the beginning and end of a line are useless for Pattern 95 // '*' at the beginning and end of a line are useless for Pattern
96 // XXX although how about **.txt - such globs can be seen in a config, are they valid for HgIgnore?
96 while (start <= end && line.charAt(start) == '*') start++; 97 while (start <= end && line.charAt(start) == '*') start++;
97 while (end > start && line.charAt(end) == '*') end--; 98 while (end > start && line.charAt(end) == '*') end--;
98 99
99 for (int i = start; i <= end; i++) { 100 for (int i = start; i <= end; i++) {
100 char ch = line.charAt(i); 101 char ch = line.charAt(i);
116 sb.append(ch); 117 sb.append(ch);
117 } 118 }
118 return sb.toString(); 119 return sb.toString();
119 } 120 }
120 121
122 // TODO use Path and PathGlobMatcher
121 public boolean isIgnored(String path) { 123 public boolean isIgnored(String path) {
122 for (Pattern p : entries) { 124 for (Pattern p : entries) {
123 if (p.matcher(path).find()) { 125 if (p.matcher(path).find()) {
124 return true; 126 return true;
125 } 127 }