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@206: import org.tmatesoft.hg.core.HgOutgoingCommand;
tikhomirov@206: import org.tmatesoft.hg.core.HgRepoFacade;
tikhomirov@74: import org.tmatesoft.hg.core.Nodeid;
tikhomirov@171: import org.tmatesoft.hg.repo.HgLookup;
tikhomirov@171: import org.tmatesoft.hg.repo.HgRemoteRepository;
tikhomirov@74:
tikhomirov@30:
tikhomirov@30: /**
tikhomirov@206: * 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@206: HgRepoFacade hgRepo = new HgRepoFacade();
tikhomirov@206: if (!hgRepo.init(cmdLineOpts.findRepository())) {
tikhomirov@206: System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation());
tikhomirov@30: return;
tikhomirov@30: }
tikhomirov@206: // XXX perhaps, HgRepoFacade shall get detectRemote() analog (to get remote server with respect of facade's repo)
tikhomirov@206: HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo.getRepository());
tikhomirov@181: if (hgRemote.isInvalid()) {
tikhomirov@181: System.err.printf("Remote repository %s is not valid", hgRemote.getLocation());
tikhomirov@181: return;
tikhomirov@172: }
tikhomirov@206: //
tikhomirov@206: HgOutgoingCommand cmd = hgRepo.createOutgoingCommand();
tikhomirov@206: cmd.against(hgRemote);
tikhomirov@171:
tikhomirov@171: // find all local children of commonKnown
tikhomirov@215: List result = cmd.executeLite();
tikhomirov@185: dump("Lite", result);
tikhomirov@192: //
tikhomirov@192: //
tikhomirov@185: System.out.println("Full");
tikhomirov@185: // show all, starting from next to common
tikhomirov@206: final ChangesetDumpHandler h = new ChangesetDumpHandler(hgRepo.getRepository());
tikhomirov@206: h.complete(cmdLineOpts.getBoolean("--debug")).verbose(cmdLineOpts.getBoolean("-v", "--verbose"));
tikhomirov@206: cmd.executeFull(h);
tikhomirov@206: h.done();
tikhomirov@171: }
tikhomirov@192:
tikhomirov@206: // public static class ChangesetFormatter {
tikhomirov@206: // private final StringBuilder sb = new StringBuilder(1024);
tikhomirov@206: //
tikhomirov@206: // public CharSequence simple(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
tikhomirov@206: // sb.setLength(0);
tikhomirov@206: // sb.append(String.format("changeset: %d:%s\n", revisionNumber, nodeid.toString()));
tikhomirov@206: // sb.append(String.format("user: %s\n", cset.user()));
tikhomirov@206: // sb.append(String.format("date: %s\n", cset.dateString()));
tikhomirov@206: // sb.append(String.format("comment: %s\n\n", cset.comment()));
tikhomirov@206: // return sb;
tikhomirov@206: // }
tikhomirov@206: // }
tikhomirov@171:
tikhomirov@30:
tikhomirov@206: 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: }