Mercurial > jhg
changeset 72:9a03a80a0f2f
Command-line frontend moved to separate source root with new package statement
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 23 Jan 2011 03:46:59 +0100 |
parents | ce6d23673f2d |
children | 0d279bcc4442 |
files | .classpath TODO cmdline/org/tmatesoft/hg/console/Cat.java cmdline/org/tmatesoft/hg/console/Log.java cmdline/org/tmatesoft/hg/console/Manifest.java cmdline/org/tmatesoft/hg/console/Status.java src/com/tmate/hgkit/console/Cat.java src/com/tmate/hgkit/console/Log.java src/com/tmate/hgkit/console/Manifest.java src/com/tmate/hgkit/console/Status.java |
diffstat | 10 files changed, 554 insertions(+), 493 deletions(-) [+] |
line wrap: on
line diff
--- a/.classpath Sun Jan 23 03:34:24 2011 +0100 +++ b/.classpath Sun Jan 23 03:46:59 2011 +0100 @@ -2,6 +2,7 @@ <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="test"/> + <classpathentry kind="src" path="cmdline"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="output" path="bin"/> </classpath>
--- a/TODO Sun Jan 23 03:34:24 2011 +0100 +++ b/TODO Sun Jan 23 03:46:59 2011 +0100 @@ -18,4 +18,9 @@ Read-only support, version 1.1 ============================== +Committed: +* http, https and ssh connections: + +* incoming +* outgoing
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmdline/org/tmatesoft/hg/console/Cat.java Sun Jan 23 03:46:59 2011 +0100 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2010-2011 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@svnkit.com + */ +package org.tmatesoft.hg.console; + +import com.tmate.hgkit.fs.RepositoryLookup; +import com.tmate.hgkit.ll.DigestHelper; +import com.tmate.hgkit.ll.HgDataFile; +import com.tmate.hgkit.ll.HgRepository; +import com.tmate.hgkit.ll.Internals; + +/** + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class Cat { + + public static void main(String[] args) throws Exception { + RepositoryLookup repoLookup = new RepositoryLookup(); + RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); + HgRepository hgRepo = repoLookup.detect(cmdLineOpts); + if (hgRepo.isInvalid()) { + System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); + return; + } + Internals debug = new Internals(hgRepo); + String[] toCheck = new String[] {"design.txt", "src/com/tmate/hgkit/ll/Changelog.java", "src/Extras.java", "bin/com/tmate/hgkit/ll/Changelog.class"}; + boolean[] checkResult = debug.checkIgnored(toCheck); + for (int i = 0; i < toCheck.length; i++) { + System.out.println("Ignored " + toCheck[i] + ": " + checkResult[i]); + } + DigestHelper dh = new DigestHelper(); + for (String fname : cmdLineOpts.files) { + System.out.println(fname); + HgDataFile fn = hgRepo.getFileNode(fname); + if (fn.exists()) { + int total = fn.getRevisionCount(); + System.out.printf("Total revisions: %d\n", total); + for (int i = 0; i < total; i++) { + byte[] content = fn.content(i); + System.out.println("==========>"); + System.out.println(new String(content)); + int[] parentRevisions = new int[2]; + byte[] parent1 = new byte[20]; + byte[] parent2 = new byte[20]; + fn.parents(i, parentRevisions, parent1, parent2); + System.out.println(dh.sha1(parent1, parent2, content).asHexString()); + } + } else { + System.out.println(">>>Not found!"); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmdline/org/tmatesoft/hg/console/Log.java Sun Jan 23 03:46:59 2011 +0100 @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2010-2011 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@svnkit.com + */ +package org.tmatesoft.hg.console; + +import java.util.Formatter; +import java.util.LinkedList; +import java.util.List; + +import org.tmatesoft.hg.core.Cset; +import org.tmatesoft.hg.core.LogCommand; +import org.tmatesoft.hg.core.LogCommand.FileRevision; +import org.tmatesoft.hg.core.Path; + +import com.tmate.hgkit.fs.RepositoryLookup; +import com.tmate.hgkit.ll.HgDataFile; +import com.tmate.hgkit.ll.HgRepository; +import com.tmate.hgkit.ll.Nodeid; +import com.tmate.hgkit.ll.Revlog; + +/** + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class Log { + + public static void main(String[] args) throws Exception { + RepositoryLookup repoLookup = new RepositoryLookup(); + RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); + HgRepository hgRepo = repoLookup.detect(cmdLineOpts); + if (hgRepo.isInvalid()) { + System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); + return; + } + System.out.println(hgRepo.getLocation()); + final Dump dump = new Dump(hgRepo); + dump.complete = true; //cmdLineOpts; + dump.verbose = false; //cmdLineOpts; + dump.reverseOrder = true; + LogCommand cmd = new LogCommand(hgRepo); + if (cmdLineOpts.users != null) { + for (String u : cmdLineOpts.users) { + cmd.user(u); + } + } + if (cmdLineOpts.branches != null) { + for (String b : cmdLineOpts.branches) { + cmd.branch(b); + } + } + if (cmdLineOpts.limit != -1) { + cmd.limit(cmdLineOpts.limit); + + } + if (cmdLineOpts.files.isEmpty()) { + if (cmdLineOpts.limit == -1) { + // no revisions and no limit + cmd.execute(dump); + } else { + // 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, cmdLineOpts.limit) == 0) { + System.out.println("No changes"); + return; + } + cmd.range(r[0], r[1]).execute(dump); + } + dump.complete(); + } else { + for (String fname : cmdLineOpts.files) { + HgDataFile f1 = hgRepo.getFileNode(fname); + System.out.println("History of the file: " + f1.getPath()); + if (cmdLineOpts.limit == -1) { + cmd.file(Path.create(fname)).execute(dump); + } else { + int[] r = new int[] { 0, f1.getRevisionCount() }; + if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) { + System.out.println("No changes"); + continue; + } + cmd.range(r[0], r[1]).file(Path.create(fname)).execute(dump); + } + dump.complete(); + } + } + // + // XXX new ChangelogWalker().setFile("hello.c").setRevisionRange(1, 4).accept(new Visitor); + } + + private static int fixRange(int[] start_end, boolean reverse, int limit) { + assert start_end.length == 2; + if (limit < start_end[1]) { + if (reverse) { + // adjust left boundary of the range + start_end[0] = start_end[1] - limit; + } else { + start_end[1] = limit; // adjust right boundary + } + } + int rv = start_end[1] - start_end[0]; + start_end[1]--; // range needs index, not length + return rv; + } + + private static final class Dump implements LogCommand.Handler { + // 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 Revlog.ParentWalker changelogWalker; + private final int tip ; + + public Dump(HgRepository hgRepo) { + repo = hgRepo; + tip = hgRepo.getChangelog().getRevisionCount() - 1; + } + + public void next(Cset changeset) { + final String s = print(changeset); + if (reverseOrder) { + 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(Cset 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); + int p1x = p1 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevisionNumber(p1); + int p2x = p2 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevisionNumber(p2); + int mx = repo.getManifest().getLocalRevisionNumber(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(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmdline/org/tmatesoft/hg/console/Manifest.java Sun Jan 23 03:46:59 2011 +0100 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2010-2011 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@svnkit.com + */ +package org.tmatesoft.hg.console; + +import static com.tmate.hgkit.ll.HgRepository.TIP; + +import org.tmatesoft.hg.core.Path; +import org.tmatesoft.hg.core.RepositoryTreeWalker; +import org.tmatesoft.hg.core.LogCommand.FileRevision; + +import com.tmate.hgkit.fs.RepositoryLookup; +import com.tmate.hgkit.ll.HgManifest; +import com.tmate.hgkit.ll.HgRepository; +import com.tmate.hgkit.ll.Nodeid; + +/** + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class Manifest { + + public static void main(String[] args) throws Exception { + RepositoryLookup repoLookup = new RepositoryLookup(); + RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); + HgRepository hgRepo = repoLookup.detect(cmdLineOpts); + if (hgRepo.isInvalid()) { + System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); + return; + } + System.out.println(hgRepo.getLocation()); + hgRepo.getManifest().walk(0, TIP, new Dump()); + // + new RepositoryTreeWalker(hgRepo).dirs(true).walk(new RepositoryTreeWalker.Handler() { + + public void begin(Nodeid manifestRevision) { + System.out.println(">> " + manifestRevision); + } + public void dir(Path p) { + System.out.println(p); + } + public void file(FileRevision fileRevision) { + System.out.print(fileRevision.getRevision());; + System.out.print(" "); + System.out.println(fileRevision.getPath()); + } + + public void end(Nodeid manifestRevision) { + System.out.println(); + } + }); + } + + public static final class Dump implements HgManifest.Inspector { + public boolean begin(int revision, Nodeid nid) { + System.out.printf("%d : %s\n", revision, nid); + return true; + } + + public boolean next(Nodeid nid, String fname, String flags) { + System.out.println(nid + "\t" + fname + "\t\t" + flags); + return true; + } + + public boolean end(int revision) { + System.out.println(); + return true; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmdline/org/tmatesoft/hg/console/Status.java Sun Jan 23 03:46:59 2011 +0100 @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2010-2011 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@svnkit.com + */ +package org.tmatesoft.hg.console; + +import static com.tmate.hgkit.ll.HgRepository.TIP; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.tmate.hgkit.fs.RepositoryLookup; +import com.tmate.hgkit.ll.HgDataFile; +import com.tmate.hgkit.ll.HgRepository; +import com.tmate.hgkit.ll.Internals; +import com.tmate.hgkit.ll.LocalHgRepo; +import com.tmate.hgkit.ll.Nodeid; +import com.tmate.hgkit.ll.StatusCollector; +import com.tmate.hgkit.ll.WorkingCopyStatusCollector; + +/** + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class Status { + + public static void main(String[] args) throws Exception { + RepositoryLookup repoLookup = new RepositoryLookup(); + RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); + HgRepository hgRepo = repoLookup.detect(cmdLineOpts); + if (hgRepo.isInvalid()) { + System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); + return; + } + System.out.println(hgRepo.getLocation()); + Internals debug = new Internals(hgRepo); + debug.dumpDirstate(); + final StatusDump dump = new StatusDump(); + dump.showIgnored = false; + dump.showClean = false; + StatusCollector sc = new StatusCollector(hgRepo); + final int r1 = 0, r2 = 3; + System.out.printf("Status for changes between revision %d and %d:\n", r1, r2); + sc.walk(r1, r2, dump); + // + System.out.println("\n\nSame, but sorted in the way hg status does:"); + StatusCollector.Record r = sc.status(r1, r2); + sortAndPrint('M', r.getModified()); + sortAndPrint('A', r.getAdded()); + sortAndPrint('R', r.getRemoved()); + // + System.out.println("\n\nTry hg status --change <rev>:"); + sc.change(0, dump); + System.out.println("\nStatus against working dir:"); + WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(hgRepo, ((LocalHgRepo) hgRepo).createWorkingDirWalker()); + wcc.walk(TIP, dump); + System.out.println(); + System.out.printf("Manifest of the revision %d:\n", r2); + hgRepo.getManifest().walk(r2, r2, new Manifest.Dump()); + System.out.println(); + System.out.printf("\nStatus of working dir against %d:\n", r2); + r = wcc.status(r2); + sortAndPrint('M', r.getModified()); + sortAndPrint('A', r.getAdded()); + sortAndPrint('R', r.getRemoved()); + sortAndPrint('?', r.getUnknown()); + sortAndPrint('I', r.getIgnored()); + sortAndPrint('C', r.getClean()); + sortAndPrint('!', r.getMissing()); + } + + private static void sortAndPrint(char prefix, List<String> ul) { + ArrayList<String> sortList = new ArrayList<String>(ul); + Collections.sort(sortList); + for (String s : sortList) { + System.out.print(prefix); + System.out.print(' '); + System.out.println(s); + } + } + + protected static void testStatusInternals(HgRepository hgRepo) { + HgDataFile n = hgRepo.getFileNode("design.txt"); + for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) { + // expected: 359, 2123, 3079 + byte[] b = s.getBytes(); + final Nodeid nid = Nodeid.fromAscii(b, 0, b.length); + System.out.println(s + " : " + n.length(nid)); + } + } + + private static class StatusDump implements StatusCollector.Inspector { + public boolean hideStatusPrefix = false; // hg status -n option + public boolean showCopied = true; // -C + public boolean showIgnored = true; // -i + public boolean showClean = true; // -c + + public void modified(String fname) { + print('M', fname); + } + + public void added(String fname) { + print('A', fname); + } + + public void copied(String fnameOrigin, String fnameAdded) { + added(fnameAdded); + if (showCopied) { + print(' ', fnameOrigin); + } + } + + public void removed(String fname) { + print('R', fname); + } + + public void clean(String fname) { + if (showClean) { + print('C', fname); + } + } + + public void missing(String fname) { + print('!', fname); + } + + public void unknown(String fname) { + print('?', fname); + } + + public void ignored(String fname) { + if (showIgnored) { + print('I', fname); + } + } + + private void print(char status, String fname) { + if (!hideStatusPrefix) { + System.out.print(status); + System.out.print(' '); + } + System.out.println(fname); + } + } +}
--- a/src/com/tmate/hgkit/console/Cat.java Sun Jan 23 03:34:24 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2010 Artem Tikhomirov - */ -package com.tmate.hgkit.console; - -import com.tmate.hgkit.fs.RepositoryLookup; -import com.tmate.hgkit.ll.DigestHelper; -import com.tmate.hgkit.ll.HgDataFile; -import com.tmate.hgkit.ll.HgRepository; -import com.tmate.hgkit.ll.Internals; - -/** - * @author artem - * - */ -public class Cat { - - public static void main(String[] args) throws Exception { - RepositoryLookup repoLookup = new RepositoryLookup(); - RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); - HgRepository hgRepo = repoLookup.detect(cmdLineOpts); - if (hgRepo.isInvalid()) { - System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); - return; - } - Internals debug = new Internals(hgRepo); - String[] toCheck = new String[] {"design.txt", "src/com/tmate/hgkit/ll/Changelog.java", "src/Extras.java", "bin/com/tmate/hgkit/ll/Changelog.class"}; - boolean[] checkResult = debug.checkIgnored(toCheck); - for (int i = 0; i < toCheck.length; i++) { - System.out.println("Ignored " + toCheck[i] + ": " + checkResult[i]); - } - DigestHelper dh = new DigestHelper(); - for (String fname : cmdLineOpts.files) { - System.out.println(fname); - HgDataFile fn = hgRepo.getFileNode(fname); - if (fn.exists()) { - int total = fn.getRevisionCount(); - System.out.printf("Total revisions: %d\n", total); - for (int i = 0; i < total; i++) { - byte[] content = fn.content(i); - System.out.println("==========>"); - System.out.println(new String(content)); - int[] parentRevisions = new int[2]; - byte[] parent1 = new byte[20]; - byte[] parent2 = new byte[20]; - fn.parents(i, parentRevisions, parent1, parent2); - System.out.println(dh.sha1(parent1, parent2, content).asHexString()); - } - } else { - System.out.println(">>>Not found!"); - } - } - } -}
--- a/src/com/tmate/hgkit/console/Log.java Sun Jan 23 03:34:24 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,224 +0,0 @@ -/* - * Copyright (c) 2010, 2011 Artem Tikhomirov - */ -package com.tmate.hgkit.console; - -import java.util.Formatter; -import java.util.LinkedList; -import java.util.List; - -import org.tmatesoft.hg.core.Cset; -import org.tmatesoft.hg.core.LogCommand; -import org.tmatesoft.hg.core.LogCommand.FileRevision; -import org.tmatesoft.hg.core.Path; - -import com.tmate.hgkit.fs.RepositoryLookup; -import com.tmate.hgkit.ll.HgDataFile; -import com.tmate.hgkit.ll.HgRepository; -import com.tmate.hgkit.ll.Nodeid; -import com.tmate.hgkit.ll.Revlog; - -/** - * @author artem - */ -public class Log { - - public static void main(String[] args) throws Exception { - RepositoryLookup repoLookup = new RepositoryLookup(); - RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); - HgRepository hgRepo = repoLookup.detect(cmdLineOpts); - if (hgRepo.isInvalid()) { - System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); - return; - } - System.out.println(hgRepo.getLocation()); - final Dump dump = new Dump(hgRepo); - dump.complete = true; //cmdLineOpts; - dump.verbose = false; //cmdLineOpts; - dump.reverseOrder = true; - LogCommand cmd = new LogCommand(hgRepo); - if (cmdLineOpts.users != null) { - for (String u : cmdLineOpts.users) { - cmd.user(u); - } - } - if (cmdLineOpts.branches != null) { - for (String b : cmdLineOpts.branches) { - cmd.branch(b); - } - } - if (cmdLineOpts.limit != -1) { - cmd.limit(cmdLineOpts.limit); - - } - if (cmdLineOpts.files.isEmpty()) { - if (cmdLineOpts.limit == -1) { - // no revisions and no limit - cmd.execute(dump); - } else { - // 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, cmdLineOpts.limit) == 0) { - System.out.println("No changes"); - return; - } - cmd.range(r[0], r[1]).execute(dump); - } - dump.complete(); - } else { - for (String fname : cmdLineOpts.files) { - HgDataFile f1 = hgRepo.getFileNode(fname); - System.out.println("History of the file: " + f1.getPath()); - if (cmdLineOpts.limit == -1) { - cmd.file(Path.create(fname)).execute(dump); - } else { - int[] r = new int[] { 0, f1.getRevisionCount() }; - if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) { - System.out.println("No changes"); - continue; - } - cmd.range(r[0], r[1]).file(Path.create(fname)).execute(dump); - } - dump.complete(); - } - } - // - // XXX new ChangelogWalker().setFile("hello.c").setRevisionRange(1, 4).accept(new Visitor); - } - - private static int fixRange(int[] start_end, boolean reverse, int limit) { - assert start_end.length == 2; - if (limit < start_end[1]) { - if (reverse) { - // adjust left boundary of the range - start_end[0] = start_end[1] - limit; - } else { - start_end[1] = limit; // adjust right boundary - } - } - int rv = start_end[1] - start_end[0]; - start_end[1]--; // range needs index, not length - return rv; - } - - private static final class Dump implements LogCommand.Handler { - // 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 Revlog.ParentWalker changelogWalker; - private final int tip ; - - public Dump(HgRepository hgRepo) { - repo = hgRepo; - tip = hgRepo.getChangelog().getRevisionCount() - 1; - } - - public void next(Cset changeset) { - final String s = print(changeset); - if (reverseOrder) { - 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(Cset 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); - int p1x = p1 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevisionNumber(p1); - int p2x = p2 == Nodeid.NULL ? -1 : repo.getChangelog().getLocalRevisionNumber(p2); - int mx = repo.getManifest().getLocalRevisionNumber(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(); - } - } -}
--- a/src/com/tmate/hgkit/console/Manifest.java Sun Jan 23 03:34:24 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2010, 2011 Artem Tikhomirov - */ -package com.tmate.hgkit.console; - -import static com.tmate.hgkit.ll.HgRepository.TIP; - -import org.tmatesoft.hg.core.Path; -import org.tmatesoft.hg.core.RepositoryTreeWalker; -import org.tmatesoft.hg.core.LogCommand.FileRevision; - -import com.tmate.hgkit.fs.RepositoryLookup; -import com.tmate.hgkit.ll.HgManifest; -import com.tmate.hgkit.ll.HgRepository; -import com.tmate.hgkit.ll.Nodeid; - -/** - * - * @author artem - */ -public class Manifest { - - public static void main(String[] args) throws Exception { - RepositoryLookup repoLookup = new RepositoryLookup(); - RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); - HgRepository hgRepo = repoLookup.detect(cmdLineOpts); - if (hgRepo.isInvalid()) { - System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); - return; - } - System.out.println(hgRepo.getLocation()); - hgRepo.getManifest().walk(0, TIP, new Dump()); - // - new RepositoryTreeWalker(hgRepo).dirs(true).walk(new RepositoryTreeWalker.Handler() { - - public void begin(Nodeid manifestRevision) { - System.out.println(">> " + manifestRevision); - } - public void dir(Path p) { - System.out.println(p); - } - public void file(FileRevision fileRevision) { - System.out.print(fileRevision.getRevision());; - System.out.print(" "); - System.out.println(fileRevision.getPath()); - } - - public void end(Nodeid manifestRevision) { - System.out.println(); - } - }); - } - - public static final class Dump implements HgManifest.Inspector { - public boolean begin(int revision, Nodeid nid) { - System.out.printf("%d : %s\n", revision, nid); - return true; - } - - public boolean next(Nodeid nid, String fname, String flags) { - System.out.println(nid + "\t" + fname + "\t\t" + flags); - return true; - } - - public boolean end(int revision) { - System.out.println(); - return true; - } - } -}
--- a/src/com/tmate/hgkit/console/Status.java Sun Jan 23 03:34:24 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2010, 2011 Artem Tikhomirov - */ -package com.tmate.hgkit.console; - -import static com.tmate.hgkit.ll.HgRepository.TIP; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import com.tmate.hgkit.fs.RepositoryLookup; -import com.tmate.hgkit.ll.HgDataFile; -import com.tmate.hgkit.ll.HgRepository; -import com.tmate.hgkit.ll.Internals; -import com.tmate.hgkit.ll.LocalHgRepo; -import com.tmate.hgkit.ll.Nodeid; -import com.tmate.hgkit.ll.StatusCollector; -import com.tmate.hgkit.ll.WorkingCopyStatusCollector; - -/** - * - * @author artem - */ -public class Status { - - public static void main(String[] args) throws Exception { - RepositoryLookup repoLookup = new RepositoryLookup(); - RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args); - HgRepository hgRepo = repoLookup.detect(cmdLineOpts); - if (hgRepo.isInvalid()) { - System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); - return; - } - System.out.println(hgRepo.getLocation()); - Internals debug = new Internals(hgRepo); - debug.dumpDirstate(); - final StatusDump dump = new StatusDump(); - dump.showIgnored = false; - dump.showClean = false; - StatusCollector sc = new StatusCollector(hgRepo); - final int r1 = 0, r2 = 3; - System.out.printf("Status for changes between revision %d and %d:\n", r1, r2); - sc.walk(r1, r2, dump); - // - System.out.println("\n\nSame, but sorted in the way hg status does:"); - StatusCollector.Record r = sc.status(r1, r2); - sortAndPrint('M', r.getModified()); - sortAndPrint('A', r.getAdded()); - sortAndPrint('R', r.getRemoved()); - // - System.out.println("\n\nTry hg status --change <rev>:"); - sc.change(0, dump); - System.out.println("\nStatus against working dir:"); - WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(hgRepo, ((LocalHgRepo) hgRepo).createWorkingDirWalker()); - wcc.walk(TIP, dump); - System.out.println(); - System.out.printf("Manifest of the revision %d:\n", r2); - hgRepo.getManifest().walk(r2, r2, new Manifest.Dump()); - System.out.println(); - System.out.printf("\nStatus of working dir against %d:\n", r2); - r = wcc.status(r2); - sortAndPrint('M', r.getModified()); - sortAndPrint('A', r.getAdded()); - sortAndPrint('R', r.getRemoved()); - sortAndPrint('?', r.getUnknown()); - sortAndPrint('I', r.getIgnored()); - sortAndPrint('C', r.getClean()); - sortAndPrint('!', r.getMissing()); - } - - private static void sortAndPrint(char prefix, List<String> ul) { - ArrayList<String> sortList = new ArrayList<String>(ul); - Collections.sort(sortList); - for (String s : sortList) { - System.out.print(prefix); - System.out.print(' '); - System.out.println(s); - } - } - - protected static void testStatusInternals(HgRepository hgRepo) { - HgDataFile n = hgRepo.getFileNode("design.txt"); - for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) { - // expected: 359, 2123, 3079 - byte[] b = s.getBytes(); - final Nodeid nid = Nodeid.fromAscii(b, 0, b.length); - System.out.println(s + " : " + n.length(nid)); - } - } - - private static class StatusDump implements StatusCollector.Inspector { - public boolean hideStatusPrefix = false; // hg status -n option - public boolean showCopied = true; // -C - public boolean showIgnored = true; // -i - public boolean showClean = true; // -c - - public void modified(String fname) { - print('M', fname); - } - - public void added(String fname) { - print('A', fname); - } - - public void copied(String fnameOrigin, String fnameAdded) { - added(fnameAdded); - if (showCopied) { - print(' ', fnameOrigin); - } - } - - public void removed(String fname) { - print('R', fname); - } - - public void clean(String fname) { - if (showClean) { - print('C', fname); - } - } - - public void missing(String fname) { - print('!', fname); - } - - public void unknown(String fname) { - print('?', fname); - } - - public void ignored(String fname) { - if (showIgnored) { - print('I', fname); - } - } - - private void print(char status, String fname) { - if (!hideStatusPrefix) { - System.out.print(status); - System.out.print(' '); - } - System.out.println(fname); - } - } -}