diff src/org/tmatesoft/hg/repo/StatusCollector.java @ 90:a95c700408a9

Correctly report copy/rename events for rev..working copy case
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 26 Jan 2011 06:31:40 +0100
parents 42bcb4bffd17
children d55d4eedfc57
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/StatusCollector.java	Wed Jan 26 06:18:31 2011 +0100
+++ b/src/org/tmatesoft/hg/repo/StatusCollector.java	Wed Jan 26 06:31:40 2011 +0100
@@ -147,26 +147,10 @@
 					inspector.modified(fname);
 				}
 			} else {
-				HgDataFile df = repo.getFileNode(fname);
-				boolean isCopy = false;
-				while (df.isCopy()) {
-					Path original = df.getCopySourceName();
-					if (r1Files.contains(original.toString())) {
-						df = repo.getFileNode(original);
-						int changelogRevision = df.getChangesetLocalRevision(0);
-						if (changelogRevision <= rev1) {
-							// copy/rename source was known prior to rev1 
-							// (both r1Files.contains is true and original was created earlier than rev1)
-							// without r1Files.contains changelogRevision <= rev1 won't suffice as the file
-							// might get removed somewhere in between (changelogRevision < R < rev1)
-							inspector.copied(original.toString(), fname);
-							isCopy = true;
-						}
-						break;
-					} 
-					df = repo.getFileNode(original); // try more steps away
-				}
-				if (!isCopy) {
+				String copyOrigin = getOriginIfCopy(repo, fname, r1Files, rev1);
+				if (copyOrigin != null) {
+					inspector.copied(copyOrigin, fname);
+				} else {
 					inspector.added(fname);
 				}
 			}
@@ -182,6 +166,27 @@
 		walk(rev1, rev2, rv);
 		return rv;
 	}
+	
+	/*package-local*/static String getOriginIfCopy(HgRepository hgRepo, String fname, Collection<String> originals, int originalChangelogRevision) {
+		HgDataFile df = hgRepo.getFileNode(fname);
+		while (df.isCopy()) {
+			Path original = df.getCopySourceName();
+			if (originals.contains(original.toString())) {
+				df = hgRepo.getFileNode(original);
+				int changelogRevision = df.getChangesetLocalRevision(0);
+				if (changelogRevision <= originalChangelogRevision) {
+					// copy/rename source was known prior to rev1 
+					// (both r1Files.contains is true and original was created earlier than rev1)
+					// without r1Files.contains changelogRevision <= rev1 won't suffice as the file
+					// might get removed somewhere in between (changelogRevision < R < rev1)
+					return original.toString();
+				}
+				break; // copy/rename done later
+			} 
+			df = hgRepo.getFileNode(original); // try more steps away
+		}
+		return null;
+	}
 
 	public interface Inspector {
 		void modified(String fname);