annotate cmdline/org/tmatesoft/hg/console/Cat.java @ 72:9a03a80a0f2f

Command-line frontend moved to separate source root with new package statement
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 23 Jan 2011 03:46:59 +0100
parents src/com/tmate/hgkit/console/Cat.java@b771e94a4f7c
children 6f1b88693d48
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
9a03a80a0f2f Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
15 * contact TMate Software at support@svnkit.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
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
19 import com.tmate.hgkit.fs.RepositoryLookup;
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
20 import com.tmate.hgkit.ll.DigestHelper;
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
21 import com.tmate.hgkit.ll.HgDataFile;
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import com.tmate.hgkit.ll.HgRepository;
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 42
diff changeset
23 import com.tmate.hgkit.ll.Internals;
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 /**
72
9a03a80a0f2f Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
26 * @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
27 * @author TMate Software Ltd.
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 public class Cat {
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 public static void main(String[] args) throws Exception {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
32 RepositoryLookup repoLookup = new RepositoryLookup();
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
33 RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args);
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
34 HgRepository hgRepo = repoLookup.detect(cmdLineOpts);
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 if (hgRepo.isInvalid()) {
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 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
37 return;
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 }
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 42
diff changeset
39 Internals debug = new Internals(hgRepo);
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 42
diff changeset
40 String[] toCheck = new String[] {"design.txt", "src/com/tmate/hgkit/ll/Changelog.java", "src/Extras.java", "bin/com/tmate/hgkit/ll/Changelog.class"};
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 42
diff changeset
41 boolean[] checkResult = debug.checkIgnored(toCheck);
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 42
diff changeset
42 for (int i = 0; i < toCheck.length; i++) {
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 42
diff changeset
43 System.out.println("Ignored " + toCheck[i] + ": " + checkResult[i]);
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
44 }
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
45 DigestHelper dh = new DigestHelper();
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
46 for (String fname : cmdLineOpts.files) {
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()) {
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
50 int total = fn.getRevisionCount();
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
51 System.out.printf("Total revisions: %d\n", total);
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
52 for (int i = 0; i < total; i++) {
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
53 byte[] content = fn.content(i);
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
54 System.out.println("==========>");
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
55 System.out.println(new String(content));
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
56 int[] parentRevisions = new int[2];
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
57 byte[] parent1 = new byte[20];
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
58 byte[] parent2 = new byte[20];
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
59 fn.parents(i, parentRevisions, parent1, parent2);
42
92c3d0920d58 Real integrity check, with exception. DigestHelper refactored to accomodate new needs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 17
diff changeset
60 System.out.println(dh.sha1(parent1, parent2, content).asHexString());
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
61 }
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
62 } else {
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
63 System.out.println(">>>Not found!");
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
64 }
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
65 }
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 }
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 }