Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/ForwardAnnotateInspector.java @ 676:3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Thu, 18 Jul 2013 18:03:51 +0200 | 
| parents | |
| children | 1c49c0cee540 | 
| 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.HgAnnotateCommand.LineInfo; | 
| 
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.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 | 22 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 | 23 import org.tmatesoft.hg.core.HgDiffCommand; | 
| 
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.core.HgException; | 
| 
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.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 | 26 import org.tmatesoft.hg.repo.HgLookup; | 
| 
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 import org.tmatesoft.hg.repo.HgRepository; | 
| 
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 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 | 29 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 | 30 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 | 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 /** | 
| 
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 * 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 | 34 * | 
| 
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 * 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 | 36 * | 
| 
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 * (+) 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 | 38 * | 
| 
3219cfadda49
Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 39 * @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 | 40 * @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 | 41 * @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 | 42 */ | 
| 
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 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 | 44 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 | 45 // 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 | 46 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 | 47 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 | 48 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 | 49 | 
| 
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 * @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 | 52 */ | 
| 
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 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 | 54 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 | 55 } | 
| 
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 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 | 58 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 | 59 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 | 60 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 | 61 } | 
| 
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 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 | 63 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 | 64 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 | 65 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 | 66 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 | 67 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 | 68 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 | 69 final byte[] lc = revLines.get(lineInRev); | 
| 
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 li.init(line++, t.at(1), lc); | 
| 
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 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 | 72 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 | 73 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 | 74 } | 
| 
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 } | 
| 
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 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 | 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 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 | 80 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 | 81 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 | 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 | 
| 
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 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 | 85 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 | 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 | 
| 
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 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 | 89 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 | 90 } | 
| 
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 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 | 93 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 | 94 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 | 95 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 | 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 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 | 98 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 | 99 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 | 100 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 | 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 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 | 103 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 | 104 } | 
| 
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 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 | 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 | 
| 
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 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 | 109 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 | 110 } | 
| 
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 | 
| 
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 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 | 113 } | 
| 
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 | 
| 
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 private void copyBlock(int originChangesetIndex, int originStart, int 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 | 116 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 | 117 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 | 118 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 | 119 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 | 120 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 | 121 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 | 122 int originBlockEnd = 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 | 123 if (originBlockEnd > originStart) { | 
| 
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 | 124 int originBlockOverlap = Math.min(originBlockLen, originBlockEnd - originStart); | 
| 
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 assert originBlockOverlap > 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 | 126 originBlockOverlap = Math.min(originBlockOverlap, targetBlockLen); | 
| 
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 int originBlockLine = t.at(2); | 
| 
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 if (originPos < originStart) { | 
| 
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 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 | 130 } | 
| 
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 | 131 // copy fragment of original 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 | 132 current.add(originBlockOverlap, t.at(1), originBlockLine); | 
| 
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 targetBlockLen -= 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 | 134 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 | 135 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 | 136 } | 
| 
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 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 | 139 } | 
| 
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 | 140 } | 
| 
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 | 141 | 
| 
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 | 142 | 
| 
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 | 143 public static void main(String[] args) throws HgCallbackTargetException, CancelledException, HgException { | 
| 
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 | 144 HgRepository repo = new HgLookup().detect("/home/artem/hg/junit-test-repos/test-annotate/"); | 
| 
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 | 145 HgDiffCommand cmd = new HgDiffCommand(repo); | 
| 
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 | 146 cmd.file(repo.getFileNode("file1")).order(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 | 147 cmd.range(0, 8); | 
| 
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 | 148 final ForwardAnnotateInspector c2 = new ForwardAnnotateInspector(); | 
| 
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 | 149 cmd.executeAnnotate(c2); | 
| 
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 | 150 for (IntTuple t : c2.all.get(8)) { | 
| 
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 | 151 System.out.printf("Block %d lines from revision %d (starts with line %d in the origin)\n", t.at(0), t.at(1), t.at(2)); | 
| 
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 | 152 } | 
| 
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 | 153 for (IntTuple t : c2.all.get(8)) { | 
| 
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 | 154 System.out.printf("Block %d lines from revision %d (starts with line %d in the origin)\n", t.at(0), t.at(1), 1+t.at(2)); | 
| 
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 | 155 } | 
| 
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 | 156 c2.report(8, new 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 | 157 | 
| 
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 | 158 public void next(LineInfo lineInfo) 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 | 159 System.out.printf("%3d:%3d: %s", lineInfo.getChangesetIndex(), lineInfo.getLineNumber(), new String(lineInfo.getContent())); | 
| 
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 | 160 } | 
| 
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 | 161 }, ProgressSupport.Factory.get(null), CancelSupport.Factory.get(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 | 162 } | 
| 
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 | 163 } | 
