Mercurial > jhg
annotate src/org/tmatesoft/hg/core/HgAnnotateCommand.java @ 639:49f0749307a0 smartgit-4.5
Issue 46: Files with backslashes (legal on Linux) cause troubles
(grafted from 170b6ecc890e476f38108067daa3dfffe9758013)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 06 Jun 2013 14:21:11 +0200 |
parents | 73c20c648c1f |
children | 707b5c7c6fa4 |
rev | line source |
---|---|
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.core; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.util.Arrays; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import org.tmatesoft.hg.internal.Callback; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.tmatesoft.hg.internal.CsetParamKeeper; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import org.tmatesoft.hg.internal.Experimental; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import org.tmatesoft.hg.internal.FileAnnotation; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.tmatesoft.hg.internal.FileAnnotation.LineDescriptor; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import org.tmatesoft.hg.internal.FileAnnotation.LineInspector; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgBlameFacility.BlockData; |
569
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
30 import org.tmatesoft.hg.repo.HgBlameFacility; |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgDataFile; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import org.tmatesoft.hg.repo.HgRepository; |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
33 import org.tmatesoft.hg.util.CancelSupport; |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 import org.tmatesoft.hg.util.CancelledException; |
569
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
35 import org.tmatesoft.hg.util.Path; |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
36 import org.tmatesoft.hg.util.ProgressSupport; |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 /** |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 * WORK IN PROGRESS. UNSTABLE API |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 * |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * 'hg annotate' counterpart, report origin revision and file line-by-line |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 * |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 * @author Artem Tikhomirov |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 * @author TMate Software Ltd. |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 */ |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 @Experimental(reason="Work in progress. Unstable API") |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 public class HgAnnotateCommand extends HgAbstractCommand<HgAnnotateCommand> { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 private final HgRepository repo; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 private final CsetParamKeeper annotateRevision; |
569
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
51 private Path file; |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
52 private boolean followRename; |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 public HgAnnotateCommand(HgRepository hgRepo) { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 repo = hgRepo; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 annotateRevision = new CsetParamKeeper(repo); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 annotateRevision.doSet(HgRepository.TIP); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 public HgAnnotateCommand changeset(Nodeid nodeid) throws HgBadArgumentException { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 annotateRevision.set(nodeid); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 return this; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 public HgAnnotateCommand changeset(int changelogRevIndex) throws HgBadArgumentException { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 annotateRevision.set(changelogRevIndex); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 return this; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 |
569
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
70 /** |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
71 * Select file to annotate, origin of renamed/copied file would be followed, too. |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
72 * |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
73 * @param filePath path relative to repository root |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
74 * @return <code>this</code> for convenience |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
75 */ |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
76 public HgAnnotateCommand file(Path filePath) { |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
77 return file(filePath, true); |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
78 } |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
79 |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
80 /** |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
81 * Select file to annotate. |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
82 * |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
83 * @param filePath path relative to repository root |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
84 * @param followCopyRename true to follow copies/renames. |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
85 * @return <code>this</code> for convenience |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
86 */ |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
87 public HgAnnotateCommand file(Path filePath, boolean followCopyRename) { |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
88 file = filePath; |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
89 followRename = followCopyRename; |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 return this; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 // TODO [1.1] set encoding and provide String line content from LineInfo |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 |
586
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
584
diff
changeset
|
95 /** |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
584
diff
changeset
|
96 * Annotate selected file |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
584
diff
changeset
|
97 * |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
584
diff
changeset
|
98 * @param inspector |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
584
diff
changeset
|
99 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
584
diff
changeset
|
100 * @throws HgCallbackTargetException |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
584
diff
changeset
|
101 * @throws CancelledException if execution of the command was cancelled |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
584
diff
changeset
|
102 */ |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 public void execute(Inspector inspector) throws HgException, HgCallbackTargetException, CancelledException { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 if (inspector == null) { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 throw new IllegalArgumentException(); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 if (file == null) { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 throw new HgBadArgumentException("Command needs file argument", null); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 } |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
110 final ProgressSupport progress = getProgressSupport(inspector); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
111 final CancelSupport cancellation = getCancelSupport(inspector, true); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
112 cancellation.checkCancelled(); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
113 progress.start(2); |
569
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
114 HgDataFile df = repo.getFileNode(file); |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
115 if (!df.exists()) { |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
116 return; |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
117 } |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
118 final int changesetStart = followRename ? 0 : df.getChangesetRevisionIndex(0); |
582
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
119 Collector c = new Collector(cancellation); |
569
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
120 FileAnnotation fa = new FileAnnotation(c); |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
121 HgBlameFacility af = new HgBlameFacility(df); |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
122 af.annotate(changesetStart, annotateRevision.get(), fa, HgIterateDirection.NewToOld); |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
123 progress.worked(1); |
582
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
124 c.throwIfCancelled(); |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
125 cancellation.checkCancelled(); |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
126 ProgressSupport.Sub subProgress = new ProgressSupport.Sub(progress, 1); |
584
ed243b668502
Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
582
diff
changeset
|
127 subProgress.start(c.lineRevisions.length); |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 LineImpl li = new LineImpl(); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 for (int i = 0; i < c.lineRevisions.length; i++) { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 li.init(i+1, c.lineRevisions[i], c.line(i)); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 inspector.next(li); |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
132 subProgress.worked(1); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
133 cancellation.checkCancelled(); |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 } |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
135 subProgress.done(); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
569
diff
changeset
|
136 progress.done(); |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 /** |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 * Callback to receive annotated lines |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 */ |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 @Callback |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 public interface Inspector { |
569
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
144 // start(FileDescriptor) throws HgCallbackTargetException; |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
145 void next(LineInfo lineInfo) throws HgCallbackTargetException; |
c4fd1037bc6f
Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
566
diff
changeset
|
146 // end(FileDescriptor) throws HgCallbackTargetException; |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 /** |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 * Describes a line reported through {@link Inspector#next(LineInfo)} |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 * |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 * Clients shall not implement this interface |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 */ |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 public interface LineInfo { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 int getLineNumber(); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 int getChangesetIndex(); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 byte[] getContent(); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 // FIXME there's no need in FileAnnotation.LineInspector, merge it here |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 private static class Collector implements LineInspector { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 private int[] lineRevisions; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 private byte[][] lines; |
582
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
164 private final CancelSupport cancelSupport; |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
165 private CancelledException cancelEx; |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 |
582
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
167 Collector(CancelSupport cancellation) { |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
168 cancelSupport = cancellation; |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 public void line(int lineNumber, int changesetRevIndex, BlockData lineContent, LineDescriptor ld) { |
582
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
172 if (cancelEx != null) { |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
173 return; |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
174 } |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 if (lineRevisions == null) { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 lineRevisions = new int [ld.totalLines()]; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 Arrays.fill(lineRevisions, NO_REVISION); |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 lines = new byte[ld.totalLines()][]; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 lineRevisions[lineNumber] = changesetRevIndex; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 lines[lineNumber] = lineContent.asArray(); |
582
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
182 try { |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
183 cancelSupport.checkCancelled(); |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
184 } catch (CancelledException ex) { |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
185 cancelEx = ex; |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
186 } |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 public byte[] line(int i) { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 return lines[i]; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 } |
582
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
192 |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
193 public void throwIfCancelled() throws CancelledException { |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
194 if (cancelEx != null) { |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
195 throw cancelEx; |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
196 } |
90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
581
diff
changeset
|
197 } |
566
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
199 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
200 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 private static class LineImpl implements LineInfo { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
202 private int ln; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
203 private int rev; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
204 private byte[] content; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
206 void init(int line, int csetRev, byte[] cnt) { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
207 ln = line; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
208 rev = csetRev; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
209 content = cnt; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
210 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
211 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
212 public int getLineNumber() { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
213 return ln; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
214 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
215 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
216 public int getChangesetIndex() { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
217 return rev; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
218 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
219 |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
220 public byte[] getContent() { |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
221 return content; |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
222 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
223 } |
32453f30de07
Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
224 } |