annotate src/org/tmatesoft/hg/internal/FileAnnotation.java @ 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
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 24 Feb 2013 00:11:40 +0100
parents e55f17a7a195
children 154718ae23ed
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
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
19 import java.util.Formatter;
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
20
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
21 import org.tmatesoft.hg.core.HgIterateDirection;
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
22 import org.tmatesoft.hg.repo.HgBlameFacility;
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
23 import org.tmatesoft.hg.repo.HgInvalidStateException;
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
24 import org.tmatesoft.hg.repo.HgBlameFacility.AddBlock;
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
25 import org.tmatesoft.hg.repo.HgBlameFacility.BlockData;
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
26 import org.tmatesoft.hg.repo.HgBlameFacility.ChangeBlock;
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
27 import org.tmatesoft.hg.repo.HgBlameFacility.DeleteBlock;
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
28 import org.tmatesoft.hg.repo.HgBlameFacility.EqualBlock;
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.HgBlameFacility.RevisionDescriptor;
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
30 import org.tmatesoft.hg.repo.HgDataFile;
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
31
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
32 /**
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
33 * Produce output like 'hg annotate' does
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
34 *
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
35 * @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
36 * @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
37 */
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
38 public class FileAnnotation implements HgBlameFacility.BlockInspector, RevisionDescriptor.Recipient {
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
39
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
40 @Experimental(reason="The line-by-line inspector likely to become part of core/command API")
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
41 @Callback
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
42 public interface LineInspector {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
43 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
44 * Not necessarily invoked sequentially by line numbers
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
45 */
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
46 void line(int lineNumber, int changesetRevIndex, BlockData lineContent, LineDescriptor ld);
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
47 }
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
48
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
49 public interface LineDescriptor {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
50 int totalLines();
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
51 }
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 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
54 * Annotate file revision, line by line.
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
55 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
56 public static void annotate(HgDataFile df, int changelogRevisionIndex, LineInspector insp) {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
57 if (!df.exists()) {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
58 return;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
59 }
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
60 FileAnnotation fa = new FileAnnotation(insp);
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
61 HgBlameFacility af = new HgBlameFacility();
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
62 af.annotate(df, changelogRevisionIndex, fa, HgIterateDirection.NewToOld);
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
63 }
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
64
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
65 // keeps <startSeq1, startSeq2, len> of equal blocks, origin to target, from some previous step
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
66 private RangeSeq activeEquals;
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
67 // 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
68 // to track line number (current target to ultimate target) mapping
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
69 private RangeSeq intermediateEquals = new RangeSeq();
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
70
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
71 private boolean[] knownLines;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
72 private final LineInspector delegate;
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
73 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
74 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
75
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
76 private IntMap<RangeSeq> mergedRanges = new IntMap<RangeSeq>(10);
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
77 private IntMap<RangeSeq> equalRanges = new IntMap<RangeSeq>(10);
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
78 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
79
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
80 public FileAnnotation(LineInspector lineInspector) {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
81 delegate = lineInspector;
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()];
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
89 activeEquals = new RangeSeq();
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
90 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
91 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
92 } 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
93 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
94 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
95 // 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
96 // 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
97 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
98 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
99 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
100 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
101 }
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 }
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
103 }
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
104 }
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
105
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
106 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
107 // update line numbers of the intermediate target to point to ultimate target's line numbers
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
108 RangeSeq v = intermediateEquals.intersect(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
109 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
110 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
111 } 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
112 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
113 }
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 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
115 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
116 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
117 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
118 }
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
119
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
120 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
121 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
122 }
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
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 public void added(AddBlock 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
125 RangeSeq 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
126 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
127 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
128 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
129 mergedRanges.put(revisionDescriptor.mergeChangesetIndex(), rs = new RangeSeq());
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 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
133 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
134 }
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 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
136 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
137 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
138 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
139 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
140 } 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
141 delegate.line(lnInFinal, block.targetChangesetIndex(), lineContent.elementAt(lnInFinal), new LineDescriptorImpl());
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 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
144 }
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 }
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 }
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
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 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
149 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
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
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 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
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 private final class LineDescriptorImpl implements LineDescriptor {
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 LineDescriptorImpl() {
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 }
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 public int totalLines() {
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 return FileAnnotation.this.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
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 }
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
163
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
164 private static class RangeSeq {
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
165 // XXX smth like IntSliceVector to access triples (or slices of any size, in fact)
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 // with easy indexing, e.g. #get(sliceIndex, indexWithinSlice)
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
167 // and vect.get(7,2) instead of vect.get(7*SIZEOF_SLICE+2)
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
168 private final IntVector ranges = new IntVector(3*10, 3*5);
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
169 private int count;
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
170
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
171 public void add(int start1, int start2, int 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
172 if (count > 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
173 int lastIndex = 3 * (count-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
174 int lastS1 = ranges.get(lastIndex);
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
175 int lastS2 = ranges.get(lastIndex + 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
176 int lastLen = ranges.get(lastIndex + 2);
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
177 if (start1 == lastS1 + lastLen && start2 == lastS2 + lastLen) {
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
178 // new range continues the previous one - just increase the 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
179 ranges.set(lastIndex + 2, lastLen + 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
180 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
181 }
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
182 }
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
183 ranges.add(start1, start2, 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
184 count++;
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
185 }
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
186
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
187 public void 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
188 ranges.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
189 count = 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
190 }
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
191
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
192 public int size() {
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
193 return count;
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
194 }
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
195
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
196 public int mapLineIndex(int 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
197 for (int i = 0; i < ranges.size(); i += 3) {
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
198 int s1 = ranges.get(i);
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
199 if (s1 > 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
200 return -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
201 }
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
202 int l = ranges.get(i+2);
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
203 if (s1 + l > 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
204 int s2 = ranges.get(i + 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
205 return s2 + (ln - s1);
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
206 }
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
207 }
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
208 return -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
209 }
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
210
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
211 public RangeSeq intersect(RangeSeq 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
212 RangeSeq v = new RangeSeq();
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
213 for (int i = 0; i < ranges.size(); i += 3) {
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
214 int originLine = ranges.get(i);
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
215 int targetLine = ranges.get(i + 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
216 int length = ranges.get(i + 2);
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
217 int startTargetLine = -1, startOriginLine = -1, c = 0;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
218 for (int j = 0; j < length; j++) {
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
219 int lnInFinal = target.mapLineIndex(targetLine + j);
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
220 if (lnInFinal == -1 || (startTargetLine != -1 && lnInFinal != startTargetLine + c)) {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
221 // the line is not among "same" in ultimate origin
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
222 // or belongs to another/next "same" chunk
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
223 if (startOriginLine == -1) {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
224 continue;
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
225 }
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
226 v.add(startOriginLine, startTargetLine, c);
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
227 c = 0;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
228 startOriginLine = startTargetLine = -1;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
229 // fall-through to check if it's not complete miss but a next chunk
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
230 }
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
231 if (lnInFinal != -1) {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
232 if (startOriginLine == -1) {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
233 startOriginLine = originLine + j;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
234 startTargetLine = lnInFinal;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
235 c = 1;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
236 } else {
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
237 // lnInFinal != startTargetLine + s is covered above
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
238 assert lnInFinal == startTargetLine + c;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
239 c++;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
240 }
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
241 }
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
242 }
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
243 if (startOriginLine != -1) {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
244 assert c > 0;
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
245 v.add(startOriginLine, startTargetLine, c);
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
246 }
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
247 }
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
248 return v;
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
249 }
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
250
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
251 @SuppressWarnings("unused")
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
252 public CharSequence dump() {
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
253 StringBuilder sb = new StringBuilder();
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
254 Formatter f = new Formatter(sb);
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
255 for (int i = 0; i < ranges.size(); i += 3) {
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
256 int s1 = ranges.get(i);
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
257 int s2 = ranges.get(i + 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
258 int len = ranges.get(i + 2);
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
259 f.format("[%d..%d) == [%d..%d); ", s1, s1 + len, s2, s2 + len);
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
260 }
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
261 return sb;
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
262 }
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
263
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
264 @Override
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
265 public String toString() {
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
266 return String.format("RangeSeq[%d]:%s", count, dump());
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
267 }
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
268 }
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
269 }