Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 539:9edfd5a223b8
Commit: handle empty repository case
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 13 Feb 2013 18:44:58 +0100 |
parents | 2f9ed6bcefa2 |
children | e4ee4bf4c7d0 |
comparison
equal
deleted
inserted
replaced
538:dd4f6311af52 | 539:9edfd5a223b8 |
---|---|
182 } | 182 } |
183 | 183 |
184 public HgChangelog getChangelog() { | 184 public HgChangelog getChangelog() { |
185 if (changelog == null) { | 185 if (changelog == null) { |
186 File chlogFile = impl.getFileFromStoreDir("00changelog.i"); | 186 File chlogFile = impl.getFileFromStoreDir("00changelog.i"); |
187 if (!chlogFile.exists()) { | |
188 // fake its existence | |
189 chlogFile = fakeNonExistentFile(chlogFile); | |
190 } | |
191 RevlogStream content = new RevlogStream(impl.getDataAccess(), chlogFile); | 187 RevlogStream content = new RevlogStream(impl.getDataAccess(), chlogFile); |
192 changelog = new HgChangelog(this, content); | 188 changelog = new HgChangelog(this, content); |
193 } | 189 } |
194 return changelog; | 190 return changelog; |
195 } | 191 } |
196 | 192 |
197 public HgManifest getManifest() { | 193 public HgManifest getManifest() { |
198 if (manifest == null) { | 194 if (manifest == null) { |
199 File manifestFile = impl.getFileFromStoreDir("00manifest.i"); | 195 File manifestFile = impl.getFileFromStoreDir("00manifest.i"); |
200 if (!manifestFile.exists()) { | |
201 manifestFile = fakeNonExistentFile(manifestFile); | |
202 } | |
203 RevlogStream content = new RevlogStream(impl.getDataAccess(), manifestFile); | 196 RevlogStream content = new RevlogStream(impl.getDataAccess(), manifestFile); |
204 manifest = new HgManifest(this, content, impl.buildFileNameEncodingHelper()); | 197 manifest = new HgManifest(this, content, impl.buildFileNameEncodingHelper()); |
205 } | 198 } |
206 return manifest; | 199 return manifest; |
207 } | 200 } |
510 return s; | 503 return s; |
511 } | 504 } |
512 return null; | 505 return null; |
513 } | 506 } |
514 | 507 |
515 private File fakeNonExistentFile(File expected) throws HgInvalidFileException { | 508 /*package-local*/ RevlogStream createStoreFile(Path path) throws HgInvalidControlFileException { |
509 File f = impl.getFileFromDataDir(path); | |
516 try { | 510 try { |
517 File fake = File.createTempFile(expected.getName(), null); | 511 if (!f.exists()) { |
518 fake.deleteOnExit(); | 512 f.getParentFile().mkdirs(); |
519 return fake; | 513 f.createNewFile(); |
514 } | |
515 RevlogStream s = new RevlogStream(impl.getDataAccess(), f); | |
516 if (impl.shallCacheRevlogs()) { | |
517 streamsCache.put(path, new SoftReference<RevlogStream>(s)); | |
518 } | |
519 return s; | |
520 } catch (IOException ex) { | 520 } catch (IOException ex) { |
521 getSessionContext().getLog().dump(getClass(), Info, ex, null); | 521 throw new HgInvalidControlFileException("Can't create a file in the storage", ex, f); |
522 throw new HgInvalidFileException(String.format("Failed to fake existence of file %s", expected), ex); | |
523 } | 522 } |
524 } | 523 } |
525 | 524 |
526 /*package-local*/ List<Filter> getFiltersFromRepoToWorkingDir(Path p) { | 525 /*package-local*/ List<Filter> getFiltersFromRepoToWorkingDir(Path p) { |
527 return instantiateFilters(p, new Filter.Options(Filter.Direction.FromRepo)); | 526 return instantiateFilters(p, new Filter.Options(Filter.Direction.FromRepo)); |