changeset 21:e929cecae4e1

Refactor to move revlog content to base class
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 05 Jan 2011 04:10:28 +0100
parents 11cfabe692b3
children 603806cd2dc6
files design.txt src/com/tmate/hgkit/ll/Changelog.java src/com/tmate/hgkit/ll/HgDataFile.java src/com/tmate/hgkit/ll/HgManifest.java src/com/tmate/hgkit/ll/LocalHgRepo.java src/com/tmate/hgkit/ll/Revlog.java
diffstat 6 files changed, 45 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/design.txt	Tue Jan 04 02:08:25 2011 +0100
+++ b/design.txt	Wed Jan 05 04:10:28 2011 +0100
@@ -29,6 +29,7 @@
 *.hgignored processing
 
 DataAccess - collect debug info (buffer misses, file size/total read operations) to find out better strategy to buffer size detection.
+DataAccess - implement memory mapped files, compare performance.
 delta merge
 Changeset to get index (local revision number)
 RevisionWalker (on manifest) and WorkingCopyWalker (io.File) talking to ? and/or dirstate 
@@ -52,6 +53,6 @@
 
 File access:
 * NIO and mapped files - should be fast. Although seems to give less control on mem usage. 
-* Regular InputStreams and  chunked stream on top - allocate List<byte[]>, each (but last) chunk of fixed size (depending on initial file size) 
+* Regular InputStreams and chunked stream on top - allocate List<byte[]>, each (but last) chunk of fixed size (depending on initial file size) 
 
 <<<<<
\ No newline at end of file
--- a/src/com/tmate/hgkit/ll/Changelog.java	Tue Jan 04 02:08:25 2011 +0100
+++ b/src/com/tmate/hgkit/ll/Changelog.java	Wed Jan 05 04:10:28 2011 +0100
@@ -1,5 +1,5 @@
-/**
- * Copyright (c) 2010 Artem Tikhomirov
+/*
+ * Copyright (c) 2010, 2011 Artem Tikhomirov
  */
 package com.tmate.hgkit.ll;
 
