Mercurial > jhg
comparison cmdline/org/tmatesoft/hg/console/Incoming.java @ 184:ec1820f64d2b
Complete incoming cmdline client, with both lite (revisions) and complete (full changeset) information dump
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Wed, 13 Apr 2011 19:09:10 +0200 |
| parents | f26ffe04ced0 |
| children | 44a34baabea0 |
comparison
equal
deleted
inserted
replaced
| 183:9807bf8f3a9c | 184:ec1820f64d2b |
|---|---|
| 21 import java.util.Collections; | 21 import java.util.Collections; |
| 22 import java.util.Comparator; | 22 import java.util.Comparator; |
| 23 import java.util.HashSet; | 23 import java.util.HashSet; |
| 24 import java.util.Iterator; | 24 import java.util.Iterator; |
| 25 import java.util.LinkedHashMap; | 25 import java.util.LinkedHashMap; |
| 26 import java.util.LinkedHashSet; | |
| 26 import java.util.LinkedList; | 27 import java.util.LinkedList; |
| 27 import java.util.List; | 28 import java.util.List; |
| 28 import java.util.ListIterator; | 29 import java.util.ListIterator; |
| 29 import java.util.Map.Entry; | 30 import java.util.Map.Entry; |
| 30 | 31 |
| 32 import org.tmatesoft.hg.core.HgBadStateException; | |
| 31 import org.tmatesoft.hg.core.HgException; | 33 import org.tmatesoft.hg.core.HgException; |
| 32 import org.tmatesoft.hg.core.Nodeid; | 34 import org.tmatesoft.hg.core.Nodeid; |
| 33 import org.tmatesoft.hg.internal.RepositoryComparator; | 35 import org.tmatesoft.hg.internal.RepositoryComparator; |
| 34 import org.tmatesoft.hg.internal.RepositoryComparator.BranchChain; | 36 import org.tmatesoft.hg.internal.RepositoryComparator.BranchChain; |
| 37 import org.tmatesoft.hg.repo.HgBundle; | |
| 35 import org.tmatesoft.hg.repo.HgChangelog; | 38 import org.tmatesoft.hg.repo.HgChangelog; |
| 36 import org.tmatesoft.hg.repo.HgLookup; | 39 import org.tmatesoft.hg.repo.HgLookup; |
| 37 import org.tmatesoft.hg.repo.HgRemoteRepository; | 40 import org.tmatesoft.hg.repo.HgRemoteRepository; |
| 38 import org.tmatesoft.hg.repo.HgRepository; | 41 import org.tmatesoft.hg.repo.HgRepository; |
| 42 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | |
| 39 | 43 |
| 40 | 44 |
| 41 /** | 45 /** |
| 42 * WORK IN PROGRESS, DO NOT USE | 46 * WORK IN PROGRESS, DO NOT USE |
| 43 * hg incoming counterpart | 47 * hg incoming counterpart |
| 51 if (Boolean.FALSE.booleanValue()) { | 55 if (Boolean.FALSE.booleanValue()) { |
| 52 new SequenceConstructor().test(); | 56 new SequenceConstructor().test(); |
| 53 return; | 57 return; |
| 54 } | 58 } |
| 55 Options cmdLineOpts = Options.parse(args); | 59 Options cmdLineOpts = Options.parse(args); |
| 56 HgRepository hgRepo = cmdLineOpts.findRepository(); | 60 final HgRepository hgRepo = cmdLineOpts.findRepository(); |
| 57 if (hgRepo.isInvalid()) { | 61 if (hgRepo.isInvalid()) { |
| 58 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); | 62 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
| 59 return; | 63 return; |
| 60 } | 64 } |
| 61 HgRemoteRepository hgRemote = new HgLookup().detectRemote("svnkit", hgRepo); | 65 HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo); |
| 62 if (hgRemote.isInvalid()) { | 66 if (hgRemote.isInvalid()) { |
| 63 System.err.printf("Remote repository %s is not valid", hgRemote.getLocation()); | 67 System.err.printf("Remote repository %s is not valid", hgRemote.getLocation()); |
| 64 return; | 68 return; |
| 65 } | 69 } |
| 66 // | 70 // |
| 70 pw.init(); | 74 pw.init(); |
| 71 // | 75 // |
| 72 RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote); | 76 RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote); |
| 73 repoCompare.compare(null); | 77 repoCompare.compare(null); |
| 74 List<BranchChain> missingBranches0 = repoCompare.calculateMissingBranches(); | 78 List<BranchChain> missingBranches0 = repoCompare.calculateMissingBranches(); |
| 79 final LinkedHashSet<Nodeid> common = new LinkedHashSet<Nodeid>(); | |
| 80 // XXX common can be obtained from repoCompare, but at the moment it would almost duplicate work of calculateMissingBranches | |
| 81 // once I refactor latter, common shall be taken from repoCompare. | |
| 75 for (BranchChain bc : missingBranches0) { | 82 for (BranchChain bc : missingBranches0) { |
| 76 bc.dump(); | 83 bc.dump(); |
| 77 | 84 common.add(bc.branchRoot); // common known node |
| 78 List<Nodeid> missing = visitBranches(repoCompare, bc); | 85 List<Nodeid> missing = visitBranches(repoCompare, bc); |
| 79 // Collections.reverse(missing); // useful to test output, from newer to older | 86 assert bc.branchRoot.equals(missing.get(0)); |
| 87 missing.remove(0); | |
| 88 Collections.reverse(missing); // useful to test output, from newer to older | |
| 89 System.out.println("Nodes to fetch in this branch:"); | |
| 80 for (Nodeid n : missing) { | 90 for (Nodeid n : missing) { |
| 81 if (pw.knownNode(n)) { | 91 if (pw.knownNode(n)) { |
| 82 System.out.println("Erroneous to fetch:" + n); | 92 System.out.println("Erroneous to fetch:" + n); |
| 83 } else { | 93 } else { |
| 84 System.out.println(n); | 94 System.out.println(n); |
| 85 } | 95 } |
| 86 } | 96 } |
| 87 System.out.println("Branch done"); | 97 System.out.println("Branch done"); |
| 88 } | 98 } |
| 89 | 99 // |
| 100 // Complete | |
| 101 HgBundle changegroup = hgRemote.getChanges(new LinkedList<Nodeid>(common)); | |
| 102 changegroup.changes(hgRepo, new HgChangelog.Inspector() { | |
| 103 private int localIndex; | |
| 104 | |
| 105 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { | |
| 106 if (pw.knownNode(nodeid)) { | |
| 107 if (!common.contains(nodeid)) { | |
| 108 throw new HgBadStateException("Bundle shall not report known nodes other than roots we've supplied"); | |
| 109 } | |
| 110 localIndex = hgRepo.getChangelog().getLocalRevision(nodeid); | |
| 111 return; | |
| 112 } | |
| 113 System.out.printf("changeset: %d:%s\n", ++localIndex, nodeid.toString()); | |
| 114 System.out.printf("user: %s\n", cset.user()); | |
| 115 System.out.printf("date: %s\n", cset.dateString()); | |
| 116 System.out.printf("comment: %s\n\n", cset.comment()); | |
| 117 | |
| 118 } | |
| 119 }); | |
| 90 } | 120 } |
| 91 | 121 |
| 92 | 122 // returns in order from branch root to head |
| 123 // for a non-empty BranchChain, shall return modifiable list | |
| 93 private static List<Nodeid> visitBranches(RepositoryComparator repoCompare, BranchChain bc) throws HgException { | 124 private static List<Nodeid> visitBranches(RepositoryComparator repoCompare, BranchChain bc) throws HgException { |
| 94 if (bc == null) { | 125 if (bc == null) { |
| 95 return Collections.emptyList(); | 126 return Collections.emptyList(); |
| 96 } | 127 } |
| 97 List<Nodeid> mine = repoCompare.completeBranch(bc.branchRoot, bc.branchHead); | 128 List<Nodeid> mine = repoCompare.completeBranch(bc.branchRoot, bc.branchHead); |
