Mercurial > jhg
diff 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 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgRepository.java Tue Feb 05 22:30:21 2013 +0100 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Wed Feb 13 18:44:58 2013 +0100 @@ -184,10 +184,6 @@ public HgChangelog getChangelog() { if (changelog == null) { File chlogFile = impl.getFileFromStoreDir("00changelog.i"); - if (!chlogFile.exists()) { - // fake its existence - chlogFile = fakeNonExistentFile(chlogFile); - } RevlogStream content = new RevlogStream(impl.getDataAccess(), chlogFile); changelog = new HgChangelog(this, content); } @@ -197,9 +193,6 @@ public HgManifest getManifest() { if (manifest == null) { File manifestFile = impl.getFileFromStoreDir("00manifest.i"); - if (!manifestFile.exists()) { - manifestFile = fakeNonExistentFile(manifestFile); - } RevlogStream content = new RevlogStream(impl.getDataAccess(), manifestFile); manifest = new HgManifest(this, content, impl.buildFileNameEncodingHelper()); } @@ -512,14 +505,20 @@ return null; } - private File fakeNonExistentFile(File expected) throws HgInvalidFileException { + /*package-local*/ RevlogStream createStoreFile(Path path) throws HgInvalidControlFileException { + File f = impl.getFileFromDataDir(path); try { - File fake = File.createTempFile(expected.getName(), null); - fake.deleteOnExit(); - return fake; + if (!f.exists()) { + f.getParentFile().mkdirs(); + f.createNewFile(); + } + RevlogStream s = new RevlogStream(impl.getDataAccess(), f); + if (impl.shallCacheRevlogs()) { + streamsCache.put(path, new SoftReference<RevlogStream>(s)); + } + return s; } catch (IOException ex) { - getSessionContext().getLog().dump(getClass(), Info, ex, null); - throw new HgInvalidFileException(String.format("Failed to fake existence of file %s", expected), ex); + throw new HgInvalidControlFileException("Can't create a file in the storage", ex, f); } }