annotate test/org/tmatesoft/hg/test/TestBlame.java @ 549:83afa680555d

Annotate merge revision (combined diff against two parents without looking further)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 19 Feb 2013 21:17:39 +0100
parents ab21ac7dd833
children 45751456b471
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.test;
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
19 import static org.junit.Assert.assertEquals;
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
20 import static org.junit.Assert.assertTrue;
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
21 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
22 import static org.tmatesoft.hg.repo.HgRepository.TIP;
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
23
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
24 import java.io.ByteArrayOutputStream;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
25 import java.io.PrintStream;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
26 import java.util.Arrays;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
27 import java.util.regex.Pattern;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
28
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
29 import org.junit.Assert;
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
30 import org.junit.Rule;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.junit.Test;
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
32 import org.tmatesoft.hg.console.Bundle.Dump;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import org.tmatesoft.hg.internal.AnnotateFacility;
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import org.tmatesoft.hg.internal.AnnotateFacility.AddBlock;
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
35 import org.tmatesoft.hg.internal.AnnotateFacility.Block;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 import org.tmatesoft.hg.internal.AnnotateFacility.ChangeBlock;
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 import org.tmatesoft.hg.internal.AnnotateFacility.DeleteBlock;
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
38 import org.tmatesoft.hg.internal.AnnotateFacility.EqualBlock;
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
39 import org.tmatesoft.hg.internal.AnnotateFacility.LineDescriptor;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 import org.tmatesoft.hg.internal.IntMap;
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 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
42 import org.tmatesoft.hg.repo.HgLookup;
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 import org.tmatesoft.hg.repo.HgRepository;
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 /**
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 *
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 * @author Artem Tikhomirov
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 * @author TMate Software Ltd.
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 */
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 public class TestBlame {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
52 @Rule
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
53 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
54
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 @Test
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 public void testSingleParentBlame() throws Exception {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 HgRepository repo = new HgLookup().detectFromWorkingDir();
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
59 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java";
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
60 final int checkChangeset = 539;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
61 HgDataFile df = repo.getFileNode(fname);
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
62 ByteArrayOutputStream bos = new ByteArrayOutputStream();
544
7f5998a9619d Refactor PatchGenerator to be generic and welcome sequence of any nature
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 543
diff changeset
63 new AnnotateFacility().annotateChange(df, checkChangeset, new DiffOutInspector(new PrintStream(bos)));
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
64 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+");
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
65 ExecHelper eh = new ExecHelper(gp, null);
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
66 eh.run("hg", "diff", "-c", String.valueOf(checkChangeset), "-U", "0", fname);
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
67 //
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
68 String[] apiResult = splitLines(bos.toString());
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
69 String[] expected = splitLines(gp.result());
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
70 Assert.assertArrayEquals(expected, apiResult);
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
71 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
72
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
73 @Test
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
74 public void testFileAnnotate() throws Exception {
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
75 HgRepository repo = new HgLookup().detectFromWorkingDir();
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
76 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java";
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
77 HgDataFile df = repo.getFileNode(fname);
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
78 OutputParser.Stub op = new OutputParser.Stub();
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
79 ExecHelper eh = new ExecHelper(op, null);
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
80
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
81 for (int startChangeset : new int[] { TIP, /*539, 541/ *, TIP */}) {
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
82 FileAnnotateInspector fa = new FileAnnotateInspector();
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
83 new AnnotateFacility().annotate(df, startChangeset, fa);
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
84
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
85
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
86 op.reset();
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
87 eh.run("hg", "annotate", "-r", startChangeset == TIP ? "tip" : String.valueOf(startChangeset), fname);
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
88
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
89 String[] hgAnnotateLines = splitLines(op.result());
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
90 assertTrue("[sanity]", hgAnnotateLines.length > 0);
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
91 assertEquals("Number of lines reported by native annotate and our impl", hgAnnotateLines.length, fa.lineRevisions.length);
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
92
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
93 for (int i = 0; i < fa.lineRevisions.length; i++) {
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
94 int hgAnnotateRevIndex = Integer.parseInt(hgAnnotateLines[i].substring(0, hgAnnotateLines[i].indexOf(':')));
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
95 errorCollector.assertEquals(String.format("Revision mismatch for line %d", i+1), hgAnnotateRevIndex, fa.lineRevisions[i]);
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
96 }
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
97 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
98 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
99
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
100 private static String[] splitLines(CharSequence seq) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
101 int lineCount = 0;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
102 for (int i = 0, x = seq.length(); i < x; i++) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
103 if (seq.charAt(i) == '\n') {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
104 lineCount++;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 }
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
106 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
107 if (seq.length() > 0 && seq.charAt(seq.length()-1) != '\n') {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
108 lineCount++;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
109 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
110 String[] rv = new String[lineCount];
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
111 int lineStart = 0, lineEnd = 0, ix = 0;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
112 do {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
113 while (lineEnd < seq.length() && seq.charAt(lineEnd) != '\n') lineEnd++;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
114 if (lineEnd == lineStart) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
115 continue;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 }
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
117 CharSequence line = seq.subSequence(lineStart, lineEnd);
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
118 rv[ix++] = line.toString();
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
119 lineStart = ++lineEnd;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
120 } while (lineStart < seq.length());
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
121 assert ix == lineCount;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
122 return rv;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
123 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
124
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
125
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
126 private void aaa() throws Exception {
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
127 HgRepository repo = new HgLookup().detectFromWorkingDir();
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
128 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java";
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
129 final int checkChangeset = 539;
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
130 HgDataFile df = repo.getFileNode(fname);
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
131 AnnotateFacility af = new AnnotateFacility();
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
132 DiffOutInspector dump = new DiffOutInspector(System.out);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
133 System.out.println("541 -> 543");
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
134 af.annotateChange(df, 543, dump);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
135 System.out.println("539 -> 541");
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
136 af.annotateChange(df, 541, dump);
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
137 System.out.println("536 -> 539");
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
138 af.annotateChange(df, checkChangeset, dump);
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
139 System.out.println("531 -> 536");
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
140 af.annotateChange(df, 536, dump);
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
141 System.out.println(" -1 -> 531");
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
142 af.annotateChange(df, 531, dump);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
143
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
144 FileAnnotateInspector fai = new FileAnnotateInspector();
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
145 af.annotate(df, TIP, fai);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
146 for (int i = 0; i < fai.lineRevisions.length; i++) {
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
147 System.out.printf("%3d: LINE %d\n", fai.lineRevisions[i], i+1);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
148 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
149 }
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
150
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
151 private void bbb() throws Exception {
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
152 HgRepository repo = new HgLookup().detectFromWorkingDir();
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
153 final String fname = "src/org/tmatesoft/hg/repo/HgManifest.java";
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
154 final int checkChangeset = 415;
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
155 HgDataFile df = repo.getFileNode(fname);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
156 AnnotateFacility af = new AnnotateFacility();
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
157 DiffOutInspector dump = new DiffOutInspector(System.out);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
158 System.out.println("413 -> 415");
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
159 af.diff(df, 413, 415, dump);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
160 System.out.println("408 -> 415");
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
161 af.diff(df, 408, 415, dump);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
162 System.out.println("Combined (with merge):");
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
163 dump.needRevisions(true);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
164 af.annotateChange(df, checkChangeset, dump);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
165 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
166
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
167 private void leftovers() throws Exception {
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
168 IntMap<String> linesOld = new IntMap<String>(100), linesNew = new IntMap<String>(100);
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 System.out.println("Changes to old revision:");
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 for (int i = linesOld.firstKey(), x = linesOld.lastKey(); i < x; i++) {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 if (linesOld.containsKey(i)) {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 System.out.println(linesOld.get(i));
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 System.out.println("Changes in the new revision:");
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 for (int i = linesNew.firstKey(), x = linesNew.lastKey(); i < x; i++) {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 if (linesNew.containsKey(i)) {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 System.out.println(linesNew.get(i));
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 public static void main(String[] args) throws Exception {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
185 // System.out.println(Arrays.equals(new String[0], splitLines("")));
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
186 // System.out.println(Arrays.equals(new String[] { "abc" }, splitLines("abc")));
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
187 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc")));
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
188 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc\n")));
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
189 new TestBlame().bbb();
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 }
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
191
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
192 static class DiffOutInspector implements AnnotateFacility.BlockInspector {
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
193 private final PrintStream out;
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
194 private boolean dumpRevs;
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
195
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
196 DiffOutInspector(PrintStream ps) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
197 out = ps;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
198 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
199
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
200 public void needRevisions(boolean dumpRevs) {
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
201 // Note, true makes output incompatible with 'hg diff'
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
202 this.dumpRevs = dumpRevs;
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
203 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
204
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
205 private void printRevs(Block b) {
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
206 if (dumpRevs) {
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
207 out.printf("[%3d -> %3d] ", b.originChangesetIndex(), b.targetChangesetIndex());
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
208 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
209 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
210
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
211 public void same(EqualBlock 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
212 // nothing
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
213 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
214
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
215 public void deleted(DeleteBlock block) {
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
216 printRevs(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
217 out.printf("@@ -%d,%d +%d,0 @@\n", block.firstRemovedLine() + 1, block.totalRemovedLines(), block.removedAt());
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
218 // String[] lines = block.removedLines();
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
219 // assert lines.length == block.totalRemovedLines();
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
220 // for (int i = 0, ln = block.firstRemovedLine(); i < lines.length; i++, ln++) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
221 // linesOld.put(ln, String.format("%3d:---:%s", ln, lines[i]));
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
222 // }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
223 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
224
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
225 public void changed(ChangeBlock block) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
226 // deleted(block);
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
227 // added(block);
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
228 printRevs(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
229 out.printf("@@ -%d,%d +%d,%d @@\n", block.firstRemovedLine() + 1, block.totalRemovedLines(), block.firstAddedLine() + 1, block.totalAddedLines());
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
230 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
231
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
232 public void added(AddBlock block) {
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
233 printRevs(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
234 out.printf("@@ -%d,0 +%d,%d @@\n", block.insertedAt(), block.firstAddedLine() + 1, block.totalAddedLines());
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
235 // String[] addedLines = block.addedLines();
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
236 // assert addedLines.length == block.totalAddedLines();
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
237 // for (int i = 0, ln = block.firstAddedLine(), x = addedLines.length; i < x; i++, ln++) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
238 // linesNew.put(ln, String.format("%3d:+++:%s", ln, addedLines[i]));
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
239 // }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
240 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
241 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
242
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
243 public static class LineGrepOutputParser implements OutputParser {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
244
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
245 private final Pattern pattern;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
246 private final StringBuilder result = new StringBuilder();
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
247
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
248 public LineGrepOutputParser(String regexp) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
249 pattern = Pattern.compile(regexp);
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
250 }
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 public CharSequence result() {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
253 return result;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
254 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
255
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
256 public void parse(CharSequence seq) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
257 int lineStart = 0, lineEnd = 0;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
258 do {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
259 while (lineEnd < seq.length() && seq.charAt(lineEnd) != '\n') lineEnd++;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
260 if (lineEnd == lineStart) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
261 continue;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
262 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
263 CharSequence line = seq.subSequence(lineStart, lineEnd);
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
264 if (pattern.matcher(line).matches()) {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
265 result.append(line);
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
266 result.append('\n');
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
267 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
268 lineStart = ++lineEnd;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
269 } while (lineStart < seq.length());
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
270 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
271 }
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
272
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
273 private static class FileAnnotateInspector implements AnnotateFacility.LineInspector {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
274 private int[] lineRevisions;
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
275
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
276 FileAnnotateInspector() {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
277 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
278
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
279 public void line(int lineNumber, int changesetRevIndex, LineDescriptor ld) {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
280 if (lineRevisions == null) {
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
281 lineRevisions = new int [ld.totalLines()];
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
282 Arrays.fill(lineRevisions, NO_REVISION);
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
283 }
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
284 lineRevisions[lineNumber] = changesetRevIndex;
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
285 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
286 }
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
287
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
288 }