diff cmdline/org/tmatesoft/hg/console/Outgoing.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 e5407b5a586a
children 41a778e3fd31
line wrap: on
line diff
--- a/cmdline/org/tmatesoft/hg/console/Outgoing.java	Thu Apr 28 02:00:42 2011 +0200
+++ b/cmdline/org/tmatesoft/hg/console/Outgoing.java	Thu Apr 28 02:47:44 2011 +0200
@@ -19,18 +19,15 @@
 import java.util.Collection;
 import java.util.List;
 
+import org.tmatesoft.hg.core.HgOutgoingCommand;
+import org.tmatesoft.hg.core.HgRepoFacade;
 import org.tmatesoft.hg.core.Nodeid;
-import org.tmatesoft.hg.internal.RepositoryComparator;
-import org.tmatesoft.hg.repo.HgChangelog;
-import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
 import org.tmatesoft.hg.repo.HgLookup;
 import org.tmatesoft.hg.repo.HgRemoteRepository;
-import org.tmatesoft.hg.repo.HgRepository;
 
 
 /**
- * WORK IN PROGRESS, DO NOT USE
- * hg outgoing
+ * <em>hg outgoing</em>
  * 
  * @author Artem Tikhomirov
  * @author TMate Software Ltd.
@@ -38,60 +35,50 @@
 public class Outgoing {
 
 	public static void main(String[] args) throws Exception {
-		final boolean debug = true; // perhaps, use hg4j.remote.debug or own property?
 		Options cmdLineOpts = Options.parse(args);
-		HgRepository hgRepo = cmdLineOpts.findRepository();
-		if (hgRepo.isInvalid()) {
-			System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation());
+		HgRepoFacade hgRepo = new HgRepoFacade();
+		if (!hgRepo.init(cmdLineOpts.findRepository())) {
+			System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation());
 			return;
 		}
-		HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo);
+		// XXX perhaps, HgRepoFacade shall get detectRemote() analog (to get remote server with respect of facade's repo)
+		HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo.getRepository());
 		if (hgRemote.isInvalid()) {
 			System.err.printf("Remote repository %s is not valid", hgRemote.getLocation());
 			return;
 		}
-
-		HgChangelog changelog = hgRepo.getChangelog();
-		HgChangelog.ParentWalker pw = changelog.new ParentWalker();
-		pw.init();
+		//
+		HgOutgoingCommand cmd = hgRepo.createOutgoingCommand();
+		cmd.against(hgRemote);
 		
-		RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote);
-		repoCompare.compare(null);
-		if (debug) {
-			List<Nodeid> commonKnown = repoCompare.getCommon();
-			dump("Nodes known to be both locally and at remote server", commonKnown);
-		}
 		// find all local children of commonKnown
-		List<Nodeid> result = repoCompare.getLocalOnlyRevisions();
+		List<Nodeid> result = cmd.executeLite(null);
 		dump("Lite", result);
 		//
 		//
 		System.out.println("Full");
 		// show all, starting from next to common 
-		repoCompare.visitLocalOnlyRevisions(new HgChangelog.Inspector() {
-			private final ChangesetFormatter formatter = new ChangesetFormatter();
-			
-			public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
-				System.out.println(formatter.simple(revisionNumber, nodeid, cset));
-			}
-		});
+		final ChangesetDumpHandler h = new ChangesetDumpHandler(hgRepo.getRepository());
+		h.complete(cmdLineOpts.getBoolean("--debug")).verbose(cmdLineOpts.getBoolean("-v", "--verbose"));
+		cmd.executeFull(h);
+		h.done();
 	}
 
-	public static class ChangesetFormatter {
-		private final StringBuilder sb = new StringBuilder(1024);
-
-		public CharSequence simple(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
-			sb.setLength(0);
-			sb.append(String.format("changeset:  %d:%s\n", revisionNumber, nodeid.toString()));
-			sb.append(String.format("user:       %s\n", cset.user()));
-			sb.append(String.format("date:       %s\n", cset.dateString()));
-			sb.append(String.format("comment:    %s\n\n", cset.comment()));
-			return sb;
-		}
-	}
+//	public static class ChangesetFormatter {
+//		private final StringBuilder sb = new StringBuilder(1024);
+//
+//		public CharSequence simple(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
+//			sb.setLength(0);
+//			sb.append(String.format("changeset:  %d:%s\n", revisionNumber, nodeid.toString()));
+//			sb.append(String.format("user:       %s\n", cset.user()));
+//			sb.append(String.format("date:       %s\n", cset.dateString()));
+//			sb.append(String.format("comment:    %s\n\n", cset.comment()));
+//			return sb;
+//		}
+//	}
 	
 
-	private static void dump(String s, Collection<Nodeid> c) {
+	static void dump(String s, Collection<Nodeid> c) {
 		System.out.println(s);
 		for (Nodeid n : c) {
 			System.out.println(n);