diff src/org/tmatesoft/hg/internal/RevlogStreamFactory.java @ 621:99ad1e3a4e4d

RevlogStream: be aware of existence (not HgDataFile), facilitate use of an added HgDataFile over a commit; Rollback: be more sensitive about file changes (file size is not enough: write/rollback leaves it intact); tests
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 18 May 2013 22:23:57 +0200
parents e1b29756f901
children
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/RevlogStreamFactory.java	Sat May 18 21:55:31 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/RevlogStreamFactory.java	Sat May 18 22:23:57 2013 +0200
@@ -17,11 +17,9 @@
 package org.tmatesoft.hg.internal;
 
 import java.io.File;
-import java.io.IOException;
 import java.lang.ref.SoftReference;
 import java.util.HashMap;
 
-import org.tmatesoft.hg.repo.HgInvalidControlFileException;
 import org.tmatesoft.hg.util.Path;
 
 /**
@@ -57,14 +55,14 @@
 	 * @param path - normalized file name
 	 * @return <code>null</code> if path doesn't resolve to a existing file
 	 */
-	/*package-local*/ RevlogStream resolveStoreFile(Path path) {
+	/*package-local*/ RevlogStream getStoreFile(Path path, boolean onlyIfExists) {
 		final SoftReference<RevlogStream> ref = shallCacheRevlogs() ? streamsCache.get(path) : null;
 		RevlogStream cached = ref == null ? null : ref.get();
 		if (cached != null) {
 			return cached;
 		}
 		File f = repo.getFileFromDataDir(path);
-		if (f.exists()) {
+		if (!onlyIfExists || f.exists()) {
 			RevlogStream s = create(f);
 			if (shallCacheRevlogs()) {
 				streamsCache.put(path, new SoftReference<RevlogStream>(s));
@@ -74,23 +72,6 @@
 		return null;
 	}
 	
-	/*package-local*/ RevlogStream createStoreFile(Path path) throws HgInvalidControlFileException {
-		File f = repo.getFileFromDataDir(path);
-		try {
-			if (!f.exists()) {
-				f.getParentFile().mkdirs();
-				f.createNewFile();
-			}
-			RevlogStream s = create(f);
-			if (shallCacheRevlogs()) {
-				streamsCache.put(path, new SoftReference<RevlogStream>(s));
-			}
-			return s;
-		} catch (IOException ex) {
-			throw new HgInvalidControlFileException("Can't create a file in the storage", ex, f);
-		}
-	}
-
 	private boolean shallCacheRevlogs() {
 		return streamsCache != null;
 	}