annotate cmdline/org/tmatesoft/hg/console/Log.java @ 212:edb2e2829352 gradle

Project uses Gradle for build.
author Alexander Kitaev <kitaev@gmail.com>
date Mon, 09 May 2011 11:49:23 +0200
parents 63c9fed4369e
children 41a778e3fd31
rev   line source
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
1 /*
72
9a03a80a0f2f Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 65
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: 65
diff changeset
3 *
9a03a80a0f2f Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 65
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: 65
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: 65
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: 65
diff changeset
7 *
9a03a80a0f2f Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 65
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: 65
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: 65
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: 65
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: 65
diff changeset
12 *
9a03a80a0f2f Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 65
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: 65
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: 98
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: 65
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
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
19 import java.util.List;
65
e21df6259f83 Log commandline sample updated to use LogCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 60
diff changeset
20
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
21 import org.tmatesoft.hg.core.HgLogCommand;
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
22 import org.tmatesoft.hg.core.HgLogCommand.FileRevision;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 72
diff changeset
23 import org.tmatesoft.hg.repo.HgDataFile;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 72
diff changeset
24 import org.tmatesoft.hg.repo.HgRepository;
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
25
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 /**
72
9a03a80a0f2f Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 65
diff changeset
28 * @author Artem Tikhomirov
9a03a80a0f2f Command-line frontend moved to separate source root with new package statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 65
diff changeset
29 * @author TMate Software Ltd.
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 public class Log {
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
197
3a7696fb457c Investigate optimization options to allow fast processing of huge repositories. Fix defect in StatusCollector that lead to wrong result comparing first revision to empty repo (-1 to 0), due to same TIP constant value
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 143
diff changeset
33 // -agentlib:hprof=heap=sites,depth=10,etc might be handy to debug speed/memory issues
3a7696fb457c Investigate optimization options to allow fast processing of huge repositories. Fix defect in StatusCollector that lead to wrong result comparing first revision to empty repo (-1 to 0), due to same TIP constant value
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 143
diff changeset
34
1
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 }
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
42 final Dump dump = new Dump(hgRepo);
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
43 dump.complete(cmdLineOpts.getBoolean("--debug"));
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
44 dump.verbose(cmdLineOpts.getBoolean("-v", "--verbose"));
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
45 final boolean reverseOrder = true;
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
46 dump.reversed(reverseOrder);
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
47 HgLogCommand cmd = new HgLogCommand(hgRepo);
143
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
48 for (String u : cmdLineOpts.getList("-u", "--user")) {
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
49 cmd.user(u);
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
50 }
143
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
51 for (String b : cmdLineOpts.getList("-b", "--branches")) {
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
52 cmd.branch(b);
65
e21df6259f83 Log commandline sample updated to use LogCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 60
diff changeset
53 }
143
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
54 int limit = cmdLineOpts.getSingleInt(-1, "-l", "--limit");
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
55 if (limit != -1) {
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
56 cmd.limit(limit);
65
e21df6259f83 Log commandline sample updated to use LogCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 60
diff changeset
57 }
143
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
58 List<String> files = cmdLineOpts.getList("");
197
3a7696fb457c Investigate optimization options to allow fast processing of huge repositories. Fix defect in StatusCollector that lead to wrong result comparing first revision to empty repo (-1 to 0), due to same TIP constant value
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 143
diff changeset
59 final long start = System.currentTimeMillis();
143
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
60 if (files.isEmpty()) {
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
61 if (limit == -1) {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
62 // no revisions and no limit
65
e21df6259f83 Log commandline sample updated to use LogCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 60
diff changeset
63 cmd.execute(dump);
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
64 } else {
49
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
65 // in fact, external (to dump inspector) --limit processing yelds incorrect results when other args
26e3eeaa3962 branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 48
diff changeset
66 // e.g. -u or -b are used (i.e. with -u shall give <limit> csets with user, not check last <limit> csets for user
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
67 int[] r = new int[] { 0, hgRepo.getChangelog().getRevisionCount() };
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
68 if (fixRange(r, reverseOrder, limit) == 0) {
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
69 System.out.println("No changes");
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
70 return;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
71 }
65
e21df6259f83 Log commandline sample updated to use LogCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 60
diff changeset
72 cmd.range(r[0], r[1]).execute(dump);
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
73 }
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
74 dump.done();
6
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
75 } else {
143
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
76 for (String fname : files) {
6
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
77 HgDataFile f1 = hgRepo.getFileNode(fname);
8
a78c980749e3 Filename mangling according to requires options of the store (fncache incomplete for long names)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 6
diff changeset
78 System.out.println("History of the file: " + f1.getPath());
143
b9700740553a Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
79 if (limit == -1) {
142
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
80 cmd.file(f1.getPath(), true).execute(dump);
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
81 } else {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
82 int[] r = new int[] { 0, f1.getRevisionCount() };
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
83 if (fixRange(r, reverseOrder, limit) == 0) {
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
84 System.out.println("No changes");
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
85 continue;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
86 }
142
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
87 cmd.range(r[0], r[1]).file(f1.getPath(), true).execute(dump);
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
88 }
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
89 dump.done();
6
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
90 }
5abe5af181bd Ant script to build commands and run sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 4
diff changeset
91 }
197
3a7696fb457c Investigate optimization options to allow fast processing of huge repositories. Fix defect in StatusCollector that lead to wrong result comparing first revision to empty repo (-1 to 0), due to same TIP constant value
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 143
diff changeset
92 // cmd = null;
3a7696fb457c Investigate optimization options to allow fast processing of huge repositories. Fix defect in StatusCollector that lead to wrong result comparing first revision to empty repo (-1 to 0), due to same TIP constant value
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 143
diff changeset
93 System.out.println("Total time:" + (System.currentTimeMillis() - start));
3a7696fb457c Investigate optimization options to allow fast processing of huge repositories. Fix defect in StatusCollector that lead to wrong result comparing first revision to empty repo (-1 to 0), due to same TIP constant value
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 143
diff changeset
94 // Main.force_gc();
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 }
48
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
96
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
97 private static int fixRange(int[] start_end, boolean reverse, int limit) {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
98 assert start_end.length == 2;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
99 if (limit < start_end[1]) {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
100 if (reverse) {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
101 // adjust left boundary of the range
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
102 start_end[0] = start_end[1] - limit;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
103 } else {
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
104 start_end[1] = limit; // adjust right boundary
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
105 }
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
106 }
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
107 int rv = start_end[1] - start_end[0];
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
108 start_end[1]--; // range needs index, not length
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
109 return rv;
e34f90b9ded1 Limit option for history/log
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
110 }
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
111
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
112 private static final class Dump extends ChangesetDumpHandler implements HgLogCommand.FileHistoryHandler {
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
113
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
114 public Dump(HgRepository hgRepo) {
206
63c9fed4369e Sample command line tools for incoming/outgoing to use commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 198
diff changeset
115 super(hgRepo);
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
116 }
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
117
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
118 public void copy(FileRevision from, FileRevision to) {
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
119 System.out.printf("Got notified that %s(%s) was originally known as %s(%s)\n", to.getPath(), to.getRevision(), from.getPath(), from.getRevision());
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
120 }
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 8
diff changeset
121 }
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 }