Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestBlame.java @ 542:a71a05ec11bc
Towards annotate/blame support: general outline of the functionality
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 14 Feb 2013 16:36:13 +0100 |
parents | |
children | 1e95f48d9886 |
comparison
equal
deleted
inserted
replaced
541:946b13196252 | 542:a71a05ec11bc |
---|---|
1 /* | |
2 * Copyright (c) 2013 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.test; | |
18 | |
19 import org.junit.Test; | |
20 import org.tmatesoft.hg.internal.AnnotateFacility; | |
21 import org.tmatesoft.hg.internal.AnnotateFacility.AddBlock; | |
22 import org.tmatesoft.hg.internal.AnnotateFacility.ChangeBlock; | |
23 import org.tmatesoft.hg.internal.AnnotateFacility.DeleteBlock; | |
24 import org.tmatesoft.hg.internal.IntMap; | |
25 import org.tmatesoft.hg.internal.AnnotateFacility.Block; | |
26 import org.tmatesoft.hg.repo.HgDataFile; | |
27 import org.tmatesoft.hg.repo.HgLookup; | |
28 import org.tmatesoft.hg.repo.HgRepository; | |
29 | |
30 /** | |
31 * | |
32 * @author Artem Tikhomirov | |
33 * @author TMate Software Ltd. | |
34 */ | |
35 public class TestBlame { | |
36 | |
37 | |
38 @Test | |
39 public void testSingleParentBlame() throws Exception { | |
40 HgRepository repo = new HgLookup().detectFromWorkingDir(); | |
41 HgDataFile df = repo.getFileNode("src/org/tmatesoft/hg/internal/PatchGenerator.java"); | |
42 final IntMap<String> linesOld= new IntMap<String>(100); | |
43 final IntMap<String> linesNew = new IntMap<String>(100); | |
44 new AnnotateFacility().annotate(df, 539, new AnnotateFacility.Inspector() { | |
45 | |
46 public void same(Block block) { | |
47 // TODO Auto-generated method stub | |
48 | |
49 } | |
50 | |
51 public void deleted(DeleteBlock block) { | |
52 String[] lines = block.removedLines(); | |
53 assert lines.length == block.totalRemovedLines(); | |
54 for (int i = 0, ln = block.firstRemovedLine(); i < lines.length; i++, ln++) { | |
55 linesOld.put(ln, String.format("%3d:---:%s", ln, lines[i])); | |
56 } | |
57 } | |
58 | |
59 public void changed(ChangeBlock block) { | |
60 deleted(block); | |
61 added(block); | |
62 } | |
63 | |
64 public void added(AddBlock block) { | |
65 String[] addedLines = block.addedLines(); | |
66 assert addedLines.length == block.totalAddedLines(); | |
67 for (int i = 0, ln = block.firstAddedLine(), x = addedLines.length; i < x; i++, ln++) { | |
68 linesNew.put(ln, String.format("%3d:+++:%s", ln, addedLines[i])); | |
69 } | |
70 } | |
71 }); | |
72 | |
73 System.out.println("Changes to old revision:"); | |
74 for (int i = linesOld.firstKey(), x = linesOld.lastKey(); i < x; i++) { | |
75 if (linesOld.containsKey(i)) { | |
76 System.out.println(linesOld.get(i)); | |
77 } | |
78 } | |
79 | |
80 System.out.println("Changes in the new revision:"); | |
81 for (int i = linesNew.firstKey(), x = linesNew.lastKey(); i < x; i++) { | |
82 if (linesNew.containsKey(i)) { | |
83 System.out.println(linesNew.get(i)); | |
84 } | |
85 } | |
86 } | |
87 | |
88 public static void main(String[] args) throws Exception { | |
89 new TestBlame().testSingleParentBlame(); | |
90 } | |
91 } |