changeset 686:f1f095e42555

Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 25 Jul 2013 22:12:14 +0200
parents 9897cbfd2790
children 9859fcea475d
files src/org/tmatesoft/hg/core/HgAnnotateCommand.java src/org/tmatesoft/hg/internal/ForwardAnnotateInspector.java
diffstat 2 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgAnnotateCommand.java	Thu Jul 25 21:32:09 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgAnnotateCommand.java	Thu Jul 25 22:12:14 2013 +0200
@@ -16,6 +16,8 @@
  */
 package org.tmatesoft.hg.core;
 
+import static org.tmatesoft.hg.repo.HgRepository.TIP;
+
 import org.tmatesoft.hg.internal.Callback;
 import org.tmatesoft.hg.internal.CsetParamKeeper;
 import org.tmatesoft.hg.internal.ForwardAnnotateInspector;
@@ -44,7 +46,7 @@
 	public HgAnnotateCommand(HgRepository hgRepo) {
 		repo = hgRepo;
 		annotateRevision = new CsetParamKeeper(repo);
-		annotateRevision.doSet(HgRepository.TIP);
+		annotateRevision.doSet(TIP);
 	}
 
 	public HgAnnotateCommand changeset(Nodeid nodeid) throws HgBadArgumentException {
@@ -119,7 +121,7 @@
 				return;
 			}
 			final int changesetStart = followRename ? 0 : df.getChangesetRevisionIndex(0);
-			final int annotateRevIndex = annotateRevision.get();
+			final int annotateRevIndex = annotateRevision.get(TIP);
 			HgDiffCommand cmd = new HgDiffCommand(repo).file(df);
 			cmd.range(changesetStart, annotateRevIndex);
 			cmd.set(cancellation);
@@ -131,7 +133,14 @@
 			//
 			cmd.executeAnnotate(ai);
 			cancellation.checkCancelled();
-			ai.report(annotateRevIndex, inspector, new ProgressSupport.Sub(progress, 100), cancellation);
+			final int lastCsetWithFileChange;
+			Nodeid fileRev = repo.getManifest().getFileRevision(annotateRevIndex, df.getPath());
+			if (fileRev != null) {
+				lastCsetWithFileChange = df.getChangesetRevisionIndex(df.getRevisionIndex(fileRev));
+			} else {
+				lastCsetWithFileChange = annotateRevIndex;
+			}
+			ai.report(lastCsetWithFileChange, inspector, new ProgressSupport.Sub(progress, 100), cancellation);
 		} catch (HgRuntimeException ex) {
 			throw new HgLibraryFailureException(ex);
 		}
--- a/src/org/tmatesoft/hg/internal/ForwardAnnotateInspector.java	Thu Jul 25 21:32:09 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/ForwardAnnotateInspector.java	Thu Jul 25 22:12:14 2013 +0200
@@ -29,7 +29,7 @@
  * 
  * At the moment, doesn't handle start from any revision but 0
  * 
- * (+) May report annotate for any revision in the visited range.
+ * (+) May report annotate for any revision (with actual file change) in the visited range.
  * 
  * @see ReverseAnnotateInspector
  * @author Artem Tikhomirov
@@ -51,6 +51,9 @@
 
 	public void report(int revision, Inspector insp, ProgressSupport progress, CancelSupport cancel) throws HgCallbackTargetException, CancelledException {
 		int totalLines = 0;
+		if (!all.containsKey(revision)) {
+			throw new IllegalArgumentException(String.format("Revision %d has not been visited", revision));
+		}
 		for (IntTuple t : all.get(revision)) {
 			totalLines += t.at(0);
 		}