Mercurial > jhg
annotate cmdline/org/tmatesoft/hg/console/Cat.java @ 145:acc6151b1b7a
toString for friendly debug
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 18 Feb 2011 04:53:34 +0100 |
parents | b9700740553a |
children | 6b55f10ef54b |
rev | line source |
---|---|
17
571e1b2cc3f7
Query file for its parents. Demo of recently added ignore and digest support from within cat cmd
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
5
diff
changeset
|
1 /* |
72
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
2 * Copyright (c) 2010-2011 TMate Software Ltd |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
3 * |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
7 * |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
11 * GNU General Public License for more details. |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
12 * |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
13 * For information on how to redistribute this software under |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
102
a3a2e5deb320
Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
96
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
72
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
17 package org.tmatesoft.hg.console; |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
19 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
20 |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
21 import java.io.OutputStream; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
22 import java.nio.ByteBuffer; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
23 |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
24 import org.tmatesoft.hg.repo.HgDataFile; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
25 import org.tmatesoft.hg.repo.HgRepository; |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
26 import org.tmatesoft.hg.util.ByteChannel; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
27 |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 /** |
72
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
30 * @author Artem Tikhomirov |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
31 * @author TMate Software Ltd. |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 */ |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 public class Cat { |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 public static void main(String[] args) throws Exception { |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
36 Options cmdLineOpts = Options.parse(args); |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
37 HgRepository hgRepo = cmdLineOpts.findRepository(); |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 if (hgRepo.isInvalid()) { |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 return; |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 } |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
42 int rev = cmdLineOpts.getSingleInt(TIP, "-r", "--rev"); |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
43 OutputStreamChannel out = new OutputStreamChannel(System.out); |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
44 for (String fname : cmdLineOpts.getList("")) { |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
45 System.out.println(fname); |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
46 HgDataFile fn = hgRepo.getFileNode(fname); |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
47 if (fn.exists()) { |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
48 fn.content(rev, out, true); |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
49 System.out.println(); |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
50 } else { |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
51 System.out.printf("%s not found!\n", fname); |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
52 } |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
53 } |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
55 |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
56 private static class OutputStreamChannel implements ByteChannel { |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
57 |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
58 private final OutputStream stream; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
59 |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
60 public OutputStreamChannel(OutputStream out) { |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
61 stream = out; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
62 } |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
63 |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
64 public int write(ByteBuffer buffer) throws Exception { |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
65 int count = buffer.remaining(); |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
66 while(buffer.hasRemaining()) { |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
67 stream.write(buffer.get()); |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
68 } |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
69 return count; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
70 } |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
71 } |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 } |