Mercurial > jhg
diff src/org/tmatesoft/hg/repo/HgRepository.java @ 142:37a34044e6bd
More reasonable use of path normalizer and path.source
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 17 Feb 2011 05:06:07 +0100 |
parents | 8248aae33f7d |
children | acc6151b1b7a |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgRepository.java Thu Feb 17 04:08:34 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Thu Feb 17 05:06:07 2011 +0100 @@ -57,17 +57,7 @@ private final File repoDir; // .hg folder private final String repoLocation; private final DataAccessProvider dataAccess; - private final PathRewrite normalizePath = new PathRewrite() { - - public String rewrite(String path) { - // TODO handle . and .. (although unlikely to face them from GUI client) - path = path.replace('\\', '/').replace("//", "/"); - if (path.startsWith("/")) { - path = path.substring(1); - } - return path; - } - }; + private final PathRewrite normalizePath; private final PathRewrite dataPathHelper; private final PathRewrite repoPathHelper; @@ -86,6 +76,7 @@ repoLocation = repositoryPath; dataAccess = null; dataPathHelper = repoPathHelper = null; + normalizePath = null; } HgRepository(File repositoryRoot) throws IOException { @@ -93,6 +84,22 @@ repoDir = repositoryRoot; repoLocation = repositoryRoot.getParentFile().getCanonicalPath(); dataAccess = new DataAccessProvider(); + final boolean runningOnWindows = System.getProperty("os.name").indexOf("Windows") != -1; + if (runningOnWindows) { + normalizePath = new PathRewrite() { + + public String rewrite(String path) { + // TODO handle . and .. (although unlikely to face them from GUI client) + path = path.replace('\\', '/').replace("//", "/"); + if (path.startsWith("/")) { + path = path.substring(1); + } + return path; + } + }; + } else { + normalizePath = new PathRewrite.Empty(); // or strip leading slash, perhaps? + } parseRequires(); dataPathHelper = impl.buildDataFilesHelper(); repoPathHelper = impl.buildRepositoryFilesHelper(); @@ -158,7 +165,8 @@ return new HgDataFile(this, path, content); } - public PathRewrite getPathHelper() { // Really need to be public? + /* clients need to rewrite path from their FS to a repository-friendly paths, and, perhaps, vice versa*/ + public PathRewrite getToRepoPathHelper() { return normalizePath; } @@ -194,7 +202,7 @@ // FIXME not sure repository shall create walkers /*package-local*/ FileIterator createWorkingDirWalker() { File repoRoot = repoDir.getParentFile(); - Path.Source pathSrc = new Path.SimpleSource(new PathRewrite.Composite(new RelativePathRewrite(repoRoot), getPathHelper())); + Path.Source pathSrc = new Path.SimpleSource(new PathRewrite.Composite(new RelativePathRewrite(repoRoot), getToRepoPathHelper())); // Impl note: simple source is enough as files in the working dir are all unique // even if they might get reused (i.e. after FileIterator#reset() and walking once again), // path caching is better to be done in the code which knows that path are being reused