diff src/com/tmate/hgkit/ll/LocalHgRepo.java @ 3:24bb4f365164

Rudimentary log functionality with basic infrastructure is in place
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 Dec 2010 02:50:36 +0100
parents a3576694a4d1
children a78c980749e3
line wrap: on
line diff
--- a/src/com/tmate/hgkit/ll/LocalHgRepo.java	Sun Dec 19 05:41:31 2010 +0100
+++ b/src/com/tmate/hgkit/ll/LocalHgRepo.java	Mon Dec 20 02:50:36 2010 +0100
@@ -5,6 +5,8 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.ref.SoftReference;
+import java.util.HashMap;
 
 /**
  * @author artem
@@ -30,4 +32,44 @@
 	public String getLocation() {
 		return repoLocation;
 	}
+
+	private final HashMap<String, SoftReference<RevlogStream>> streamsCache = new HashMap<String, SoftReference<RevlogStream>>();
+
+	/**
+	 * path - repository storage path (i.e. one usually with .i or .d)
+	 */
+	@Override
+	protected RevlogStream resolve(String path) {
+		final SoftReference<RevlogStream> ref = streamsCache.get(path);
+		RevlogStream cached = ref == null ? null : ref.get();
+		if (cached != null) {
+			return cached;
+		}
+		File f = new File(repoDir, path);
+		if (f.exists()) {
+			RevlogStream s = new RevlogStream(f);
+			streamsCache.put(path, new SoftReference<RevlogStream>(s));
+			return s;
+		}
+		return null;
+	}
+
+	@Override
+	public HgDataFile getFileNode(String path) {
+		String nPath = normalize(path);
+		String storagePath = toStoragePath(nPath);
+		RevlogStream content = resolve(storagePath);
+		// XXX no content when no file? or HgDataFile.exists() to detect that? How about files that were removed in previous releases?
+		return new HgDataFile(this, nPath, content);
+	}
+	
+	// FIXME much more to be done, see store.py:_hybridencode
+	private static String toStoragePath(String path) {
+		// XXX works for lowercase names only
+		return "store/data/" + path.replace('\\', '/') + ".i";
+	}
+
+	private static String normalize(String path) {
+		return path.replace('\\', '/');
+	}
 }