tikhomirov@30: /* tikhomirov@74: * Copyright (c) 2011 TMate Software Ltd tikhomirov@74: * tikhomirov@74: * This program is free software; you can redistribute it and/or modify tikhomirov@74: * it under the terms of the GNU General Public License as published by tikhomirov@74: * the Free Software Foundation; version 2 of the License. tikhomirov@74: * tikhomirov@74: * This program is distributed in the hope that it will be useful, tikhomirov@74: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@74: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@74: * GNU General Public License for more details. tikhomirov@74: * tikhomirov@74: * For information on how to redistribute this software under tikhomirov@74: * the terms of a license other than GNU General Public License tikhomirov@74: * contact TMate Software at support@svnkit.com tikhomirov@30: */ tikhomirov@74: package org.tmatesoft.hg.console; tikhomirov@30: tikhomirov@30: import java.util.Collection; tikhomirov@30: import java.util.LinkedHashSet; tikhomirov@30: import java.util.LinkedList; tikhomirov@30: import java.util.List; tikhomirov@30: tikhomirov@74: import org.tmatesoft.hg.core.Nodeid; tikhomirov@97: import org.tmatesoft.hg.repo.HgChangelog; tikhomirov@74: import org.tmatesoft.hg.repo.HgRepository; tikhomirov@74: tikhomirov@30: tikhomirov@30: /** tikhomirov@74: * WORK IN PROGRESS, DO NOT USE tikhomirov@30: * hg out tikhomirov@74: * tikhomirov@74: * @author Artem Tikhomirov tikhomirov@74: * @author TMate Software Ltd. tikhomirov@30: */ tikhomirov@30: public class Outgoing { tikhomirov@30: tikhomirov@30: public static void main(String[] args) throws Exception { tikhomirov@74: Options cmdLineOpts = Options.parse(args); tikhomirov@74: HgRepository hgRepo = cmdLineOpts.findRepository(); tikhomirov@30: if (hgRepo.isInvalid()) { tikhomirov@30: System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); tikhomirov@30: return; tikhomirov@30: } tikhomirov@30: // FIXME detection of tikhomirov@30: List base = new LinkedList(); tikhomirov@30: base.add(Nodeid.fromAscii("d6d2a630f4a6d670c90a5ca909150f2b426ec88f".getBytes(), 0, 40)); tikhomirov@30: // tikhomirov@30: // fill with all known tikhomirov@74: Changelog.ParentWalker pw = hgRepo.getChangelog().new ParentWalker(); tikhomirov@30: pw.init(); tikhomirov@30: LinkedHashSet sendToRemote = new LinkedHashSet(pw.allNodes()); tikhomirov@30: dump("initial state", sendToRemote); tikhomirov@30: // remove base and its parents tikhomirov@30: LinkedList queueToClean = new LinkedList(base); tikhomirov@30: while (!queueToClean.isEmpty()) { tikhomirov@30: Nodeid nid = queueToClean.removeFirst(); tikhomirov@30: if (sendToRemote.remove(nid)) { tikhomirov@30: pw.appendParentsOf(nid, queueToClean); tikhomirov@30: } tikhomirov@30: } tikhomirov@30: dump("Clean from known parents", sendToRemote); tikhomirov@30: // XXX I think sendToRemote is what we actually need here - everything local, missing from remote tikhomirov@30: // however, if we need to send only a subset of these, need to proceed. tikhomirov@30: LinkedList result = new LinkedList(); tikhomirov@30: // find among left those without parents tikhomirov@30: for (Nodeid nid : sendToRemote) { tikhomirov@30: Nodeid p1 = pw.firstParent(nid); tikhomirov@30: // in fact, we may assume nulls are never part of sendToRemote tikhomirov@30: if (p1 != null && !sendToRemote.contains(p1)) { tikhomirov@30: Nodeid p2 = pw.secondParent(nid); tikhomirov@30: if (p2 == null || !sendToRemote.contains(p2)) { tikhomirov@30: result.add(nid); tikhomirov@30: } tikhomirov@30: } tikhomirov@30: } tikhomirov@30: dump("Result", result); tikhomirov@30: // final outcome is the collection of nodes between(lastresult and revision/tip) tikhomirov@30: // tikhomirov@30: System.out.println("TODO: nodes between result and tip"); tikhomirov@30: } tikhomirov@30: tikhomirov@30: private static void dump(String s, Collection c) { tikhomirov@30: System.out.println(s); tikhomirov@30: for (Nodeid n : c) { tikhomirov@30: System.out.println(n); tikhomirov@30: } tikhomirov@30: } tikhomirov@30: }