Mercurial > hg4j
changeset 133:4a948ec83980
core.Path to util.Path as it's not Hg repo dependant
line wrap: on
line diff
--- a/cmdline/org/tmatesoft/hg/console/Log.java Wed Feb 16 20:56:43 2011 +0100 +++ b/cmdline/org/tmatesoft/hg/console/Log.java Wed Feb 16 20:59:39 2011 +0100 @@ -24,10 +24,10 @@ import org.tmatesoft.hg.core.HgLogCommand; import org.tmatesoft.hg.core.HgLogCommand.FileRevision; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.repo.HgChangelog; import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.Path; /**
--- a/cmdline/org/tmatesoft/hg/console/Manifest.java Wed Feb 16 20:56:43 2011 +0100 +++ b/cmdline/org/tmatesoft/hg/console/Manifest.java Wed Feb 16 20:59:39 2011 +0100 @@ -20,10 +20,10 @@ import org.tmatesoft.hg.core.HgLogCommand.FileRevision; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.core.HgManifestCommand; import org.tmatesoft.hg.repo.HgManifest; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.Path; /**
--- a/cmdline/org/tmatesoft/hg/console/Status.java Wed Feb 16 20:56:43 2011 +0100 +++ b/cmdline/org/tmatesoft/hg/console/Status.java Wed Feb 16 20:59:39 2011 +0100 @@ -24,7 +24,6 @@ import java.util.Map; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.repo.HgStatusInspector; @@ -32,6 +31,7 @@ import org.tmatesoft.hg.repo.HgStatusCollector; import org.tmatesoft.hg.repo.HgStatusCollector.Record; import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; +import org.tmatesoft.hg.util.Path; /** *
--- a/src/org/tmatesoft/hg/core/HgCatCommand.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/core/HgCatCommand.java Wed Feb 16 20:59:39 2011 +0100 @@ -24,6 +24,7 @@ import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.util.ByteChannel; +import org.tmatesoft.hg.util.Path; /** * Command to obtain content of a file, 'hg cat' counterpart.
--- a/src/org/tmatesoft/hg/core/HgChangeset.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/core/HgChangeset.java Wed Feb 16 20:59:39 2011 +0100 @@ -24,6 +24,7 @@ import org.tmatesoft.hg.repo.HgChangelog.Changeset; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.repo.HgStatusCollector; +import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathPool;
--- a/src/org/tmatesoft/hg/core/HgLogCommand.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/core/HgLogCommand.java Wed Feb 16 20:59:39 2011 +0100 @@ -31,6 +31,7 @@ import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.repo.HgStatusCollector; +import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathPool;
--- a/src/org/tmatesoft/hg/core/HgManifestCommand.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/core/HgManifestCommand.java Wed Feb 16 20:59:39 2011 +0100 @@ -26,6 +26,7 @@ import org.tmatesoft.hg.core.HgLogCommand.FileRevision; import org.tmatesoft.hg.repo.HgManifest; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathPool;
--- a/src/org/tmatesoft/hg/core/HgStatus.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/core/HgStatus.java Wed Feb 16 20:59:39 2011 +0100 @@ -20,6 +20,7 @@ import org.tmatesoft.hg.internal.ChangelogHelper; import org.tmatesoft.hg.repo.HgChangelog.Changeset; +import org.tmatesoft.hg.util.Path; /** * Repository file status and extra handy information.
--- a/src/org/tmatesoft/hg/core/HgStatusCommand.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/core/HgStatusCommand.java Wed Feb 16 20:59:39 2011 +0100 @@ -21,12 +21,13 @@ import java.util.ConcurrentModificationException; -import org.tmatesoft.hg.core.Path.Matcher; import org.tmatesoft.hg.internal.ChangelogHelper; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.repo.HgStatusCollector; import org.tmatesoft.hg.repo.HgStatusInspector; import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; +import org.tmatesoft.hg.util.Path; +import org.tmatesoft.hg.util.Path.Matcher; /** * Command to obtain file status information, 'hg status' counterpart.
--- a/src/org/tmatesoft/hg/core/Path.java Wed Feb 16 20:56:43 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2011 TMate Software Ltd - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For information on how to redistribute this software under - * the terms of a license other than GNU General Public License - * contact TMate Software at support@hg4j.com - */ -package org.tmatesoft.hg.core; - -/** - * Identify repository files (not String nor io.File). Convenient for pattern matching. Memory-friendly. - * - * @author Artem Tikhomirov - * @author TMate Software Ltd. - */ -public final class Path implements CharSequence, Comparable<Path>/*Cloneable? - although clone for paths make no sense*/{ -// private String[] segments; -// private int flags; // dir, unparsed - private String path; - - /*package-local*/Path(String p) { - path = p; - } - - public int length() { - return path.length(); - } - - public char charAt(int index) { - return path.charAt(index); - } - - public CharSequence subSequence(int start, int end) { - // new Path if start-end matches boundaries of any subpath - return path.substring(start, end); - } - - @Override - public String toString() { - return path; // CharSequence demands toString() impl - } - - public int compareTo(Path o) { - return path.compareTo(o.path); - } - - @Override - public boolean equals(Object obj) { - if (obj != null && getClass() == obj.getClass()) { - return this == obj || path.equals(((Path) obj).path); - } - return false; - } - @Override - public int hashCode() { - return path.hashCode(); - } - - public static Path create(String path) { - if (path == null) { - throw new IllegalArgumentException(); - } - if (path.indexOf('\\') != -1) { - throw new IllegalArgumentException(); - } - Path rv = new Path(path); - return rv; - } - public interface Matcher { - public boolean accept(Path path); - } -}
--- a/src/org/tmatesoft/hg/internal/ChangelogHelper.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/ChangelogHelper.java Wed Feb 16 20:59:39 2011 +0100 @@ -18,11 +18,11 @@ import java.util.TreeMap; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.repo.HgChangelog.Changeset; import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgInternals; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.Path; /** *
--- a/src/org/tmatesoft/hg/internal/Filter.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/Filter.java Wed Feb 16 20:59:39 2011 +0100 @@ -18,8 +18,8 @@ import java.nio.ByteBuffer; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.Path; /** *
--- a/src/org/tmatesoft/hg/internal/KeywordFilter.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/KeywordFilter.java Wed Feb 16 20:59:39 2011 +0100 @@ -21,9 +21,9 @@ import java.util.Map; import java.util.TreeMap; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.repo.HgChangelog.Changeset; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.Path; /** *
--- a/src/org/tmatesoft/hg/internal/NewlineFilter.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/NewlineFilter.java Wed Feb 16 20:59:39 2011 +0100 @@ -27,9 +27,9 @@ import java.util.ArrayList; import java.util.Map; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.repo.HgInternals; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.Path; /** *
--- a/src/org/tmatesoft/hg/internal/PathGlobMatcher.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/PathGlobMatcher.java Wed Feb 16 20:59:39 2011 +0100 @@ -18,7 +18,7 @@ import java.util.regex.PatternSyntaxException; -import org.tmatesoft.hg.core.Path; +import org.tmatesoft.hg.util.Path; /** *
--- a/src/org/tmatesoft/hg/internal/PathRegexpMatcher.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/PathRegexpMatcher.java Wed Feb 16 20:59:39 2011 +0100 @@ -19,8 +19,8 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import org.tmatesoft.hg.core.Path; -import org.tmatesoft.hg.core.Path.Matcher; +import org.tmatesoft.hg.util.Path; +import org.tmatesoft.hg.util.Path.Matcher; /** *
--- a/src/org/tmatesoft/hg/repo/HgDataFile.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgDataFile.java Wed Feb 16 20:59:39 2011 +0100 @@ -24,10 +24,10 @@ import java.util.TreeMap; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.internal.FilterByteChannel; import org.tmatesoft.hg.internal.RevlogStream; import org.tmatesoft.hg.util.ByteChannel; +import org.tmatesoft.hg.util.Path;
--- a/src/org/tmatesoft/hg/repo/HgRepository.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Wed Feb 16 20:59:39 2011 +0100 @@ -24,13 +24,13 @@ import java.util.HashMap; import java.util.List; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.internal.ConfigFile; import org.tmatesoft.hg.internal.DataAccessProvider; import org.tmatesoft.hg.internal.Filter; import org.tmatesoft.hg.internal.RequiresFile; import org.tmatesoft.hg.internal.RevlogStream; import org.tmatesoft.hg.util.FileWalker; +import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathRewrite;
--- a/src/org/tmatesoft/hg/repo/HgStatusCollector.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgStatusCollector.java Wed Feb 16 20:59:39 2011 +0100 @@ -29,7 +29,7 @@ import java.util.TreeSet; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.core.Path; +import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathPool; import org.tmatesoft.hg.util.PathRewrite;
--- a/src/org/tmatesoft/hg/repo/HgStatusInspector.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgStatusInspector.java Wed Feb 16 20:59:39 2011 +0100 @@ -16,7 +16,7 @@ */ package org.tmatesoft.hg.repo; -import org.tmatesoft.hg.core.Path; +import org.tmatesoft.hg.util.Path; /** * Callback to get file status information
--- a/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Wed Feb 16 20:59:39 2011 +0100 @@ -31,11 +31,11 @@ import java.util.TreeSet; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.internal.FilterByteChannel; import org.tmatesoft.hg.repo.HgStatusCollector.ManifestRevisionInspector; import org.tmatesoft.hg.util.ByteChannel; import org.tmatesoft.hg.util.FileWalker; +import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathPool; import org.tmatesoft.hg.util.PathRewrite;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/tmatesoft/hg/util/Path.java Wed Feb 16 20:59:39 2011 +0100 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2011 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@hg4j.com + */ +package org.tmatesoft.hg.util; + +/** + * Identify repository files (not String nor io.File). Convenient for pattern matching. Memory-friendly. + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public final class Path implements CharSequence, Comparable<Path>/*Cloneable? - although clone for paths make no sense*/{ +// private String[] segments; +// private int flags; // dir, unparsed + private String path; + + /*package-local*/Path(String p) { + path = p; + } + + public int length() { + return path.length(); + } + + public char charAt(int index) { + return path.charAt(index); + } + + public CharSequence subSequence(int start, int end) { + // new Path if start-end matches boundaries of any subpath + return path.substring(start, end); + } + + @Override + public String toString() { + return path; // CharSequence demands toString() impl + } + + public int compareTo(Path o) { + return path.compareTo(o.path); + } + + @Override + public boolean equals(Object obj) { + if (obj != null && getClass() == obj.getClass()) { + return this == obj || path.equals(((Path) obj).path); + } + return false; + } + @Override + public int hashCode() { + return path.hashCode(); + } + + public static Path create(String path) { + if (path == null) { + throw new IllegalArgumentException(); + } + if (path.indexOf('\\') != -1) { + throw new IllegalArgumentException(); + } + Path rv = new Path(path); + return rv; + } + + /** + * Path filter. + */ + public interface Matcher { + public boolean accept(Path path); + } +}
--- a/src/org/tmatesoft/hg/util/PathPool.java Wed Feb 16 20:56:43 2011 +0100 +++ b/src/org/tmatesoft/hg/util/PathPool.java Wed Feb 16 20:59:39 2011 +0100 @@ -19,7 +19,6 @@ import java.lang.ref.SoftReference; import java.util.WeakHashMap; -import org.tmatesoft.hg.core.Path; /** *
--- a/test/org/tmatesoft/hg/test/ManifestOutputParser.java Wed Feb 16 20:56:43 2011 +0100 +++ b/test/org/tmatesoft/hg/test/ManifestOutputParser.java Wed Feb 16 20:59:39 2011 +0100 @@ -22,7 +22,7 @@ import java.util.regex.Pattern; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.core.Path; +import org.tmatesoft.hg.util.Path; /**
--- a/test/org/tmatesoft/hg/test/StatusOutputParser.java Wed Feb 16 20:56:43 2011 +0100 +++ b/test/org/tmatesoft/hg/test/StatusOutputParser.java Wed Feb 16 20:59:39 2011 +0100 @@ -23,8 +23,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.repo.HgStatusCollector; +import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathPool; import org.tmatesoft.hg.util.PathRewrite;
--- a/test/org/tmatesoft/hg/test/TestHistory.java Wed Feb 16 20:56:43 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestHistory.java Wed Feb 16 20:59:39 2011 +0100 @@ -33,10 +33,10 @@ import org.tmatesoft.hg.core.HgLogCommand.CollectHandler; import org.tmatesoft.hg.core.HgLogCommand.FileHistoryHandler; import org.tmatesoft.hg.core.HgLogCommand.FileRevision; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.test.LogOutputParser.Record; +import org.tmatesoft.hg.util.Path; /**
--- a/test/org/tmatesoft/hg/test/TestManifest.java Wed Feb 16 20:56:43 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestManifest.java Wed Feb 16 20:59:39 2011 +0100 @@ -32,10 +32,10 @@ import org.junit.Test; import org.tmatesoft.hg.core.HgLogCommand.FileRevision; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.core.HgManifestCommand; import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.Path; /**
--- a/test/org/tmatesoft/hg/test/TestStatus.java Wed Feb 16 20:56:43 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestStatus.java Wed Feb 16 20:59:39 2011 +0100 @@ -33,12 +33,12 @@ import org.junit.Rule; import org.junit.Test; import org.tmatesoft.hg.core.HgStatus; -import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.core.HgStatusCommand; import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.repo.HgStatusCollector; import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; +import org.tmatesoft.hg.util.Path; /**