diff src/org/tmatesoft/hg/core/HgLogCommand.java @ 507:a6435c1a42d0

Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 12 Dec 2012 14:17:12 +0100
parents b3c16d1aede0
children ca5202afea90
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgLogCommand.java	Fri Nov 30 22:52:39 2012 +0100
+++ b/src/org/tmatesoft/hg/core/HgLogCommand.java	Wed Dec 12 14:17:12 2012 +0100
@@ -330,36 +330,65 @@
 			}
 		};
 		final ProgressSupport progressHelper = getProgressSupport(handler);
-		progressHelper.start(4);
 		final CancelSupport cancelHelper = getCancelSupport(handler, true);
-		cancelHelper.checkCancelled();
-		HgDataFile fileNode = repo.getFileNode(file);
-		// build tree of nodes according to parents in file's revlog
-		final TreeBuildInspector treeBuildInspector = new TreeBuildInspector();
-		final HistoryNode[] completeHistory = treeBuildInspector.go(fileNode);
-		progressHelper.worked(1);
-		cancelHelper.checkCancelled();
-		ElementImpl ei = new ElementImpl(treeBuildInspector.commitRevisions.length);
-		final ProgressSupport ph2;
-		if (treeBuildInspector.commitRevisions.length < 100 /*XXX is it really worth it? */) {
-			ei.initTransform();
-			repo.getChangelog().range(ei, treeBuildInspector.commitRevisions);
+
+		LinkedList<HgDataFile> fileRenamesQueue = buildFileRenamesQueue();
+		progressHelper.start(4 * fileRenamesQueue.size());
+		do {
+			HgDataFile fileNode = fileRenamesQueue.removeLast();
+			cancelHelper.checkCancelled();
+			// build tree of nodes according to parents in file's revlog
+			final TreeBuildInspector treeBuildInspector = new TreeBuildInspector();
+			final HistoryNode[] completeHistory = treeBuildInspector.go(fileNode);
 			progressHelper.worked(1);
-			ph2 = new ProgressSupport.Sub(progressHelper, 2);
-		} else {
-			ph2 = new ProgressSupport.Sub(progressHelper, 3);
-		}
-		ph2.start(completeHistory.length);
-		// XXX shall sort completeHistory according to changeset numbers?
-		for (int i = 0; i < completeHistory.length; i++ ) {
-			final HistoryNode n = completeHistory[i];
-			handler.treeElement(ei.init(n));
-			ph2.worked(1);
 			cancelHelper.checkCancelled();
-		}
+			ElementImpl ei = new ElementImpl(treeBuildInspector.commitRevisions.length);
+			final ProgressSupport ph2;
+			if (treeBuildInspector.commitRevisions.length < 100 /*XXX is it really worth it? */) {
+				ei.initTransform();
+				repo.getChangelog().range(ei, treeBuildInspector.commitRevisions);
+				progressHelper.worked(1);
+				ph2 = new ProgressSupport.Sub(progressHelper, 2);
+			} else {
+				ph2 = new ProgressSupport.Sub(progressHelper, 3);
+			}
+			ph2.start(completeHistory.length);
+			// XXX shall sort completeHistory according to changeset numbers?
+			for (int i = 0; i < completeHistory.length; i++ ) {
+				final HistoryNode n = completeHistory[i];
+				handler.treeElement(ei.init(n));
+				ph2.worked(1);
+				cancelHelper.checkCancelled();
+			}
+		} while (!fileRenamesQueue.isEmpty());
 		progressHelper.done();
 	}
 	
+	/**
+	 * Follows file renames and build a list of all corresponding file nodes. If {@link #followHistory} is <code>false</code>, 
+	 * the list contains one element only, file node with the name of the file as it was specified by the user.
+	 * 
+	 * @return list of file renames, with most recent file first
+	 */
+	private LinkedList<HgDataFile> buildFileRenamesQueue() {
+		LinkedList<HgDataFile> rv = new LinkedList<HgDataFile>();
+		if (!followHistory) {
+			rv.add(repo.getFileNode(file));
+			return rv;
+		}
+		HgDataFile fileNode;
+		Path fp = file;
+		boolean isCopy;
+		do {
+			fileNode = repo.getFileNode(fp);
+			rv.addLast(fileNode);
+			if (isCopy = fileNode.isCopy()) {
+				fp = fileNode.getCopySourceName();
+			}
+		} while (isCopy);
+		return rv;
+	}
+
 	//
 	
 	public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {