Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 202:706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Tue, 26 Apr 2011 02:50:06 +0200 |
| parents | 3a7696fb457c |
| children | 8de327242aa0 |
comparison
equal
deleted
inserted
replaced
| 201:a736f42ed75b | 202:706bcc7cfee4 |
|---|---|
| 122 } | 122 } |
| 123 | 123 |
| 124 public HgChangelog getChangelog() { | 124 public HgChangelog getChangelog() { |
| 125 if (this.changelog == null) { | 125 if (this.changelog == null) { |
| 126 String storagePath = repoPathHelper.rewrite("00changelog.i"); | 126 String storagePath = repoPathHelper.rewrite("00changelog.i"); |
| 127 RevlogStream content = resolve(Path.create(storagePath)); | 127 RevlogStream content = resolve(Path.create(storagePath), true); |
| 128 this.changelog = new HgChangelog(this, content); | 128 this.changelog = new HgChangelog(this, content); |
| 129 } | 129 } |
| 130 return this.changelog; | 130 return this.changelog; |
| 131 } | 131 } |
| 132 | 132 |
| 133 public HgManifest getManifest() { | 133 public HgManifest getManifest() { |
| 134 if (this.manifest == null) { | 134 if (this.manifest == null) { |
| 135 RevlogStream content = resolve(Path.create(repoPathHelper.rewrite("00manifest.i"))); | 135 RevlogStream content = resolve(Path.create(repoPathHelper.rewrite("00manifest.i")), true); |
| 136 this.manifest = new HgManifest(this, content); | 136 this.manifest = new HgManifest(this, content); |
| 137 } | 137 } |
| 138 return this.manifest; | 138 return this.manifest; |
| 139 } | 139 } |
| 140 | 140 |
| 152 } | 152 } |
| 153 | 153 |
| 154 public HgDataFile getFileNode(String path) { | 154 public HgDataFile getFileNode(String path) { |
| 155 String nPath = normalizePath.rewrite(path); | 155 String nPath = normalizePath.rewrite(path); |
| 156 String storagePath = dataPathHelper.rewrite(nPath); | 156 String storagePath = dataPathHelper.rewrite(nPath); |
| 157 RevlogStream content = resolve(Path.create(storagePath)); | 157 RevlogStream content = resolve(Path.create(storagePath), false); |
| 158 Path p = Path.create(nPath); | 158 Path p = Path.create(nPath); |
| 159 if (content == null) { | 159 if (content == null) { |
| 160 return new HgDataFile(this, p); | 160 return new HgDataFile(this, p); |
| 161 } | 161 } |
| 162 return new HgDataFile(this, p, content); | 162 return new HgDataFile(this, p, content); |
| 163 } | 163 } |
| 164 | 164 |
| 165 public HgDataFile getFileNode(Path path) { | 165 public HgDataFile getFileNode(Path path) { |
| 166 String storagePath = dataPathHelper.rewrite(path.toString()); | 166 String storagePath = dataPathHelper.rewrite(path.toString()); |
| 167 RevlogStream content = resolve(Path.create(storagePath)); | 167 RevlogStream content = resolve(Path.create(storagePath), false); |
| 168 // XXX no content when no file? or HgDataFile.exists() to detect that? | 168 // XXX no content when no file? or HgDataFile.exists() to detect that? |
| 169 if (content == null) { | 169 if (content == null) { |
| 170 return new HgDataFile(this, path); | 170 return new HgDataFile(this, path); |
| 171 } | 171 } |
| 172 return new HgDataFile(this, path, content); | 172 return new HgDataFile(this, path, content); |
| 218 | 218 |
| 219 /** | 219 /** |
| 220 * Perhaps, should be separate interface, like ContentLookup | 220 * Perhaps, should be separate interface, like ContentLookup |
| 221 * path - repository storage path (i.e. one usually with .i or .d) | 221 * path - repository storage path (i.e. one usually with .i or .d) |
| 222 */ | 222 */ |
| 223 /*package-local*/ RevlogStream resolve(Path path) { | 223 /*package-local*/ RevlogStream resolve(Path path, boolean shallFakeNonExistent) { |
| 224 final SoftReference<RevlogStream> ref = streamsCache.get(path); | 224 final SoftReference<RevlogStream> ref = streamsCache.get(path); |
| 225 RevlogStream cached = ref == null ? null : ref.get(); | 225 RevlogStream cached = ref == null ? null : ref.get(); |
| 226 if (cached != null) { | 226 if (cached != null) { |
| 227 return cached; | 227 return cached; |
| 228 } | 228 } |
| 229 File f = new File(repoDir, path.toString()); | 229 File f = new File(repoDir, path.toString()); |
| 230 if (f.exists()) { | 230 if (f.exists()) { |
| 231 RevlogStream s = new RevlogStream(dataAccess, f); | 231 RevlogStream s = new RevlogStream(dataAccess, f); |
| 232 streamsCache.put(path, new SoftReference<RevlogStream>(s)); | 232 streamsCache.put(path, new SoftReference<RevlogStream>(s)); |
| 233 return s; | 233 return s; |
| 234 } else { | |
| 235 if (shallFakeNonExistent) { | |
| 236 try { | |
| 237 File fake = File.createTempFile(f.getName(), null); | |
| 238 fake.deleteOnExit(); | |
| 239 return new RevlogStream(dataAccess, fake); | |
| 240 } catch (IOException ex) { | |
| 241 ex.printStackTrace(); // FIXME report in debug | |
| 242 } | |
| 243 } | |
| 234 } | 244 } |
| 235 return null; // XXX empty stream instead? | 245 return null; // XXX empty stream instead? |
| 236 } | 246 } |
| 237 | 247 |
| 238 // can't expose internal class, otherwise seems reasonable to have it in API | 248 // can't expose internal class, otherwise seems reasonable to have it in API |
