diff src/org/tmatesoft/hg/core/HgAnnotateCommand.java @ 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 58a6900f845d
children 7839ff0bfd78
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);
 		}