changeset 455:281cfb60e2ef smartgit3

Added option to turn detection of copied files off during status operation
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 18 Jun 2012 20:26:59 +0200
parents 39fe00407937
children a0507a9f3da0
files src/org/tmatesoft/hg/repo/HgStatusCollector.java
diffstat 1 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgStatusCollector.java	Fri Jun 08 17:55:00 2012 +0200
+++ b/src/org/tmatesoft/hg/repo/HgStatusCollector.java	Mon Jun 18 20:26:59 2012 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 TMate Software Ltd
+ * Copyright (c) 2011-2012 TMate Software Ltd
  *  
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -60,6 +60,8 @@
 	private final Pool<Path> cacheFilenames;
 	private final ManifestRevision emptyFakeState;
 	private Path.Matcher scope = new Path.Matcher.Any();
+	// @see #detectCopies()
+	private boolean detectCopies = true;
 	
 
 	public HgStatusCollector(HgRepository hgRepo) {
@@ -184,6 +186,30 @@
 		// do not assign null, ever
 		scope = scopeMatcher == null ? new Path.Matcher.Any() : scopeMatcher;
 	}
+
+	/**
+	 * Select whether Collector shall tell "added-new" from "added-by-copy/rename" files.
+	 * This is analogous to '-C' switch of 'hg status' command.
+	 * 
+	 * <p>With copy detection turned off, files continue be reported as plain 'added' files.
+	 * 
+	 * <p>By default, copy detection is <em>on</em>, as it's reasonably cheap. However,
+	 * in certain scenarios it may be reasonable to turn it off, for example when it's a merge
+	 * of two very different branches and there are a lot of files added/moved.
+	 *  
+	 * Another legitimate reason to set detection to off if you're lazy to 
+	 * implement {@link HgStatusInspector#copied(Path, Path)} ;)
+	 * 
+	 * @param detect <code>true</code> if copies detection is desirable
+	 */
+	public void detectCopies(boolean detect) {
+		// cpython, revision:72161, p1:72159, p2:72160
+		// p2 comes from another branch with 321 file added (looks like copied/moved, however, the isCopy
+		// record present only for couple of them). With 2,5 ms per isCopy() operation, almost a second
+		// is spent detecting origins (according to Marc, of little use in this scenario, as it's second parent 
+		// in the merge) - in fact, most of the time of the status operation
+		detectCopies = detect;
+	}
 	
 	// hg status --change <rev>
 	public void change(int rev, HgStatusInspector inspector) throws /*FIXME HInvalidRevisionException,*/ HgInvalidControlFileException {
@@ -264,7 +290,7 @@
 			} else {
 				try {
 					Path copyTarget = r2fname;
-					Path copyOrigin = getOriginIfCopy(repo, copyTarget, r1Files, rev1);
+					Path copyOrigin = detectCopies ? getOriginIfCopy(repo, copyTarget, r1Files, rev1) : null;
 					if (copyOrigin != null) {
 						inspector.copied(getPathPool().path(copyOrigin) /*pipe through pool, just in case*/, copyTarget);
 					} else {