diff src/org/tmatesoft/hg/internal/RevlogStream.java @ 594:cc7b0c4dc993

Cache only in-memory revision representations
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 02 May 2013 19:22:43 +0200
parents 9619301a7bb9
children 5daa42067e7c
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/RevlogStream.java	Thu May 02 16:51:02 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/RevlogStream.java	Thu May 02 19:22:43 2013 +0200
@@ -323,7 +323,7 @@
 
 		ReaderN1 r = new ReaderN1(needData, inspector, dataAccess.shallMergePatches());
 		try {
-			r.start(sortedRevisions.length, lastRevisionRead == null ? null : lastRevisionRead.get());
+			r.start(sortedRevisions.length, getLastRevisionRead());
 			for (int i = 0; i < sortedRevisions.length; ) {
 				int x = i;
 				i++;
@@ -571,7 +571,16 @@
 		public CachedRevision finish() {
 			CachedRevision rv = null;
 			if (lastUserData != null) {
-				rv = new CachedRevision(lastRevisionRead, lastUserData);
+				if (lastUserData instanceof ByteArrayDataAccess) {
+					// it's safe to cache only in-memory revision texts,
+					// if lastUserData is merely a filter over file stream,
+					// we'd need to keep file open, and this is bad.
+					// XXX perhaps, wrap any DataAccess.byteArray into
+					// ByteArrayDataAccess?
+					rv = new CachedRevision(lastRevisionRead, lastUserData);
+				} else {
+					lastUserData.done();
+				}
 				lastUserData = null;
 			}
 			if (lifecycleListener != null) {