kitaev@213: /* kitaev@213: * Copyright (c) 2010-2011 TMate Software Ltd kitaev@213: * kitaev@213: * This program is free software; you can redistribute it and/or modify kitaev@213: * it under the terms of the GNU General Public License as published by kitaev@213: * the Free Software Foundation; version 2 of the License. kitaev@213: * kitaev@213: * This program is distributed in the hope that it will be useful, kitaev@213: * but WITHOUT ANY WARRANTY; without even the implied warranty of kitaev@213: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the kitaev@213: * GNU General Public License for more details. kitaev@213: * kitaev@213: * For information on how to redistribute this software under kitaev@213: * the terms of a license other than GNU General Public License kitaev@213: * contact TMate Software at support@hg4j.com kitaev@213: */ kitaev@213: package org.tmatesoft.hg.console; kitaev@213: kitaev@213: import java.util.List; kitaev@213: kitaev@213: import org.tmatesoft.hg.core.HgLogCommand; kitaev@213: import org.tmatesoft.hg.core.HgLogCommand.FileRevision; kitaev@213: import org.tmatesoft.hg.repo.HgDataFile; kitaev@213: import org.tmatesoft.hg.repo.HgRepository; kitaev@213: kitaev@213: kitaev@213: /** kitaev@213: * @author Artem Tikhomirov kitaev@213: * @author TMate Software Ltd. kitaev@213: */ kitaev@213: public class Log { kitaev@213: kitaev@213: // -agentlib:hprof=heap=sites,depth=10,etc might be handy to debug speed/memory issues kitaev@213: kitaev@213: public static void main(String[] args) throws Exception { kitaev@213: Options cmdLineOpts = Options.parse(args); kitaev@213: HgRepository hgRepo = cmdLineOpts.findRepository(); kitaev@213: if (hgRepo.isInvalid()) { kitaev@213: System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); kitaev@213: return; kitaev@213: } kitaev@213: final Dump dump = new Dump(hgRepo); kitaev@213: dump.complete(cmdLineOpts.getBoolean("--debug")); kitaev@213: dump.verbose(cmdLineOpts.getBoolean("-v", "--verbose")); kitaev@213: final boolean reverseOrder = true; kitaev@213: dump.reversed(reverseOrder); kitaev@213: HgLogCommand cmd = new HgLogCommand(hgRepo); kitaev@213: for (String u : cmdLineOpts.getList("-u", "--user")) { kitaev@213: cmd.user(u); kitaev@213: } kitaev@213: for (String b : cmdLineOpts.getList("-b", "--branches")) { kitaev@213: cmd.branch(b); kitaev@213: } kitaev@213: int limit = cmdLineOpts.getSingleInt(-1, "-l", "--limit"); kitaev@213: if (limit != -1) { kitaev@213: cmd.limit(limit); kitaev@213: } kitaev@213: List files = cmdLineOpts.getList(""); kitaev@213: final long start = System.currentTimeMillis(); kitaev@213: if (files.isEmpty()) { kitaev@213: if (limit == -1) { kitaev@213: // no revisions and no limit kitaev@213: cmd.execute(dump); kitaev@213: } else { kitaev@213: // in fact, external (to dump inspector) --limit processing yelds incorrect results when other args kitaev@213: // e.g. -u or -b are used (i.e. with -u shall give csets with user, not check last csets for user kitaev@213: int[] r = new int[] { 0, hgRepo.getChangelog().getRevisionCount() }; kitaev@213: if (fixRange(r, reverseOrder, limit) == 0) { kitaev@213: System.out.println("No changes"); kitaev@213: return; kitaev@213: } kitaev@213: cmd.range(r[0], r[1]).execute(dump); kitaev@213: } kitaev@213: dump.done(); kitaev@213: } else { kitaev@213: for (String fname : files) { kitaev@213: HgDataFile f1 = hgRepo.getFileNode(fname); kitaev@213: System.out.println("History of the file: " + f1.getPath()); kitaev@213: if (limit == -1) { kitaev@213: cmd.file(f1.getPath(), true).execute(dump); kitaev@213: } else { kitaev@213: int[] r = new int[] { 0, f1.getRevisionCount() }; kitaev@213: if (fixRange(r, reverseOrder, limit) == 0) { kitaev@213: System.out.println("No changes"); kitaev@213: continue; kitaev@213: } kitaev@213: cmd.range(r[0], r[1]).file(f1.getPath(), true).execute(dump); kitaev@213: } kitaev@213: dump.done(); kitaev@213: } kitaev@213: } kitaev@213: // cmd = null; kitaev@213: System.out.println("Total time:" + (System.currentTimeMillis() - start)); kitaev@213: // Main.force_gc(); kitaev@213: } kitaev@213: kitaev@213: private static int fixRange(int[] start_end, boolean reverse, int limit) { kitaev@213: assert start_end.length == 2; kitaev@213: if (limit < start_end[1]) { kitaev@213: if (reverse) { kitaev@213: // adjust left boundary of the range kitaev@213: start_end[0] = start_end[1] - limit; kitaev@213: } else { kitaev@213: start_end[1] = limit; // adjust right boundary kitaev@213: } kitaev@213: } kitaev@213: int rv = start_end[1] - start_end[0]; kitaev@213: start_end[1]--; // range needs index, not length kitaev@213: return rv; kitaev@213: } kitaev@213: kitaev@213: private static final class Dump extends ChangesetDumpHandler implements HgLogCommand.FileHistoryHandler { kitaev@213: kitaev@213: public Dump(HgRepository hgRepo) { kitaev@213: super(hgRepo); kitaev@213: } kitaev@213: kitaev@213: public void copy(FileRevision from, FileRevision to) { kitaev@213: System.out.printf("Got notified that %s(%s) was originally known as %s(%s)\n", to.getPath(), to.getRevision(), from.getPath(), from.getRevision()); kitaev@213: } kitaev@213: } kitaev@213: }