diff src/com/tmate/hgkit/ll/LocalHgRepo.java @ 10:382cfe9463db

Dirstate parsing. DataAccess refactored to allow reuse and control over constants
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 25 Dec 2010 21:50:12 +0100
parents d6d2a630f4a6
children 865bf07f381f
line wrap: on
line diff
--- a/src/com/tmate/hgkit/ll/LocalHgRepo.java	Sat Dec 25 04:45:59 2010 +0100
+++ b/src/com/tmate/hgkit/ll/LocalHgRepo.java	Sat Dec 25 21:50:12 2010 +0100
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2010 Artem Tikhomirov 
  */
 package com.tmate.hgkit.ll;
@@ -13,6 +13,8 @@
 import java.util.HashMap;
 import java.util.TreeSet;
 
+import com.tmate.hgkit.fs.DataAccessProvider;
+
 /**
  * @author artem
  */
@@ -20,10 +22,12 @@
 
 	private File repoDir; // .hg folder
 	private final String repoLocation;
+	private final DataAccessProvider dataAccess;
 
 	public LocalHgRepo(String repositoryPath) {
 		setInvalid(true);
 		repoLocation = repositoryPath;
+		dataAccess = null;
 	}
 	
 	public LocalHgRepo(File repositoryRoot) throws IOException {
@@ -31,6 +35,7 @@
 		setInvalid(false);
 		repoDir = repositoryRoot;
 		repoLocation = repositoryRoot.getParentFile().getCanonicalPath();
+		dataAccess = new DataAccessProvider();
 		parseRequires();
 	}
 
@@ -39,6 +44,16 @@
 		return repoLocation;
 	}
 
+	// XXX package-local, unless there are cases when required from outside (guess, working dir/revision walkers may hide dirstate access and no public visibility needed)
+	public final HgDirstate loadDirstate() {
+		// XXX may cache in SoftReference if creation is expensive
+		return new HgDirstate(this, new File(repoDir, "dirstate"));
+	}
+
+	/*package-local*/ DataAccessProvider getDataAccess() {
+		return dataAccess;
+	}
+
 	private final HashMap<String, SoftReference<RevlogStream>> streamsCache = new HashMap<String, SoftReference<RevlogStream>>();
 
 	/**
@@ -53,7 +68,7 @@
 		}
 		File f = new File(repoDir, path);
 		if (f.exists()) {
-			RevlogStream s = new RevlogStream(f);
+			RevlogStream s = new RevlogStream(dataAccess, f);
 			streamsCache.put(path, new SoftReference<RevlogStream>(s));
 			return s;
 		}