# HG changeset patch # User Artem Tikhomirov # Date 1374783134 -7200 # Node ID f1f095e42555e85056f95964be804d6f0f81bb64 # Parent 9897cbfd2790a473cad1dfca9f03791f1ef26b14 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) diff -r 9897cbfd2790 -r f1f095e42555 src/org/tmatesoft/hg/core/HgAnnotateCommand.java --- 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); } diff -r 9897cbfd2790 -r f1f095e42555 src/org/tmatesoft/hg/internal/ForwardAnnotateInspector.java --- 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); }