annotate test/org/tmatesoft/hg/test/TestBlame.java @ 677:1c49c0cee540

Report line number at the first appearance, like 'hg annotate -l' does
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 18 Jul 2013 18:47:45 +0200
parents 3219cfadda49
children 58a6900f845d
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;
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
21 import static org.tmatesoft.hg.core.HgIterateDirection.NewToOld;
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
22 import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew;
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
23 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
24
543
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.ByteArrayOutputStream;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
26 import java.io.File;
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
27 import java.io.IOException;
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
28 import java.io.OutputStream;
543
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 java.io.PrintStream;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
30 import java.util.ArrayList;
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
31 import java.util.Arrays;
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
32 import java.util.LinkedHashSet;
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
33 import java.util.LinkedList;
557
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
34 import java.util.ListIterator;
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
35 import java.util.regex.Matcher;
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
36 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
37
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
38 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
39 import org.junit.Rule;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 import org.junit.Test;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
41 import org.tmatesoft.hg.core.HgAnnotateCommand;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
42 import org.tmatesoft.hg.core.HgAnnotateCommand.LineInfo;
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
43 import org.tmatesoft.hg.core.HgBlameInspector;
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
44 import org.tmatesoft.hg.core.HgCallbackTargetException;
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
45 import org.tmatesoft.hg.core.HgDiffCommand;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
46 import org.tmatesoft.hg.core.HgRepoFacade;
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
47 import org.tmatesoft.hg.core.Nodeid;
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
48 import org.tmatesoft.hg.internal.ForwardAnnotateInspector;
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
49 import org.tmatesoft.hg.internal.IntVector;
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
50 import org.tmatesoft.hg.internal.ReverseAnnotateInspector;
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
51 import org.tmatesoft.hg.repo.HgChangelog;
557
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
52 import org.tmatesoft.hg.repo.HgDataFile;
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
53 import org.tmatesoft.hg.repo.HgLookup;
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
54 import org.tmatesoft.hg.repo.HgRepository;
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
55 import org.tmatesoft.hg.util.CancelSupport;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
56 import org.tmatesoft.hg.util.CancelledException;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
57 import org.tmatesoft.hg.util.Path;
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
58 import org.tmatesoft.hg.util.ProgressSupport;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 /**
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 *
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 * @author Artem Tikhomirov
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 * @author TMate Software Ltd.
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 */
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 public class TestBlame {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
67 @Rule
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
68 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
69
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 @Test
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 public void testSingleParentBlame() throws Exception {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 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
74 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java";
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
75 final int checkChangeset = repo.getChangelog().getRevisionIndex(Nodeid.fromAscii("946b131962521f9199e1fedbdc2487d3aaef5e46")); // 539
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
76 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
77 ByteArrayOutputStream bos = new ByteArrayOutputStream();
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
78 HgDiffCommand diffCmd = new HgDiffCommand(repo);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
79 diffCmd.file(df).changeset(checkChangeset);
632
54e16ab771ec Progress/cancel for HgDiffCommand. Renamed execute method
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 630
diff changeset
80 diffCmd.executeParentsAnnotate(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
81 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
82 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
83 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
84 //
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
85 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
86 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
87 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
88 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
89
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
90 @Test
557
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
91 public void testFileLineAnnotate1() throws Exception {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
92 HgRepository repo = new HgLookup().detectFromWorkingDir();
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
93 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
94 HgDataFile df = repo.getFileNode(fname);
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
95 AnnotateRunner ar = new AnnotateRunner(df.getPath(), null);
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
96
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
97 final HgDiffCommand diffCmd = new HgDiffCommand(repo);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
98 diffCmd.file(df).order(NewToOld);
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
99 final HgChangelog clog = repo.getChangelog();
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
100 final int[] toTest = new int[] {
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
101 clog.getRevisionIndex(Nodeid.fromAscii("946b131962521f9199e1fedbdc2487d3aaef5e46")), // 539
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
102 clog.getRevisionIndex(Nodeid.fromAscii("1e95f48d9886abe79b9711ab371bc877ca5e773e")), // 541
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
103 /*, TIP */};
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
104 for (int cs : toTest) {
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
105 ar.run(cs, false);
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
106 diffCmd.range(0, cs);
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
107 final ReverseAnnotateInspector insp = new ReverseAnnotateInspector();
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
108 diffCmd.executeAnnotate(insp);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
109 AnnotateInspector fa = new AnnotateInspector().fill(cs, insp);
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
110 doAnnotateLineCheck(cs, ar, fa);
557
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
111 }
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
112 }
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
113
557
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
114 @Test
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
115 public void testFileLineAnnotate2() throws Exception {
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
116 HgRepository repo = Configuration.get().find("test-annotate");
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
117 HgDataFile df = repo.getFileNode("file1");
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
118 AnnotateRunner ar = new AnnotateRunner(df.getPath(), repo.getWorkingDir());
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
119
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
120 final HgDiffCommand diffCmd = new HgDiffCommand(repo).file(df).order(NewToOld);
558
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
121 for (int cs : new int[] { 4, 6 /*, 8 see below*/, TIP}) {
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
122 ar.run(cs, false);
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
123 diffCmd.range(0, cs);
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
124 final ReverseAnnotateInspector insp = new ReverseAnnotateInspector();
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
125 diffCmd.executeAnnotate(insp);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
126 AnnotateInspector fa = new AnnotateInspector().fill(cs, insp);
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
127 doAnnotateLineCheck(cs, ar, fa);
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
128 }
558
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
129 /*`hg annotate -r 8` and HgBlameFacility give different result
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
130 * for "r0, line 5" line, which was deleted in rev2 and restored back in
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
131 * rev4 (both in default branch), while branch with r3 and r6 kept the line intact.
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
132 * HgBlame reports rev4 for the line, `hg annotate` gives original, rev0.
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
133 * However `hg annotate -r 4` shows rev4 for the line, too. The aforementioned rev0 for
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
134 * the merge rev8 results from the iteration order and is implementation specific
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
135 * (i.e. one can't tell which one is right). Mercurial walks from parents to children,
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
136 * and traces equal lines, while HgBlameFacility walks from child to parents and records
558
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
137 * changes (additions). Seems it processes branch with rev3 and rev6 first
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
138 * (printout in context.py, annotate and annotate.pair reveals that), and the line 0_5
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
139 * comes as unchanged through this branch, and later processing rev2 and rev4 doesn't
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
140 * change that.
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
141 */
545
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
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
144 @Test
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
145 public void testComplexHistoryAnnotate() throws Exception {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
146 HgRepository repo = Configuration.get().find("test-annotate");
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
147 HgDataFile df = repo.getFileNode("file1");
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
148 ByteArrayOutputStream bos = new ByteArrayOutputStream();
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
149 DiffOutInspector dump = new DiffOutInspector(new PrintStream(bos));
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
150 HgDiffCommand diffCmd = new HgDiffCommand(repo);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
151 diffCmd.file(df).range(0, TIP).order(OldToNew);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
152 diffCmd.executeAnnotate(dump);
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
153 LinkedList<String> apiResult = new LinkedList<String>(Arrays.asList(splitLines(bos.toString())));
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
154
557
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
155 /*
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
156 * FIXME this is an ugly hack to deal with the way `hg diff -c <mergeRev>` describes the change
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
157 * and our merge handling approach. For merged revision m, and lines changed both in p1 and p2
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
158 * we report lines from p2 as pure additions, regardless of intersecting p1 changes (which
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
159 * are reported as deletions, if no sufficient changed lines in m found)
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
160 * So, here we try to combine deletion that follows a change (based on identical insertionPoint)
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
161 * into a single change
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
162 * To fix, need to find better approach to find out reference info (i.e. `hg diff -c` is flawed in this case,
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
163 * as it uses first parent only).
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
164 */
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
165 Pattern fix = Pattern.compile("@@ -(\\d+),(\\d+) \\+(\\d+),(\\d+) @@");
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
166 int v1, v2, v3, v4;
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
167 v1 = v2 = v3 = v4 = -1;
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
168 for (ListIterator<String> it = apiResult.listIterator(); it.hasNext();) {
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
169 String n = it.next();
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
170 Matcher m = fix.matcher(n);
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
171 if (m.find()) {
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
172 int d1 = Integer.parseInt(m.group(1));
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
173 int d2 = Integer.parseInt(m.group(2));
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
174 int d3 = Integer.parseInt(m.group(3));
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
175 int d4 = Integer.parseInt(m.group(4));
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
176 if (v1 == d1 && d4 == 0) {
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
177 it.previous(); // shift to current element
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
178 it.previous(); // to real previous
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
179 it.remove();
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
180 it.next();
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
181 it.set(String.format("@@ -%d,%d +%d,%d @@", v1, v2+d2, v3, v4));
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
182 }
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
183 v1 = d1;
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
184 v2 = d2;
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
185 v3 = d3;
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
186 v4 = d4;
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
187 }
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
188 }
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
189
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
190 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+");
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
191 ExecHelper eh = new ExecHelper(gp, repo.getWorkingDir());
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
192 for (int cs : dump.getReportedTargetRevisions()) {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
193 gp.reset();
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
194 eh.run("hg", "diff", "-c", String.valueOf(cs), "-U", "0", df.getPath().toString());
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
195 for (String expected : splitLines(gp.result())) {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
196 if (!apiResult.remove(expected)) {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
197 errorCollector.fail(String.format("Expected diff output '%s' for changes in revision %d", expected, cs));
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
198 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
199 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
200 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
201 errorCollector.assertTrue(String.format("Annotate API reported excessive diff: %s ", apiResult.toString()), apiResult.isEmpty());
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
202 }
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
203
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
204
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
205 @Test
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
206 public void testPartialHistoryFollow() throws Exception {
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
207 HgRepository repo = Configuration.get().find("test-annotate2");
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
208 HgDataFile df = repo.getFileNode("file1b.txt");
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
209 // rev3: file1 -> file1a, rev7: file1a -> file1b, tip: rev10
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
210 DiffOutInspector insp = new DiffOutInspector(new PrintStream(new OutputStream() {
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
211 @Override
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
212 public void write(int b) throws IOException {
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
213 // NULL OutputStream
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
214 }
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
215 }));
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
216 // rev6 changes rev4, rev4 changes rev3. Plus, anything changed
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
217 // earlier than rev2 shall be reported as new from change3
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
218 int[] change_2_8_new2old = new int[] {4, 6, 3, 4, -1, 3};
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
219 int[] change_2_8_old2new = new int[] {-1, 3, 3, 4, 4, 6 };
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
220 final HgDiffCommand cmd = new HgDiffCommand(repo);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
221 cmd.file(df);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
222 cmd.range(2, 8).order(NewToOld);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
223 cmd.executeAnnotate(insp);
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
224 Assert.assertArrayEquals(change_2_8_new2old, insp.getReportedRevisionPairs());
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
225 insp.reset();
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
226 cmd.order(OldToNew).executeAnnotate(insp);
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
227 Assert.assertArrayEquals(change_2_8_old2new, insp.getReportedRevisionPairs());
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
228 // same as 2 to 8, with addition of rev9 changes rev7 (rev6 to rev7 didn't change content, only name)
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
229 int[] change_3_9_new2old = new int[] {7, 9, 4, 6, 3, 4, -1, 3 };
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
230 int[] change_3_9_old2new = new int[] {-1, 3, 3, 4, 4, 6, 7, 9 };
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
231 insp.reset();
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
232 cmd.range(3, 9).order(NewToOld).executeAnnotate(insp);
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
233 Assert.assertArrayEquals(change_3_9_new2old, insp.getReportedRevisionPairs());
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
234 insp.reset();
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
235 cmd.order(OldToNew).executeAnnotate(insp);
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
236 Assert.assertArrayEquals(change_3_9_old2new, insp.getReportedRevisionPairs());
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
237 }
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
238
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
239 @Test
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
240 public void testAnnotateCmdFollowNoFollow() throws Exception {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
241 HgRepoFacade hgRepoFacade = new HgRepoFacade();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
242 HgRepository repo = Configuration.get().find("test-annotate2");
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
243 hgRepoFacade.init(repo);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
244 HgAnnotateCommand cmd = hgRepoFacade.createAnnotateCommand();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
245 final Path fname = Path.create("file1b.txt");
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
246 final int changeset = TIP;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
247 AnnotateInspector ai = new AnnotateInspector();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
248
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
249 cmd.changeset(changeset);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
250 // follow
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
251 cmd.file(fname);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
252 cmd.execute(ai);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
253 AnnotateRunner ar = new AnnotateRunner(fname, repo.getWorkingDir());
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
254 ar.run(changeset, true);
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
255 doAnnotateLineCheck(changeset, ar, ai);
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
256
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
257 // no follow
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
258 cmd.file(fname, false);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
259 ai = new AnnotateInspector();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
260 cmd.execute(ai);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
261 ar.run(changeset, false);
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
262 doAnnotateLineCheck(changeset, ar, ai);
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
263 }
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
264
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
265 private void doAnnotateLineCheck(int cs, AnnotateRunner ar, AnnotateInspector hg4jResult) {
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
266 String[] hgAnnotateLines = ar.getLines();
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
267 assertTrue("[sanity]", hgAnnotateLines.length > 0);
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
268 assertEquals("Number of lines reported by native annotate and our impl", hgAnnotateLines.length, hg4jResult.getLineCount());
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
269
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
270 for (int i = 0; i < hgAnnotateLines.length; i++) {
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
271 String[] hgLine = hgAnnotateLines[i].split(":");
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
272 assertTrue(hgAnnotateLines[i], hgLine.length >= 3);
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
273 int hgAnnotateRevIndex = Integer.parseInt(hgLine[0].trim());
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
274 int hgFirstAppLine = Integer.parseInt(hgLine[1].trim());
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
275 String hgLineText = hgAnnotateLines[i].substring(hgLine[0].length() + hgLine[1].length() + 2).trim();
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
276 errorCollector.assertEquals(String.format("Revision mismatch for line %d (annotating rev: %d)", i+1, cs), hgAnnotateRevIndex, hg4jResult.getChangeset(i));
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
277 errorCollector.assertEquals(hgLineText, hg4jResult.getLine(i).trim());
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
278 errorCollector.assertEquals(hgFirstAppLine, hg4jResult.getOriginLine(i));
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
279 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
280 }
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
281
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
282
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
283 @Test
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
284 public void testDiffTwoRevisions() throws Exception {
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
285 HgRepository repo = Configuration.get().find("test-annotate");
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
286 HgDataFile df = repo.getFileNode("file1");
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
287 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+");
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
288 ExecHelper eh = new ExecHelper(gp, repo.getWorkingDir());
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
289 int[] toTest = { 3, 4, 5 }; // p1 ancestry line, p2 ancestry line, not in ancestry line
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
290 final HgDiffCommand diffCmd = new HgDiffCommand(repo).file(df);
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
291 for (int cs : toTest) {
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
292 ByteArrayOutputStream bos = new ByteArrayOutputStream();
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
293 diffCmd.range(cs, 8).executeDiff(new DiffOutInspector(new PrintStream(bos)));
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
294 eh.run("hg", "diff", "-r", String.valueOf(cs), "-r", "8", "-U", "0", df.getPath().toString());
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
295 //
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
296 String[] apiResult = splitLines(bos.toString());
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
297 String[] expected = splitLines(gp.result());
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
298 Assert.assertArrayEquals("diff -r " + cs + "-r 8", expected, apiResult);
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
299 gp.reset();
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
300 }
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
301 }
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
302
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
303 /**
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
304 * Make sure boundary values are ok (down to BlameHelper#prepare and FileHistory)
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
305 */
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
306 @Test
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
307 public void testAnnotateFirstFileRev() throws Exception {
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
308 HgRepository repo = Configuration.get().find("test-annotate");
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
309 HgDataFile df = repo.getFileNode("file1");
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
310 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+");
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
311 ExecHelper eh = new ExecHelper(gp, repo.getWorkingDir());
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
312 eh.run("hg", "diff", "-c", "0", "-U", "0", df.getPath().toString());
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
313 //
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
314 ByteArrayOutputStream bos = new ByteArrayOutputStream();
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
315 HgDiffCommand diffCmd = new HgDiffCommand(repo).file(df);
632
54e16ab771ec Progress/cancel for HgDiffCommand. Renamed execute method
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 630
diff changeset
316 diffCmd.changeset(0).executeParentsAnnotate(new DiffOutInspector(new PrintStream(bos)));
625
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
317 //
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
318 String[] apiResult = splitLines(bos.toString());
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
319 String[] expected = splitLines(gp.result());
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
320 Assert.assertArrayEquals(expected, apiResult);
b4948b159ab1 Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
321 }
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
322
624
507602cb4fb3 FIXMEs and TODOs: pay some technical debt
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
323 // TODO HgWorkingCopyStatusCollector (and HgStatusCollector), with their ancestors (rev 59/69) have examples
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
324 // of *incorrect* assignment of common lines (like "}") - our impl doesn't process common lines in any special way
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
325 // while original diff lib does. Would be nice to behave as close to original, as possible.
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
326
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
327 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
328 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
329 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
330 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
331 lineCount++;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
332 }
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
333 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
334 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
335 lineCount++;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
336 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
337 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
338 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
339 do {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
340 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
341 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
342 continue;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
343 }
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
344 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
345 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
346 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
347 } 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
348 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
349 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
350 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
351
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
352
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
353 private void ccc() throws Throwable {
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
354 HgRepository repo = new HgLookup().detect("/home/artem/hg/hgtest-annotate-merge/");
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
355 HgDataFile df = repo.getFileNode("file.txt");
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
356 DiffOutInspector dump = new DiffOutInspector(System.out);
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
357 dump.needRevisions(true);
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
358 HgDiffCommand diffCmd = new HgDiffCommand(repo);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
359 diffCmd.file(df);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
360 diffCmd.range(0, 8).order(NewToOld);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
361 diffCmd.executeAnnotate(dump);
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
362 // af.annotateSingleRevision(df, 113, dump);
557
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
363 // System.out.println();
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
364 // af.annotate(df, TIP, new LineDumpInspector(true), HgIterateDirection.NewToOld);
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
365 // System.out.println();
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
366 // af.annotate(df, TIP, new LineDumpInspector(false), HgIterateDirection.NewToOld);
b9e5ac26dd83 Annotate: Line annotation needs true line position from merged blocks; test-annotate repo updated to show elements from both parents in the merged revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 556
diff changeset
367 // System.out.println();
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
368 /*
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
369 OutputParser.Stub op = new OutputParser.Stub();
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
370 eh = new ExecHelper(op, repo.getWorkingDir());
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
371 for (int cs : new int[] { 24, 46, 49, 52, 59, 62, 64, TIP}) {
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
372 doLineAnnotateTest(df, cs, op);
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
373 }
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
374 errorCollector.verify();
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
375 */
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
376 ForwardAnnotateInspector insp = new ForwardAnnotateInspector();
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
377 diffCmd.range(0, 8).order(insp.iterateDirection());
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
378 diffCmd.executeAnnotate(insp);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
379 AnnotateInspector fa = new AnnotateInspector().fill(8, insp);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
380 for (int i = 0; i < fa.changesets.size(); i++) {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
381 final String line = fa.lines.get(i);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
382 System.out.printf("%d: %s", fa.changesets.get(i), line == null ? "null\n" : line);
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
383 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
384 }
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
385
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
386 public static void main(String[] args) throws Throwable {
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
387 TestBlame tt = new TestBlame();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
388 tt.ccc();
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
389 }
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
390
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
391 private static class DiffOutInspector implements HgBlameInspector {
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
392 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
393 private boolean dumpRevs;
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
394 private IntVector reportedRevisionPairs = new IntVector();
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
395
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
396 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
397 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
398 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
399
554
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
400 // Note, true makes output incompatible with 'hg diff'
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
401 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
402 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
403 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
404
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
405 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
406 if (dumpRevs) {
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
407 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
408 }
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
409 reportedRevisionPairs.add(b.originChangesetIndex(), b.targetChangesetIndex());
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
410 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
411
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
412 int[] getReportedTargetRevisions() {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
413 LinkedHashSet<Integer> rv = new LinkedHashSet<Integer>();
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
414 for (int i = 1; i < reportedRevisionPairs.size(); i += 2) {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
415 rv.add(reportedRevisionPairs.get(i));
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
416 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
417 int[] x = new int[rv.size()];
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
418 int i = 0;
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
419 for (int v : rv) {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
420 x[i++] = v;
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
421 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
422 return x;
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
423 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
424
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
425 int[] getReportedRevisionPairs() {
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
426 return reportedRevisionPairs.toArray();
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
427 }
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
428
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
429 void reset() {
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
430 reportedRevisionPairs.clear();
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
431 }
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
432
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
433 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
434 // nothing
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
435 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
436
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
437 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
438 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
439 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
440 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
441
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
442 public void changed(ChangeBlock block) {
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
443 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
444 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
445 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
446
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
447 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
448 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
449 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
450 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
451 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
452
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
453 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
454
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
455 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
456 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
457
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
458 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
459 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
460 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
461
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
462 public void reset() {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
463 result.setLength(0);
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
464 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
465
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
466 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
467 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
468 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
469
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
470 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
471 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
472 do {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
473 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
474 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
475 continue;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
476 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
477 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
478 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
479 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
480 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
481 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
482 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
483 } 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
484 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
485 }
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
486
603
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
487 @SuppressWarnings("unused")
707b5c7c6fa4 Refactor HgBlameFacility: relevant action methods moved to proper home (HgDataFile), as facility doesn't provide anything but packaging of relevant methods/interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
488 private static class LineDumpInspector implements HgBlameInspector {
554
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
489
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
490 private final boolean lineByLine;
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
491
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
492 public LineDumpInspector(boolean lineByLine) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
493 this.lineByLine = lineByLine;
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
494 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
495
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
496 public void same(EqualBlock block) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
497 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
498
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
499 public void added(AddBlock block) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
500 BlockData lines = block.addedLines();
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
501 printBlock(lines, block.targetChangesetIndex(), block.firstAddedLine(), block.totalAddedLines(), "+++");
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
502 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
503
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
504 public void changed(ChangeBlock block) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
505 deleted(block);
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
506 added(block);
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
507 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
508
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
509 public void deleted(DeleteBlock block) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
510 BlockData lines = block.removedLines();
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
511 assert lines.elementCount() == block.totalRemovedLines();
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
512 printBlock(lines, block.originChangesetIndex(), block.firstRemovedLine(), block.totalRemovedLines(), "---");
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
513 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
514
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
515 private void printBlock(BlockData lines, int cset, int first, int length, String marker) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
516 assert lines.elementCount() == length;
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
517 if (lineByLine) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
518 for (int i = 0, ln = first; i < length; i++, ln++) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
519 String line = new String(lines.elementAt(i).asArray());
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
520 System.out.printf("%3d:%3d:%s:%s", cset, ln, marker, line);
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
521 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
522 } else {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
523 String content = new String(lines.asArray());
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
524 System.out.printf("%3d:%s:[%d..%d):\n%s", cset, marker, first, first+length, content);
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
525 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
526 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
527 }
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
528
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
529 /**
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
530 * Note, this class expects lines coming in natural sequence (not the order they are detected - possible with {@link ReverseAnnotateInspector})
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
531 * Once async lines are done, shall change implementation here
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
532 */
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
533 static class AnnotateInspector implements HgAnnotateCommand.Inspector {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
534 private int lineNumber = 1;
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
535 private final ArrayList<String> lines = new ArrayList<String>();
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
536 private final IntVector changesets = new IntVector();
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
537 private final IntVector firstAppLines = new IntVector();
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
538
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
539 AnnotateInspector fill(int rev, ReverseAnnotateInspector ai) throws HgCallbackTargetException, CancelledException {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
540 ai.report(rev, this, ProgressSupport.Factory.get(null), CancelSupport.Factory.get(null));
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
541 return this;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
542 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
543 AnnotateInspector fill(int rev, ForwardAnnotateInspector ai) throws HgCallbackTargetException, CancelledException {
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
544 ai.report(rev, this, ProgressSupport.Factory.get(null), CancelSupport.Factory.get(null));
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
545 return this;
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
546 }
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 632
diff changeset
547
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
548 public void next(LineInfo lineInfo) throws HgCallbackTargetException {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
549 Assert.assertEquals(lineInfo.getLineNumber(), lineNumber);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
550 lineNumber++;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
551 lines.add(new String(lineInfo.getContent()));
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
552 changesets.add(lineInfo.getChangesetIndex());
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
553 firstAppLines.add(lineInfo.getOriginLineNumber());
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
554 }
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
555
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
556 int getLineCount() {
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
557 return changesets.size();
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
558 }
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
559 int getChangeset(int line) {
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
560 return changesets.get(line);
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
561 }
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
562 String getLine(int line) {
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
563 return lines.get(line);
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
564 }
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
565 int getOriginLine(int line) {
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
566 return firstAppLines.get(line);
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
567 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
568 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
569
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
570 private static class AnnotateRunner {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
571 private final ExecHelper eh;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
572 private final OutputParser.Stub op;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
573 private final Path file;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
574
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
575 public AnnotateRunner(Path filePath, File repoDir) {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
576 file = filePath;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
577 op = new OutputParser.Stub();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
578 eh = new ExecHelper(op, repoDir);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
579 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
580
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
581 public void run(int cset, boolean follow) throws Exception {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
582 op.reset();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
583 ArrayList<String> args = new ArrayList<String>();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
584 args.add("hg");
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
585 args.add("annotate");
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
586 args.add("--line-number");
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
587 args.add("-r");
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
588 args.add(cset == TIP ? "tip" : String.valueOf(cset));
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
589 if (!follow) {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
590 args.add("--no-follow");
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
591 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
592 args.add(file.toString());
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
593 eh.run(args);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
594 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
595
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
596 public String[] getLines() {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
597 return splitLines(op.result());
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
598 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
599 }
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
600 }