Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/AnnotateFacility.java @ 555:e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 22 Feb 2013 19:03:25 +0100 |
parents | a5fd757d1b5d |
children |
rev | line source |
---|---|
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; |
548
ab21ac7dd833
Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
546
diff
changeset
|
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
22 import java.util.BitSet; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
23 import java.util.LinkedList; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
24 import java.util.ListIterator; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
25 |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
26 import org.tmatesoft.hg.core.HgIterateDirection; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.tmatesoft.hg.core.Nodeid; |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
28 import org.tmatesoft.hg.internal.AnnotateFacility.RevisionDescriptor.Recipient; |
551
4ea0351ca878
Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
549
diff
changeset
|
29 import org.tmatesoft.hg.internal.DiffHelper.LineSequence; |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
30 import org.tmatesoft.hg.internal.DiffHelper.LineSequence.ByteChain; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgDataFile; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import org.tmatesoft.hg.repo.HgInvalidStateException; |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
33 import org.tmatesoft.hg.repo.HgRepository; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
34 import org.tmatesoft.hg.util.Adaptable; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import org.tmatesoft.hg.util.CancelledException; |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
36 import org.tmatesoft.hg.util.Pair; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 /** |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
39 * Facility with diff/annotate functionality. |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 * |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * @author Artem Tikhomirov |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 * @author TMate Software Ltd. |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 */ |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 @Experimental(reason="work in progress") |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 public class AnnotateFacility { |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
46 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
47 /** |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
48 * mimic 'hg diff -r clogRevIndex1 -r clogRevIndex2' |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
49 */ |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
50 public void diff(HgDataFile df, int clogRevIndex1, int clogRevIndex2, BlockInspector insp) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
51 int fileRevIndex1 = fileRevIndex(df, clogRevIndex1); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
52 int fileRevIndex2 = fileRevIndex(df, clogRevIndex2); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
53 FileLinesCache fileInfoCache = new FileLinesCache(df, 5); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
54 LineSequence c1 = fileInfoCache.lines(fileRevIndex1); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
55 LineSequence c2 = fileInfoCache.lines(fileRevIndex2); |
551
4ea0351ca878
Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
549
diff
changeset
|
56 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>(); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
57 pg.init(c1, c2); |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
58 pg.findMatchingBlocks(new BlameBlockInspector(insp, clogRevIndex1, clogRevIndex2)); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
59 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
60 |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
61 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
62 * Walk file history up to revision at given changeset and report changes for each revision |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
63 */ |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
64 public void annotate(HgDataFile df, int changelogRevisionIndex, BlockInspector insp, HgIterateDirection iterateOrder) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
65 if (!df.exists()) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
66 return; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
67 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
68 // Note, changelogRevisionIndex may be TIP, while #implAnnotateChange doesn't tolerate constants |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
69 // |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
70 // XXX df.indexWalk(0, fileRevIndex, ) might be more effective |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
71 int fileRevIndex = fileRevIndex(df, changelogRevisionIndex); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
72 int[] fileRevParents = new int[2]; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
73 IntVector fileParentRevs = new IntVector((fileRevIndex+1) * 2, 0); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
74 fileParentRevs.add(NO_REVISION, NO_REVISION); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
75 for (int i = 1; i <= fileRevIndex; i++) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
76 df.parents(i, fileRevParents, null, null); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
77 fileParentRevs.add(fileRevParents[0], fileRevParents[1]); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
78 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
79 // collect file revisions to visit, from newest to oldest |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
80 IntVector fileRevsToVisit = new IntVector(fileRevIndex + 1, 0); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
81 LinkedList<Integer> queue = new LinkedList<Integer>(); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
82 BitSet seen = new BitSet(fileRevIndex + 1); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
83 queue.add(fileRevIndex); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
84 do { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
85 int x = queue.removeFirst(); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
86 if (seen.get(x)) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
87 continue; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
88 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
89 seen.set(x); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
90 fileRevsToVisit.add(x); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
91 int p1 = fileParentRevs.get(2*x); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
92 int p2 = fileParentRevs.get(2*x + 1); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
93 if (p1 != NO_REVISION) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
94 queue.addLast(p1); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
95 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
96 if (p2 != NO_REVISION) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
97 queue.addLast(p2); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
98 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
99 } while (!queue.isEmpty()); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
100 FileLinesCache fileInfoCache = new FileLinesCache(df, 10); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
101 // fileRevsToVisit now { r10, r7, r6, r5, r0 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
102 // and we'll iterate it from behind, e.g. old to new unless reversed |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
103 if (iterateOrder == HgIterateDirection.NewToOld) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
104 fileRevsToVisit.reverse(); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
105 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
106 for (int i = fileRevsToVisit.size() - 1; i >= 0; i--) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
107 int fri = fileRevsToVisit.get(i); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
108 int clogRevIndex = df.getChangesetRevisionIndex(fri); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
109 fileRevParents[0] = fileParentRevs.get(fri * 2); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
110 fileRevParents[1] = fileParentRevs.get(fri * 2 + 1); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
111 implAnnotateChange(fileInfoCache, clogRevIndex, fri, fileRevParents, insp); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
112 } |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
113 } |
548
ab21ac7dd833
Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
546
diff
changeset
|
114 |
ab21ac7dd833
Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
546
diff
changeset
|
115 /** |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
116 * Annotates changes of the file against its parent(s). |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
117 * Unlike {@link #annotate(HgDataFile, int, BlockInspector, HgIterateDirection)}, doesn't |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
118 * walk file history, looks at the specified revision only. Handles both parents (if merge revision). |
548
ab21ac7dd833
Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
546
diff
changeset
|
119 */ |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
120 public void annotateSingleRevision(HgDataFile df, int changelogRevisionIndex, BlockInspector insp) { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
121 // TODO detect if file is text/binary (e.g. looking for chars < ' ' and not \t\r\n\f |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
122 int fileRevIndex = fileRevIndex(df, changelogRevisionIndex); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 int[] fileRevParents = new int[2]; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 df.parents(fileRevIndex, fileRevParents, null, null); |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
125 if (changelogRevisionIndex == TIP) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
126 changelogRevisionIndex = df.getChangesetRevisionIndex(fileRevIndex); |
548
ab21ac7dd833
Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
546
diff
changeset
|
127 } |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
128 implAnnotateChange(new FileLinesCache(df, 5), changelogRevisionIndex, fileRevIndex, fileRevParents, insp); |
548
ab21ac7dd833
Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
546
diff
changeset
|
129 } |
ab21ac7dd833
Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
546
diff
changeset
|
130 |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
131 private void implAnnotateChange(FileLinesCache fl, int csetRevIndex, int fileRevIndex, int[] fileParentRevs, BlockInspector insp) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
132 final LineSequence fileRevLines = fl.lines(fileRevIndex); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
133 if (fileParentRevs[0] != NO_REVISION && fileParentRevs[1] != NO_REVISION) { |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
134 LineSequence p1Lines = fl.lines(fileParentRevs[0]); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
135 LineSequence p2Lines = fl.lines(fileParentRevs[1]); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
136 int p1ClogIndex = fl.getChangesetRevisionIndex(fileParentRevs[0]); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
137 int p2ClogIndex = fl.getChangesetRevisionIndex(fileParentRevs[1]); |
551
4ea0351ca878
Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
549
diff
changeset
|
138 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>(); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
139 pg.init(p2Lines, fileRevLines); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
140 EqualBlocksCollector p2MergeCommon = new EqualBlocksCollector(); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
141 pg.findMatchingBlocks(p2MergeCommon); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
142 // |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
143 pg.init(p1Lines); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
144 BlameBlockInspector bbi = new BlameBlockInspector(insp, p1ClogIndex, csetRevIndex); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
145 bbi.setMergeParent2(p2MergeCommon, p2ClogIndex); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
146 pg.findMatchingBlocks(bbi); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
147 } else if (fileParentRevs[0] == fileParentRevs[1]) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
148 // may be equal iff both are unset |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
149 assert fileParentRevs[0] == NO_REVISION; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
150 // everything added |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
151 BlameBlockInspector bbi = new BlameBlockInspector(insp, NO_REVISION, csetRevIndex); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
152 bbi.begin(LineSequence.newlines(new byte[0]), fileRevLines); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
153 bbi.match(0, fileRevLines.chunkCount()-1, 0); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
154 bbi.end(); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
155 } else { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
156 int soleParent = fileParentRevs[0] == NO_REVISION ? fileParentRevs[1] : fileParentRevs[0]; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
157 assert soleParent != NO_REVISION; |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
158 LineSequence parentLines = fl.lines(soleParent); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
159 |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
160 int parentChangesetRevIndex = fl.getChangesetRevisionIndex(soleParent); |
551
4ea0351ca878
Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
549
diff
changeset
|
161 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>(); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
162 pg.init(parentLines, fileRevLines); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
163 pg.findMatchingBlocks(new BlameBlockInspector(insp, parentChangesetRevIndex, csetRevIndex)); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
164 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
165 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
166 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
167 private static int fileRevIndex(HgDataFile df, int csetRevIndex) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
168 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(csetRevIndex, df.getPath()); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
169 return df.getRevisionIndex(fileRev); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
170 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
171 |
552
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
172 private static class FileLinesCache { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
173 private final HgDataFile df; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
174 private final LinkedList<Pair<Integer, LineSequence>> lruCache; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
175 private final int limit; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
176 private IntMap<Integer> fileToClogIndexMap = new IntMap<Integer>(20); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
177 |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
178 public FileLinesCache(HgDataFile file, int lruLimit) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
179 df = file; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
180 limit = lruLimit; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
181 lruCache = new LinkedList<Pair<Integer, LineSequence>>(); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
182 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
183 |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
184 public int getChangesetRevisionIndex(int fileRevIndex) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
185 Integer cached = fileToClogIndexMap.get(fileRevIndex); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
186 if (cached == null) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
187 cached = df.getChangesetRevisionIndex(fileRevIndex); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
188 fileToClogIndexMap.put(fileRevIndex, cached); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
189 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
190 return cached.intValue(); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
191 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
192 |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
193 public LineSequence lines(int fileRevIndex) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
194 Pair<Integer, LineSequence> cached = checkCache(fileRevIndex); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
195 if (cached != null) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
196 return cached.second(); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
197 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
198 try { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
199 ByteArrayChannel c; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
200 df.content(fileRevIndex, c = new ByteArrayChannel()); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
201 LineSequence rv = LineSequence.newlines(c.toArray()); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
202 lruCache.addFirst(new Pair<Integer, LineSequence>(fileRevIndex, rv)); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
203 if (lruCache.size() > limit) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
204 lruCache.removeLast(); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
205 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
206 return rv; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
207 } catch (CancelledException ex) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
208 // TODO likely it was bad idea to throw cancelled exception from content() |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
209 // deprecate and provide alternative? |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
210 HgInvalidStateException ise = new HgInvalidStateException("ByteArrayChannel never throws CancelledException"); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
211 ise.initCause(ex); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
212 throw ise; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
213 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
214 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
215 |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
216 private Pair<Integer,LineSequence> checkCache(int fileRevIndex) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
217 Pair<Integer, LineSequence> rv = null; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
218 for (ListIterator<Pair<Integer, LineSequence>> it = lruCache.listIterator(); it.hasNext(); ) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
219 Pair<Integer, LineSequence> p = it.next(); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
220 if (p.first() == fileRevIndex) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
221 rv = p; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
222 it.remove(); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
223 break; |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
224 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
225 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
226 if (rv != null) { |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
227 lruCache.addFirst(rv); |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
228 } |
45751456b471
Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
551
diff
changeset
|
229 return rv; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
230 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
231 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
232 |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
233 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
234 * Client's sink for revision differences. |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
235 * |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
236 * When implemented, clients shall not expect new {@link Block blocks} instances in each call. |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
237 * |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
238 * In case more information about annotated revision is needed, inspector instances may supply |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
239 * {@link RevisionDescriptor.Recipient} through {@link Adaptable}. |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
240 */ |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
241 @Callback |
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:
545
diff
changeset
|
242 public interface BlockInspector { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
243 void same(EqualBlock block); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
244 void added(AddBlock block); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
245 void changed(ChangeBlock block); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
246 void deleted(DeleteBlock block); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
247 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
248 |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
249 /** |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
250 * Represents content of a block, either as a sequence of bytes or a |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
251 * sequence of smaller blocks (lines), if appropriate (according to usage context). |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
252 * |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
253 * This approach allows line-by-line access to content data along with complete byte sequence for the whole block, i.e. |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
254 * <pre> |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
255 * BlockData bd = addBlock.addedLines() |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
256 * // bd describes data from the addition completely. |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
257 * // elements of the BlockData are lines |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
258 * bd.elementCount() == addBlock.totalAddedLines(); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
259 * // one cat obtain complete addition with |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
260 * byte[] everythingAdded = bd.asArray(); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
261 * // or iterate line by line |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
262 * for (int i = 0; i < bd.elementCount(); i++) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
263 * byte[] lineContent = bd.elementAt(i); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
264 * String line = new String(lineContent, fileEncodingCharset); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
265 * } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
266 * where bd.elementAt(0) is the line at index addBlock.firstAddedLine() |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
267 * </pre> |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
268 * |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
269 * LineData or ChunkData? |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
270 */ |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
271 public interface BlockData { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
272 BlockData elementAt(int index); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
273 int elementCount(); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
274 byte[] asArray(); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
275 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
276 |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
277 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
278 * {@link BlockInspector} may optionally request extra information about revisions |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
279 * being inspected, denoting itself as a {@link RevisionDescriptor.Recipient}. This class |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
280 * provides complete information about file revision under annotation now. |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
281 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
282 public interface RevisionDescriptor { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
283 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
284 * @return complete source of the diff origin, never <code>null</code> |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
285 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
286 BlockData origin(); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
287 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
288 * @return complete source of the diff target, never <code>null</code> |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
289 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
290 BlockData target(); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
291 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
292 * @return changeset revision index of original file, or {@link HgRepository#NO_REVISION} if it's the very first revision |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
293 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
294 int originChangesetIndex(); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
295 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
296 * @return changeset revision index of the target file |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
297 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
298 int targetChangesetIndex(); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
299 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
300 * @return <code>true</code> if this revision is merge |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
301 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
302 boolean isMerge(); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
303 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
304 * @return changeset revision index of the second, merged parent |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
305 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
306 int mergeChangesetIndex(); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
307 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
308 * @return revision index of the change in file's revlog |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
309 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
310 int fileRevisionIndex(); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
311 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
312 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
313 * Implement to indicate interest in {@link RevisionDescriptor}. |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
314 * |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
315 * Note, instance of {@link RevisionDescriptor} is the same for |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
316 * {@link #start(RevisionDescriptor)} and {@link #done(RevisionDescriptor)} |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
317 * methods, and not necessarily a new one (i.e. <code>==</code>) for the next |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
318 * revision announced. |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
319 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
320 @Callback |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
321 public interface Recipient { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
322 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
323 * Comes prior to any change {@link Block blocks} |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
324 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
325 void start(RevisionDescriptor revisionDescription); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
326 /** |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
327 * Comes after all change {@link Block blocks} were dispatched |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
328 */ |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
329 void done(RevisionDescriptor revisionDescription); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
330 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
331 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
332 |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
333 public interface Block { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
334 int originChangesetIndex(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
335 int targetChangesetIndex(); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
336 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
337 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
338 public interface EqualBlock extends Block { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
339 int originStart(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
340 int targetStart(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
341 int length(); |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
342 BlockData content(); |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
343 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
344 |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
345 public interface AddBlock extends Block { |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
346 int insertedAt(); // line index in the old file |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
347 int firstAddedLine(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
348 int totalAddedLines(); |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
349 BlockData addedLines(); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
350 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
351 public interface DeleteBlock extends Block { |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
352 int removedAt(); // line index in the new file |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
353 int firstRemovedLine(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
354 int totalRemovedLines(); |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
355 BlockData removedLines(); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
356 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
357 public interface ChangeBlock extends AddBlock, DeleteBlock { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
358 } |
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:
545
diff
changeset
|
359 |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
360 private static class BlameBlockInspector extends DiffHelper.DeltaInspector<LineSequence> { |
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:
545
diff
changeset
|
361 private final BlockInspector insp; |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
362 private final int csetOrigin; |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
363 private final int csetTarget; |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
364 private EqualBlocksCollector p2MergeCommon; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
365 private int csetMergeParent; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
366 private IntVector mergeRanges; |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
367 private final AnnotateRev annotatedRevision; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
368 |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
369 public BlameBlockInspector(BlockInspector inspector, int originCset, int targetCset) { |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
370 assert inspector != null; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
371 insp = inspector; |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
372 annotatedRevision = new AnnotateRev(); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
373 csetOrigin = originCset; |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
374 csetTarget = targetCset; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
375 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
376 |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
377 public void setMergeParent2(EqualBlocksCollector p2Merge, int parentCset2) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
378 p2MergeCommon = p2Merge; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
379 csetMergeParent = parentCset2; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
380 mergeRanges = new IntVector(3*10, 3*10); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
381 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
382 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
383 @Override |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
384 public void begin(LineSequence s1, LineSequence s2) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
385 super.begin(s1, s2); |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
386 ContentBlock originContent = new ContentBlock(s1); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
387 ContentBlock targetContent = new ContentBlock(s2); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
388 annotatedRevision.set(originContent, targetContent); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
389 annotatedRevision.set(csetOrigin, csetTarget, p2MergeCommon != null ? csetMergeParent : NO_REVISION); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
390 Recipient curious = Adaptable.Factory.getAdapter(insp, Recipient.class, null); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
391 if (curious != null) { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
392 curious.start(annotatedRevision); |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
393 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
394 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
395 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
396 @Override |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
397 public void end() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
398 super.end(); |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
399 Recipient curious = Adaptable.Factory.getAdapter(insp, Recipient.class, null); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
400 if (curious != null) { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
401 curious.done(annotatedRevision); |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
402 } |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
403 p2MergeCommon = null; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
404 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
405 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
406 @Override |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
407 protected void changed(int s1From, int s1To, int s2From, int s2To) { |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
408 if (p2MergeCommon != null) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
409 mergeRanges.clear(); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
410 p2MergeCommon.combineAndMarkRangesWithTarget(s2From, s2To - s2From, csetOrigin, csetMergeParent, mergeRanges); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
411 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
412 /* |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
413 * Usecases: |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
414 * 3 lines changed to 10 lines. range of 10 lines breaks down to 2 from p2, 3 from p1, and 5 from p2. |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
415 * We report: 2 lines changed to 2(p2), then 1 line changed with 3(p1) and 5 lines added from p2. |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
416 * |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
417 * 10 lines changed to 3 lines, range of 3 lines breaks down to 2 line from p1 and 1 line from p2. |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
418 * We report: 2 lines changed to 2(p1) and 8 lines changed to 1(p2) |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
419 */ |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
420 int s1TotalLines = s1To - s1From, s1ConsumedLines = 0, s1Start = s1From; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
421 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
422 for (int i = 0; i < mergeRanges.size(); i += 3) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
423 final int rangeOrigin = mergeRanges.get(i); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
424 final int rangeStart = mergeRanges.get(i+1); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
425 final int rangeLen = mergeRanges.get(i+2); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
426 final boolean lastRange = i+3 >= mergeRanges.size(); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
427 final int s1LinesLeft = s1TotalLines - s1ConsumedLines; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
428 // how many lines we may reported as changed (don't use more than in range unless it's the very last range) |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
429 final int s1LinesToBorrow = lastRange ? s1LinesLeft : Math.min(s1LinesLeft, rangeLen); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
430 if (s1LinesToBorrow > 0) { |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
431 ChangeBlockImpl block = getChangeBlock(s1Start, s1LinesToBorrow, rangeStart, rangeLen); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
432 block.setOriginAndTarget(rangeOrigin, csetTarget); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
433 insp.changed(block); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
434 s1ConsumedLines += s1LinesToBorrow; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
435 s1Start += s1LinesToBorrow; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
436 } else { |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
437 ChangeBlockImpl block = getAddBlock(rangeStart, rangeLen, s1Start); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
438 block.setOriginAndTarget(rangeOrigin, csetTarget); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
439 insp.added(block); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
440 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
441 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
442 if (s1ConsumedLines != s1TotalLines) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
443 throw new HgInvalidStateException(String.format("Expected to process %d lines, but actually was %d", s1TotalLines, s1ConsumedLines)); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
444 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
445 } else { |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
446 ChangeBlockImpl block = getChangeBlock(s1From, s1To-s1From, s2From, s2To - s2From); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
447 block.setOriginAndTarget(csetOrigin, csetTarget); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
448 insp.changed(block); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
449 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
450 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
451 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
452 @Override |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
453 protected void added(int s1InsertPoint, int s2From, int s2To) { |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
454 if (p2MergeCommon != null) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
455 mergeRanges.clear(); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
456 p2MergeCommon.combineAndMarkRangesWithTarget(s2From, s2To - s2From, csetOrigin, csetMergeParent, mergeRanges); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
457 int insPoint = s1InsertPoint; // track changes to insertion point |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
458 for (int i = 0; i < mergeRanges.size(); i += 3) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
459 int rangeOrigin = mergeRanges.get(i); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
460 int rangeStart = mergeRanges.get(i+1); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
461 int rangeLen = mergeRanges.get(i+2); |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
462 ChangeBlockImpl block = getAddBlock(rangeStart, rangeLen, insPoint); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
463 block.setOriginAndTarget(rangeOrigin, csetTarget); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
464 insp.added(block); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
465 // indicate insPoint moved down number of lines we just reported |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
466 insPoint += rangeLen; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
467 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
468 } else { |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
469 ChangeBlockImpl block = getAddBlock(s2From, s2To - s2From, s1InsertPoint); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
470 block.setOriginAndTarget(csetOrigin, csetTarget); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
471 insp.added(block); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
472 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
473 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
474 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
475 @Override |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
476 protected void deleted(int s2DeletePoint, int s1From, int s1To) { |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
477 ChangeBlockImpl block = new ChangeBlockImpl(annotatedRevision.origin, null, s1From, s1To - s1From, -1, -1, -1, s2DeletePoint); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
478 block.setOriginAndTarget(csetOrigin, csetTarget); |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
479 insp.deleted(block); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
480 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
481 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
482 @Override |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
483 protected void unchanged(int s1From, int s2From, int length) { |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
484 EqualBlockImpl block = new EqualBlockImpl(s1From, s2From, length, annotatedRevision.target); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
485 block.setOriginAndTarget(csetOrigin, csetTarget); |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
486 insp.same(block); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
487 } |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
488 |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
489 private ChangeBlockImpl getAddBlock(int start, int len, int insPoint) { |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
490 return new ChangeBlockImpl(null, annotatedRevision.target, -1, -1, start, len, insPoint, -1); |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
491 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
492 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
493 private ChangeBlockImpl getChangeBlock(int start1, int end1, int start2, int end2) { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
494 return new ChangeBlockImpl(annotatedRevision.origin, annotatedRevision.target, start1, end1-start1, start2, end2-start2, start1, start2); |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
495 } |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
496 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
497 |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
498 private static class BlockImpl implements Block { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
499 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
500 private int originCset; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
501 private int targetCset; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
502 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
503 void setOriginAndTarget(int originChangesetIndex, int targetChangesetIndex) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
504 // XXX perhaps, shall be part of Inspector API, rather than Block's |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
505 // as they don't change between blocks (although the moment about merged revisions) |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
506 // is not yet clear to me |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
507 originCset = originChangesetIndex; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
508 targetCset = targetChangesetIndex; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
509 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
510 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
511 public int originChangesetIndex() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
512 return originCset; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
513 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
514 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
515 public int targetChangesetIndex() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
516 return targetCset; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
517 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
518 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
519 |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
520 private static class EqualBlockImpl extends BlockImpl implements EqualBlock { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
521 private final int start1, start2; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
522 private final int length; |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
523 private final ContentBlock fullContent; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
524 private FilterBlock myContent; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
525 |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
526 EqualBlockImpl(int blockStartSeq1, int blockStartSeq2, int blockLength, ContentBlock targetContent) { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
527 start1 = blockStartSeq1; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
528 start2 = blockStartSeq2; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
529 length = blockLength; |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
530 fullContent = targetContent; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
531 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
532 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
533 public int originStart() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
534 return start1; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
535 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
536 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
537 public int targetStart() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
538 return start2; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
539 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
540 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
541 public int length() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
542 return length; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
543 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
544 |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
545 public BlockData content() { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
546 if (myContent == null) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
547 myContent = new FilterBlock(fullContent, start2, length); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
548 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
549 return myContent; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
550 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
551 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
552 @Override |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
553 public String toString() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
554 return String.format("@@ [%d..%d) == [%d..%d) @@", start1, start1+length, start2, start2+length); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
555 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
556 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
557 |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
558 private static class ChangeBlockImpl extends BlockImpl implements ChangeBlock { |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
559 |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
560 private final ContentBlock oldContent; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
561 private final ContentBlock newContent; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
562 private final int s1Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
563 private final int s1Len; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
564 private final int s2Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
565 private final int s2Len; |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
566 private final int s1InsertPoint; |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
567 private final int s2DeletePoint; |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
568 private FilterBlock addedBlock, removedBlock; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
569 |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
570 public ChangeBlockImpl(ContentBlock c1, ContentBlock c2, int s1Start, int s1Len, int s2Start, int s2Len, int s1InsertPoint, int s2DeletePoint) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
571 oldContent = c1; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
572 newContent = c2; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
573 this.s1Start = s1Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
574 this.s1Len = s1Len; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
575 this.s2Start = s2Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
576 this.s2Len = s2Len; |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
577 this.s1InsertPoint = s1InsertPoint; |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
578 this.s2DeletePoint = s2DeletePoint; |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
579 } |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
580 |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
581 public int insertedAt() { |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
582 return s1InsertPoint; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
583 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
584 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
585 public int firstAddedLine() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
586 return s2Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
587 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
588 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
589 public int totalAddedLines() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
590 return s2Len; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
591 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
592 |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
593 public BlockData addedLines() { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
594 if (addedBlock == null) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
595 addedBlock = new FilterBlock(newContent, firstAddedLine(), totalAddedLines()); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
596 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
597 return addedBlock; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
598 } |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
599 |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
600 public int removedAt() { |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
601 return s2DeletePoint; |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
602 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
603 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
604 public int firstRemovedLine() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
605 return s1Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
606 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
607 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
608 public int totalRemovedLines() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
609 return s1Len; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
610 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
611 |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
612 public BlockData removedLines() { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
613 if (removedBlock == null) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
614 removedBlock = new FilterBlock(oldContent, firstRemovedLine(), totalRemovedLines()); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
615 } |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
616 return removedBlock; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
617 } |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
618 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
619 @Override |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
620 public String toString() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
621 if (s2DeletePoint == -1) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
622 return String.format("@@ -%d,0 +%d,%d @@", insertedAt(), firstAddedLine(), totalAddedLines()); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
623 } else if (s1InsertPoint == -1) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
624 // delete only |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
625 return String.format("@@ -%d,%d +%d,0 @@", firstRemovedLine(), totalRemovedLines(), removedAt()); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
626 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
627 return String.format("@@ -%d,%d +%d,%d @@", firstRemovedLine(), totalRemovedLines(), firstAddedLine(), totalAddedLines()); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
628 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
629 } |
554
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
630 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
631 private static class SingleLine implements BlockData { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
632 private final ByteChain line; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
633 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
634 public SingleLine(ByteChain lineContent) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
635 line = lineContent; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
636 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
637 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
638 public BlockData elementAt(int index) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
639 assert false; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
640 return null; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
641 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
642 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
643 public int elementCount() { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
644 return 0; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
645 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
646 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
647 public byte[] asArray() { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
648 return line.data(); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
649 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
650 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
651 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
652 private static class ContentBlock implements BlockData { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
653 private final LineSequence seq; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
654 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
655 public ContentBlock(LineSequence sequence) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
656 seq = sequence; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
657 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
658 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
659 public BlockData elementAt(int index) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
660 return new SingleLine(seq.chunk(index)); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
661 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
662 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
663 public int elementCount() { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
664 return seq.chunkCount() - 1; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
665 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
666 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
667 public byte[] asArray() { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
668 return seq.data(0, seq.chunkCount() - 1); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
669 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
670 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
671 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
672 private static class FilterBlock implements BlockData { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
673 private final ContentBlock contentBlock; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
674 private final int from; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
675 private final int length; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
676 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
677 public FilterBlock(ContentBlock bd, int startFrom, int len) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
678 assert bd != null; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
679 assert startFrom + len < bd.seq.chunkCount(); // there's one extra chunk in the end, so strict less is ok |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
680 contentBlock = bd; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
681 from = startFrom; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
682 length = len; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
683 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
684 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
685 public BlockData elementAt(int index) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
686 if (index < 0 || index >= length) { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
687 throw new IllegalArgumentException(String.format("Expected value from [0..%d), got %d", length, index)); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
688 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
689 return contentBlock.elementAt(from + index); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
690 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
691 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
692 public int elementCount() { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
693 return length; |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
694 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
695 |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
696 public byte[] asArray() { |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
697 return contentBlock.seq.data(from, from + length); |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
698 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
699 } |
a5fd757d1b5d
Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
553
diff
changeset
|
700 |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
701 |
551
4ea0351ca878
Better (precise) name for diff facility, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
549
diff
changeset
|
702 static class EqualBlocksCollector implements DiffHelper.MatchInspector<LineSequence> { |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
703 private final IntVector matches = new IntVector(10*3, 2*3); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
704 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
705 public void begin(LineSequence s1, LineSequence s2) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
706 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
707 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
708 public void match(int startSeq1, int startSeq2, int matchLength) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
709 matches.add(startSeq1); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
710 matches.add(startSeq2); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
711 matches.add(matchLength); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
712 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
713 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
714 public void end() { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
715 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
716 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
717 // true when specified line in origin is equal to a line in target |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
718 public boolean includesOriginLine(int ln) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
719 return includes(ln, 0); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
720 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
721 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
722 // true when specified line in target is equal to a line in origin |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
723 public boolean includesTargetLine(int ln) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
724 return includes(ln, 1); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
725 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
726 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
727 public void intersectWithTarget(int start, int length, IntVector result) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
728 int s = start; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
729 for (int l = start, x = start + length; l < x; l++) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
730 if (!includesTargetLine(l)) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
731 if (l - s > 0) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
732 result.add(s); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
733 result.add(l - s); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
734 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
735 s = l+1; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
736 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
737 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
738 if (s < start+length) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
739 result.add(s); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
740 result.add((start + length) - s); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
741 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
742 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
743 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
744 /* |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
745 * intersects [start..start+length) with ranges of target lines, and based on the intersection |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
746 * breaks initial range into smaller ranges and records them into result, with marker to indicate |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
747 * whether the range is from initial range (markerSource) or is a result of the intersection with target |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
748 * (markerTarget) |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
749 */ |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
750 public void combineAndMarkRangesWithTarget(int start, int length, int markerSource, int markerTarget, IntVector result) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
751 int sourceStart = start, targetStart = start, sourceEnd = start + length; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
752 for (int l = sourceStart; l < sourceEnd; l++) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
753 if (includesTargetLine(l)) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
754 // l is from target |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
755 if (sourceStart < l) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
756 // few lines from source range were not in the target, report them |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
757 result.add(markerSource); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
758 result.add(sourceStart); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
759 result.add(l - sourceStart); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
760 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
761 // indicate the earliest line from source range to use |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
762 sourceStart = l + 1; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
763 } else { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
764 // l is not in target |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
765 if (targetStart < l) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
766 // report lines from target range |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
767 result.add(markerTarget); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
768 result.add(targetStart); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
769 result.add(l - targetStart); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
770 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
771 // next line *may* be from target |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
772 targetStart = l + 1; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
773 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
774 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
775 // if source range end with line from target, sourceStart would be == sourceEnd, and we need to add range with markerTarget |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
776 // if source range doesn't end with target line, targetStart == sourceEnd, while sourceStart < sourceEnd |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
777 if (sourceStart < sourceEnd) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
778 assert targetStart == sourceEnd; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
779 // something left from the source range |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
780 result.add(markerSource); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
781 result.add(sourceStart); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
782 result.add(sourceEnd - sourceStart); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
783 } else if (targetStart < sourceEnd) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
784 assert sourceStart == sourceEnd; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
785 result.add(markerTarget); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
786 result.add(targetStart); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
787 result.add(sourceEnd - targetStart); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
788 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
789 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
790 |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
791 private boolean includes(int ln, int o) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
792 for (int i = 2; i < matches.size(); o += 3, i+=3) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
793 int rangeStart = matches.get(o); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
794 if (rangeStart > ln) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
795 return false; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
796 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
797 int rangeLen = matches.get(i); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
798 if (rangeStart + rangeLen > ln) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
799 return true; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
800 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
801 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
802 return false; |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
803 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
804 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
805 |
555
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
806 private static class AnnotateRev implements RevisionDescriptor { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
807 public ContentBlock origin, target; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
808 public int originCset, targetCset, mergeCset, fileRevIndex; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
809 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
810 public void set(ContentBlock o, ContentBlock t) { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
811 origin = o; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
812 target = t; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
813 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
814 public void set(int o, int t, int m) { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
815 originCset = o; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
816 targetCset = t; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
817 mergeCset = m; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
818 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
819 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
820 public BlockData origin() { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
821 return origin; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
822 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
823 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
824 public BlockData target() { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
825 return target; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
826 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
827 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
828 public int originChangesetIndex() { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
829 return originCset; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
830 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
831 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
832 public int targetChangesetIndex() { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
833 return targetCset; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
834 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
835 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
836 public boolean isMerge() { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
837 return mergeCset != NO_REVISION; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
838 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
839 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
840 public int mergeChangesetIndex() { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
841 return mergeCset; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
842 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
843 |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
844 public int fileRevisionIndex() { |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
845 return fileRevIndex; |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
846 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
847 } |
e623aa2ca526
Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
554
diff
changeset
|
848 |
549
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
849 public static void main(String[] args) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
850 EqualBlocksCollector bc = new EqualBlocksCollector(); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
851 bc.match(-1, 5, 3); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
852 bc.match(-1, 10, 2); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
853 bc.match(-1, 15, 3); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
854 bc.match(-1, 20, 3); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
855 assert !bc.includesTargetLine(4); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
856 assert bc.includesTargetLine(7); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
857 assert !bc.includesTargetLine(8); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
858 assert bc.includesTargetLine(10); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
859 assert !bc.includesTargetLine(12); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
860 IntVector r = new IntVector(); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
861 bc.intersectWithTarget(7, 10, r); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
862 for (int i = 0; i < r.size(); i+=2) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
863 System.out.printf("[%d..%d) ", r.get(i), r.get(i) + r.get(i+1)); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
864 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
865 System.out.println(); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
866 r.clear(); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
867 bc.combineAndMarkRangesWithTarget(0, 16, 508, 514, r); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
868 for (int i = 0; i < r.size(); i+=3) { |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
869 System.out.printf("%d:[%d..%d) ", r.get(i), r.get(i+1), r.get(i+1) + r.get(i+2)); |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
870 } |
83afa680555d
Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
548
diff
changeset
|
871 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
872 } |