Mercurial > hg4j
annotate cmdline/org/tmatesoft/hg/console/Manifest.java @ 423:9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 23 Mar 2012 22:51:18 +0100 |
parents | ee8264d80747 |
children | 31a89587eb04 |
rev | line source |
---|---|
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
2 * Copyright (c) 2010-2012 TMate Software Ltd |
72
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
3 * |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
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:
64
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:
64
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:
64
diff
changeset
|
7 * |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
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:
64
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:
64
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:
64
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:
64
diff
changeset
|
12 * |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
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:
64
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:
74
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
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:
64
diff
changeset
|
17 package org.tmatesoft.hg.console; |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
299
45dc79e545f5
Recognize flag options (options with no arguments) in command line sample apps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
19 import static org.tmatesoft.hg.console.Options.asSet; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
13
diff
changeset
|
21 |
249
4c3b9f679412
Deprecated HgLogCommand.FileRevision gone, top-level HgFileRevision is bright and shiny replacement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
143
diff
changeset
|
22 import org.tmatesoft.hg.core.HgFileRevision; |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
23 import org.tmatesoft.hg.core.HgManifestCommand; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
24 import org.tmatesoft.hg.core.Nodeid; |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
415
diff
changeset
|
25 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
415
diff
changeset
|
26 import org.tmatesoft.hg.repo.HgInvalidRevisionException; |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
27 import org.tmatesoft.hg.repo.HgManifest; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
28 import org.tmatesoft.hg.repo.HgRepository; |
133
4a948ec83980
core.Path to util.Path as it's not Hg repo dependant
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
131
diff
changeset
|
29 import org.tmatesoft.hg.util.Path; |
64
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
30 |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 /** |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 * |
72
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
34 * @author Artem Tikhomirov |
9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
64
diff
changeset
|
35 * @author TMate Software Ltd. |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 */ |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 public class Manifest { |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 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:
249
diff
changeset
|
40 Options cmdLineOpts = Options.parse(args, asSet("--debug", "-v", "--verbose")); |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
72
diff
changeset
|
41 HgRepository hgRepo = cmdLineOpts.findRepository(); |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 if (hgRepo.isInvalid()) { |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 return; |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 } |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
46 final boolean debug = cmdLineOpts.getBoolean("--debug"); |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
47 final boolean verbose = cmdLineOpts.getBoolean("-v", "--verbose"); |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
48 HgManifestCommand.Handler h = new HgManifestCommand.Handler() { |
64
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
49 |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
50 public void begin(Nodeid manifestRevision) { |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
51 } |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
52 public void dir(Path p) { |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
53 } |
249
4c3b9f679412
Deprecated HgLogCommand.FileRevision gone, top-level HgFileRevision is bright and shiny replacement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
143
diff
changeset
|
54 public void file(HgFileRevision fileRevision) { |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
55 try { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
56 if (debug) { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
57 System.out.print(fileRevision.getRevision());; |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
58 } |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
59 if (debug || verbose) { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
60 HgManifest.Flags flags = fileRevision.getFileFlags(); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
61 Object s; |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
62 if (flags == HgManifest.Flags.RegularFile) { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
63 s = Integer.toOctalString(0644); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
64 } else if (flags == HgManifest.Flags.Exec) { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
65 s = Integer.toOctalString(0755); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
66 } else if (flags == HgManifest.Flags.Link) { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
67 s = "lnk"; |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
68 } else { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
69 s = String.valueOf(flags); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
70 } |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
71 System.out.printf(" %s ", s); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
72 } |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
73 System.out.println(fileRevision.getPath()); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
74 } catch (HgInvalidControlFileException e) { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
75 e.printStackTrace(); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
76 } catch (HgInvalidRevisionException e) { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
299
diff
changeset
|
77 e.printStackTrace(); |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
78 } |
64
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
79 } |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
80 |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
81 public void end(Nodeid manifestRevision) { |
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
82 } |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
83 }; |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
84 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:
133
diff
changeset
|
85 new HgManifestCommand(hgRepo).dirs(false).revision(rev).execute(h); |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
19
diff
changeset
|
86 } |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |