Mercurial > hg4j
annotate cmdline/org/tmatesoft/hg/console/Cat.java @ 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)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 25 Jul 2013 22:12:14 +0200 |
parents | 45dc79e545f5 |
children |
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 |
150
6b55f10ef54b
Unused variables removed.
Alexander Kitaev <kitaev@gmail.com>
parents:
143
diff
changeset
|
21 import java.io.IOException; |
143
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.io.OutputStream; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
23 import java.nio.ByteBuffer; |
299
45dc79e545f5
Recognize flag options (options with no arguments) in command line sample apps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
24 import java.util.Collections; |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
25 |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
26 import org.tmatesoft.hg.repo.HgDataFile; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
27 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
|
28 import org.tmatesoft.hg.util.ByteChannel; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
29 |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 /** |
72
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
59
diff
changeset
|
32 * @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
|
33 * @author TMate Software Ltd. |
1
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 class Cat { |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 public static void main(String[] args) throws Exception { |
299
45dc79e545f5
Recognize flag options (options with no arguments) in command line sample apps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
38 Options cmdLineOpts = Options.parse(args, Collections.<String>emptySet()); |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
39 HgRepository hgRepo = cmdLineOpts.findRepository(); |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 if (hgRepo.isInvalid()) { |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 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
|
42 return; |
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 } |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 System.out.println(fname); |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
48 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
|
49 if (fn.exists()) { |
157
d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
150
diff
changeset
|
50 fn.contentWithFilters(rev, out); |
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.println(); |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
52 } else { |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
53 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
|
54 } |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
3
diff
changeset
|
55 } |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 } |
143
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 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
|
59 |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
60 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
|
61 |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
62 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
|
63 stream = out; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
64 } |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
65 |
150
6b55f10ef54b
Unused variables removed.
Alexander Kitaev <kitaev@gmail.com>
parents:
143
diff
changeset
|
66 public int write(ByteBuffer buffer) throws IOException { |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 } |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
71 return count; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
72 } |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
73 } |
1
a3576694a4d1
Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 } |