comparison cmdline/org/tmatesoft/hg/console/Annotate.java @ 566:32453f30de07 v1.1m3

Annotate command with command-line example
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 09 Apr 2013 19:25:34 +0200
parents
children c4fd1037bc6f
comparison
equal deleted inserted replaced
565:78a9e26e670d 566:32453f30de07
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.console;
18
19 import static org.tmatesoft.hg.repo.HgRepository.TIP;
20
21 import java.util.Collections;
22
23 import org.tmatesoft.hg.core.HgAnnotateCommand;
24 import org.tmatesoft.hg.core.HgAnnotateCommand.LineInfo;
25 import org.tmatesoft.hg.core.HgRepoFacade;
26 import org.tmatesoft.hg.repo.HgDataFile;
27
28 /**
29 *
30 * @author Artem Tikhomirov
31 * @author TMate Software Ltd.
32 */
33 public class Annotate {
34
35 public static void main(String[] args) throws Exception {
36 Options cmdLineOpts = Options.parse(args, Collections.<String>emptySet());
37 HgRepoFacade repo = new HgRepoFacade();
38 if (!repo.init(cmdLineOpts.findRepository())) {
39 System.err.printf("Can't find repository in: %s\n", repo.getRepository().getLocation());
40 return;
41 }
42 int rev = cmdLineOpts.getSingleInt(TIP, "-r", "--rev");
43 HgAnnotateCommand cmd = repo.createAnnotateCommand();
44 AnnotateDumpInspector insp = new AnnotateDumpInspector(cmdLineOpts.getBoolean(false, "-l", "--line-number"));
45 cmd.changeset(rev);
46 for (String fname : cmdLineOpts.getList("")) {
47 HgDataFile fn = repo.getRepository().getFileNode(fname);
48 cmd.file(fn);
49 cmd.execute(insp);
50 }
51 }
52
53 private static class AnnotateDumpInspector implements HgAnnotateCommand.Inspector {
54 private final boolean lineNumbers;
55
56 public AnnotateDumpInspector(boolean printLineNumbers) {
57 lineNumbers = printLineNumbers;
58 }
59
60 public void next(LineInfo lineInfo) {
61 if (lineNumbers) {
62 System.out.printf("%3d:%3d:%s", lineInfo.getChangesetIndex(), lineInfo.getLineNumber(), new String(lineInfo.getContent()));
63 } else {
64 System.out.printf("%3d:%s", lineInfo.getChangesetIndex(), new String(lineInfo.getContent()));
65 }
66 }
67 }
68 }