comparison cmdline/org/tmatesoft/hg/console/Outgoing.java @ 192:e5407b5a586a

Incoming and Outgoing commands are alive
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 15 Apr 2011 03:17:03 +0200
parents c6fa4dbfc458
children 63c9fed4369e
comparison
equal deleted inserted replaced
191:b777502a06f5 192:e5407b5a586a
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
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.Collections;
21 import java.util.List; 20 import java.util.List;
22 21
23 import org.tmatesoft.hg.core.HgBadStateException;
24 import org.tmatesoft.hg.core.HgException;
25 import org.tmatesoft.hg.core.Nodeid; 22 import org.tmatesoft.hg.core.Nodeid;
26 import org.tmatesoft.hg.internal.RepositoryComparator; 23 import org.tmatesoft.hg.internal.RepositoryComparator;
27 import org.tmatesoft.hg.repo.HgChangelog; 24 import org.tmatesoft.hg.repo.HgChangelog;
25 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
28 import org.tmatesoft.hg.repo.HgLookup; 26 import org.tmatesoft.hg.repo.HgLookup;
29 import org.tmatesoft.hg.repo.HgRemoteRepository; 27 import org.tmatesoft.hg.repo.HgRemoteRepository;
30 import org.tmatesoft.hg.repo.HgRepository; 28 import org.tmatesoft.hg.repo.HgRepository;
31 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
32 29
33 30
34 /** 31 /**
35 * WORK IN PROGRESS, DO NOT USE 32 * WORK IN PROGRESS, DO NOT USE
36 * hg outgoing 33 * hg outgoing
39 * @author TMate Software Ltd. 36 * @author TMate Software Ltd.
40 */ 37 */
41 public class Outgoing { 38 public class Outgoing {
42 39
43 public static void main(String[] args) throws Exception { 40 public static void main(String[] args) throws Exception {
41 final boolean debug = true; // perhaps, use hg4j.remote.debug or own property?
44 Options cmdLineOpts = Options.parse(args); 42 Options cmdLineOpts = Options.parse(args);
45 HgRepository hgRepo = cmdLineOpts.findRepository(); 43 HgRepository hgRepo = cmdLineOpts.findRepository();
46 if (hgRepo.isInvalid()) { 44 if (hgRepo.isInvalid()) {
47 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); 45 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation());
48 return; 46 return;
57 HgChangelog.ParentWalker pw = changelog.new ParentWalker(); 55 HgChangelog.ParentWalker pw = changelog.new ParentWalker();
58 pw.init(); 56 pw.init();
59 57
60 RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote); 58 RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote);
61 repoCompare.compare(null); 59 repoCompare.compare(null);
62 List<Nodeid> commonKnown = repoCompare.getCommon(); 60 if (debug) {
63 dump("Nodes known to be both locally and at remote server", commonKnown); 61 List<Nodeid> commonKnown = repoCompare.getCommon();
64 // sanity check 62 dump("Nodes known to be both locally and at remote server", commonKnown);
65 for (Nodeid n : commonKnown) {
66 if (!pw.knownNode(n)) {
67 throw new HgException("Unknown node reported as common:" + n);
68 }
69 } 63 }
70 // find all local children of commonKnown 64 // find all local children of commonKnown
71 List<Nodeid> result = pw.childrenOf(commonKnown); 65 List<Nodeid> result = repoCompare.getLocalOnlyRevisions();
72 dump("Lite", result); 66 dump("Lite", result);
73 // another approach to get all changes after common: 67 //
74 // find index of earliest revision, and report all that were later 68 //
75 int earliestRevision = Integer.MAX_VALUE;
76 for (Nodeid n : commonKnown) {
77 if (pw.childrenOf(Collections.singletonList(n)).isEmpty()) {
78 // there might be (old) nodes, known both locally and remotely, with no children
79 // hence, we don't need to consider their local revision number
80 continue;
81 }
82 int lr = changelog.getLocalRevision(n);
83 if (lr < earliestRevision) {
84 earliestRevision = lr;
85 }
86 }
87 if (earliestRevision < 0 || earliestRevision >= changelog.getLastRevision()) {
88 throw new HgBadStateException(String.format("Invalid index of common known revision: %d in total of %d", earliestRevision, 1+changelog.getLastRevision()));
89 }
90 System.out.println("Full"); 69 System.out.println("Full");
91 // show all, starting from next to common 70 // show all, starting from next to common
92 changelog.range(earliestRevision+1, changelog.getLastRevision(), new HgChangelog.Inspector() { 71 repoCompare.visitLocalOnlyRevisions(new HgChangelog.Inspector() {
72 private final ChangesetFormatter formatter = new ChangesetFormatter();
93 73
94 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 74 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
95 System.out.printf("changeset: %d:%s\n", revisionNumber, nodeid.toString()); 75 System.out.println(formatter.simple(revisionNumber, nodeid, cset));
96 System.out.printf("user: %s\n", cset.user());
97 System.out.printf("date: %s\n", cset.dateString());
98 System.out.printf("comment: %s\n\n", cset.comment());
99 } 76 }
100 }); 77 });
78 }
79
80 public static class ChangesetFormatter {
81 private final StringBuilder sb = new StringBuilder(1024);
82
83 public CharSequence simple(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
84 sb.setLength(0);
85 sb.append(String.format("changeset: %d:%s\n", revisionNumber, nodeid.toString()));
86 sb.append(String.format("user: %s\n", cset.user()));
87 sb.append(String.format("date: %s\n", cset.dateString()));
88 sb.append(String.format("comment: %s\n\n", cset.comment()));
89 return sb;
90 }
101 } 91 }
102 92
103 93
104 private static void dump(String s, Collection<Nodeid> c) { 94 private static void dump(String s, Collection<Nodeid> c) {
105 System.out.println(s); 95 System.out.println(s);