Mercurial > jhg
comparison cmdline/org/tmatesoft/hg/console/Outgoing.java @ 74:6f1b88693d48
Complete refactoring to org.tmatesoft
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 24 Jan 2011 03:14:45 +0100 |
parents | src/com/tmate/hgkit/console/Outgoing.java@de7217a0aa4d |
children | ee2c750b036d |
comparison
equal
deleted
inserted
replaced
73:0d279bcc4442 | 74:6f1b88693d48 |
---|---|
1 /* | |
2 * Copyright (c) 2011 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@svnkit.com | |
16 */ | |
17 package org.tmatesoft.hg.console; | |
18 | |
19 import java.util.Collection; | |
20 import java.util.LinkedHashSet; | |
21 import java.util.LinkedList; | |
22 import java.util.List; | |
23 | |
24 import org.tmatesoft.hg.core.Nodeid; | |
25 import org.tmatesoft.hg.repo.Changelog; | |
26 import org.tmatesoft.hg.repo.HgRepository; | |
27 | |
28 | |
29 /** | |
30 * WORK IN PROGRESS, DO NOT USE | |
31 * hg out | |
32 * | |
33 * @author Artem Tikhomirov | |
34 * @author TMate Software Ltd. | |
35 */ | |
36 public class Outgoing { | |
37 | |
38 public static void main(String[] args) throws Exception { | |
39 Options cmdLineOpts = Options.parse(args); | |
40 HgRepository hgRepo = cmdLineOpts.findRepository(); | |
41 if (hgRepo.isInvalid()) { | |
42 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); | |
43 return; | |
44 } | |
45 // FIXME detection of | |
46 List<Nodeid> base = new LinkedList<Nodeid>(); | |
47 base.add(Nodeid.fromAscii("d6d2a630f4a6d670c90a5ca909150f2b426ec88f".getBytes(), 0, 40)); | |
48 // | |
49 // fill with all known | |
50 Changelog.ParentWalker pw = hgRepo.getChangelog().new ParentWalker(); | |
51 pw.init(); | |
52 LinkedHashSet<Nodeid> sendToRemote = new LinkedHashSet<Nodeid>(pw.allNodes()); | |
53 dump("initial state", sendToRemote); | |
54 // remove base and its parents | |
55 LinkedList<Nodeid> queueToClean = new LinkedList<Nodeid>(base); | |
56 while (!queueToClean.isEmpty()) { | |
57 Nodeid nid = queueToClean.removeFirst(); | |
58 if (sendToRemote.remove(nid)) { | |
59 pw.appendParentsOf(nid, queueToClean); | |
60 } | |
61 } | |
62 dump("Clean from known parents", sendToRemote); | |
63 // XXX I think sendToRemote is what we actually need here - everything local, missing from remote | |
64 // however, if we need to send only a subset of these, need to proceed. | |
65 LinkedList<Nodeid> result = new LinkedList<Nodeid>(); | |
66 // find among left those without parents | |
67 for (Nodeid nid : sendToRemote) { | |
68 Nodeid p1 = pw.firstParent(nid); | |
69 // in fact, we may assume nulls are never part of sendToRemote | |
70 if (p1 != null && !sendToRemote.contains(p1)) { | |
71 Nodeid p2 = pw.secondParent(nid); | |
72 if (p2 == null || !sendToRemote.contains(p2)) { | |
73 result.add(nid); | |
74 } | |
75 } | |
76 } | |
77 dump("Result", result); | |
78 // final outcome is the collection of nodes between(lastresult and revision/tip) | |
79 // | |
80 System.out.println("TODO: nodes between result and tip"); | |
81 } | |
82 | |
83 private static void dump(String s, Collection<Nodeid> c) { | |
84 System.out.println(s); | |
85 for (Nodeid n : c) { | |
86 System.out.println(n); | |
87 } | |
88 } | |
89 } |