tikhomirov@47: /* tikhomirov@47: * Copyright (c) 2010, 2011 Artem Tikhomirov tikhomirov@1: */ tikhomirov@1: package com.tmate.hgkit.console; tikhomirov@1: tikhomirov@47: import java.util.Formatter; tikhomirov@47: import java.util.LinkedList; tikhomirov@47: import java.util.List; tikhomirov@47: tikhomirov@2: import com.tmate.hgkit.fs.RepositoryLookup; tikhomirov@2: import com.tmate.hgkit.ll.Changeset; tikhomirov@2: import com.tmate.hgkit.ll.HgDataFile; tikhomirov@1: import com.tmate.hgkit.ll.HgRepository; tikhomirov@47: import com.tmate.hgkit.ll.Nodeid; tikhomirov@1: tikhomirov@1: /** tikhomirov@1: * @author artem tikhomirov@1: */ tikhomirov@1: public class Log { tikhomirov@1: tikhomirov@1: public static void main(String[] args) throws Exception { tikhomirov@2: RepositoryLookup repoLookup = new RepositoryLookup(); tikhomirov@4: RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); tikhomirov@4: HgRepository hgRepo = repoLookup.detect(cmdLineOpts); tikhomirov@1: if (hgRepo.isInvalid()) { tikhomirov@1: System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); tikhomirov@1: return; tikhomirov@1: } tikhomirov@1: System.out.println(hgRepo.getLocation()); tikhomirov@47: final Dump dump = new Dump(hgRepo); tikhomirov@47: dump.complete = false; //cmdLineOpts; tikhomirov@47: dump.reverseOrder = true; tikhomirov@6: if (cmdLineOpts.files.isEmpty()) { tikhomirov@47: // no revisions and no limit tikhomirov@47: hgRepo.getChangelog().all(dump); tikhomirov@47: dump.complete(); tikhomirov@6: } else { tikhomirov@6: for (String fname : cmdLineOpts.files) { tikhomirov@6: HgDataFile f1 = hgRepo.getFileNode(fname); tikhomirov@8: System.out.println("History of the file: " + f1.getPath()); tikhomirov@47: f1.history(dump); tikhomirov@47: dump.complete(); tikhomirov@6: } tikhomirov@6: } tikhomirov@2: // tikhomirov@3: // System.out.println("\n\n========================="); tikhomirov@3: // System.out.println("Range 1-3:"); tikhomirov@3: // f1.history(1,3, callback); tikhomirov@3: // tikhomirov@1: //new ChangelogWalker().setFile("hello.c").setRevisionRange(1, 4).accept(new Visitor); tikhomirov@1: } tikhomirov@47: tikhomirov@47: private static final class Dump implements Changeset.Inspector { tikhomirov@47: // params tikhomirov@47: boolean complete = false; tikhomirov@47: boolean reverseOrder = false; tikhomirov@47: // own tikhomirov@47: private LinkedList l = new LinkedList(); tikhomirov@47: private final HgRepository repo; tikhomirov@47: tikhomirov@47: public Dump(HgRepository hgRepo) { tikhomirov@47: this.repo = hgRepo; tikhomirov@47: } tikhomirov@47: tikhomirov@47: public void next(int revisionNumber, Nodeid nodeid, Changeset cset) { tikhomirov@47: final String s = print(revisionNumber, nodeid, cset); tikhomirov@47: if (reverseOrder) { tikhomirov@47: l.addFirst(s); tikhomirov@47: } else { tikhomirov@47: System.out.print(s); tikhomirov@47: } tikhomirov@47: } tikhomirov@47: tikhomirov@47: public void complete() { tikhomirov@47: if (!reverseOrder) { tikhomirov@47: return; tikhomirov@47: } tikhomirov@47: for (String s : l) { tikhomirov@47: System.out.print(s); tikhomirov@47: } tikhomirov@47: l.clear(); tikhomirov@47: } tikhomirov@47: tikhomirov@47: private String print(int revNumber, Nodeid csetNodeid, Changeset cset) { tikhomirov@47: StringBuilder sb = new StringBuilder(); tikhomirov@47: Formatter f = new Formatter(sb); tikhomirov@47: f.format("changeset: %d:%s\n", revNumber, complete ? csetNodeid : csetNodeid.shortNotation()); tikhomirov@47: if (complete) { tikhomirov@47: f.format("parent: %s\nparent: %s\nmanifest: %s", "-1", "-1", cset.manifest()); tikhomirov@47: } tikhomirov@47: f.format("user: %s\ndate: %s\n", cset.user(), cset.dateString()); tikhomirov@47: if (complete) { tikhomirov@47: final List files = cset.files(); tikhomirov@47: sb.append("files: "); tikhomirov@47: for (String s : files) { tikhomirov@47: sb.append(' '); tikhomirov@47: sb.append(s); tikhomirov@47: } tikhomirov@47: f.format("description:\n%s\n\n", cset.comment()); tikhomirov@47: } else { tikhomirov@47: f.format("summary: %s\n\n", cset.comment()); tikhomirov@47: } tikhomirov@47: if (cset.extras() != null) { tikhomirov@47: f.format("extra: " + cset.extras()); // TODO tikhomirov@47: } tikhomirov@47: return sb.toString(); tikhomirov@47: } tikhomirov@47: } tikhomirov@1: }