comparison hg4j-cli/src/main/java/org/tmatesoft/hg/console/Log.java @ 213:6ec4af642ba8 gradle

Project uses Gradle for build - actual changes
author Alexander Kitaev <kitaev@gmail.com>
date Tue, 10 May 2011 10:52:53 +0200
parents
children
comparison
equal deleted inserted replaced
212:edb2e2829352 213:6ec4af642ba8
1 /*
2 * Copyright (c) 2010-2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.console;
18
19 import java.util.List;
20
21 import org.tmatesoft.hg.core.HgLogCommand;
22 import org.tmatesoft.hg.core.HgLogCommand.FileRevision;
23 import org.tmatesoft.hg.repo.HgDataFile;
24 import org.tmatesoft.hg.repo.HgRepository;
25
26
27 /**
28 * @author Artem Tikhomirov
29 * @author TMate Software Ltd.
30 */
31 public class Log {
32
33 // -agentlib:hprof=heap=sites,depth=10,etc might be handy to debug speed/memory issues
34
35 public static void main(String[] args) throws Exception {
36 Options cmdLineOpts = Options.parse(args);
37 HgRepository hgRepo = cmdLineOpts.findRepository();
38 if (hgRepo.isInvalid()) {
39 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation());
40 return;
41 }
42 final Dump dump = new Dump(hgRepo);
43 dump.complete(cmdLineOpts.getBoolean("--debug"));
44 dump.verbose(cmdLineOpts.getBoolean("-v", "--verbose"));
45 final boolean reverseOrder = true;
46 dump.reversed(reverseOrder);
47 HgLogCommand cmd = new HgLogCommand(hgRepo);
48 for (String u : cmdLineOpts.getList("-u", "--user")) {
49 cmd.user(u);
50 }
51 for (String b : cmdLineOpts.getList("-b", "--branches")) {
52 cmd.branch(b);
53 }
54 int limit = cmdLineOpts.getSingleInt(-1, "-l", "--limit");
55 if (limit != -1) {
56 cmd.limit(limit);
57 }
58 List<String> files = cmdLineOpts.getList("");
59 final long start = System.currentTimeMillis();
60 if (files.isEmpty()) {
61 if (limit == -1) {
62 // no revisions and no limit
63 cmd.execute(dump);
64 } else {
65 // in fact, external (to dump inspector) --limit processing yelds incorrect results when other args
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
67 int[] r = new int[] { 0, hgRepo.getChangelog().getRevisionCount() };
68 if (fixRange(r, reverseOrder, limit) == 0) {
69 System.out.println("No changes");
70 return;
71 }
72 cmd.range(r[0], r[1]).execute(dump);
73 }
74 dump.done();
75 } else {
76 for (String fname : files) {
77 HgDataFile f1 = hgRepo.getFileNode(fname);
78 System.out.println("History of the file: " + f1.getPath());
79 if (limit == -1) {
80 cmd.file(f1.getPath(), true).execute(dump);
81 } else {
82 int[] r = new int[] { 0, f1.getRevisionCount() };
83 if (fixRange(r, reverseOrder, limit) == 0) {
84 System.out.println("No changes");
85 continue;
86 }
87 cmd.range(r[0], r[1]).file(f1.getPath(), true).execute(dump);
88 }
89 dump.done();
90 }
91 }
92 // cmd = null;
93 System.out.println("Total time:" + (System.currentTimeMillis() - start));
94 // Main.force_gc();
95 }
96
97 private static int fixRange(int[] start_end, boolean reverse, int limit) {
98 assert start_end.length == 2;
99 if (limit < start_end[1]) {
100 if (reverse) {
101 // adjust left boundary of the range
102 start_end[0] = start_end[1] - limit;
103 } else {
104 start_end[1] = limit; // adjust right boundary
105 }
106 }
107 int rv = start_end[1] - start_end[0];
108 start_end[1]--; // range needs index, not length
109 return rv;
110 }
111
112 private static final class Dump extends ChangesetDumpHandler implements HgLogCommand.FileHistoryHandler {
113
114 public Dump(HgRepository hgRepo) {
115 super(hgRepo);
116 }
117
118 public void copy(FileRevision from, FileRevision to) {
119 System.out.printf("Got notified that %s(%s) was originally known as %s(%s)\n", to.getPath(), to.getRevision(), from.getPath(), from.getRevision());
120 }
121 }
122 }