changeset 193:37f3d4a596e4

Use common low to hi-level changeset api transformer
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 15 Apr 2011 03:28:12 +0200
parents e5407b5a586a
children 344e8d7e4d6e
files src/org/tmatesoft/hg/core/ChangesetTransformer.java src/org/tmatesoft/hg/core/HgLogCommand.java
diffstat 2 files changed, 19 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/ChangesetTransformer.java	Fri Apr 15 03:17:03 2011 +0200
+++ b/src/org/tmatesoft/hg/core/ChangesetTransformer.java	Fri Apr 15 03:28:12 2011 +0200
@@ -16,6 +16,8 @@
  */
 package org.tmatesoft.hg.core;
 
+import java.util.Set;
+
 import org.tmatesoft.hg.repo.HgChangelog;
 import org.tmatesoft.hg.repo.HgRepository;
 import org.tmatesoft.hg.repo.HgStatusCollector;
@@ -32,12 +34,14 @@
 /*package-local*/ class ChangesetTransformer implements HgChangelog.Inspector {
 	private final HgLogCommand.Handler handler;
 	private final HgChangeset changeset;
+	private Set<String> branches;
 
 	public ChangesetTransformer(HgRepository hgRepo, HgLogCommand.Handler delegate) {
 		if (hgRepo == null || delegate == null) {
 			throw new IllegalArgumentException();
 		}
 		HgStatusCollector statusCollector = new HgStatusCollector(hgRepo);
+		// files listed in a changeset don't need their names to be rewritten (they are normalized already)
 		PathPool pp = new PathPool(new PathRewrite.Empty());
 		statusCollector.setPathPool(pp);
 		changeset = new HgChangeset(statusCollector, pp);
@@ -45,7 +49,15 @@
 	}
 	
 	public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
+		if (branches != null && !branches.contains(cset.branch())) {
+			return;
+		}
+
 		changeset.init(revisionNumber, nodeid, cset);
 		handler.next(changeset);
 	}
+	
+	public void limitBranches(Set<String> branches) {
+		this.branches = branches;
+	}
 }
\ No newline at end of file
--- a/src/org/tmatesoft/hg/core/HgLogCommand.java	Fri Apr 15 03:17:03 2011 +0200
+++ b/src/org/tmatesoft/hg/core/HgLogCommand.java	Fri Apr 15 03:28:12 2011 +0200
@@ -31,12 +31,9 @@
 import org.tmatesoft.hg.repo.HgChangelog;
 import org.tmatesoft.hg.repo.HgDataFile;
 import org.tmatesoft.hg.repo.HgRepository;
-import org.tmatesoft.hg.repo.HgStatusCollector;
 import org.tmatesoft.hg.util.ByteChannel;
 import org.tmatesoft.hg.util.CancelledException;
 import org.tmatesoft.hg.util.Path;
-import org.tmatesoft.hg.util.PathPool;
-import org.tmatesoft.hg.util.PathRewrite;
 
 
 /**
@@ -58,11 +55,10 @@
 	private Set<String> branches;
 	private int limit = 0, count = 0;
 	private int startRev = 0, endRev = TIP;
-	private Handler delegate;
 	private Calendar date;
 	private Path file;
 	private boolean followHistory; // makes sense only when file != null
-	private HgChangeset changeset;
+	private ChangesetTransformer csetTransform;
 	
 	public HgLogCommand(HgRepository hgRepo) {
 		repo = hgRepo;
@@ -183,18 +179,14 @@
 		if (handler == null) {
 			throw new IllegalArgumentException();
 		}
-		if (delegate != null) {
+		if (csetTransform != null) {
 			throw new ConcurrentModificationException();
 		}
 		try {
-			delegate = handler;
 			count = 0;
-			HgStatusCollector statusCollector = new HgStatusCollector(repo);
-			// files listed in a changeset don't need their names to be rewritten (they are normalized already)
-			PathPool pp = new PathPool(new PathRewrite.Empty());
-			// #file(String, boolean) above may utilize PathPool as well. CommandContext?
-			statusCollector.setPathPool(pp);
-			changeset = new HgChangeset(statusCollector, pp);
+			// ChangesetTransfrom creates a blank PathPool, and #file(String, boolean) above 
+			// may utilize it as well. CommandContext? How about StatusCollector there as well?
+			csetTransform = new ChangesetTransformer(repo, handler);
 			if (file == null) {
 				repo.getChangelog().range(startRev, endRev, this);
 			} else {
@@ -220,8 +212,7 @@
 				}
 			}
 		} finally {
-			delegate = null;
-			changeset = null;
+			csetTransform = null;
 		}
 	}
 
@@ -251,8 +242,7 @@
 			// FIXME
 		}
 		count++;
-		changeset.init(revisionNumber, nodeid, cset);
-		delegate.next(changeset);
+		csetTransform.next(revisionNumber, nodeid, cset);
 	}
 
 	public interface Handler {