Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 292:a415fe296a50
Refactor PathRewrite to accept any char sequence, not only string
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 14 Sep 2011 02:16:19 +0200 |
parents | 086a326f181f |
children | 981f9f50bb6c |
comparison
equal
deleted
inserted
replaced
291:1483e57541ef | 292:a415fe296a50 |
---|---|
30 import org.tmatesoft.hg.internal.ByteArrayChannel; | 30 import org.tmatesoft.hg.internal.ByteArrayChannel; |
31 import org.tmatesoft.hg.internal.ConfigFile; | 31 import org.tmatesoft.hg.internal.ConfigFile; |
32 import org.tmatesoft.hg.internal.DataAccessProvider; | 32 import org.tmatesoft.hg.internal.DataAccessProvider; |
33 import org.tmatesoft.hg.internal.Experimental; | 33 import org.tmatesoft.hg.internal.Experimental; |
34 import org.tmatesoft.hg.internal.Filter; | 34 import org.tmatesoft.hg.internal.Filter; |
35 import org.tmatesoft.hg.internal.Internals; | |
35 import org.tmatesoft.hg.internal.RequiresFile; | 36 import org.tmatesoft.hg.internal.RequiresFile; |
36 import org.tmatesoft.hg.internal.RevlogStream; | 37 import org.tmatesoft.hg.internal.RevlogStream; |
37 import org.tmatesoft.hg.internal.SubrepoManager; | 38 import org.tmatesoft.hg.internal.SubrepoManager; |
38 import org.tmatesoft.hg.util.CancelledException; | 39 import org.tmatesoft.hg.util.CancelledException; |
39 import org.tmatesoft.hg.util.Pair; | 40 import org.tmatesoft.hg.util.Pair; |
69 private final String repoLocation; | 70 private final String repoLocation; |
70 private final DataAccessProvider dataAccess; | 71 private final DataAccessProvider dataAccess; |
71 private final PathRewrite normalizePath; | 72 private final PathRewrite normalizePath; |
72 private final PathRewrite dataPathHelper; | 73 private final PathRewrite dataPathHelper; |
73 private final PathRewrite repoPathHelper; | 74 private final PathRewrite repoPathHelper; |
75 private final boolean isCaseSensitiveFileSystem; | |
74 | 76 |
75 private HgChangelog changelog; | 77 private HgChangelog changelog; |
76 private HgManifest manifest; | 78 private HgManifest manifest; |
77 private HgTags tags; | 79 private HgTags tags; |
78 private HgBranches branches; | 80 private HgBranches branches; |
91 workingDir = null; | 93 workingDir = null; |
92 repoLocation = repositoryPath; | 94 repoLocation = repositoryPath; |
93 dataAccess = null; | 95 dataAccess = null; |
94 dataPathHelper = repoPathHelper = null; | 96 dataPathHelper = repoPathHelper = null; |
95 normalizePath = null; | 97 normalizePath = null; |
98 isCaseSensitiveFileSystem = !Internals.runningOnWindows(); | |
96 } | 99 } |
97 | 100 |
98 HgRepository(String repositoryPath, File repositoryRoot) { | 101 HgRepository(String repositoryPath, File repositoryRoot) { |
99 assert ".hg".equals(repositoryRoot.getName()) && repositoryRoot.isDirectory(); | 102 assert ".hg".equals(repositoryRoot.getName()) && repositoryRoot.isDirectory(); |
100 assert repositoryPath != null; | 103 assert repositoryPath != null; |
104 if (workingDir == null) { | 107 if (workingDir == null) { |
105 throw new IllegalArgumentException(repoDir.toString()); | 108 throw new IllegalArgumentException(repoDir.toString()); |
106 } | 109 } |
107 repoLocation = repositoryPath; | 110 repoLocation = repositoryPath; |
108 dataAccess = new DataAccessProvider(); | 111 dataAccess = new DataAccessProvider(); |
109 final boolean runningOnWindows = System.getProperty("os.name").indexOf("Windows") != -1; | 112 final boolean runningOnWindows = Internals.runningOnWindows(); |
113 isCaseSensitiveFileSystem = !runningOnWindows; | |
110 if (runningOnWindows) { | 114 if (runningOnWindows) { |
111 normalizePath = new PathRewrite() { | 115 normalizePath = new PathRewrite() { |
112 | 116 |
113 public String rewrite(String path) { | 117 public CharSequence rewrite(CharSequence p) { |
114 // TODO handle . and .. (although unlikely to face them from GUI client) | 118 // TODO handle . and .. (although unlikely to face them from GUI client) |
119 String path = p.toString(); | |
115 path = path.replace('\\', '/').replace("//", "/"); | 120 path = path.replace('\\', '/').replace("//", "/"); |
116 if (path.startsWith("/")) { | 121 if (path.startsWith("/")) { |
117 path = path.substring(1); | 122 path = path.substring(1); |
118 } | 123 } |
119 return path; | 124 return path; |
140 return repoDir == null || !repoDir.exists() || !repoDir.isDirectory(); | 145 return repoDir == null || !repoDir.exists() || !repoDir.isDirectory(); |
141 } | 146 } |
142 | 147 |
143 public HgChangelog getChangelog() { | 148 public HgChangelog getChangelog() { |
144 if (this.changelog == null) { | 149 if (this.changelog == null) { |
145 String storagePath = repoPathHelper.rewrite("00changelog.i"); | 150 CharSequence storagePath = repoPathHelper.rewrite("00changelog.i"); |
146 RevlogStream content = resolve(Path.create(storagePath), true); | 151 RevlogStream content = resolve(Path.create(storagePath), true); |
147 this.changelog = new HgChangelog(this, content); | 152 this.changelog = new HgChangelog(this, content); |
148 } | 153 } |
149 return this.changelog; | 154 return this.changelog; |
150 } | 155 } |
205 } | 210 } |
206 return mergeState; | 211 return mergeState; |
207 } | 212 } |
208 | 213 |
209 public HgDataFile getFileNode(String path) { | 214 public HgDataFile getFileNode(String path) { |
210 String nPath = normalizePath.rewrite(path); | 215 CharSequence nPath = normalizePath.rewrite(path); |
211 String storagePath = dataPathHelper.rewrite(nPath); | 216 CharSequence storagePath = dataPathHelper.rewrite(nPath); |
212 RevlogStream content = resolve(Path.create(storagePath), false); | 217 RevlogStream content = resolve(Path.create(storagePath), false); |
213 Path p = Path.create(nPath); | 218 Path p = Path.create(nPath); |
214 if (content == null) { | 219 if (content == null) { |
215 return new HgDataFile(this, p); | 220 return new HgDataFile(this, p); |
216 } | 221 } |
217 return new HgDataFile(this, p, content); | 222 return new HgDataFile(this, p, content); |
218 } | 223 } |
219 | 224 |
220 public HgDataFile getFileNode(Path path) { | 225 public HgDataFile getFileNode(Path path) { |
221 String storagePath = dataPathHelper.rewrite(path.toString()); | 226 CharSequence storagePath = dataPathHelper.rewrite(path.toString()); |
222 RevlogStream content = resolve(Path.create(storagePath), false); | 227 RevlogStream content = resolve(Path.create(storagePath), false); |
223 // XXX no content when no file? or HgDataFile.exists() to detect that? | 228 // XXX no content when no file? or HgDataFile.exists() to detect that? |
224 if (content == null) { | 229 if (content == null) { |
225 return new HgDataFile(this, path); | 230 return new HgDataFile(this, path); |
226 } | 231 } |
271 } | 276 } |
272 | 277 |
273 // 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) | 278 // 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) |
274 // XXX consider passing Path pool or factory to produce (shared) Path instead of Strings | 279 // XXX consider passing Path pool or factory to produce (shared) Path instead of Strings |
275 /*package-local*/ final HgDirstate loadDirstate(PathPool pathPool) { | 280 /*package-local*/ final HgDirstate loadDirstate(PathPool pathPool) { |
276 return new HgDirstate(this, new File(repoDir, "dirstate"), pathPool); | 281 PathRewrite canonicalPath = null; |
282 if (!isCaseSensitiveFileSystem) { | |
283 canonicalPath = new PathRewrite() { | |
284 | |
285 public CharSequence rewrite(CharSequence path) { | |
286 return path.toString().toLowerCase(); | |
287 } | |
288 }; | |
289 } | |
290 return new HgDirstate(this, new File(repoDir, "dirstate"), pathPool, canonicalPath); | |
277 } | 291 } |
278 | 292 |
279 /** | 293 /** |
280 * Access to configured set of ignored files. | 294 * Access to configured set of ignored files. |
281 * @see HgIgnore#isIgnored(Path) | 295 * @see HgIgnore#isIgnored(Path) |