@@ -13,11 +13,8 @@
  */
 public class Changelog extends Revlog {
 
-	private final RevlogStream content;
-
 	/*package-local*/ Changelog(HgRepository hgRepo, RevlogStream content) {
-		super(hgRepo);
-		this.content = content;
+		super(hgRepo, content);
 	}
 
 	public void all(final Changeset.Inspector inspector) {
--- a/src/com/tmate/hgkit/ll/HgDataFile.java	Tue Jan 04 02:08:25 2011 +0100
+++ b/src/com/tmate/hgkit/ll/HgDataFile.java	Wed Jan 05 04:10:28 2011 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010 Artem Tikhomirov 
+ * Copyright (c) 2010, 2011 Artem Tikhomirov 
  */
 package com.tmate.hgkit.ll;
 
@@ -14,17 +14,14 @@
  */
 public class HgDataFile extends Revlog {
 
-	private final RevlogStream content; // XXX move up to Revlog?
-
 	// absolute from repo root?
 	// slashes, unix-style?
 	// repo location agnostic, just to give info to user, not to access real storage
 	private final String path;
 	
 	/*package-local*/HgDataFile(HgRepository hgRepo, String path, RevlogStream content) {
-		super(hgRepo);
+		super(hgRepo, content);
 		this.path = path;
-		this.content = content;
 	}
 	
 	public boolean exists() {
@@ -35,10 +32,6 @@
 		return path; // hgRepo.backresolve(this) -> name?
 	}
 
-	public int getRevisionCount() {
-		return content.revisionCount();
-	}
-
 	public byte[] content() {
 		return content(TIP);
 	}
--- a/src/com/tmate/hgkit/ll/HgManifest.java	Tue Jan 04 02:08:25 2011 +0100
+++ b/src/com/tmate/hgkit/ll/HgManifest.java	Wed Jan 05 04:10:28 2011 +0100
@@ -9,11 +9,8 @@
  */
 public class HgManifest extends Revlog {
 
-	private final RevlogStream content;
-
 	/*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content) {
-		super(hgRepo);
-		this.content = content;
+		super(hgRepo, content);
 	}
 
 	public void walk(int start, int end, final Inspector inspector) {
--- a/src/com/tmate/hgkit/ll/LocalHgRepo.java	Tue Jan 04 02:08:25 2011 +0100
+++ b/src/com/tmate/hgkit/ll/LocalHgRepo.java	Wed Jan 05 04:10:28 2011 +0100
@@ -47,25 +47,7 @@
 	
 	@Override
 	public void status(int rev1, int rev2, final StatusInspector inspector) {
-		final HashMap<String, Nodeid> idsMap = new HashMap<String, Nodeid>();
-		final HashMap<String, String> flagsMap = new HashMap<String, String>();
-		HgManifest.Inspector collect = new HgManifest.Inspector() {
-			
-			
-			public boolean next(Nodeid nid, String fname, String flags) {
-				idsMap.put(fname, nid);
-				flagsMap.put(fname, flags);
-				return true;
-			}
-			
-			public boolean end(int revision) {
-				return false;
-			}
-			
-			public boolean begin(int revision, Nodeid nid) {
-				return true;
-			}
-		};
+		final ManifestRevisionCollector collect = new ManifestRevisionCollector();
 		getManifest().walk(rev1, rev1, collect);
 		
 		HgManifest.Inspector compare = new HgManifest.Inspector() {
@@ -75,8 +57,8 @@
 			}
 
 			public boolean next(Nodeid nid, String fname, String flags) {
-				Nodeid nidR1 = idsMap.remove(fname);
-				String flagsR1 = flagsMap.remove(fname);
+				Nodeid nidR1 = collect.idsMap.remove(fname);
+				String flagsR1 = collect.flagsMap.remove(fname);
 				if (nidR1 == null) {
 					inspector.added(fname);
 				} else {
@@ -90,10 +72,10 @@
 			}
 
 			public boolean end(int revision) {
-				for (String fname : idsMap.keySet()) {
+				for (String fname : collect.idsMap.keySet()) {
 					inspector.removed(fname);
 				}
-				if (idsMap.size() != flagsMap.size()) {
+				if (collect.idsMap.size() != collect.flagsMap.size()) {
 					throw new IllegalStateException();
 				}
 				return false;
@@ -102,13 +84,18 @@
 		getManifest().walk(rev2, rev2, compare);
 	}
 	
-	public void statusLocal(int rev1, StatusInspector inspector) {
+	public void statusLocal(int baseRevision, StatusInspector inspector) {
 		LinkedList<File> folders = new LinkedList<File>();
 		final File rootDir = repoDir.getParentFile();
 		folders.add(rootDir);
 		final HgDirstate dirstate = loadDirstate();
 		final HgIgnore hgignore = loadIgnore();
 		TreeSet<String> knownEntries = dirstate.all();
+		final boolean isTipBase = baseRevision == TIP || baseRevision == getManifest().revisionCount();
+		final ManifestRevisionCollector collect = isTipBase ? null : new ManifestRevisionCollector();
+		if (!isTipBase) {
+			getManifest().walk(baseRevision, baseRevision, collect);
+		}
 		do {
 			File d = folders.removeFirst();
 			for (File f : d.listFiles()) {
@@ -336,4 +323,23 @@
 		}
 		return path;
 	}
+
+	private final class ManifestRevisionCollector implements HgManifest.Inspector {
+		final HashMap<String, Nodeid> idsMap = new HashMap<String, Nodeid>();
+		final HashMap<String, String> flagsMap = new HashMap<String, String>();
+
+		public boolean next(Nodeid nid, String fname, String flags) {
+			idsMap.put(fname, nid);
+			flagsMap.put(fname, flags);
+			return true;
+		}
+
+		public boolean end(int revision) {
+			return false;
+		}
+
+		public boolean begin(int revision, Nodeid nid) {
+			return true;
+		}
+	}
 }
--- a/src/com/tmate/hgkit/ll/Revlog.java	Tue Jan 04 02:08:25 2011 +0100
+++ b/src/com/tmate/hgkit/ll/Revlog.java	Wed Jan 05 04:10:28 2011 +0100
@@ -10,18 +10,24 @@
 public abstract class Revlog {
 
 	private final HgRepository hgRepo;
+	protected final RevlogStream content;
 
-	protected Revlog(HgRepository hgRepo) {
+	protected Revlog(HgRepository hgRepo, RevlogStream content) {
 		if (hgRepo == null) {
 			throw new NullPointerException();
 		}
 		this.hgRepo = hgRepo;
+		this.content = content;
 	}
 
 	public final HgRepository getRepo() {
 		return hgRepo;
 	}
 
+	public int getRevisionCount() {
+		return content.revisionCount();
+	}
+
 	public interface Inspector {
 		// XXX boolean retVal to indicate whether to continue?
 		void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[/*32*/] nodeid, byte[] data);