annotate cmdline/org/tmatesoft/hg/console/Annotate.java @ 668:d25f0324a27a

Delete bundle with push/pull changes once command completes successfully. Test for bundle generator
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 11 Jul 2013 18:41:40 +0200
parents c4fd1037bc6f
children 1c49c0cee540
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.console;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
19 import static java.util.Arrays.asList;
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import static org.tmatesoft.hg.repo.HgRepository.TIP;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
22 import java.util.TreeSet;
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.tmatesoft.hg.core.HgAnnotateCommand;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.core.HgAnnotateCommand.LineInfo;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.core.HgRepoFacade;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
27 import org.tmatesoft.hg.util.Path;
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 /**
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 *
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 * @author Artem Tikhomirov
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 * @author TMate Software Ltd.
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 */
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 public class Annotate {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 public static void main(String[] args) throws Exception {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
37 String[] boolOpts = new String[] {"-l", "--line-number" };
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
38 Options cmdLineOpts = Options.parse(args, new TreeSet<String>(asList(boolOpts)));
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 HgRepoFacade repo = new HgRepoFacade();
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 if (!repo.init(cmdLineOpts.findRepository())) {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 System.err.printf("Can't find repository in: %s\n", repo.getRepository().getLocation());
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 return;
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 }
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 int rev = cmdLineOpts.getSingleInt(TIP, "-r", "--rev");
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 HgAnnotateCommand cmd = repo.createAnnotateCommand();
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 AnnotateDumpInspector insp = new AnnotateDumpInspector(cmdLineOpts.getBoolean(false, "-l", "--line-number"));
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 cmd.changeset(rev);
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 for (String fname : cmdLineOpts.getList("")) {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
49 cmd.file(Path.create(fname));
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 cmd.execute(insp);
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 }
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 private static class AnnotateDumpInspector implements HgAnnotateCommand.Inspector {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 private final boolean lineNumbers;
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 AnnotateDumpInspector(boolean printLineNumbers) {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 lineNumbers = printLineNumbers;
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
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 public void next(LineInfo lineInfo) {
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 if (lineNumbers) {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
63 System.out.printf("%3d:%3d: %s", lineInfo.getChangesetIndex(), lineInfo.getLineNumber(), new String(lineInfo.getContent()));
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 } else {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 566
diff changeset
65 System.out.printf("%3d: %s", lineInfo.getChangesetIndex(), new String(lineInfo.getContent()));
566
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 }
32453f30de07 Annotate command with command-line example
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 }
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 }