Mercurial > hg4j
diff cmdline/org/tmatesoft/hg/console/Log.java @ 206:63c9fed4369e
Sample command line tools for incoming/outgoing to use commands
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 28 Apr 2011 02:47:44 +0200 |
parents | 33a7d76f067b |
children | 41a778e3fd31 |
line wrap: on
line diff
--- a/cmdline/org/tmatesoft/hg/console/Log.java Thu Apr 28 02:00:42 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Log.java Thu Apr 28 02:47:44 2011 +0200 @@ -16,17 +16,12 @@ */ package org.tmatesoft.hg.console; -import java.util.Formatter; -import java.util.LinkedList; import java.util.List; -import org.tmatesoft.hg.core.HgChangeset; import org.tmatesoft.hg.core.HgLogCommand; import org.tmatesoft.hg.core.HgLogCommand.FileRevision; -import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgRepository; -import org.tmatesoft.hg.util.Path; /** @@ -45,9 +40,10 @@ return; } final Dump dump = new Dump(hgRepo); - dump.complete = cmdLineOpts.getBoolean("--debug"); - dump.verbose = cmdLineOpts.getBoolean("-v", "--verbose"); - dump.reverseOrder = true; + dump.complete(cmdLineOpts.getBoolean("--debug")); + dump.verbose(cmdLineOpts.getBoolean("-v", "--verbose")); + final boolean reverseOrder = true; + dump.reversed(reverseOrder); HgLogCommand cmd = new HgLogCommand(hgRepo); for (String u : cmdLineOpts.getList("-u", "--user")) { cmd.user(u); @@ -69,13 +65,13 @@ // in fact, external (to dump inspector) --limit processing yelds incorrect results when other args // e.g. -u or -b are used (i.e. with -u shall give <limit> csets with user, not check last <limit> csets for user int[] r = new int[] { 0, hgRepo.getChangelog().getRevisionCount() }; - if (fixRange(r, dump.reverseOrder, limit) == 0) { + if (fixRange(r, reverseOrder, limit) == 0) { System.out.println("No changes"); return; } cmd.range(r[0], r[1]).execute(dump); } - dump.complete(); + dump.done(); } else { for (String fname : files) { HgDataFile f1 = hgRepo.getFileNode(fname); @@ -84,13 +80,13 @@ cmd.file(f1.getPath(), true).execute(dump); } else { int[] r = new int[] { 0, f1.getRevisionCount() }; - if (fixRange(r, dump.reverseOrder, limit) == 0) { + if (fixRange(r, reverseOrder, limit) == 0) { System.out.println("No changes"); continue; } cmd.range(r[0], r[1]).file(f1.getPath(), true).execute(dump); } - dump.complete(); + dump.done(); } } // cmd = null; @@ -113,132 +109,14 @@ return rv; } - private static final class Dump implements HgLogCommand.FileHistoryHandler { - // params - boolean complete = false; // roughly --debug - boolean reverseOrder = false; - boolean verbose = true; // roughly -v - // own - private LinkedList<String> l = new LinkedList<String>(); - private final HgRepository repo; -// private HgChangelog.ParentWalker changelogWalker; - private final int tip ; + private static final class Dump extends ChangesetDumpHandler implements HgLogCommand.FileHistoryHandler { public Dump(HgRepository hgRepo) { - repo = hgRepo; - tip = hgRepo.getChangelog().getLastRevision(); + super(hgRepo); } public void copy(FileRevision from, FileRevision to) { System.out.printf("Got notified that %s(%s) was originally known as %s(%s)\n", to.getPath(), to.getRevision(), from.getPath(), from.getRevision()); } - - public void next(HgChangeset changeset) { - final String s = print(changeset); - if (reverseOrder) { - // XXX in fact, need to insert s into l according to changeset.getRevision() - // because when file history is being followed, revisions of the original file (with smaller revNumber) - // are reported *after* revisions of present file and with addFirst appear above them - l.addFirst(s); - } else { - System.out.print(s); - } - } - - public void complete() { - if (!reverseOrder) { - return; - } - for (String s : l) { - System.out.print(s); - } - l.clear(); -// changelogWalker = null; - } - - private String print(HgChangeset cset) { - StringBuilder sb = new StringBuilder(); - Formatter f = new Formatter(sb); - final Nodeid csetNodeid = cset.getNodeid(); - f.format("changeset: %d:%s\n", cset.getRevision(), complete ? csetNodeid : csetNodeid.shortNotation()); - if (cset.getRevision() == tip || repo.getTags().isTagged(csetNodeid)) { - - sb.append("tag: "); - for (String t : repo.getTags().tags(csetNodeid)) { - sb.append(t); - sb.append(' '); - } - if (cset.getRevision() == tip) { - sb.append("tip"); - } - sb.append('\n'); - } - if (complete) { -// if (changelogWalker == null) { -// changelogWalker = repo.getChangelog().new ParentWalker(); -// changelogWalker.init(); -// } -// Nodeid p1 = changelogWalker.safeFirstParent(csetNodeid); -// Nodeid p2 = changelogWalker.safeSecondParent(csetNodeid); - Nodeid p1 = cset.getFirstParentRevision(); - Nodeid p2 = cset.getSecondParentRevision(); - int p1x = p1 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevision(p1); - int p2x = p2 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevision(p2); - int mx = repo.getManifest().getLocalRevision(cset.getManifestRevision()); - f.format("parent: %d:%s\nparent: %d:%s\nmanifest: %d:%s\n", p1x, p1, p2x, p2, mx, cset.getManifestRevision()); - } - f.format("user: %s\ndate: %s\n", cset.getUser(), cset.getDate()); - if (!complete && verbose) { - final List<Path> files = cset.getAffectedFiles(); - sb.append("files: "); - for (Path s : files) { - sb.append(' '); - sb.append(s); - } - sb.append('\n'); - } - if (complete) { - if (!cset.getModifiedFiles().isEmpty()) { - sb.append("files: "); - for (FileRevision s : cset.getModifiedFiles()) { - sb.append(' '); - sb.append(s.getPath()); - } - sb.append('\n'); - } - if (!cset.getAddedFiles().isEmpty()) { - sb.append("files+: "); - for (FileRevision s : cset.getAddedFiles()) { - sb.append(' '); - sb.append(s.getPath()); - } - sb.append('\n'); - } - if (!cset.getRemovedFiles().isEmpty()) { - sb.append("files-: "); - for (Path s : cset.getRemovedFiles()) { - sb.append(' '); - sb.append(s); - } - sb.append('\n'); - } -// if (cset.extras() != null) { -// sb.append("extra: "); -// for (Map.Entry<String, String> e : cset.extras().entrySet()) { -// sb.append(' '); -// sb.append(e.getKey()); -// sb.append('='); -// sb.append(e.getValue()); -// } -// sb.append('\n'); -// } - } - if (complete || verbose) { - f.format("description:\n%s\n\n", cset.getComment()); - } else { - f.format("summary: %s\n\n", cset.getComment()); - } - return sb.toString(); - } } }