comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 237:6e1373b54e9b

Allow access to working copy content through HgDataFile. Give access to repository's working dir
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 10 Jun 2011 04:35:21 +0200
parents fd845a53f53d
children df9d2854d3d6
comparison
equal deleted inserted replaced
236:883300108179 237:6e1373b54e9b
20 20
21 import java.io.File; 21 import java.io.File;
22 import java.io.IOException; 22 import java.io.IOException;
23 import java.io.StringReader; 23 import java.io.StringReader;
24 import java.lang.ref.SoftReference; 24 import java.lang.ref.SoftReference;
25 import java.nio.charset.Charset;
26 import java.util.ArrayList; 25 import java.util.ArrayList;
27 import java.util.Collections; 26 import java.util.Collections;
28 import java.util.HashMap; 27 import java.util.HashMap;
29 import java.util.List; 28 import java.util.List;
30 29
62 public static IllegalStateException notImplemented() { 61 public static IllegalStateException notImplemented() {
63 return new IllegalStateException("Not implemented"); 62 return new IllegalStateException("Not implemented");
64 } 63 }
65 64
66 private final File repoDir; // .hg folder 65 private final File repoDir; // .hg folder
66 private final File workingDir; // .hg/../
67 private final String repoLocation; 67 private final String repoLocation;
68 private final DataAccessProvider dataAccess; 68 private final DataAccessProvider dataAccess;
69 private final PathRewrite normalizePath; 69 private final PathRewrite normalizePath;
70 private final PathRewrite dataPathHelper; 70 private final PathRewrite dataPathHelper;
71 private final PathRewrite repoPathHelper; 71 private final PathRewrite repoPathHelper;
83 private HgIgnore ignore; 83 private HgIgnore ignore;
84 private ConfigFile configFile; 84 private ConfigFile configFile;
85 85
86 HgRepository(String repositoryPath) { 86 HgRepository(String repositoryPath) {
87 repoDir = null; 87 repoDir = null;
88 workingDir = null;
88 repoLocation = repositoryPath; 89 repoLocation = repositoryPath;
89 dataAccess = null; 90 dataAccess = null;
90 dataPathHelper = repoPathHelper = null; 91 dataPathHelper = repoPathHelper = null;
91 normalizePath = null; 92 normalizePath = null;
92 } 93 }
94 HgRepository(String repositoryPath, File repositoryRoot) { 95 HgRepository(String repositoryPath, File repositoryRoot) {
95 assert ".hg".equals(repositoryRoot.getName()) && repositoryRoot.isDirectory(); 96 assert ".hg".equals(repositoryRoot.getName()) && repositoryRoot.isDirectory();
96 assert repositoryPath != null; 97 assert repositoryPath != null;
97 assert repositoryRoot != null; 98 assert repositoryRoot != null;
98 repoDir = repositoryRoot; 99 repoDir = repositoryRoot;
100 workingDir = repoDir.getParentFile();
101 if (workingDir == null) {
102 throw new IllegalArgumentException(repoDir.toString());
103 }
99 repoLocation = repositoryPath; 104 repoLocation = repositoryPath;
100 dataAccess = new DataAccessProvider(); 105 dataAccess = new DataAccessProvider();
101 final boolean runningOnWindows = System.getProperty("os.name").indexOf("Windows") != -1; 106 final boolean runningOnWindows = System.getProperty("os.name").indexOf("Windows") != -1;
102 if (runningOnWindows) { 107 if (runningOnWindows) {
103 normalizePath = new PathRewrite() { 108 normalizePath = new PathRewrite() {
228 public Pair<Nodeid,Nodeid> getWorkingCopyParents() { 233 public Pair<Nodeid,Nodeid> getWorkingCopyParents() {
229 Nodeid[] p = loadDirstate().parents(); 234 Nodeid[] p = loadDirstate().parents();
230 return new Pair<Nodeid,Nodeid>(NULL == p[0] ? null : p[0], NULL == p[1] ? null : p[1]); 235 return new Pair<Nodeid,Nodeid>(NULL == p[0] ? null : p[0], NULL == p[1] ? null : p[1]);
231 } 236 }
232 237
233 // local to hide use of io.File. 238 /**
239 * @return location where user files (shall) reside
240 */
241 public File getWorkingDir() {
242 return workingDir;
243 }
244
245 // shall be of use only for internal classes
234 /*package-local*/ File getRepositoryRoot() { 246 /*package-local*/ File getRepositoryRoot() {
235 return repoDir; 247 return repoDir;
236 } 248 }
237 249
238 // XXX package-local, unless there are cases when required from outside (guess, working dir/revision walkers may hide dirstate access and no public visibility needed) 250 // XXX package-local, unless there are cases when required from outside (guess, working dir/revision walkers may hide dirstate access and no public visibility needed)
305 } 317 }
306 318
307 /*package-local*/ List<Filter> getFiltersFromWorkingDirToRepo(Path p) { 319 /*package-local*/ List<Filter> getFiltersFromWorkingDirToRepo(Path p) {
308 return instantiateFilters(p, new Filter.Options(Filter.Direction.ToRepo)); 320 return instantiateFilters(p, new Filter.Options(Filter.Direction.ToRepo));
309 } 321 }
322
323 /*package-local*/ File getFile(HgDataFile dataFile) {
324 return new File(getWorkingDir(), dataFile.getPath().toString());
325 }
310 326
311 private List<Filter> instantiateFilters(Path p, Filter.Options opts) { 327 private List<Filter> instantiateFilters(Path p, Filter.Options opts) {
312 List<Filter.Factory> factories = impl.getFilters(this, getConfigFile()); 328 List<Filter.Factory> factories = impl.getFilters(this, getConfigFile());
313 if (factories.isEmpty()) { 329 if (factories.isEmpty()) {
314 return Collections.emptyList(); 330 return Collections.emptyList();