annotate src/org/tmatesoft/hg/core/HgAnnotateCommand.java @ 711:a62079bc422b

Keyword filtering that doesn't depend on input buffer size and the way input lines got split between filter() calls. KewordFilter got state to keep processed suspicious ...$ lines
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 11 Oct 2013 21:35:41 +0200
parents 7839ff0bfd78
children
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
686
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.TIP;
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
20
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import org.tmatesoft.hg.internal.Callback;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import org.tmatesoft.hg.internal.CsetParamKeeper;
703
7839ff0bfd78 Refactor: move diff/blame related code to a separate package
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 686
diff changeset
23 import org.tmatesoft.hg.internal.diff.ForwardAnnotateInspector;
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.tmatesoft.hg.repo.HgDataFile;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.repo.HgRepository;
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
26 import org.tmatesoft.hg.repo.HgRuntimeException;
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
27 import org.tmatesoft.hg.util.CancelSupport;
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 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
29 import org.tmatesoft.hg.util.Path;
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
30 import org.tmatesoft.hg.util.ProgressSupport;
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 /**
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 * '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
34 *
613
f41dd9a3b8af Remove few Experimental annotations as the API they've marked graduates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 603
diff changeset
35 * @since 1.1
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @author Artem Tikhomirov
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 * @author TMate Software Ltd.
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 public class HgAnnotateCommand extends HgAbstractCommand<HgAnnotateCommand> {
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 private final HgRepository repo;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 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
43 private Path file;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
44 private boolean followRename;
566
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 public HgAnnotateCommand(HgRepository hgRepo) {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 repo = hgRepo;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 annotateRevision = new CsetParamKeeper(repo);
686
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
49 annotateRevision.doSet(TIP);
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 }
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 public HgAnnotateCommand changeset(Nodeid nodeid) throws HgBadArgumentException {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 annotateRevision.set(nodeid);
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 return this;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 }
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 public HgAnnotateCommand changeset(int changelogRevIndex) throws HgBadArgumentException {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 annotateRevision.set(changelogRevIndex);
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 return this;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 }
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
62 /**
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
63 * 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
64 *
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
65 * @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
66 * @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
67 */
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
68 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
69 return file(filePath, true);
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
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 * Select file to annotate.
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
74 *
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
75 * @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
76 * @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
77 * @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
78 */
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
79 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
80 file = filePath;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
81 followRename = followCopyRename;
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 return this;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 }
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84
680
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
85
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
86 /**
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
87 * Select file to annotate,
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
88 * @param fileNode repository file to annotate
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
89 * @param followCopyRename true to follow copies/renames.
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
90 * @return <code>this</code> for convenience
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
91 */
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
92 public HgAnnotateCommand file(HgDataFile fileNode, boolean followCopyRename) {
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
93 return file(fileNode.getPath(), followCopyRename);
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
94 }
58a6900f845d Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 677
diff changeset
95
626
5afc7eedb3dd @since, TODOs. Tests: add 1 sec to deal with fs timestamp granularity on linux
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
96 // TODO [post-1.1] set encoding and provide String line content from LineInfo
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
97 // TODO FWIW: diff algorithms: http://bramcohen.livejournal.com/73318.html
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
99 /**
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
100 * Annotate selected file
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
101 *
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
102 * @param inspector
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
103 * @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
104 * @throws HgCallbackTargetException
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
105 * @throws CancelledException if execution of the command was cancelled
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
106 */
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 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
108 if (inspector == null) {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 throw new IllegalArgumentException();
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 }
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 if (file == null) {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 throw new HgBadArgumentException("Command needs file argument", null);
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 }
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
114 final ProgressSupport progress = getProgressSupport(inspector);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
115 final CancelSupport cancellation = getCancelSupport(inspector, true);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
116 cancellation.checkCancelled();
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
117 progress.start(200);
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
118 try {
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
119 HgDataFile df = repo.getFileNode(file);
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
120 if (!df.exists()) {
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
121 return;
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
122 }
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
123 final int changesetStart = followRename ? 0 : df.getChangesetRevisionIndex(0);
686
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
124 final int annotateRevIndex = annotateRevision.get(TIP);
676
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
125 HgDiffCommand cmd = new HgDiffCommand(repo).file(df);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
126 cmd.range(changesetStart, annotateRevIndex);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
127 cmd.set(cancellation);
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
128 cmd.set(new ProgressSupport.Sub(progress, 100));
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
129 //
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
130 // ReverseAnnotateInspector ai = new ReverseAnnotateInspector();
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
131 ForwardAnnotateInspector ai = new ForwardAnnotateInspector();
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
132 cmd.order(ai.iterateDirection());
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
133 //
3219cfadda49 Switch to alternative annotate producer (walks from parents to children). Refactor FileAnnotation to match updated annotate approach
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
134 cmd.executeAnnotate(ai);
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
135 cancellation.checkCancelled();
686
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
136 final int lastCsetWithFileChange;
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
137 Nodeid fileRev = repo.getManifest().getFileRevision(annotateRevIndex, df.getPath());
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
138 if (fileRev != null) {
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
139 lastCsetWithFileChange = df.getChangesetRevisionIndex(df.getRevisionIndex(fileRev));
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
140 } else {
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
141 lastCsetWithFileChange = annotateRevIndex;
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
142 }
f1f095e42555 Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 680
diff changeset
143 ai.report(lastCsetWithFileChange, inspector, new ProgressSupport.Sub(progress, 100), cancellation);
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
144 } catch (HgRuntimeException ex) {
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
145 throw new HgLibraryFailureException(ex);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
146 }
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 569
diff changeset
147 progress.done();
566
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 /**
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 * Callback to receive annotated lines
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 */
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 @Callback
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 public interface Inspector {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
155 // start(FileDescriptor) throws HgCallbackTargetException;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
156 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
157 // end(FileDescriptor) throws HgCallbackTargetException;
566
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 /**
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 * 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
162 *
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 * Clients shall not implement this interface
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 */
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 public interface LineInfo {
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
166 /**
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
167 * @return 1-based index of the line in the annotated revision
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
168 */
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 int getLineNumber();
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
170
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
171 /**
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
172 * @return 1-based line number at the first appearance, at changeset {@link #getChangesetIndex()}
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
173 */
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
174 int getOriginLineNumber();
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
175 /**
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
176 * @return changeset revision this line was introduced at
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
177 */
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 int getChangesetIndex();
677
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
179
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
180 /**
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
181 * @return line content
1c49c0cee540 Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 676
diff changeset
182 */
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 byte[] getContent();
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 }
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 }