comparison 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
comparison
equal deleted inserted replaced
205:ffc5f6d59f7e 206:63c9fed4369e
17 package org.tmatesoft.hg.console; 17 package org.tmatesoft.hg.console;
18 18
19 import java.util.Collection; 19 import java.util.Collection;
20 import java.util.List; 20 import java.util.List;
21 21
22 import org.tmatesoft.hg.core.HgOutgoingCommand;
23 import org.tmatesoft.hg.core.HgRepoFacade;
22 import org.tmatesoft.hg.core.Nodeid; 24 import org.tmatesoft.hg.core.Nodeid;
23 import org.tmatesoft.hg.internal.RepositoryComparator;
24 import org.tmatesoft.hg.repo.HgChangelog;
25 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
26 import org.tmatesoft.hg.repo.HgLookup; 25 import org.tmatesoft.hg.repo.HgLookup;
27 import org.tmatesoft.hg.repo.HgRemoteRepository; 26 import org.tmatesoft.hg.repo.HgRemoteRepository;
28 import org.tmatesoft.hg.repo.HgRepository;
29 27
30 28
31 /** 29 /**
32 * WORK IN PROGRESS, DO NOT USE 30 * <em>hg outgoing</em>
33 * hg outgoing
34 * 31 *
35 * @author Artem Tikhomirov 32 * @author Artem Tikhomirov
36 * @author TMate Software Ltd. 33 * @author TMate Software Ltd.
37 */ 34 */
38 public class Outgoing { 35 public class Outgoing {
39 36
40 public static void main(String[] args) throws Exception { 37 public static void main(String[] args) throws Exception {
41 final boolean debug = true; // perhaps, use hg4j.remote.debug or own property?
42 Options cmdLineOpts = Options.parse(args); 38 Options cmdLineOpts = Options.parse(args);
43 HgRepository hgRepo = cmdLineOpts.findRepository(); 39 HgRepoFacade hgRepo = new HgRepoFacade();
44 if (hgRepo.isInvalid()) { 40 if (!hgRepo.init(cmdLineOpts.findRepository())) {
45 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); 41 System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation());
46 return; 42 return;
47 } 43 }
48 HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo); 44 // XXX perhaps, HgRepoFacade shall get detectRemote() analog (to get remote server with respect of facade's repo)
45 HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo.getRepository());
49 if (hgRemote.isInvalid()) { 46 if (hgRemote.isInvalid()) {
50 System.err.printf("Remote repository %s is not valid", hgRemote.getLocation()); 47 System.err.printf("Remote repository %s is not valid", hgRemote.getLocation());
51 return; 48 return;
52 } 49 }
53 50 //
54 HgChangelog changelog = hgRepo.getChangelog(); 51 HgOutgoingCommand cmd = hgRepo.createOutgoingCommand();
55 HgChangelog.ParentWalker pw = changelog.new ParentWalker(); 52 cmd.against(hgRemote);
56 pw.init();
57 53
58 RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote);
59 repoCompare.compare(null);
60 if (debug) {
61 List<Nodeid> commonKnown = repoCompare.getCommon();
62 dump("Nodes known to be both locally and at remote server", commonKnown);
63 }
64 // find all local children of commonKnown 54 // find all local children of commonKnown
65 List<Nodeid> result = repoCompare.getLocalOnlyRevisions(); 55 List<Nodeid> result = cmd.executeLite(null);
66 dump("Lite", result); 56 dump("Lite", result);
67 // 57 //
68 // 58 //
69 System.out.println("Full"); 59 System.out.println("Full");
70 // show all, starting from next to common 60 // show all, starting from next to common
71 repoCompare.visitLocalOnlyRevisions(new HgChangelog.Inspector() { 61 final ChangesetDumpHandler h = new ChangesetDumpHandler(hgRepo.getRepository());
72 private final ChangesetFormatter formatter = new ChangesetFormatter(); 62 h.complete(cmdLineOpts.getBoolean("--debug")).verbose(cmdLineOpts.getBoolean("-v", "--verbose"));
73 63 cmd.executeFull(h);
74 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 64 h.done();
75 System.out.println(formatter.simple(revisionNumber, nodeid, cset));
76 }
77 });
78 } 65 }
79 66
80 public static class ChangesetFormatter { 67 // public static class ChangesetFormatter {
81 private final StringBuilder sb = new StringBuilder(1024); 68 // private final StringBuilder sb = new StringBuilder(1024);
82 69 //
83 public CharSequence simple(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 70 // public CharSequence simple(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
84 sb.setLength(0); 71 // sb.setLength(0);
85 sb.append(String.format("changeset: %d:%s\n", revisionNumber, nodeid.toString())); 72 // sb.append(String.format("changeset: %d:%s\n", revisionNumber, nodeid.toString()));
86 sb.append(String.format("user: %s\n", cset.user())); 73 // sb.append(String.format("user: %s\n", cset.user()));
87 sb.append(String.format("date: %s\n", cset.dateString())); 74 // sb.append(String.format("date: %s\n", cset.dateString()));
88 sb.append(String.format("comment: %s\n\n", cset.comment())); 75 // sb.append(String.format("comment: %s\n\n", cset.comment()));
89 return sb; 76 // return sb;
90 } 77 // }
91 } 78 // }
92 79
93 80
94 private static void dump(String s, Collection<Nodeid> c) { 81 static void dump(String s, Collection<Nodeid> c) {
95 System.out.println(s); 82 System.out.println(s);
96 for (Nodeid n : c) { 83 for (Nodeid n : c) {
97 System.out.println(n); 84 System.out.println(n);
98 } 85 }
99 } 86 }