comparison cmdline/org/tmatesoft/hg/console/Outgoing.java @ 185:c6fa4dbfc458

Complete Outgoing cmdline, with both lite (revisions) and complete (changeset) information dump
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 13 Apr 2011 19:55:59 +0200
parents cd3371670f0b
children e5407b5a586a
comparison
equal deleted inserted replaced
184:ec1820f64d2b 185:c6fa4dbfc458
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;
20 import java.util.List; 21 import java.util.List;
21 22
23 import org.tmatesoft.hg.core.HgBadStateException;
22 import org.tmatesoft.hg.core.HgException; 24 import org.tmatesoft.hg.core.HgException;
23 import org.tmatesoft.hg.core.Nodeid; 25 import org.tmatesoft.hg.core.Nodeid;
24 import org.tmatesoft.hg.internal.RepositoryComparator; 26 import org.tmatesoft.hg.internal.RepositoryComparator;
25 import org.tmatesoft.hg.repo.HgChangelog; 27 import org.tmatesoft.hg.repo.HgChangelog;
26 import org.tmatesoft.hg.repo.HgLookup; 28 import org.tmatesoft.hg.repo.HgLookup;
27 import org.tmatesoft.hg.repo.HgRemoteRepository; 29 import org.tmatesoft.hg.repo.HgRemoteRepository;
28 import org.tmatesoft.hg.repo.HgRepository; 30 import org.tmatesoft.hg.repo.HgRepository;
31 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
29 32
30 33
31 /** 34 /**
32 * WORK IN PROGRESS, DO NOT USE 35 * WORK IN PROGRESS, DO NOT USE
33 * hg outgoing 36 * hg outgoing
42 HgRepository hgRepo = cmdLineOpts.findRepository(); 45 HgRepository hgRepo = cmdLineOpts.findRepository();
43 if (hgRepo.isInvalid()) { 46 if (hgRepo.isInvalid()) {
44 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); 47 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation());
45 return; 48 return;
46 } 49 }
47 HgRemoteRepository hgRemote = new HgLookup().detectRemote("hg4j-gc", hgRepo); 50 HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo);
48 if (hgRemote.isInvalid()) { 51 if (hgRemote.isInvalid()) {
49 System.err.printf("Remote repository %s is not valid", hgRemote.getLocation()); 52 System.err.printf("Remote repository %s is not valid", hgRemote.getLocation());
50 return; 53 return;
51 } 54 }
52 55
53 HgChangelog.ParentWalker pw = hgRepo.getChangelog().new ParentWalker(); 56 HgChangelog changelog = hgRepo.getChangelog();
57 HgChangelog.ParentWalker pw = changelog.new ParentWalker();
54 pw.init(); 58 pw.init();
55 59
56 RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote); 60 RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote);
57 repoCompare.compare(null); 61 repoCompare.compare(null);
58 List<Nodeid> commonKnown = repoCompare.getCommon(); 62 List<Nodeid> commonKnown = repoCompare.getCommon();
63 throw new HgException("Unknown node reported as common:" + n); 67 throw new HgException("Unknown node reported as common:" + n);
64 } 68 }
65 } 69 }
66 // find all local children of commonKnown 70 // find all local children of commonKnown
67 List<Nodeid> result = pw.childrenOf(commonKnown); 71 List<Nodeid> result = pw.childrenOf(commonKnown);
68 dump("Result", result); 72 dump("Lite", result);
73 // another approach to get all changes after common:
74 // find index of earliest revision, and report all that were later
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");
91 // show all, starting from next to common
92 changelog.range(earliestRevision+1, changelog.getLastRevision(), new HgChangelog.Inspector() {
93
94 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
95 System.out.printf("changeset: %d:%s\n", revisionNumber, nodeid.toString());
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 }
100 });
69 } 101 }
70 102
71 103
72 private static void dump(String s, Collection<Nodeid> c) { 104 private static void dump(String s, Collection<Nodeid> c) {
73 System.out.println(s); 105 System.out.println(s);