annotate src/org/tmatesoft/hg/internal/diff/BlameHelper.java @ 703:7839ff0bfd78

Refactor: move diff/blame related code to a separate package
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 14 Aug 2013 14:51:51 +0200
parents src/org/tmatesoft/hg/internal/BlameHelper.java@58a6900f845d
children 497e697636fc
rev   line source
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
703
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
17 package org.tmatesoft.hg.internal.diff;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
19 import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
22 import java.util.ArrayList;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
23 import java.util.Arrays;
674
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
24 import java.util.Iterator;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.LinkedList;
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
26 import java.util.List;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.ListIterator;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.core.HgCallbackTargetException;
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
30 import org.tmatesoft.hg.core.Nodeid;
703
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
31 import org.tmatesoft.hg.internal.ByteArrayChannel;
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
32 import org.tmatesoft.hg.internal.FileHistory;
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
33 import org.tmatesoft.hg.internal.FileRevisionHistoryChunk;
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
34 import org.tmatesoft.hg.internal.IntSliceSeq;
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
35 import org.tmatesoft.hg.internal.IntTuple;
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
36 import org.tmatesoft.hg.internal.IntVector;
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
37 import org.tmatesoft.hg.internal.diff.DiffHelper.LineSequence;
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
38 import org.tmatesoft.hg.internal.diff.DiffHelper.LineSequence.ByteChain;
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
39 import org.tmatesoft.hg.internal.diff.DiffRangeMap.RangePair;
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
40 import org.tmatesoft.hg.core.HgBlameInspector;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
41 import org.tmatesoft.hg.core.HgBlameInspector.*;
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
42 import org.tmatesoft.hg.repo.HgChangelog;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 import org.tmatesoft.hg.repo.HgDataFile;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 import org.tmatesoft.hg.repo.HgInvalidStateException;
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
45 import org.tmatesoft.hg.repo.HgParentChildMap;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
46 import org.tmatesoft.hg.repo.HgRepository;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
47 import org.tmatesoft.hg.repo.HgRevisionMap;
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 625
diff changeset
48 import org.tmatesoft.hg.repo.HgRuntimeException;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 import org.tmatesoft.hg.util.Adaptable;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 import org.tmatesoft.hg.util.CancelledException;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 import org.tmatesoft.hg.util.Pair;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 /**
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 * Blame implementation
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
55 * @see HgBlameInspector
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 * @author Artem Tikhomirov
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 * @author TMate Software Ltd.
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 */
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 public class BlameHelper {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
61 private final HgBlameInspector insp;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 private FileLinesCache linesCache;
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
63 private HgParentChildMap<HgChangelog> clogMap;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
65 public BlameHelper(HgBlameInspector inspector) {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 insp = inspector;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 }
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
68
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
69 /**
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
70 * Build history of the file for the specified range (follow renames if necessary). This history
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
71 * is used to access various file revision data during subsequent {@link #diff(int, int, int, int)} and
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
72 * {@link #annotateChange(int, int, int[], int[])} calls. Callers can use returned history for own approaches
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
73 * to iteration over file history.
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
74
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
75 * <p>NOTE, clogRevIndexEnd has to list name of the supplied file in the corresponding manifest,
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
76 * as it's not possible to trace rename history otherwise.
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
77 */
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 625
diff changeset
78 public FileHistory prepare(HgDataFile df, int clogRevIndexStart, int clogRevIndexEnd) throws HgRuntimeException {
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
79 assert clogRevIndexStart <= clogRevIndexEnd;
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
80 FileHistory fileHistory = new FileHistory(df, clogRevIndexStart, clogRevIndexEnd);
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
81 fileHistory.build();
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
82 int cacheHint = 5; // cache comes useful when we follow merge branches and don't want to
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
83 // parse base revision twice. There's no easy way to determine max(distance(all(base,merge))),
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
84 // hence the heuristics to use the longest history chunk:
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
85 for (FileRevisionHistoryChunk c : fileHistory.iterate(OldToNew)) {
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
86 // iteration order is not important here
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
87 if (c.revisionCount() > cacheHint) {
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
88 cacheHint = c.revisionCount();
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
89 }
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
90 }
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
91 linesCache = new FileLinesCache(cacheHint);
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
92 for (FileRevisionHistoryChunk fhc : fileHistory.iterate(OldToNew)) {
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
93 // iteration order is not important here
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
94 linesCache.useFileUpTo(fhc.getFile(), fhc.getEndChangeset());
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
95 }
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
96 return fileHistory;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 // NO_REVISION is not allowed as any argument
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 625
diff changeset
100 public void diff(int fileRevIndex1, int clogRevIndex1, int fileRevIndex2, int clogRevIndex2) throws HgCallbackTargetException, HgRuntimeException {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 HgDataFile targetFile = linesCache.getFile(clogRevIndex2);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 LineSequence c1 = linesCache.lines(clogRevIndex1, fileRevIndex1);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 LineSequence c2 = linesCache.lines(clogRevIndex2, fileRevIndex2);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 pg.init(c1, c2);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 BlameBlockInspector bbi = new BlameBlockInspector(targetFile, fileRevIndex2, insp, clogRevIndex1, clogRevIndex2);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 pg.findMatchingBlocks(bbi);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 bbi.checkErrors();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 625
diff changeset
111 public void annotateChange(int fileRevIndex, int csetRevIndex, int[] fileParentRevs, int[] fileParentClogRevs) throws HgCallbackTargetException, HgRuntimeException {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 HgDataFile targetFile = linesCache.getFile(csetRevIndex);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 final LineSequence fileRevLines = linesCache.lines(csetRevIndex, fileRevIndex);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 if (fileParentClogRevs[0] != NO_REVISION && fileParentClogRevs[1] != NO_REVISION) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 int p1ClogIndex = fileParentClogRevs[0];
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 int p2ClogIndex = fileParentClogRevs[1];
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 LineSequence p1Lines = linesCache.lines(p1ClogIndex, fileParentRevs[0]);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 LineSequence p2Lines = linesCache.lines(p2ClogIndex, fileParentRevs[1]);
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
119 MergeResolutionStrategy mergeResolver = createMergeStrategy(fileRevLines, p1Lines, p2Lines, csetRevIndex, fileParentClogRevs);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
120 //
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>();
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
122 pg.init(p1Lines, fileRevLines);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 BlameBlockInspector bbi = new BlameBlockInspector(targetFile, fileRevIndex, insp, p1ClogIndex, csetRevIndex);
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
124 bbi.setMergeParent2(mergeResolver, p2ClogIndex);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 pg.findMatchingBlocks(bbi);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 bbi.checkErrors();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 } else if (fileParentClogRevs[0] == fileParentClogRevs[1]) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 // may be equal iff both are unset
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 assert fileParentClogRevs[0] == NO_REVISION;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 // everything added
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 BlameBlockInspector bbi = new BlameBlockInspector(targetFile, fileRevIndex, insp, NO_REVISION, csetRevIndex);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 bbi.begin(LineSequence.newlines(new byte[0]), fileRevLines);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 bbi.match(0, fileRevLines.chunkCount()-1, 0);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 bbi.end();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 bbi.checkErrors();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 } else {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 int soleParentIndex = fileParentClogRevs[0] == NO_REVISION ? 1 : 0;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 assert fileParentClogRevs[soleParentIndex] != NO_REVISION;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 LineSequence parentLines = linesCache.lines(fileParentClogRevs[soleParentIndex], fileParentRevs[soleParentIndex]);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 pg.init(parentLines, fileRevLines);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 BlameBlockInspector bbi = new BlameBlockInspector(targetFile, fileRevIndex, insp, fileParentClogRevs[soleParentIndex], csetRevIndex);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 pg.findMatchingBlocks(bbi);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 bbi.checkErrors();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
149 private static final boolean useNewStrategy = Boolean.TRUE.booleanValue();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
150
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
151 private MergeResolutionStrategy createMergeStrategy(LineSequence fileRevLines, LineSequence p1Lines, LineSequence p2Lines, int csetRevIndex, int[] fileParentClogRevs) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
152 DiffHelper<LineSequence> pg = new DiffHelper<LineSequence>();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
153 if (useNewStrategy) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
154 final ArrayList<RangePairSeq> allMatches = new ArrayList<RangePairSeq>();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
155 pg.init(p2Lines, fileRevLines);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
156 pg.findAllMatchAlternatives(new DiffHelper.MatchInspector<LineSequence>() {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
157 private RangePairSeq matches;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
158
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
159 public void begin(LineSequence s1, LineSequence s2) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
160 matches = new RangePairSeq();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
161 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
162
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
163 public void match(int startSeq1, int startSeq2, int matchLength) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
164 matches.add(startSeq1, startSeq2, matchLength);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
165 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
166
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
167 public void end() {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
168 if (matches.size() > 0) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
169 allMatches.add(matches);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
170 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
171 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
172
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
173 });
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
174 //
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
175 LineSequence baseLines = getBaseRevisionLines(csetRevIndex, fileParentClogRevs);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
176 pg.init(p1Lines, baseLines);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
177 DiffRangeMap p1ToBase = new DiffRangeMap().fill(pg);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
178 pg.init(baseLines, p2Lines);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
179 DiffRangeMap baseToP2 = new DiffRangeMap().fill(pg);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
180 return new MergeStrategy2(allMatches, p1ToBase, baseToP2);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
181 } else {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
182 pg.init(p2Lines, fileRevLines);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
183 EqualBlocksCollector p2MergeCommon = new EqualBlocksCollector();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
184 pg.findMatchingBlocks(p2MergeCommon);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
185 return new MergeStrategy1(p2MergeCommon.matches);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
186 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
187 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
188
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
189 private LineSequence getBaseRevisionLines(int clogRevIndex, int[] fileParentClogRevs) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
190 assert fileParentClogRevs[0] >= 0;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
191 assert fileParentClogRevs[1] >= 0;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
192 HgDataFile targetFile = linesCache.getFile(clogRevIndex);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
193 final HgRepository repo = targetFile.getRepo();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
194 if (clogMap == null) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
195 // FIXME replace HgParentChildMap with revlog.indexWalk(AncestorIterator))
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
196 clogMap = new HgParentChildMap<HgChangelog>(repo.getChangelog());
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
197 clogMap.init();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
198 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
199 final HgRevisionMap<HgChangelog> m = clogMap.getRevisionMap();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
200 Nodeid ancestor = clogMap.ancestor(m.revision(fileParentClogRevs[0]), m.revision(fileParentClogRevs[1]));
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
201 final int ancestorRevIndex = m.revisionIndex(ancestor);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
202 Nodeid fr = repo.getManifest().getFileRevision(ancestorRevIndex, targetFile.getPath());
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
203 if (fr == null) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
204 return LineSequence.newlines(new byte[0]);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
205 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
206 return linesCache.lines(ancestorRevIndex, targetFile.getRevisionIndex(fr));
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
207 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
208
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 private static class FileLinesCache {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210 private final LinkedList<Pair<Integer, LineSequence>> lruCache;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 private final int limit;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212 private final LinkedList<Pair<Integer, HgDataFile>> files; // TODO in fact, need sparse array
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
214 /**
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
215 * @param lruLimit how many parsed file revisions to keep
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
216 */
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217 public FileLinesCache(int lruLimit) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 limit = lruLimit;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 lruCache = new LinkedList<Pair<Integer, LineSequence>>();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 files = new LinkedList<Pair<Integer,HgDataFile>>();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
222
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223 public void useFileUpTo(HgDataFile df, int clogRevIndex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 Pair<Integer, HgDataFile> newEntry = new Pair<Integer, HgDataFile>(clogRevIndex, df);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225 for (ListIterator<Pair<Integer, HgDataFile>> it = files.listIterator(); it.hasNext();) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226 Pair<Integer, HgDataFile> e = it.next();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
227 if (e.first() == clogRevIndex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 assert e.second().getPath().equals(df.getPath());
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
229 return;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
231 if (e.first() > clogRevIndex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
232 // insert new entry before current
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
233 it.previous();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
234 it.add(newEntry);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
235 return;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
236 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
237 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
238 files.add(newEntry);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 public HgDataFile getFile(int clogRevIndex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 for (Pair<Integer, HgDataFile> e : files) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 if (e.first() >= clogRevIndex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 return e.second();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
245 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
246 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
247 throw new HgInvalidStateException(String.format("Got %d file-changelog mappings, but no luck for revision %d.", files.size(), clogRevIndex));
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
248 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
249
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 625
diff changeset
250 public LineSequence lines(int clogRevIndex, int fileRevIndex) throws HgRuntimeException {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
251 Pair<Integer, LineSequence> cached = checkCache(clogRevIndex);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
252 if (cached != null) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
253 return cached.second();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
254 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
255 HgDataFile df = getFile(clogRevIndex);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
256 try {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
257 ByteArrayChannel c;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
258 df.content(fileRevIndex, c = new ByteArrayChannel());
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
259 LineSequence rv = LineSequence.newlines(c.toArray());
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
260 lruCache.addFirst(new Pair<Integer, LineSequence>(clogRevIndex, rv));
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
261 if (lruCache.size() > limit) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
262 lruCache.removeLast();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
263 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
264 return rv;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
265 } catch (CancelledException ex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
266 // TODO likely it was bad idea to throw cancelled exception from content()
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
267 // deprecate and provide alternative?
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
268 HgInvalidStateException ise = new HgInvalidStateException("ByteArrayChannel never throws CancelledException");
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
269 ise.initCause(ex);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
270 throw ise;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
271 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
272 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
273
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
274 private Pair<Integer,LineSequence> checkCache(int fileRevIndex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
275 Pair<Integer, LineSequence> rv = null;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
276 for (ListIterator<Pair<Integer, LineSequence>> it = lruCache.listIterator(); it.hasNext(); ) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
277 Pair<Integer, LineSequence> p = it.next();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
278 if (p.first() == fileRevIndex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
279 rv = p;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
280 it.remove();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
281 break;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
282 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
283 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
284 if (rv != null) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
285 lruCache.addFirst(rv);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
286 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
287 return rv;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
288 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
289 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
290
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
291 private static class BlameBlockInspector extends DiffHelper.DeltaInspector<LineSequence> {
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
292 private final HgBlameInspector insp;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
293 private final int csetOrigin;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
294 private final int csetTarget;
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
295 private MergeResolutionStrategy p2MergeCommon;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
296 private int csetMergeParent;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
297 private final AnnotateRev annotatedRevision;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
298 private HgCallbackTargetException error;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
299
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
300 public BlameBlockInspector(HgDataFile df, int fileRevIndex, HgBlameInspector inspector, int originCset, int targetCset) {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
301 assert inspector != null;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
302 insp = inspector;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
303 annotatedRevision = new AnnotateRev();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
304 annotatedRevision.set(df, fileRevIndex);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
305 csetOrigin = originCset;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
306 csetTarget = targetCset;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
307 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
308
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
309 public void setMergeParent2(MergeResolutionStrategy p2MergeStrategy, int parentCset2) {
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
310 p2MergeCommon = p2MergeStrategy;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
311 csetMergeParent = parentCset2;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
312 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
313
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
314 @Override
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
315 public void begin(LineSequence s1, LineSequence s2) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
316 super.begin(s1, s2);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
317 if (shallStop()) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
318 return;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
319 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
320 ContentBlock originContent = new ContentBlock(s1);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
321 ContentBlock targetContent = new ContentBlock(s2);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
322 annotatedRevision.set(originContent, targetContent);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
323 annotatedRevision.set(csetOrigin, csetTarget, p2MergeCommon != null ? csetMergeParent : NO_REVISION);
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
324 RevisionDescriptor.Recipient curious = Adaptable.Factory.getAdapter(insp, RevisionDescriptor.Recipient.class, null);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
325 if (curious != null) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
326 try {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
327 curious.start(annotatedRevision);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
328 } catch (HgCallbackTargetException ex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
329 error = ex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
330 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
331 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
332 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
333
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
334 @Override
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
335 public void end() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
336 super.end();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
337 if (shallStop()) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
338 return;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
339 }
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
340 RevisionDescriptor.Recipient curious = Adaptable.Factory.getAdapter(insp, RevisionDescriptor.Recipient.class, null);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
341 if (curious != null) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
342 try {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
343 curious.done(annotatedRevision);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
344 } catch (HgCallbackTargetException ex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
345 error = ex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
346 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
347 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
348 p2MergeCommon = null;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
349 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
350
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
351 @Override
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
352 protected void changed(int s1From, int s1To, int s2From, int s2To) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
353 if (shallStop()) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
354 return;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
355 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
356 try {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
357 if (p2MergeCommon != null) {
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
358 IntSliceSeq mergeRanges = p2MergeCommon.combineAndMarkRangesWithSource(s1From, s1To, s2From, s2To, csetOrigin, csetMergeParent);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
359
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
360 /*
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
361 * Usecases, how it USED TO BE initially:
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
362 * 3 lines changed to 10 lines. range of 10 lines breaks down to 2 from p2, 3 from p1, and 5 from p2.
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
363 * We report: 2 lines changed to 2(p2), then 1 line changed with 3(p1) and 5 lines added from p2.
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
364 *
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
365 * 10 lines changed to 3 lines, range of 3 lines breaks down to 2 line from p1 and 1 line from p2.
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
366 * We report: 2 lines changed to 2(p1) and 8 lines changed to 1(p2)
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
367 *
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
368 * NOW, lines from p2 are always reported as pure add (since we need their insertion point to be in p2, not in p1)
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
369 * and we try to consume p1 changes as soon as we see first p1's range
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
370 */
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
371 int s1TotalLines = s1To - s1From, s1ConsumedLines = 0, s1Start = s1From;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
372
674
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
373 for (Iterator<IntTuple> it = mergeRanges.iterator(); it.hasNext();) {
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
374 IntTuple mergeRange = it.next();
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
375 final int rangeOrigin = mergeRange.at(0);
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
376 final int rangeStart = mergeRange.at(1);
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
377 final int rangeLen = mergeRange.at(2);
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
378 final boolean lastRange = it.hasNext();
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
379 final int s1LinesLeft = s1TotalLines - s1ConsumedLines;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
380 // how many lines we may report as changed (don't use more than in range unless it's the very last range)
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
381 final int s1LinesToBorrow = lastRange ? s1LinesLeft : Math.min(s1LinesLeft, rangeLen);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
382 if (rangeOrigin != csetMergeParent && s1LinesToBorrow > 0) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
383 ChangeBlockImpl block = getChangeBlock(s1Start, s1LinesToBorrow, rangeStart, rangeLen);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
384 block.setOriginAndTarget(rangeOrigin, csetTarget);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
385 insp.changed(block);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
386 s1ConsumedLines += s1LinesToBorrow;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
387 s1Start += s1LinesToBorrow;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
388 } else {
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
389 int blockInsPoint = rangeOrigin != csetMergeParent ? s1Start : p2MergeCommon.getLineInP2(rangeStart);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
390 ChangeBlockImpl block = getAddBlock(rangeStart, rangeLen, blockInsPoint);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
391 block.setOriginAndTarget(rangeOrigin, csetTarget);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
392 insp.added(block);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
393 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
394 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
395 if (s1ConsumedLines != s1TotalLines) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
396 assert s1ConsumedLines < s1TotalLines : String.format("Expected to process %d lines, but actually was %d", s1TotalLines, s1ConsumedLines);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
397 // either there were no ranges from p1, whole s2From..s2To range came from p2, shall report as deleted
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
398 // or the ranges found were not enough to consume whole s2From..s2To
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
399 // The "deletion point" is shifted to the end of last csetOrigin->csetTarget change
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
400 int s2DeletePoint = s2From + s1ConsumedLines;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
401 ChangeBlockImpl block = new ChangeBlockImpl(annotatedRevision.origin, null, s1Start, s1To - s1Start, -1, -1, -1, s2DeletePoint);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
402 block.setOriginAndTarget(csetOrigin, csetTarget);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
403 insp.deleted(block);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
404 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
405 } else {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
406 ChangeBlockImpl block = getChangeBlock(s1From, s1To - s1From, s2From, s2To - s2From);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
407 block.setOriginAndTarget(csetOrigin, csetTarget);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
408 insp.changed(block);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
409 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
410 } catch (HgCallbackTargetException ex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
411 error = ex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
412 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
413 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
414
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
415 @Override
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
416 protected void added(int s1InsertPoint, int s2From, int s2To) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
417 if (shallStop()) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
418 return;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
419 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
420 try {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
421 if (p2MergeCommon != null) {
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
422 IntSliceSeq mergeRanges = p2MergeCommon.combineAndMarkRangesWithSource(s1InsertPoint, s2From, s2To, csetOrigin, csetMergeParent);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
423 int insPoint = s1InsertPoint; // track changes to insertion point
674
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
424 for (IntTuple mergeRange : mergeRanges) {
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
425 int rangeOrigin = mergeRange.at(0);
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
426 int rangeStart = mergeRange.at(1);
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
427 int rangeLen = mergeRange.at(2);
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
428 // XXX likely need somewhat similar to the code above:
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
429 // int blockInsPoint = rangeOrigin != csetMergeParent ? s1Start : p2MergeCommon.reverseMapLine(rangeStart);
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
430 //
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
431 ChangeBlockImpl block = getAddBlock(rangeStart, rangeLen, insPoint);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
432 block.setOriginAndTarget(rangeOrigin, csetTarget);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
433 insp.added(block);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
434 // indicate insPoint moved down number of lines we just reported
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
435 insPoint += rangeLen;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
436 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
437 } else {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
438 ChangeBlockImpl block = getAddBlock(s2From, s2To - s2From, s1InsertPoint);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
439 block.setOriginAndTarget(csetOrigin, csetTarget);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
440 insp.added(block);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
441 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
442 } catch (HgCallbackTargetException ex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
443 error = ex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
444 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
445 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
446
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
447 @Override
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
448 protected void deleted(int s2DeletePoint, int s1From, int s1To) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
449 if (shallStop()) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
450 return;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
451 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
452 try {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
453 ChangeBlockImpl block = new ChangeBlockImpl(annotatedRevision.origin, null, s1From, s1To - s1From, -1, -1, -1, s2DeletePoint);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
454 block.setOriginAndTarget(csetOrigin, csetTarget);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
455 insp.deleted(block);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
456 } catch (HgCallbackTargetException ex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
457 error = ex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
458 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
459 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
460
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
461 @Override
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
462 protected void unchanged(int s1From, int s2From, int length) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
463 if (shallStop()) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
464 return;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
465 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
466 try {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
467 EqualBlockImpl block = new EqualBlockImpl(s1From, s2From, length, annotatedRevision.target);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
468 block.setOriginAndTarget(csetOrigin, csetTarget);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
469 insp.same(block);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
470 } catch (HgCallbackTargetException ex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
471 error = ex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
472 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
473 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
474
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
475 void checkErrors() throws HgCallbackTargetException {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
476 if (error != null) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
477 throw error;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
478 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
479 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
480
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
481 private boolean shallStop() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
482 return error != null;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
483 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
484
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
485 private ChangeBlockImpl getAddBlock(int start, int len, int insPoint) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
486 return new ChangeBlockImpl(null, annotatedRevision.target, -1, -1, start, len, insPoint, -1);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
487 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
488
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
489 private ChangeBlockImpl getChangeBlock(int start1, int len1, int start2, int len2) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
490 return new ChangeBlockImpl(annotatedRevision.origin, annotatedRevision.target, start1, len1, start2, len2, start1, start2);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
491 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
492 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
493
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
494 private static class BlockImpl implements Block {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
495 private int originCset;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
496 private int targetCset;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
497
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
498 void setOriginAndTarget(int originChangesetIndex, int targetChangesetIndex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
499 // XXX perhaps, shall be part of Inspector API, rather than Block's
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
500 // as they don't change between blocks (although the moment about merged revisions)
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
501 // is not yet clear to me
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
502 originCset = originChangesetIndex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
503 targetCset = targetChangesetIndex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
504 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
505
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
506 public int originChangesetIndex() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
507 return originCset;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
508 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
509
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
510 public int targetChangesetIndex() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
511 return targetCset;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
512 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
513 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
514
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
515 private static class EqualBlockImpl extends BlockImpl implements EqualBlock {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
516 private final int start1, start2;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
517 private final int length;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
518 private final ContentBlock fullContent;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
519 private FilterBlock myContent;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
520
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
521 EqualBlockImpl(int blockStartSeq1, int blockStartSeq2, int blockLength, ContentBlock targetContent) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
522 start1 = blockStartSeq1;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
523 start2 = blockStartSeq2;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
524 length = blockLength;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
525 fullContent = targetContent;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
526 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
527
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
528 public int originStart() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
529 return start1;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
530 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
531
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
532 public int targetStart() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
533 return start2;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
534 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
535
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
536 public int length() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
537 return length;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
538 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
539
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
540 public BlockData content() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
541 if (myContent == null) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
542 myContent = new FilterBlock(fullContent, start2, length);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
543 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
544 return myContent;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
545 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
546
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
547 @Override
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
548 public String toString() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
549 return String.format("@@ [%d..%d) == [%d..%d) @@", start1, start1+length, start2, start2+length);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
550 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
551 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
552
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
553 private static class ChangeBlockImpl extends BlockImpl implements ChangeBlock {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
554 private final ContentBlock oldContent;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
555 private final ContentBlock newContent;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
556 private final int s1Start;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
557 private final int s1Len;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
558 private final int s2Start;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
559 private final int s2Len;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
560 private final int s1InsertPoint;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
561 private final int s2DeletePoint;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
562 private FilterBlock addedBlock, removedBlock;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
563
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
564 public ChangeBlockImpl(ContentBlock c1, ContentBlock c2, int s1Start, int s1Len, int s2Start, int s2Len, int s1InsertPoint, int s2DeletePoint) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
565 oldContent = c1;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
566 newContent = c2;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
567 this.s1Start = s1Start;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
568 this.s1Len = s1Len;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
569 this.s2Start = s2Start;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
570 this.s2Len = s2Len;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
571 this.s1InsertPoint = s1InsertPoint;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
572 this.s2DeletePoint = s2DeletePoint;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
573 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
574
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
575 public int insertedAt() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
576 return s1InsertPoint;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
577 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
578
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
579 public int firstAddedLine() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
580 return s2Start;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
581 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
582
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
583 public int totalAddedLines() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
584 return s2Len;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
585 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
586
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
587 public BlockData addedLines() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
588 if (addedBlock == null) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
589 addedBlock = new FilterBlock(newContent, firstAddedLine(), totalAddedLines());
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
590 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
591 return addedBlock;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
592 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
593
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
594 public int removedAt() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
595 return s2DeletePoint;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
596 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
597
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
598 public int firstRemovedLine() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
599 return s1Start;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
600 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
601
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
602 public int totalRemovedLines() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
603 return s1Len;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
604 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
605
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
606 public BlockData removedLines() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
607 if (removedBlock == null) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
608 removedBlock = new FilterBlock(oldContent, firstRemovedLine(), totalRemovedLines());
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
609 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
610 return removedBlock;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
611 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
612
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
613 @Override
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
614 public String toString() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
615 if (s2DeletePoint == -1) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
616 return String.format("@@ -%d,0 +%d,%d @@", insertedAt(), firstAddedLine(), totalAddedLines());
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
617 } else if (s1InsertPoint == -1) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
618 // delete only
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
619 return String.format("@@ -%d,%d +%d,0 @@", firstRemovedLine(), totalRemovedLines(), removedAt());
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
620 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
621 return String.format("@@ -%d,%d +%d,%d @@", firstRemovedLine(), totalRemovedLines(), firstAddedLine(), totalAddedLines());
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
622 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
623 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
624
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
625 private static class SingleLine implements BlockData {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
626 private final ByteChain line;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
627
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
628 public SingleLine(ByteChain lineContent) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
629 line = lineContent;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
630 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
631
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
632 public BlockData elementAt(int index) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
633 assert false;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
634 return null;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
635 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
636
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
637 public int elementCount() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
638 return 0;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
639 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
640
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
641 public byte[] asArray() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
642 return line.data();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
643 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
644 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
645
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
646 private static class ContentBlock implements BlockData {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
647 private final LineSequence seq;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
648
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
649 public ContentBlock(LineSequence sequence) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
650 seq = sequence;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
651 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
652
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
653 public BlockData elementAt(int index) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
654 return new SingleLine(seq.chunk(index));
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
655 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
656
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
657 public int elementCount() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
658 return seq.chunkCount() - 1;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
659 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
660
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
661 public byte[] asArray() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
662 return seq.data(0, seq.chunkCount() - 1);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
663 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
664 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
665
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
666 private static class FilterBlock implements BlockData {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
667 private final ContentBlock contentBlock;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
668 private final int from;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
669 private final int length;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
670
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
671 public FilterBlock(ContentBlock bd, int startFrom, int len) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
672 assert bd != null;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
673 assert startFrom + len < bd.seq.chunkCount(); // there's one extra chunk in the end, so strict less is ok
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
674 contentBlock = bd;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
675 from = startFrom;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
676 length = len;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
677 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
678
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
679 public BlockData elementAt(int index) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
680 if (index < 0 || index >= length) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
681 throw new IllegalArgumentException(String.format("Expected value from [0..%d), got %d", length, index));
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
682 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
683 return contentBlock.elementAt(from + index);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
684 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
685
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
686 public int elementCount() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
687 return length;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
688 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
689
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
690 public byte[] asArray() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
691 return contentBlock.seq.data(from, from + length);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
692 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
693 }
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
694
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
695 private static class EqualBlocksCollector implements DiffHelper.MatchInspector<LineSequence> {
674
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
696 private final RangePairSeq matches = new RangePairSeq();
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
697
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
698 public void begin(LineSequence s1, LineSequence s2) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
699 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
700
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
701 public void match(int startSeq1, int startSeq2, int matchLength) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
702 matches.add(startSeq1, startSeq2, matchLength);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
703 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
704
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
705 public void end() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
706 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
707
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
708 public void intersectWithTarget(int start, int length, IntVector result) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
709 int s = start;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
710 for (int l = start, x = start + length; l < x; l++) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
711 if (!matches.includesTargetLine(l)) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
712 if (l - s > 0) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
713 result.add(s);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
714 result.add(l - s);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
715 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
716 s = l+1;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
717 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
718 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
719 if (s < start+length) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
720 result.add(s);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
721 result.add((start + length) - s);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
722 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
723 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
724
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
725 }
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
726
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
727 interface MergeResolutionStrategy {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
728 /**
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
729 * breaks region [start2..end2) into ranges according to deduced (or simply guessed)
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
730 * matching of [start1..end1) lines to lines in source1 and source2
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
731 * @return list of tuples (source, start, length), where source is one of the identifiers supplied
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
732 */
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
733 public IntSliceSeq combineAndMarkRangesWithSource(int start1, int end1, int start2, int end2, int source1, int source2);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
734 public IntSliceSeq combineAndMarkRangesWithSource(int insPoint, int start, int end, int source1, int source2);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
735 public int getLineInP2(int mergeLine);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
736 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
737
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
738 // report lines as merged from p2 solely based on whether target line belongs
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
739 // to a region that is equal to p2 region
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
740 private static class MergeStrategy1 implements MergeResolutionStrategy {
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
741 // equal ranges in p2 and merged revision
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
742 private final RangePairSeq matches;
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
743 private final IntSliceSeq mergeRanges;
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
744
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
745 public MergeStrategy1(RangePairSeq p2EqualToM) {
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
746 matches = p2EqualToM;
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
747 mergeRanges = new IntSliceSeq(3, 10, 10);
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
748 }
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
749
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
750 /*
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
751 * intersects [start..start+length) with ranges of target lines, and based on the intersection
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
752 * breaks initial range into smaller ranges and records them into result, with marker to indicate
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
753 * whether the range is from initial range (markerSource) or is a result of the intersection with target
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
754 * (markerTarget)
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
755 */
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
756 private IntSliceSeq doCombine(int start, int length, int markerSource, int markerTarget) {
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
757 mergeRanges.clear();
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
758 assert mergeRanges.sliceSize() == 3;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
759 int sourceStart = start, targetStart = start, sourceEnd = start + length;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
760 for (int l = sourceStart; l < sourceEnd; l++) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
761 if (matches.includesTargetLine(l)) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
762 // l is from target
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
763 if (sourceStart < l) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
764 // few lines from source range were not in the target, report them
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
765 mergeRanges.add(markerSource, sourceStart, l - sourceStart);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
766 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
767 // indicate the earliest line from source range to use
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
768 sourceStart = l + 1;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
769 } else {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
770 // l is not in target
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
771 if (targetStart < l) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
772 // report lines from target range
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
773 mergeRanges.add(markerTarget, targetStart, l - targetStart);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
774 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
775 // next line *may* be from target
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
776 targetStart = l + 1;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
777 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
778 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
779 // if source range end with line from target, sourceStart would be == sourceEnd, and we need to add range with markerTarget
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
780 // if source range doesn't end with target line, targetStart == sourceEnd, while sourceStart < sourceEnd
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
781 if (sourceStart < sourceEnd) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
782 assert targetStart == sourceEnd;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
783 // something left from the source range
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
784 mergeRanges.add(markerSource, sourceStart, sourceEnd - sourceStart);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
785 } else if (targetStart < sourceEnd) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
786 assert sourceStart == sourceEnd;
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
787 mergeRanges.add(markerTarget, targetStart, sourceEnd - targetStart);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
788 }
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
789 return mergeRanges;
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
790 }
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
791
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
792 public int getLineInP2(int mergeLine) {
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
793 return matches.reverseMapLine(mergeLine);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
794 }
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
795
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
796 public IntSliceSeq combineAndMarkRangesWithSource(int start1, int end1, int start2, int end2, int source1, int source2) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
797 return doCombine(start2, end2 - start2, source1, source2);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
798 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
799
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
800 public IntSliceSeq combineAndMarkRangesWithSource(int insPoint, int start, int end, int source1, int source2) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
801 return doCombine(start, end - start, source1, source2);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
802 }
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
803 }
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
804
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
805 private static class MergeStrategy2 implements MergeResolutionStrategy {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
806 // equal ranges in p2 and merged revision
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
807 private final List<RangePairSeq> matches;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
808 private final IntSliceSeq mergeRanges;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
809 private final DiffRangeMap p1ToBase;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
810 private final DiffRangeMap baseToP2;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
811
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
812 public MergeStrategy2(List<RangePairSeq> p2EqualToM, DiffRangeMap p1ToBaseRanges, DiffRangeMap baseToP2Ranges) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
813 matches = p2EqualToM;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
814 p1ToBase = p1ToBaseRanges;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
815 baseToP2= baseToP2Ranges;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
816 mergeRanges = new IntSliceSeq(3, 10, 10);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
817 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
818
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
819
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
820 public IntSliceSeq combineAndMarkRangesWithSource(int insPoint, int start, int end, int source1, int source2) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
821 return combineAndMarkRangesWithSource(insPoint, insPoint, start, end, source1, source2);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
822 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
823
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
824 public IntSliceSeq combineAndMarkRangesWithSource(int start1, int end1, int start2, int end2, int source1, int source2) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
825 mergeRanges.clear();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
826 IntSliceSeq mergedLines = new IntSliceSeq(2, end2-start2, 0);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
827 for (int i = start2; i < end2; i++) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
828 mergedLines.add(source1, 0);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
829 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
830 // [s1Start..s1End) // range in p1 seen as changed in m
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
831 for (RangePair p1_b : p1ToBase.findInSource(start1, end1)) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
832 // there might be few ranges in (p1-base) that overlap with (p1-m) changes
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
833 for (RangePair b_p2 : baseToP2.findInSource(p1_b.start2(), p1_b.end2())) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
834 // regions in p2 that correspond to affected regions in base
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
835 for (int p2Line = b_p2.start2(); p2Line < b_p2.end2(); p2Line++) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
836 for (RangePairSeq eq : matches) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
837 if (eq.includesOriginLine(p2Line)) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
838 // this line in p2 is equal to some line in merge
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
839 int mergeLine = eq.mapLineIndex(p2Line);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
840 if (mergeLine >= start2 && mergeLine < end2) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
841 mergedLines.set(mergeLine - start2, source2, p2Line);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
842 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
843 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
844 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
845 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
846 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
847 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
848 int lineCount = 0, start = start2;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
849 int lastSeenSource = source1;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
850 for (IntTuple t : mergedLines) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
851 if (t.at(0) == lastSeenSource) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
852 lineCount++;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
853 } else {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
854 if (lineCount > 0) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
855 mergeRanges.add(lastSeenSource, start, lineCount);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
856 start += lineCount;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
857 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
858 lineCount = 1;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
859 lastSeenSource = t.at(0);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
860 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
861 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
862 if (lineCount > 0) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
863 mergeRanges.add(lastSeenSource, start, lineCount);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
864 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
865 return mergeRanges;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
866 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
867
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
868 public int getLineInP2(int mergeLine) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
869 for (RangePairSeq eq : matches) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
870 if (eq.includesTargetLine(mergeLine)) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
871 return eq.reverseMapLine(mergeLine);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
872 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
873 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
874 return -1;
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
875 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
876 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
877
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
878
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
879 private static class AnnotateRev implements RevisionDescriptor {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
880 public ContentBlock origin, target;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
881 public int originCset, targetCset, mergeCset, fileRevIndex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
882 public HgDataFile df;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
883
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
884 public void set(HgDataFile file, int fileRev) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
885 df = file;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
886 fileRevIndex = fileRev;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
887 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
888 public void set(ContentBlock o, ContentBlock t) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
889 origin = o;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
890 target = t;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
891 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
892 public void set(int o, int t, int m) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
893 originCset = o;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
894 targetCset = t;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
895 mergeCset = m;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
896 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
897
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
898 public BlockData origin() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
899 return origin;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
900 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
901
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
902 public BlockData target() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
903 return target;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
904 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
905
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
906 public int originChangesetIndex() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
907 return originCset;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
908 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
909
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
910 public int targetChangesetIndex() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
911 return targetCset;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
912 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
913
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
914 public boolean isMerge() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
915 return mergeCset != NO_REVISION;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
916 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
917
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
918 public int mergeChangesetIndex() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
919 return mergeCset;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
920 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
921
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
922 public int fileRevisionIndex() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
923 return fileRevIndex;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
924 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
925 public HgDataFile file() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
926 return df;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
927 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
928 @Override
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
929 public String toString() {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
930 if (isMerge()) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
931 return String.format("[%d,%d->%d]", originCset, mergeCset, targetCset);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
932 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
933 return String.format("[%d->%d]", originCset, targetCset);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
934 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
935 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
936
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
937 public static void main(String[] args) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
938 EqualBlocksCollector bc = new EqualBlocksCollector();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
939 bc.match(-1, 5, 3);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
940 bc.match(-1, 10, 2);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
941 bc.match(-1, 15, 3);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
942 bc.match(-1, 20, 3);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
943 IntVector r = new IntVector();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
944 bc.intersectWithTarget(7, 10, r);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
945 for (int i = 0; i < r.size(); i+=2) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
946 System.out.printf("[%d..%d) ", r.get(i), r.get(i) + r.get(i+1));
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
947 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
948 System.out.println();
678
8625cba0a5a8 Towards better blame of merge revisions: refactor merge handling strategy
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 674
diff changeset
949 MergeStrategy1 ms = new MergeStrategy1(bc.matches);
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
950 IntSliceSeq mr = ms.doCombine(0, 16, 508, 514);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
951 for (IntTuple t : mr) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
952 System.out.printf("%d:[%d..%d) ", t.at(0), t.at(1), t.at(1) + t.at(2));
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
953 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
954 System.out.println();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
955 System.out.println();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
956 DiffRangeMap m1 = new DiffRangeMap(); // p1 -> base
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
957 m1.match(0, 0, 1); // =1..1 -> 1..1
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
958 m1.match(7, 3, 0); // *2..7 -> 2..3
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
959 DiffRangeMap m2 = new DiffRangeMap(); // base -> p2
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
960 m2.match(0, 0, 1); // =1..1 -> 1..1
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
961 m2.match(3, 3, 0); // *2..3 -> 2..3
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
962 RangePairSeq eq1 = new RangePairSeq();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
963 eq1.add(0, 0, 3);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
964 RangePairSeq eq2 = new RangePairSeq();
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
965 eq2.add(0, 4, 3);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
966 MergeStrategy2 ms2 = new MergeStrategy2(Arrays.asList(eq1, eq2), m1, m2);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 678
diff changeset
967 mr = ms2.combineAndMarkRangesWithSource(5, 7, 5, 7, 33, 44);
674
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
968 for (IntTuple t : mr) {
cce0387c6041 Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
969 System.out.printf("%d:[%d..%d) ", t.at(0), t.at(1), t.at(1) + t.at(2));
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
970 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
971 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
972 }