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@102:  * contact TMate Software at support@hg4j.com
tikhomirov@30:  */
tikhomirov@74: package org.tmatesoft.hg.console;
tikhomirov@30: 
tikhomirov@30: import java.util.Collection;
tikhomirov@30: import java.util.List;
tikhomirov@30: 
tikhomirov@171: import org.tmatesoft.hg.core.HgException;
tikhomirov@74: import org.tmatesoft.hg.core.Nodeid;
tikhomirov@181: import org.tmatesoft.hg.internal.RepositoryComparator;
tikhomirov@97: import org.tmatesoft.hg.repo.HgChangelog;
tikhomirov@171: import org.tmatesoft.hg.repo.HgLookup;
tikhomirov@171: import org.tmatesoft.hg.repo.HgRemoteRepository;
tikhomirov@74: import org.tmatesoft.hg.repo.HgRepository;
tikhomirov@74: 
tikhomirov@30: 
tikhomirov@30: /**
tikhomirov@74:  * WORK IN PROGRESS, DO NOT USE
tikhomirov@171:  * hg outgoing
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@181: 		HgRemoteRepository hgRemote = new HgLookup().detectRemote("hg4j-gc", hgRepo);
tikhomirov@181: 		if (hgRemote.isInvalid()) {
tikhomirov@181: 			System.err.printf("Remote repository %s is not valid", hgRemote.getLocation());
tikhomirov@181: 			return;
tikhomirov@172: 		}
tikhomirov@171: 
tikhomirov@98: 		HgChangelog.ParentWalker pw = hgRepo.getChangelog().new ParentWalker();
tikhomirov@30: 		pw.init();
tikhomirov@171: 		
tikhomirov@181: 		RepositoryComparator repoCompare = new RepositoryComparator(pw, hgRemote);
tikhomirov@181: 		repoCompare.compare(null);
tikhomirov@181: 		List<Nodeid> commonKnown = repoCompare.getCommon();
tikhomirov@171: 		dump("Nodes known to be both locally and at remote server", commonKnown);
tikhomirov@171: 		// sanity check
tikhomirov@171: 		for (Nodeid n : commonKnown) {
tikhomirov@171: 			if (!pw.knownNode(n)) {
tikhomirov@171: 				throw new HgException("Unknown node reported as common:" + n);
tikhomirov@30: 			}
tikhomirov@30: 		}
tikhomirov@171: 		// find all local children of commonKnown
tikhomirov@171: 		List<Nodeid> result = pw.childrenOf(commonKnown);
tikhomirov@171: 		dump("Result", result);
tikhomirov@171: 	}
tikhomirov@171: 	
tikhomirov@30: 
tikhomirov@30: 	private static void dump(String s, Collection<Nodeid> 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: }