Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/AnnotateFacility.java @ 545:15b406c7cd9d
First round of annotate file is functional
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 15 Feb 2013 22:15:13 +0100 |
parents | 7f5998a9619d |
children | cd78e8b9d7bc |
rev | line source |
---|---|
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import org.tmatesoft.hg.core.Nodeid; |
544
7f5998a9619d
Refactor PatchGenerator to be generic and welcome sequence of any nature
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
543
diff
changeset
|
22 import org.tmatesoft.hg.internal.PatchGenerator.LineSequence; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import org.tmatesoft.hg.repo.HgDataFile; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.tmatesoft.hg.repo.HgInvalidStateException; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import org.tmatesoft.hg.util.CancelledException; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 /** |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 * |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 * @author Artem Tikhomirov |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 * @author TMate Software Ltd. |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 */ |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 @Experimental(reason="work in progress") |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 public class AnnotateFacility { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 |
544
7f5998a9619d
Refactor PatchGenerator to be generic and welcome sequence of any nature
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
543
diff
changeset
|
35 /** |
7f5998a9619d
Refactor PatchGenerator to be generic and welcome sequence of any nature
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
543
diff
changeset
|
36 * Annotates changes of the file against its parent(s) |
7f5998a9619d
Refactor PatchGenerator to be generic and welcome sequence of any nature
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
543
diff
changeset
|
37 */ |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
38 public void annotateChange(HgDataFile df, int changesetRevisionIndex, Inspector insp) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
39 // TODO detect if file is text/binary (e.g. looking for chars < ' ' and not \t\r\n\f |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
40 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(changesetRevisionIndex, df.getPath()); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 int fileRevIndex = df.getRevisionIndex(fileRev); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 int[] fileRevParents = new int[2]; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 df.parents(fileRevIndex, fileRevParents, null, null); |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
44 try { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
45 if (fileRevParents[0] != NO_REVISION && fileRevParents[1] != NO_REVISION) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
46 // merge |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
47 } else if (fileRevParents[0] == fileRevParents[1]) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
48 // may be equal iff both are unset |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
49 assert fileRevParents[0] == NO_REVISION; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
50 // everything added |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
51 ByteArrayChannel c; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
52 df.content(fileRevIndex, c = new ByteArrayChannel()); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
53 BlameBlockInspector bbi = new BlameBlockInspector(insp, NO_REVISION, changesetRevisionIndex); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
54 LineSequence cls = LineSequence.newlines(c.toArray()); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
55 bbi.begin(LineSequence.newlines(new byte[0]), cls); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
56 bbi.match(0, cls.chunkCount()-1, 0); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
57 bbi.end(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
58 } else { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
59 int soleParent = fileRevParents[0] == NO_REVISION ? fileRevParents[1] : fileRevParents[0]; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
60 assert soleParent != NO_REVISION; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 ByteArrayChannel c1, c2; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 df.content(soleParent, c1 = new ByteArrayChannel()); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 df.content(fileRevIndex, c2 = new ByteArrayChannel()); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 int parentChangesetRevIndex = df.getChangesetRevisionIndex(soleParent); |
544
7f5998a9619d
Refactor PatchGenerator to be generic and welcome sequence of any nature
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
543
diff
changeset
|
65 PatchGenerator<LineSequence> pg = new PatchGenerator<LineSequence>(); |
7f5998a9619d
Refactor PatchGenerator to be generic and welcome sequence of any nature
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
543
diff
changeset
|
66 pg.init(LineSequence.newlines(c1.toArray()), LineSequence.newlines(c2.toArray())); |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
67 pg.findMatchingBlocks(new BlameBlockInspector(insp, parentChangesetRevIndex, changesetRevisionIndex)); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 } |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
69 } catch (CancelledException ex) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
70 // TODO likely it was bad idea to throw cancelled exception from content() |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
71 // deprecate and provide alternative? |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
72 HgInvalidStateException ise = new HgInvalidStateException("ByteArrayChannel never throws CancelledException"); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
73 ise.initCause(ex); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
74 throw ise; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 @Callback |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 public interface Inspector { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
80 void same(EqualBlock block); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 void added(AddBlock block); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 void changed(ChangeBlock block); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 void deleted(DeleteBlock block); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
86 @Callback |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
87 public interface InspectorEx extends Inspector { // XXX better name |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
88 // XXX perhaps, shall pass object instead of separate values for future extension? |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
89 void start(int originLineCount, int targetLineCount); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
90 void done(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
91 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
92 |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 public interface Block { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
94 int originChangesetIndex(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
95 int targetChangesetIndex(); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 // boolean isMergeRevision(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 // int fileRevisionIndex(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 // int originFileRevisionIndex(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 // String[] lines(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 // byte[] data(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
103 public interface EqualBlock extends Block { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
104 int originStart(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
105 int targetStart(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
106 int length(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
107 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
108 |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 public interface AddBlock extends Block { |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
110 int insertedAt(); // line index in the old file |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 int firstAddedLine(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 int totalAddedLines(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 String[] addedLines(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 public interface DeleteBlock extends Block { |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
116 int removedAt(); // line index in the new file |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 int firstRemovedLine(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 int totalRemovedLines(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 String[] removedLines(); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 public interface ChangeBlock extends AddBlock, DeleteBlock { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 |
544
7f5998a9619d
Refactor PatchGenerator to be generic and welcome sequence of any nature
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
543
diff
changeset
|
124 static class BlameBlockInspector extends PatchGenerator.DeltaInspector<LineSequence> { |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 private final Inspector insp; |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
126 private final int csetP1; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
127 private final int csetTarget; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
129 public BlameBlockInspector(Inspector inspector, int parentCset1, int targetCset) { |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 assert inspector != null; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 insp = inspector; |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
132 csetP1 = parentCset1; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
133 csetTarget = targetCset; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
134 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
135 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
136 @Override |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
137 public void begin(LineSequence s1, LineSequence s2) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
138 super.begin(s1, s2); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
139 if (insp instanceof InspectorEx) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
140 ((InspectorEx) insp).start(s1.chunkCount() - 1, s2.chunkCount() - 1); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
141 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
142 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
143 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
144 @Override |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
145 public void end() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
146 super.end(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
147 if(insp instanceof InspectorEx) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
148 ((InspectorEx) insp).done(); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
149 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 @Override |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 protected void changed(int s1From, int s1To, int s2From, int s2To) { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
154 BlockImpl2 block = new BlockImpl2(seq1, seq2, s1From, s1To-s1From, s2From, s2To - s2From, s1From, s2From); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
155 block.setOriginAndTarget(csetP1, csetTarget); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
156 insp.changed(block); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 @Override |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 protected void added(int s1InsertPoint, int s2From, int s2To) { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
161 BlockImpl2 block = new BlockImpl2(null, seq2, -1, -1, s2From, s2To - s2From, s1InsertPoint, -1); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
162 block.setOriginAndTarget(csetP1, csetTarget); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
163 insp.added(block); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 @Override |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
167 protected void deleted(int s2DeletePoint, int s1From, int s1To) { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
168 BlockImpl2 block = new BlockImpl2(seq1, null, s1From, s1To - s1From, -1, -1, -1, s2DeletePoint); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
169 block.setOriginAndTarget(csetP1, csetTarget); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
170 insp.deleted(block); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 @Override |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 protected void unchanged(int s1From, int s2From, int length) { |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
175 BlockImpl1 block = new BlockImpl1(s1From, s2From, length); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
176 block.setOriginAndTarget(csetP1, csetTarget); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
177 insp.same(block); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
178 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
179 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
180 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
181 static class BlockImpl implements Block { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
182 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
183 private int originCset; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
184 private int targetCset; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
185 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
186 void setOriginAndTarget(int originChangesetIndex, int targetChangesetIndex) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
187 // XXX perhaps, shall be part of Inspector API, rather than Block's |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
188 // as they don't change between blocks (although the moment about merged revisions) |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
189 // is not yet clear to me |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
190 originCset = originChangesetIndex; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
191 targetCset = targetChangesetIndex; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
192 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
193 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
194 public int originChangesetIndex() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
195 return originCset; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
196 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
197 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
198 public int targetChangesetIndex() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
199 return targetCset; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
200 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
202 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
203 static class BlockImpl1 extends BlockImpl implements EqualBlock { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
204 private final int start1, start2; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 private final int length; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
206 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
207 BlockImpl1(int blockStartSeq1, int blockStartSeq2, int blockLength) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
208 start1 = blockStartSeq1; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
209 start2 = blockStartSeq2; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
210 length = blockLength; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
211 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
212 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
213 public int originStart() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
214 return start1; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
215 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
216 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
217 public int targetStart() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
218 return start2; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
219 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
220 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
221 public int length() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
222 return length; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
223 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
224 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
225 @Override |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
226 public String toString() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
227 return String.format("@@ [%d..%d) == [%d..%d) @@", start1, start1+length, start2, start2+length); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
228 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
229 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
230 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
231 static class BlockImpl2 extends BlockImpl implements ChangeBlock { |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
232 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
233 private final LineSequence oldSeq; |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
234 private final LineSequence newSeq; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
235 private final int s1Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
236 private final int s1Len; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
237 private final int s2Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
238 private final int s2Len; |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
239 private final int s1InsertPoint; |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
240 private final int s2DeletePoint; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
241 |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
242 public BlockImpl2(LineSequence s1, LineSequence s2, int s1Start, int s1Len, int s2Start, int s2Len, int s1InsertPoint, int s2DeletePoint) { |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
243 oldSeq = s1; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
244 newSeq = s2; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
245 this.s1Start = s1Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
246 this.s1Len = s1Len; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
247 this.s2Start = s2Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
248 this.s2Len = s2Len; |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
249 this.s1InsertPoint = s1InsertPoint; |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
250 this.s2DeletePoint = s2DeletePoint; |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
251 } |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
252 |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
253 public int insertedAt() { |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
254 return s1InsertPoint; |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
255 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
256 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
257 public int firstAddedLine() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
258 return s2Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
259 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
260 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
261 public int totalAddedLines() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
262 return s2Len; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
263 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
264 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
265 public String[] addedLines() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
266 return generateLines(totalAddedLines(), firstAddedLine()); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
267 } |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
268 |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
269 public int removedAt() { |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
270 return s2DeletePoint; |
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
271 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
272 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
273 public int firstRemovedLine() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
274 return s1Start; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
275 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
276 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
277 public int totalRemovedLines() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
278 return s1Len; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
279 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
280 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
281 public String[] removedLines() { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
282 return generateLines(totalRemovedLines(), firstRemovedLine()); |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
283 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
284 |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
285 private String[] generateLines(int count, int startFrom) { |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
286 String[] rv = new String[count]; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
287 for (int i = 0; i < count; i++) { |
543
1e95f48d9886
Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
542
diff
changeset
|
288 rv[i] = String.format("LINE %d", startFrom + i+1); |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
289 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
290 return rv; |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
291 } |
545
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
292 |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
293 @Override |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
294 public String toString() { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
295 if (s2DeletePoint == -1) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
296 return String.format("@@ -%d,0 +%d,%d @@", insertedAt(), firstAddedLine(), totalAddedLines()); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
297 } else if (s1InsertPoint == -1) { |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
298 // delete only |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
299 return String.format("@@ -%d,%d +%d,0 @@", firstRemovedLine(), totalRemovedLines(), removedAt()); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
300 } |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
301 return String.format("@@ -%d,%d +%d,%d @@", firstRemovedLine(), totalRemovedLines(), firstAddedLine(), totalAddedLines()); |
15b406c7cd9d
First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
302 } |
542
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
303 } |
a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
304 } |