diff src/org/tmatesoft/hg/repo/HgManifest.java @ 412:63c5a9d7ca3f smartgit3

Follow-up for Issue 29: unify path translation for manifest and dirstate
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 21 Mar 2012 14:54:02 +0100
parents 6952d9ce97f1
children bb278ccf9866
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgManifest.java	Tue Mar 20 17:56:50 2012 +0100
+++ b/src/org/tmatesoft/hg/repo/HgManifest.java	Wed Mar 21 14:54:02 2012 +0100
@@ -51,6 +51,7 @@
  */
 public class HgManifest extends Revlog {
 	private RevisionMapper revisionMap;
+	private EncodingHelper encodingHelper;
 	
 	public enum Flags {
 		Exec, Link;
@@ -95,8 +96,9 @@
 		}
 	}
 
-	/*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content) {
+	/*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content, EncodingHelper eh) {
 		super(hgRepo, content);
+		encodingHelper = eh;
 	}
 
 	/**
@@ -171,7 +173,7 @@
 			manifestLast = manifestFirst;
 			manifestFirst = x;
 		}
-		content.iterate(manifestFirst, manifestLast, true, new ManifestParser(inspector));
+		content.iterate(manifestFirst, manifestLast, true, new ManifestParser(inspector, encodingHelper));
 	}
 	
 	/**
@@ -189,7 +191,7 @@
 			throw new IllegalArgumentException();
 		}
 		int[] manifestRevs = toManifestRevisionIndexes(revisionIndexes, inspector);
-		content.iterate(manifestRevs, true, new ManifestParser(inspector));
+		content.iterate(manifestRevs, true, new ManifestParser(inspector, encodingHelper));
 	}
 	
 	// 
@@ -331,11 +333,13 @@
 		private int start; 
 		private final int hash, length;
 		private Path result;
+		private final EncodingHelper encHelper;
 
-		public PathProxy(byte[] data, int start, int length) {
+		public PathProxy(byte[] data, int start, int length, EncodingHelper eh) {
 			this.data = data;
 			this.start = start;
 			this.length = length;
+			this.encHelper = eh;
 
 			// copy from String.hashCode(). In fact, not necessarily match result of String(data).hashCode
 			// just need some nice algorithm here
@@ -373,7 +377,7 @@
 		
 		public Path freeze() {
 			if (result == null) {
-				result = Path.create(EncodingHelper.fromManifest(data, start, length));
+				result = Path.create(encHelper.fromManifest(data, start, length));
 				// release reference to bigger data array, make a copy of relevant part only
 				// use original bytes, not those from String above to avoid cache misses due to different encodings 
 				byte[] d = new byte[length];
@@ -393,11 +397,13 @@
 		private byte[] nodeidLookupBuffer = new byte[20]; // get reassigned each time new Nodeid is added to pool
 		private final ProgressSupport progressHelper;
 		private IterateControlMediator iterateControl;
+		private final EncodingHelper encHelper;
 		
-		public ManifestParser(Inspector delegate) {
+		public ManifestParser(Inspector delegate, EncodingHelper eh) {
 			assert delegate != null;
 			inspector = delegate;
 			inspector2 = delegate instanceof Inspector2 ? (Inspector2) delegate : null;
+			encHelper = eh;
 			nodeidPool = new Pool2<Nodeid>();
 			fnamePool = new Pool2<PathProxy>();
 			thisRevPool = new Pool2<Nodeid>();
@@ -421,7 +427,7 @@
 						int x = i;
 						for( ; data[i] != '\n' && i < actualLen; i++) {
 							if (fname == null && data[i] == 0) {
-								PathProxy px = fnamePool.unify(new PathProxy(data, x, i - x));
+								PathProxy px = fnamePool.unify(new PathProxy(data, x, i - x, encHelper));
 								// if (cached = fnamePool.unify(px))== px then cacheMiss, else cacheHit
 								// cpython 0..10k: hits: 15 989 152, misses: 3020
 								fname = px.freeze();