kitaev@213: /* kitaev@213: * Copyright (c) 2011 TMate Software Ltd kitaev@213: * kitaev@213: * This program is free software; you can redistribute it and/or modify kitaev@213: * it under the terms of the GNU General Public License as published by kitaev@213: * the Free Software Foundation; version 2 of the License. kitaev@213: * kitaev@213: * This program is distributed in the hope that it will be useful, kitaev@213: * but WITHOUT ANY WARRANTY; without even the implied warranty of kitaev@213: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the kitaev@213: * GNU General Public License for more details. kitaev@213: * kitaev@213: * For information on how to redistribute this software under kitaev@213: * the terms of a license other than GNU General Public License kitaev@213: * contact TMate Software at support@hg4j.com kitaev@213: */ kitaev@213: package org.tmatesoft.hg.console; kitaev@213: kitaev@213: import java.util.Collection; kitaev@213: import java.util.List; kitaev@213: kitaev@213: import org.tmatesoft.hg.core.HgOutgoingCommand; kitaev@213: import org.tmatesoft.hg.core.HgRepoFacade; kitaev@213: import org.tmatesoft.hg.core.Nodeid; kitaev@213: import org.tmatesoft.hg.repo.HgLookup; kitaev@213: import org.tmatesoft.hg.repo.HgRemoteRepository; kitaev@213: kitaev@213: kitaev@213: /** kitaev@213: * hg outgoing kitaev@213: * kitaev@213: * @author Artem Tikhomirov kitaev@213: * @author TMate Software Ltd. kitaev@213: */ kitaev@213: public class Outgoing { kitaev@213: kitaev@213: public static void main(String[] args) throws Exception { kitaev@213: Options cmdLineOpts = Options.parse(args); kitaev@213: HgRepoFacade hgRepo = new HgRepoFacade(); kitaev@213: if (!hgRepo.init(cmdLineOpts.findRepository())) { kitaev@213: System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation()); kitaev@213: return; kitaev@213: } kitaev@213: // XXX perhaps, HgRepoFacade shall get detectRemote() analog (to get remote server with respect of facade's repo) kitaev@213: HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo.getRepository()); kitaev@213: if (hgRemote.isInvalid()) { kitaev@213: System.err.printf("Remote repository %s is not valid", hgRemote.getLocation()); kitaev@213: return; kitaev@213: } kitaev@213: // kitaev@213: HgOutgoingCommand cmd = hgRepo.createOutgoingCommand(); kitaev@213: cmd.against(hgRemote); kitaev@213: kitaev@213: // find all local children of commonKnown kitaev@213: List result = cmd.executeLite(null); kitaev@213: dump("Lite", result); kitaev@213: // kitaev@213: // kitaev@213: System.out.println("Full"); kitaev@213: // show all, starting from next to common kitaev@213: final ChangesetDumpHandler h = new ChangesetDumpHandler(hgRepo.getRepository()); kitaev@213: h.complete(cmdLineOpts.getBoolean("--debug")).verbose(cmdLineOpts.getBoolean("-v", "--verbose")); kitaev@213: cmd.executeFull(h); kitaev@213: h.done(); kitaev@213: } kitaev@213: kitaev@213: // public static class ChangesetFormatter { kitaev@213: // private final StringBuilder sb = new StringBuilder(1024); kitaev@213: // kitaev@213: // public CharSequence simple(int revisionNumber, Nodeid nodeid, RawChangeset cset) { kitaev@213: // sb.setLength(0); kitaev@213: // sb.append(String.format("changeset: %d:%s\n", revisionNumber, nodeid.toString())); kitaev@213: // sb.append(String.format("user: %s\n", cset.user())); kitaev@213: // sb.append(String.format("date: %s\n", cset.dateString())); kitaev@213: // sb.append(String.format("comment: %s\n\n", cset.comment())); kitaev@213: // return sb; kitaev@213: // } kitaev@213: // } kitaev@213: kitaev@213: kitaev@213: static void dump(String s, Collection c) { kitaev@213: System.out.println(s); kitaev@213: for (Nodeid n : c) { kitaev@213: System.out.println(n); kitaev@213: } kitaev@213: } kitaev@213: }