Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/ReverseAnnotateInspector.java @ 677:1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 18 Jul 2013 18:47:45 +0200 |
parents | 3219cfadda49 |
children |
rev | line source |
---|---|
546
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
548
ab21ac7dd833
Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
546
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
546
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
21 |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
22 import java.util.Arrays; |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
23 |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
24 import org.tmatesoft.hg.core.HgAnnotateCommand; |
629
5f52074707b2
Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
25 import org.tmatesoft.hg.core.HgBlameInspector; |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
26 import org.tmatesoft.hg.core.HgIterateDirection; |
629
5f52074707b2
Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
27 import org.tmatesoft.hg.core.HgBlameInspector.RevisionDescriptor; |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
28 import org.tmatesoft.hg.core.HgCallbackTargetException; |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgInvalidStateException; |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
30 import org.tmatesoft.hg.util.CancelSupport; |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
31 import org.tmatesoft.hg.util.CancelledException; |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
32 import org.tmatesoft.hg.util.ProgressSupport; |
546
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 /** |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
35 * Produce output like 'hg annotate' does. |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
36 * Expects revisions to come in order from child to parent. |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
37 * Unlike {@link ForwardAnnotateInspector}, can be easily modified to report lines as soon as its origin is detected. |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
38 * |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
39 * (+) Handles annotate of partial history, at any moment lines with ({@link #knownLines} == <code>false</code> indicate lines |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
40 * that were added prior to any revision already visited. |
546
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 * @author Artem Tikhomirov |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 * @author TMate Software Ltd. |
cd78e8b9d7bc
File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 */ |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
45 public class ReverseAnnotateInspector implements HgBlameInspector, RevisionDescriptor.Recipient { |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
46 |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
47 // keeps <startSeq1, startSeq2, len> of equal blocks, origin to target, from some previous step |
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
630
diff
changeset
|
48 private RangePairSeq activeEquals; |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
49 // equal blocks of the current iteration, to be recalculated before next step |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
50 // to track line number (current target to ultimate target) mapping |
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
630
diff
changeset
|
51 private RangePairSeq intermediateEquals = new RangePairSeq(); |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
52 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
53 private boolean[] knownLines; |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
54 private RevisionDescriptor revisionDescriptor; |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
55 private BlockData lineContent; |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
56 |
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
630
diff
changeset
|
57 private IntMap<RangePairSeq> mergedRanges = new IntMap<RangePairSeq>(10); |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
630
diff
changeset
|
58 private IntMap<RangePairSeq> equalRanges = new IntMap<RangePairSeq>(10); |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
59 private boolean activeEqualsComesFromMerge = false; |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
60 |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
61 private int[] lineRevisions; |
677
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
676
diff
changeset
|
62 private int[] lineNumbers; |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
63 |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
64 /** |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
65 * @return desired order of iteration for diff |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
66 */ |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
67 public HgIterateDirection iterateDirection() { |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
68 return HgIterateDirection.NewToOld; |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
69 } |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
70 |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
71 public void report(int annotateRevIndex, HgAnnotateCommand.Inspector insp, ProgressSupport progress, CancelSupport cancel) throws HgCallbackTargetException, CancelledException { |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
72 LineImpl li = new LineImpl(); |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
73 progress.start(lineRevisions.length); |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
74 for (int i = 0; i < lineRevisions.length; i++) { |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
75 byte[] c = lineContent.elementAt(i).asArray(); |
677
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
676
diff
changeset
|
76 li.init(i+1, lineNumbers[i] + 1, lineRevisions[i], c); |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
77 insp.next(li); |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
78 progress.worked(1); |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
79 cancel.checkCancelled(); |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
80 } |
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
81 progress.done(); |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
82 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
83 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
84 public void start(RevisionDescriptor rd) { |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
85 revisionDescriptor = rd; |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
86 if (knownLines == null) { |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
87 lineContent = rd.target(); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
88 knownLines = new boolean[lineContent.elementCount()]; |
677
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
676
diff
changeset
|
89 lineRevisions = new int [knownLines.length]; |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
90 Arrays.fill(lineRevisions, NO_REVISION); |
677
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
676
diff
changeset
|
91 lineNumbers = new int[knownLines.length]; |
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
630
diff
changeset
|
92 activeEquals = new RangePairSeq(); |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
93 activeEquals.add(0, 0, knownLines.length); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
94 equalRanges.put(rd.targetChangesetIndex(), activeEquals); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
95 } else { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
96 activeEquals = equalRanges.get(rd.targetChangesetIndex()); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
97 if (activeEquals == null) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
98 // we didn't see this target revision as origin yet |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
99 // the only way this may happen is that this revision was a merge parent |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
100 activeEquals = mergedRanges.get(rd.targetChangesetIndex()); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
101 activeEqualsComesFromMerge = true; |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
102 if (activeEquals == null) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
103 throw new HgInvalidStateException(String.format("Can't find previously visited revision %d (while in %d->%1$d diff)", rd.targetChangesetIndex(), rd.originChangesetIndex())); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
104 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
105 } |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
106 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
107 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
108 |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
109 public void done(RevisionDescriptor rd) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
110 // update line numbers of the intermediate target to point to ultimate target's line numbers |
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
630
diff
changeset
|
111 RangePairSeq v = intermediateEquals.intersect(activeEquals); |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
112 if (activeEqualsComesFromMerge) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
113 mergedRanges.put(rd.originChangesetIndex(), v); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
114 } else { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
115 equalRanges.put(rd.originChangesetIndex(), v); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
116 } |
560
52263817b998
Exception when no blocks from merged revision were reported and merge parent was not recorded for future use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
558
diff
changeset
|
117 if (rd.isMerge() && !mergedRanges.containsKey(rd.mergeChangesetIndex())) { |
52263817b998
Exception when no blocks from merged revision were reported and merge parent was not recorded for future use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
558
diff
changeset
|
118 // seen merge, but no lines were merged from p2. |
52263817b998
Exception when no blocks from merged revision were reported and merge parent was not recorded for future use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
558
diff
changeset
|
119 // Add empty range to avoid uncertainty when a parent of p2 pops in |
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
630
diff
changeset
|
120 mergedRanges.put(rd.mergeChangesetIndex(), new RangePairSeq()); |
560
52263817b998
Exception when no blocks from merged revision were reported and merge parent was not recorded for future use
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
558
diff
changeset
|
121 } |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
122 intermediateEquals.clear(); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
123 activeEquals = null; |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
124 activeEqualsComesFromMerge = false; |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
125 revisionDescriptor = null; |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
126 } |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
127 |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
128 public void same(EqualBlock block) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
129 intermediateEquals.add(block.originStart(), block.targetStart(), block.length()); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
130 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
131 |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
132 public void added(AddBlock block) { |
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
630
diff
changeset
|
133 RangePairSeq rs = null; |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
134 if (revisionDescriptor.isMerge() && block.originChangesetIndex() == revisionDescriptor.mergeChangesetIndex()) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
135 rs = mergedRanges.get(revisionDescriptor.mergeChangesetIndex()); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
136 if (rs == null) { |
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
630
diff
changeset
|
137 mergedRanges.put(revisionDescriptor.mergeChangesetIndex(), rs = new RangePairSeq()); |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
138 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
139 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
140 if (activeEquals.size() == 0) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
141 return; |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
142 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
143 for (int i = 0, ln = block.firstAddedLine(), x = block.totalAddedLines(); i < x; i++, ln++) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
144 int lnInFinal = activeEquals.mapLineIndex(ln); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
145 if (lnInFinal != -1/* && !knownLines[lnInFinal]*/) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
146 if (rs != null) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
147 rs.add(block.insertedAt() + i, lnInFinal, 1); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
148 } else { |
677
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
676
diff
changeset
|
149 line(lnInFinal, ln, block.targetChangesetIndex()); |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
150 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
151 knownLines[lnInFinal] = true; |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
152 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
153 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
154 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
155 |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
156 public void changed(ChangeBlock block) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
157 added(block); |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
158 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
159 |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
160 public void deleted(DeleteBlock block) { |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
161 } |
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
162 |
677
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
676
diff
changeset
|
163 private void line(int lineNumber, int firstAppearance, int changesetRevIndex) { |
676
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
164 lineRevisions[lineNumber] = changesetRevIndex; |
677
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
676
diff
changeset
|
165 lineNumbers[lineNumber] = firstAppearance; |
557
b9e5ac26dd83
Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
556
diff
changeset
|
166 } |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
167 } |