annotate test/org/tmatesoft/hg/test/TestBlame.java @ 624:507602cb4fb3

FIXMEs and TODOs: pay some technical debt
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 May 2013 20:34:33 +0200
parents 707b5c7c6fa4
children b4948b159ab1
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;
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
23 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
24 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
25
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
26 import java.io.ByteArrayOutputStream;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
27 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
28 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
29 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
30 import java.io.PrintStream;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
31 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
32 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
33 import java.util.LinkedHashSet;
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
34 import java.util.LinkedList;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
35 import java.util.List;
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
36 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
37 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
38 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
39
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
40 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
41 import org.junit.Rule;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 import org.junit.Test;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
43 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
44 import org.tmatesoft.hg.core.HgAnnotateCommand.LineInfo;
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
45 import org.tmatesoft.hg.core.HgCallbackTargetException;
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
46 import org.tmatesoft.hg.core.HgIterateDirection;
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
47 import org.tmatesoft.hg.core.HgRepoFacade;
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
48 import org.tmatesoft.hg.internal.FileAnnotation;
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.FileAnnotation.LineDescriptor;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
50 import org.tmatesoft.hg.internal.FileAnnotation.LineInspector;
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
51 import org.tmatesoft.hg.internal.IntVector;
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
52 import org.tmatesoft.hg.repo.HgBlameInspector;
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
53 import org.tmatesoft.hg.repo.HgBlameInspector.BlockData;
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
54 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
55 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
56 import org.tmatesoft.hg.repo.HgRepository;
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;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58
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 * @author Artem Tikhomirov
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 * @author TMate Software Ltd.
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 */
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 public class TestBlame {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
66 @Rule
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
67 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
68
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 @Test
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 public void testSingleParentBlame() throws Exception {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 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
73 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java";
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
74 final int checkChangeset = 539;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
75 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
76 ByteArrayOutputStream bos = new ByteArrayOutputStream();
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
77 df.annotateSingleRevision(checkChangeset, new DiffOutInspector(new PrintStream(bos)));
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
78 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
79 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
80 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
81 //
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
82 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
83 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
84 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
85 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
86
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
87 @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
88 public void testFileLineAnnotate1() throws Exception {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
89 HgRepository repo = new HgLookup().detectFromWorkingDir();
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
90 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
91 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
92 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
93
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
94 for (int cs : new int[] { 539, 541 /*, TIP */}) {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
95 ar.run(cs, false);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
96 FileAnnotateInspector fa = new FileAnnotateInspector();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
97 FileAnnotation.annotate(df, cs, fa);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
98 doAnnotateLineCheck(cs, ar.getLines(), Arrays.asList(fa.lineRevisions), Arrays.asList(fa.lines));
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
99 }
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
100 }
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
101
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
102 @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
103 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
104 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
105 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
106 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
107
558
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
108 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
109 ar.run(cs, false);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
110 FileAnnotateInspector fa = new FileAnnotateInspector();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
111 FileAnnotation.annotate(df, cs, fa);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
112 doAnnotateLineCheck(cs, ar.getLines(), Arrays.asList(fa.lineRevisions), Arrays.asList(fa.lines));
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
113 }
558
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
114 /*`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
115 * 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
116 * 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
117 * 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
118 * 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
119 * 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
120 * (i.e. one can't tell which one is right). Mercurial walks from parents to children,
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
121 * and traces equal lines, wile HgBlameFacility walks from child to parents and records
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
122 * 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
123 * (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
124 * 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
125 * change that.
154718ae23ed Annotate: refactor/reuse range handling code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 557
diff changeset
126 */
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
127 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
128
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
129 @Test
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
130 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
131 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
132 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
133 ByteArrayOutputStream bos = new ByteArrayOutputStream();
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
134 DiffOutInspector dump = new DiffOutInspector(new PrintStream(bos));
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
135 df.annotate(TIP, dump, HgIterateDirection.OldToNew);
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
136 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
137
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
138 /*
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
139 * 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
140 * 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
141 * 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
142 * 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
143 * 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
144 * 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
145 * 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
146 * 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
147 */
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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 }
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 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
167 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
168 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
169 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
170 }
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 }
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
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
173 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+");
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
174 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
175 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
176 gp.reset();
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
177 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
178 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
179 if (!apiResult.remove(expected)) {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
180 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
181 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
182 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
183 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
184 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
185 }
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
186
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
187
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
188 @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
189 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
190 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
191 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
192 // 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
193 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
194 @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
195 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
196 // 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
197 }
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
198 }));
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
199 // 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
200 // 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
201 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
202 int[] change_2_8_old2new = new int[] {-1, 3, 3, 4, 4, 6 };
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
203 df.annotate(2, 8, insp, NewToOld);
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 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
205 insp.reset();
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
206 df.annotate(2, 8, insp, OldToNew);
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
207 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
208 // 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
209 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
210 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
211 insp.reset();
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
212 df.annotate(3, 9, insp, NewToOld);
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
213 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
214 insp.reset();
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
215 df.annotate(3, 9, insp, OldToNew);
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
216 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
217 }
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
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
219 @Test
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
220 public void testAnnotateCmdFollowNoFollow() throws Exception {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
221 HgRepoFacade hgRepoFacade = new HgRepoFacade();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
222 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
223 hgRepoFacade.init(repo);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
224 HgAnnotateCommand cmd = hgRepoFacade.createAnnotateCommand();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
225 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
226 final int changeset = TIP;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
227 AnnotateInspector ai = new AnnotateInspector();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
228
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
229 cmd.changeset(changeset);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
230 // follow
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
231 cmd.file(fname);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
232 cmd.execute(ai);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
233 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
234 ar.run(changeset, true);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
235 doAnnotateLineCheck(changeset, ar.getLines(), ai.changesets, ai.lines);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
236
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
237 // no follow
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
238 cmd.file(fname, false);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
239 ai = new AnnotateInspector();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
240 cmd.execute(ai);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
241 ar.run(changeset, false);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
242 doAnnotateLineCheck(changeset, ar.getLines(), ai.changesets, ai.lines);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
243 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
244
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
245 private void doAnnotateLineCheck(int cs, String[] hgAnnotateLines, List<Integer> cmdChangesets, List<String> cmdLines) {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
246 assertTrue("[sanity]", hgAnnotateLines.length > 0);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
247 assertEquals("Number of lines reported by native annotate and our impl", hgAnnotateLines.length, cmdLines.size());
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 for (int i = 0; i < cmdChangesets.size(); i++) {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
250 int hgAnnotateRevIndex = Integer.parseInt(hgAnnotateLines[i].substring(0, hgAnnotateLines[i].indexOf(':')).trim());
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
251 errorCollector.assertEquals(String.format("Revision mismatch for line %d (annotating rev: %d)", i+1, cs), hgAnnotateRevIndex, cmdChangesets.get(i));
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
252 String hgAnnotateLine = hgAnnotateLines[i].substring(hgAnnotateLines[i].indexOf(':') + 1);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
253 String apiLine = cmdLines.get(i).trim();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
254 errorCollector.assertEquals(hgAnnotateLine.trim(), apiLine);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
255 }
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
624
507602cb4fb3 FIXMEs and TODOs: pay some technical debt
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
258 // 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
259 // 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
260 // 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
261
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
262 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
263 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
264 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
265 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
266 lineCount++;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
267 }
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
268 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
269 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
270 lineCount++;
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
271 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
272 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
273 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
274 do {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
275 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
276 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
277 continue;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
278 }
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
279 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
280 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
281 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
282 } 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
283 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
284 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
285 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
286
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
287
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
288 private void aaa() throws Exception {
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
289 HgRepository repo = new HgLookup().detectFromWorkingDir();
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
290 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java";
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
291 final int checkChangeset = 539;
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
292 HgDataFile df = repo.getFileNode(fname);
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
293 DiffOutInspector dump = new DiffOutInspector(System.out);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
294 System.out.println("541 -> 543");
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
295 df.annotateSingleRevision(543, dump);
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
296 System.out.println("539 -> 541");
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
297 df.annotateSingleRevision(541, dump);
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
298 System.out.println("536 -> 539");
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
299 df.annotateSingleRevision(checkChangeset, dump);
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
300 System.out.println("531 -> 536");
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
301 df.annotateSingleRevision(536, dump);
546
cd78e8b9d7bc File annotate test. Refactored FileAnnotation as standalone class, introduced LineInspector to make line offset calc code shared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 545
diff changeset
302 System.out.println(" -1 -> 531");
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
303 df.annotateSingleRevision(531, dump);
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
304
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
305 FileAnnotateInspector fai = new FileAnnotateInspector();
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
306 FileAnnotation.annotate(df, 541, fai);
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
307 for (int i = 0; i < fai.lineRevisions.length; i++) {
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
308 System.out.printf("%3d: LINE %d\n", fai.lineRevisions[i], i+1);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
309 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
310 }
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
311
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
312 private void bbb() throws Exception {
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
313 HgRepository repo = new HgLookup().detectFromWorkingDir();
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
314 final String fname = "src/org/tmatesoft/hg/repo/HgManifest.java";
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
315 final int checkChangeset = 415;
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
316 HgDataFile df = repo.getFileNode(fname);
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
317 DiffOutInspector dump = new DiffOutInspector(System.out);
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
318 // System.out.println("413 -> 415");
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
319 // af.diff(df, 413, 415, dump);
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
320 // System.out.println("408 -> 415");
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
321 // af.diff(df, 408, 415, dump);
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
322 // System.out.println("Combined (with merge):");
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
323 // dump.needRevisions(true);
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 549
diff changeset
324 // af.annotateChange(df, checkChangeset, dump);
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
325 dump.needRevisions(true);
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
326 df.annotate(checkChangeset, dump, HgIterateDirection.OldToNew);
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
327 }
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
328
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
329 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
330 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
331 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
332 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
333 dump.needRevisions(true);
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
334 df.annotate(8, dump, HgIterateDirection.NewToOld);
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
335 // 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
336 // 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
337 // 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
338 // 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
339 // 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
340 // System.out.println();
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
341 /*
561
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
342 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
343 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
344 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
345 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
346 }
d3c71498919c Do not process child revisions before all possible parent paths were visited
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 558
diff changeset
347 errorCollector.verify();
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
348 */
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
349 FileAnnotateInspector fa = new FileAnnotateInspector();
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
350 FileAnnotation.annotate(df, 8, fa);
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
351 for (int i = 0; i < fa.lineRevisions.length; i++) {
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
352 System.out.printf("%d: %s", fa.lineRevisions[i], fa.line(i) == null ? "null\n" : fa.line(i));
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
353 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
354 }
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
355
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 public static void main(String[] args) throws Throwable {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
357 // System.out.println(Arrays.equals(new String[0], splitLines("")));
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
358 // System.out.println(Arrays.equals(new String[] { "abc" }, splitLines("abc")));
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
359 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc")));
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
360 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc\n")));
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
361 TestBlame tt = new TestBlame();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
362 tt.ccc();
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
363 }
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
364
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
365 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
366 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
367 private boolean dumpRevs;
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
368 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
369
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
370 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
371 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
372 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
373
554
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
374 // 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
375 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
376 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
377 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
378
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
379 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
380 if (dumpRevs) {
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
381 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
382 }
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
383 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
384 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
385
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
386 int[] getReportedTargetRevisions() {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
387 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
388 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
389 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
390 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
391 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
392 int i = 0;
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
393 for (int v : rv) {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
394 x[i++] = v;
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
395 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
396 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
397 }
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
398
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
399 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
400 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
401 }
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
402
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
403 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
404 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
405 }
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
406
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
407 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
408 // nothing
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
409 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
410
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
411 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
412 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
413 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
414 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
415
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
416 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
417 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
418 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
419 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
420
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
421 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
422 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
423 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
424 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
425 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
426
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
427 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
428
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
429 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
430 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
431
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
432 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
433 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
434 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
435
553
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
436 public void reset() {
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
437 result.setLength(0);
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
438 }
093a2022dad5 Test (with tailored repository) for annotation of multiple revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 552
diff changeset
439
543
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
440 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
441 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
442 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
443
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
444 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
445 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
446 do {
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
447 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
448 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
449 continue;
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 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
452 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
453 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
454 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
455 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
456 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
457 } 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
458 }
1e95f48d9886 Report line index for insertion and deletion, test against 'hg diff' output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 542
diff changeset
459 }
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
460
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
461 private static class FileAnnotateInspector implements LineInspector {
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
462 private Integer[] lineRevisions;
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
463 private String[] lines;
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
464
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
465 FileAnnotateInspector() {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
466 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
467
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
468 public void line(int lineNumber, int changesetRevIndex, BlockData lineContent, LineDescriptor ld) {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
469 if (lineRevisions == null) {
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
470 lineRevisions = new Integer[ld.totalLines()];
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
471 Arrays.fill(lineRevisions, NO_REVISION);
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
472 lines = new String[ld.totalLines()];
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
473 }
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
474 lineRevisions[lineNumber] = changesetRevIndex;
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
475 lines[lineNumber] = new String(lineContent.asArray());
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
476 }
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
477
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
478 public String line(int i) {
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
479 return lines[i];
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
480 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
481 }
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
482
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
483 @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
484 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
485
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
486 private final boolean lineByLine;
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
487
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
488 public LineDumpInspector(boolean lineByLine) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
489 this.lineByLine = lineByLine;
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
490 }
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 void same(EqualBlock block) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
493 }
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 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
496 BlockData lines = block.addedLines();
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
497 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
498 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
499
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
500 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
501 deleted(block);
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
502 added(block);
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
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
505 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
506 BlockData lines = block.removedLines();
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
507 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
508 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
509 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
510
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
511 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
512 assert lines.elementCount() == length;
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
513 if (lineByLine) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
514 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
515 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
516 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
517 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
518 } else {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
519 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
520 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
521 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
522 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
523 }
570
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
524
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
525 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
526 private int lineNumber = 1;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
527 public final ArrayList<String> lines = new ArrayList<String>();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
528 public final ArrayList<Integer> changesets = new ArrayList<Integer>();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
529
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
530 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
531 Assert.assertEquals(lineInfo.getLineNumber(), lineNumber);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
532 lineNumber++;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
533 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
534 changesets.add(lineInfo.getChangesetIndex());
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
535 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
536 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
537
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
538 private static class AnnotateRunner {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
539 private final ExecHelper eh;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
540 private final OutputParser.Stub op;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
541 private final Path file;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
542
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
543 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
544 file = filePath;
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
545 op = new OutputParser.Stub();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
546 eh = new ExecHelper(op, repoDir);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
547 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
548
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
549 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
550 op.reset();
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
551 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
552 args.add("hg");
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
553 args.add("annotate");
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
554 args.add("-r");
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
555 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
556 if (!follow) {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
557 args.add("--no-follow");
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
558 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
559 args.add(file.toString());
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
560 eh.run(args);
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
561 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
562
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
563 public String[] getLines() {
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
564 return splitLines(op.result());
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
565 }
36853bb80a35 Tests for HgAnnotateCommand with follow/no-follow option
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
566 }
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
567 }