Mercurial > hg4j
changeset 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 | b11f6a08f748 |
children | 8faad08c709b |
files | src/org/tmatesoft/hg/repo/HgIgnore.java src/org/tmatesoft/hg/repo/HgRepository.java |
diffstat | 2 files changed, 21 insertions(+), 5 deletions(-) [+] |
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); + } }
--- a/src/org/tmatesoft/hg/repo/HgRepository.java Sat Sep 10 00:18:39 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Mon Sep 12 14:11:45 2011 +0200 @@ -276,8 +276,11 @@ return new HgDirstate(this, new File(repoDir, "dirstate"), pathPool); } - // package-local, see comment for loadDirstate - /*package-local*/ final HgIgnore getIgnore() { + /** + * Access to configured set of ignored files. + * @see HgIgnore#isIgnored(Path) + */ + public HgIgnore getIgnore() { // TODO read config for additional locations if (ignore == null) { ignore = new HgIgnore();