diff src/org/tmatesoft/hg/repo/Revlog.java @ 607:66f1cc23b906

Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 07 May 2013 16:52:46 +0200
parents c3505001a42a
children e1b29756f901
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/Revlog.java	Tue May 07 14:16:35 2013 +0200
+++ b/src/org/tmatesoft/hg/repo/Revlog.java	Tue May 07 16:52:46 2013 +0200
@@ -56,6 +56,7 @@
 	protected final RevlogStream content;
 	protected final boolean useRevisionLookup;
 	protected RevisionLookup revisionLookup;
+	private final RevlogStream.Observer revisionLookupCleaner;
 
 	protected Revlog(HgRepository hgRepo, RevlogStream contentStream, boolean needRevisionLookup) {
 		if (hgRepo == null) {
@@ -67,6 +68,16 @@
 		repo = hgRepo;
 		content = contentStream;
 		useRevisionLookup = needRevisionLookup;
+		if (needRevisionLookup) {
+			revisionLookupCleaner = new RevlogStream.Observer() {
+				
+				public void reloaded(RevlogStream src) {
+					revisionLookup = null;
+				}
+			};
+		} else {
+			revisionLookupCleaner = null;
+		}
 	}
 	
 	// invalid Revlog
@@ -74,6 +85,7 @@
 		repo = hgRepo;
 		content = null;
 		useRevisionLookup = false;
+		revisionLookupCleaner = null;
 	}
 
 	public final HgRepository getRepo() {
@@ -162,8 +174,9 @@
 	
 	private int doFindWithCache(Nodeid nid) {
 		if (useRevisionLookup) {
-			if (revisionLookup == null) {
-				revisionLookup = RevisionLookup.createFor(content);
+			if (revisionLookup == null || content.shallDropDerivedCaches()) {
+				content.detach(revisionLookupCleaner);
+				setRevisionLookup(RevisionLookup.createFor(content));
 			}
 			return revisionLookup.findIndex(nid);
 		} else {
@@ -172,6 +185,16 @@
 	}
 	
 	/**
+	 * use selected helper for revision lookup, register appropriate listeners to clear cache on revlog changes
+	 * @param rl not <code>null</code>
+	 */
+	protected void setRevisionLookup(RevisionLookup rl) {
+		assert rl != null;
+		revisionLookup = rl;
+		content.attach(revisionLookupCleaner);
+	}
+	
+	/**
 	 * Note, {@link Nodeid#NULL} nodeid is not reported as known in any revlog.
 	 * 
 	 * @param nodeid