Lines 217-225
Link Here
|
217 |
public static boolean isIgnored(File file){ |
217 |
public static boolean isIgnored(File file){ |
218 |
if (file == null) return true; |
218 |
if (file == null) return true; |
219 |
String name = file.getName(); |
219 |
String name = file.getName(); |
|
|
220 |
File topFile = Mercurial.getInstance().getTopmostManagedParent(file); |
220 |
|
221 |
|
|
|
222 |
// We assume that the toplevel directory should not be ignored. |
223 |
if (topFile == null || topFile.equals(file)) { |
224 |
return false; |
225 |
} |
226 |
|
221 |
Set<Pattern> patterns = new HashSet<Pattern>(5); |
227 |
Set<Pattern> patterns = new HashSet<Pattern>(5); |
222 |
addIgnorePatterns(patterns, Mercurial.getInstance().getTopmostManagedParent(file)); |
228 |
addIgnorePatterns(patterns, topFile); |
223 |
|
229 |
|
224 |
for (Iterator i = patterns.iterator(); i.hasNext();) { |
230 |
for (Iterator i = patterns.iterator(); i.hasNext();) { |
225 |
Pattern pattern = (Pattern) i.next(); |
231 |
Pattern pattern = (Pattern) i.next(); |
Lines 248-258
Link Here
|
248 |
File root = hg.getTopmostManagedParent(path); |
254 |
File root = hg.getTopmostManagedParent(path); |
249 |
if( root == null) return; |
255 |
if( root == null) return; |
250 |
File ignore = new File(root, FILENAME_HGIGNORE); |
256 |
File ignore = new File(root, FILENAME_HGIGNORE); |
251 |
if (ignore.exists()) return; |
257 |
if (ignore.exists()) { |
|
|
258 |
if (!confirmDialog(HgUtils.class, "MSG_IGNORE_FILES_TITLE", "MSG_IGNORE_FILES")) { // NOI18N |
259 |
return; |
260 |
} |
261 |
} |
252 |
|
262 |
|
253 |
try { |
263 |
try { |
254 |
fileWriter = new BufferedWriter( |
264 |
fileWriter = new BufferedWriter( |
255 |
new OutputStreamWriter(new FileOutputStream(ignore))); |
265 |
new OutputStreamWriter(new FileOutputStream(ignore, true))); |
256 |
for (String name : HG_IGNORE_FILES) { |
266 |
for (String name : HG_IGNORE_FILES) { |
257 |
fileWriter.write(name + "\n"); // NOI18N |
267 |
fileWriter.write(name + "\n"); // NOI18N |
258 |
} |
268 |
} |
Lines 292-297
Link Here
|
292 |
} |
302 |
} |
293 |
} |
303 |
} |
294 |
|
304 |
|
|
|
305 |
private static Boolean ignoreContainsSyntax(File directory) throws IOException { |
306 |
File hgIgnore = new File(directory, FILENAME_HGIGNORE); |
307 |
Boolean val = false; |
308 |
|
309 |
if (!hgIgnore.canRead()) return val; |
310 |
|
311 |
String s; |
312 |
BufferedReader r = null; |
313 |
try { |
314 |
r = new BufferedReader(new FileReader(hgIgnore)); |
315 |
while ((s = r.readLine()) != null) { |
316 |
String line = s.trim(); |
317 |
int indexOfHash = line.indexOf("#"); |
318 |
if (indexOfHash != -1) { |
319 |
if (indexOfHash == 0) |
320 |
continue; |
321 |
line = line.substring(0, indexOfHash -1); |
322 |
} |
323 |
String [] array = line.split(" "); |
324 |
if (array[0].equals("syntax:")) { |
325 |
val = true; |
326 |
break; |
327 |
} |
328 |
} |
329 |
} finally { |
330 |
if (r != null) try { r.close(); } catch (IOException e) {} |
331 |
} |
332 |
return val; |
333 |
} |
334 |
|
295 |
private static Set<String> readIgnoreEntries(File directory) throws IOException { |
335 |
private static Set<String> readIgnoreEntries(File directory) throws IOException { |
296 |
File hgIgnore = new File(directory, FILENAME_HGIGNORE); |
336 |
File hgIgnore = new File(directory, FILENAME_HGIGNORE); |
297 |
|
337 |
|
Lines 303-310
Link Here
|
303 |
try { |
343 |
try { |
304 |
r = new BufferedReader(new FileReader(hgIgnore)); |
344 |
r = new BufferedReader(new FileReader(hgIgnore)); |
305 |
while ((s = r.readLine()) != null) { |
345 |
while ((s = r.readLine()) != null) { |
306 |
entries.addAll(Arrays.asList(s.trim().split(" "))); |
346 |
String line = s.trim(); |
|
|
347 |
if (line.length() == 0) continue; |
348 |
int indexOfHash = line.indexOf("#"); |
349 |
if (indexOfHash != -1) { |
350 |
if (indexOfHash == 0) |
351 |
continue; |
352 |
line = line.substring(0, indexOfHash -1); |
307 |
} |
353 |
} |
|
|
354 |
String [] array = line.split(" "); |
355 |
if (array[0].equals("syntax:")) continue; |
356 |
entries.addAll(Arrays.asList(array)); |
357 |
} |
308 |
} finally { |
358 |
} finally { |
309 |
if (r != null) try { r.close(); } catch (IOException e) {} |
359 |
if (r != null) try { r.close(); } catch (IOException e) {} |
310 |
} |
360 |
} |
Lines 350-355
Link Here
|
350 |
* @param files an array of Files to be added |
400 |
* @param files an array of Files to be added |
351 |
*/ |
401 |
*/ |
352 |
public static void addIgnored(File directory, File[] files) throws IOException { |
402 |
public static void addIgnored(File directory, File[] files) throws IOException { |
|
|
403 |
if (ignoreContainsSyntax(directory)) { |
404 |
warningDialog(HgUtils.class, "MSG_UNABLE_TO_IGNORE_TITLE", "MSG_UNABLE_TO_IGNORE"); |
405 |
return; |
406 |
} |
353 |
Set<String> entries = readIgnoreEntries(directory); |
407 |
Set<String> entries = readIgnoreEntries(directory); |
354 |
for (File file: files) { |
408 |
for (File file: files) { |
355 |
String patterntoIgnore = computePatternToIgnore(directory, file); |
409 |
String patterntoIgnore = computePatternToIgnore(directory, file); |
Lines 366-371
Link Here
|
366 |
* @param files an array of Files to be removed |
420 |
* @param files an array of Files to be removed |
367 |
*/ |
421 |
*/ |
368 |
public static void removeIgnored(File directory, File[] files) throws IOException { |
422 |
public static void removeIgnored(File directory, File[] files) throws IOException { |
|
|
423 |
if (ignoreContainsSyntax(directory)) { |
424 |
warningDialog(HgUtils.class, "MSG_UNABLE_TO_UNIGNORE_TITLE", "MSG_UNABLE_TO_UNIGNORE"); |
425 |
return; |
426 |
} |
369 |
Set entries = readIgnoreEntries(directory); |
427 |
Set entries = readIgnoreEntries(directory); |
370 |
for (File file: files) { |
428 |
for (File file: files) { |
371 |
String patterntoIgnore = computePatternToIgnore(directory, file); |
429 |
String patterntoIgnore = computePatternToIgnore(directory, file); |