comparison src/com/tmate/hgkit/console/Outgoing.java @ 30:de7217a0aa4d

Look up changes in the local repo that are not in the remote
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 11 Jan 2011 04:49:06 +0100
parents
children
comparison
equal deleted inserted replaced
29:6cce719bbb62 30:de7217a0aa4d
1 /*
2 * Copyright (c) 2011 Artem Tikhomirov
3 */
4 package com.tmate.hgkit.console;
5
6 import java.util.Collection;
7 import java.util.LinkedHashSet;
8 import java.util.LinkedList;
9 import java.util.List;
10
11 import com.tmate.hgkit.fs.RepositoryLookup;
12 import com.tmate.hgkit.ll.HgRepository;
13 import com.tmate.hgkit.ll.Nodeid;
14 import com.tmate.hgkit.ll.Revlog;
15
16 /**
17 * hg out
18 * @author artem
19 */
20 public class Outgoing {
21
22 public static void main(String[] args) throws Exception {
23 RepositoryLookup repoLookup = new RepositoryLookup();
24 RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args);
25 HgRepository hgRepo = repoLookup.detect(cmdLineOpts);
26 if (hgRepo.isInvalid()) {
27 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation());
28 return;
29 }
30 // FIXME detection of
31 List<Nodeid> base = new LinkedList<Nodeid>();
32 base.add(Nodeid.fromAscii("d6d2a630f4a6d670c90a5ca909150f2b426ec88f".getBytes(), 0, 40));
33 //
34 // fill with all known
35 Revlog.ParentWalker pw = hgRepo.getChangelog().new ParentWalker();
36 pw.init();
37 LinkedHashSet<Nodeid> sendToRemote = new LinkedHashSet<Nodeid>(pw.allNodes());
38 dump("initial state", sendToRemote);
39 // remove base and its parents
40 LinkedList<Nodeid> queueToClean = new LinkedList<Nodeid>(base);
41 while (!queueToClean.isEmpty()) {
42 Nodeid nid = queueToClean.removeFirst();
43 if (sendToRemote.remove(nid)) {
44 pw.appendParentsOf(nid, queueToClean);
45 }
46 }
47 dump("Clean from known parents", sendToRemote);
48 // XXX I think sendToRemote is what we actually need here - everything local, missing from remote
49 // however, if we need to send only a subset of these, need to proceed.
50 LinkedList<Nodeid> result = new LinkedList<Nodeid>();
51 // find among left those without parents
52 for (Nodeid nid : sendToRemote) {
53 Nodeid p1 = pw.firstParent(nid);
54 // in fact, we may assume nulls are never part of sendToRemote
55 if (p1 != null && !sendToRemote.contains(p1)) {
56 Nodeid p2 = pw.secondParent(nid);
57 if (p2 == null || !sendToRemote.contains(p2)) {
58 result.add(nid);
59 }
60 }
61 }
62 dump("Result", result);
63 // final outcome is the collection of nodes between(lastresult and revision/tip)
64 //
65 System.out.println("TODO: nodes between result and tip");
66 }
67
68 private static void dump(String s, Collection<Nodeid> c) {
69 System.out.println(s);
70 for (Nodeid n : c) {
71 System.out.println(n);
72 }
73 }
74 }