Mercurial > jhg
annotate 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 | 
| 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 | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 19 import static org.tmatesoft.hg.repo.HgRepository.TIP; | 
| 
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.Collections; | 
| 
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.core.HgAnnotateCommand; | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 24 import org.tmatesoft.hg.core.HgAnnotateCommand.LineInfo; | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 25 import org.tmatesoft.hg.core.HgRepoFacade; | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 26 import org.tmatesoft.hg.repo.HgDataFile; | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 27 | 
| 
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 * @author Artem Tikhomirov | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 31 * @author TMate Software Ltd. | 
| 
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 public class Annotate { | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 34 | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 35 public static void main(String[] args) throws Exception { | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 36 Options cmdLineOpts = Options.parse(args, Collections.<String>emptySet()); | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 37 HgRepoFacade repo = new HgRepoFacade(); | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 38 if (!repo.init(cmdLineOpts.findRepository())) { | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 39 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 | 40 return; | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 41 } | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 42 int rev = cmdLineOpts.getSingleInt(TIP, "-r", "--rev"); | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 43 HgAnnotateCommand cmd = repo.createAnnotateCommand(); | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 44 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 | 45 cmd.changeset(rev); | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 46 for (String fname : cmdLineOpts.getList("")) { | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 47 HgDataFile fn = repo.getRepository().getFileNode(fname); | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 48 cmd.file(fn); | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 49 cmd.execute(insp); | 
| 
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 | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 53 private static class AnnotateDumpInspector implements HgAnnotateCommand.Inspector { | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 54 private final boolean lineNumbers; | 
| 
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 public AnnotateDumpInspector(boolean printLineNumbers) { | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 57 lineNumbers = printLineNumbers; | 
| 
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 void next(LineInfo lineInfo) { | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 61 if (lineNumbers) { | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 62 System.out.printf("%3d:%3d:%s", lineInfo.getChangesetIndex(), lineInfo.getLineNumber(), new String(lineInfo.getContent())); | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 63 } else { | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 64 System.out.printf("%3d:%s", lineInfo.getChangesetIndex(), new String(lineInfo.getContent())); | 
| 
32453f30de07
Annotate command with command-line example
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 65 } | 
| 
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 } | 
