annotate src/org/tmatesoft/hg/internal/ForwardAnnotateInspector.java @ 680:58a6900f845d

Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 21 Jul 2013 17:15:34 +0200
parents 1c49c0cee540
children f1f095e42555
rev   line source
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import org.tmatesoft.hg.core.HgAnnotateCommand.Inspector;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import org.tmatesoft.hg.core.HgBlameInspector;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import org.tmatesoft.hg.core.HgCallbackTargetException;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import org.tmatesoft.hg.core.HgIterateDirection;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import org.tmatesoft.hg.util.CancelSupport;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.tmatesoft.hg.util.CancelledException;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.util.ProgressSupport;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 /**
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 * Annotate file history iterating from parents to children
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 *
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 * At the moment, doesn't handle start from any revision but 0
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 *
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 * (+) May report annotate for any revision in the visited range.
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 *
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 * @see ReverseAnnotateInspector
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author Artem Tikhomirov
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @author TMate Software Ltd.
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 */
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 public class ForwardAnnotateInspector implements HgBlameInspector, HgBlameInspector.RevisionDescriptor.Recipient {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 final IntMap<IntSliceSeq> all = new IntMap<IntSliceSeq>(100);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 // revision->map(lineNumber->lineContent)
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 private final IntMap<IntMap<byte[]>> lineContent = new IntMap<IntMap<byte[]>>(100);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 private IntSliceSeq current;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 private RevisionDescriptor revDescriptor;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 /**
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 * @return desired order of iteration for diff
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 */
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 public HgIterateDirection iterateDirection() {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 return HgIterateDirection.OldToNew;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 public void report(int revision, Inspector insp, ProgressSupport progress, CancelSupport cancel) throws HgCallbackTargetException, CancelledException {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 int totalLines = 0;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 for (IntTuple t : all.get(revision)) {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 totalLines += t.at(0);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 progress.start(totalLines);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 LineImpl li = new LineImpl();
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 int line = 1;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 for (IntTuple t : all.get(revision)) {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 IntMap<byte[]> revLines = lineContent.get(t.at(1));
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 for (int i = 0, x = t.at(0); i < x; i++) {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 final int lineInRev = t.at(2) + i;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 final byte[] lc = revLines.get(lineInRev);
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
65 li.init(line++, lineInRev+1, t.at(1), lc);
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 insp.next(li);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 progress.worked(1);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 cancel.checkCancelled();
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 progress.done();
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 public void start(RevisionDescriptor rd) throws HgCallbackTargetException {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 all.put(rd.targetChangesetIndex(), current = new IntSliceSeq(3));
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 revDescriptor = rd;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 public void done(RevisionDescriptor rd) throws HgCallbackTargetException {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 revDescriptor = null;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 public void same(EqualBlock block) throws HgCallbackTargetException {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 copyBlock(block.originChangesetIndex(), block.originStart(), block.length());
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 public void added(AddBlock block) throws HgCallbackTargetException {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 if (revDescriptor.isMerge() && block.originChangesetIndex() == revDescriptor.mergeChangesetIndex()) {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 copyBlock(block.originChangesetIndex(), block.insertedAt(), block.totalAddedLines());
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 return;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 BlockData addedLines = block.addedLines();
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 IntMap<byte[]> revLines = lineContent.get(block.targetChangesetIndex());
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 if (revLines == null) {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 lineContent.put(block.targetChangesetIndex(), revLines = new IntMap<byte[]>(block.totalAddedLines()));
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 for (int i = 0; i < block.totalAddedLines(); i++) {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 revLines.put(block.firstAddedLine() + i, addedLines.elementAt(i).asArray());
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 current.add(block.totalAddedLines(), block.targetChangesetIndex(), block.firstAddedLine());
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 public void changed(ChangeBlock block) throws HgCallbackTargetException {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 added(block);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 public void deleted(DeleteBlock block) throws HgCallbackTargetException {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
110 private void copyBlock(int originChangesetIndex, int blockStart, int length) {
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 IntSliceSeq origin = all.get(originChangesetIndex);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 assert origin != null; // shall visit parents before came to this child
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 int originPos = 0;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 int targetBlockLen = length;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 for (IntTuple t : origin) {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 int originBlockLen = t.at(0);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 int originBlockEnd = originPos + originBlockLen;
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
118 if (originBlockEnd > blockStart) {
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
119 // part of origin block from blockStart up to originBlockEnd, but not more
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
120 // than size of the block (when blockStart is out of block start, i.e. < originPos)
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
121 int originBlockOverlap = Math.min(originBlockLen, originBlockEnd - blockStart);
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 assert originBlockOverlap > 0;
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
123 // eat as much as there's left in the block being copied
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
124 int originBlockConsumed = Math.min(originBlockOverlap, targetBlockLen);
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 int originBlockLine = t.at(2);
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
126 if (originPos < blockStart) {
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 originBlockLine += originBlockLen-originBlockOverlap;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 // copy fragment of original block;
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
130 current.add(originBlockConsumed, t.at(1), originBlockLine);
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
131 targetBlockLen -= originBlockConsumed;
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 if (targetBlockLen == 0) {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 break;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 originPos += originBlockLen;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 }