Mercurial > hg4j
diff src/org/tmatesoft/hg/repo/HgIgnore.java @ 289:086a326f181f
Provide public access to ignored files configuration to use in alternative file walkers
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 12 Sep 2011 14:11:45 +0200 |
parents | c8baeb813d74 |
children | 3d41dc148d14 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgIgnore.java Sat Sep 10 00:18:39 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgIgnore.java Mon Sep 12 14:11:45 2011 +0200 @@ -33,7 +33,7 @@ * @author Artem Tikhomirov * @author TMate Software Ltd. */ -public class HgIgnore { +public class HgIgnore implements Path.Matcher { private List<Pattern> entries; @@ -104,7 +104,9 @@ // // might be interesting, although looks like of no direct use in my case // @see http://stackoverflow.com/questions/1247772/is-there-an-equivalent-of-java-util-regex-for-glob-type-patterns - private String glob2regex(String line) { + // + // TODO consider refactoring to reuse in PathGlobMatcher#glob2regexp + private static String glob2regex(String line) { assert line.length() > 0; StringBuilder sb = new StringBuilder(line.length() + 10); if (line.charAt(0) != '*') { @@ -154,7 +156,10 @@ return sb.toString(); } - // TODO use PathGlobMatcher + /** + * @param path file or directory name in question + * @return <code>true</code> if matches repository configuration of ignored files. + */ public boolean isIgnored(Path path) { for (Pattern p : entries) { if (p.matcher(path).find()) { @@ -163,4 +168,12 @@ } return false; } + + /** + * A handy wrap of {@link #isIgnored(Path)} into {@link Path.Matcher}. Yields same result as {@link #isIgnored(Path)}. + * @return <code>true</code> if file is deemed ignored. + */ + public boolean accept(Path path) { + return isIgnored(path); + } }