tikhomirov@181: /* tikhomirov@181: * Copyright (c) 2011 TMate Software Ltd tikhomirov@181: * tikhomirov@181: * This program is free software; you can redistribute it and/or modify tikhomirov@181: * it under the terms of the GNU General Public License as published by tikhomirov@181: * the Free Software Foundation; version 2 of the License. tikhomirov@181: * tikhomirov@181: * This program is distributed in the hope that it will be useful, tikhomirov@181: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@181: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@181: * GNU General Public License for more details. tikhomirov@181: * tikhomirov@181: * For information on how to redistribute this software under tikhomirov@181: * the terms of a license other than GNU General Public License tikhomirov@181: * contact TMate Software at support@hg4j.com tikhomirov@181: */ tikhomirov@181: package org.tmatesoft.hg.core; tikhomirov@181: tikhomirov@181: import java.util.List; tikhomirov@181: tikhomirov@192: import org.tmatesoft.hg.internal.RepositoryComparator; tikhomirov@192: import org.tmatesoft.hg.repo.HgChangelog; tikhomirov@192: import org.tmatesoft.hg.repo.HgRemoteRepository; tikhomirov@181: import org.tmatesoft.hg.repo.HgRepository; tikhomirov@181: import org.tmatesoft.hg.util.CancelledException; tikhomirov@181: tikhomirov@181: /** tikhomirov@192: * Command to find out changes made in a local repository and missing at remote repository. tikhomirov@192: * tikhomirov@181: * @author Artem Tikhomirov tikhomirov@181: * @author TMate Software Ltd. tikhomirov@181: */ tikhomirov@181: public class HgOutgoingCommand { tikhomirov@192: tikhomirov@192: private final HgRepository localRepo; tikhomirov@192: private HgRemoteRepository remoteRepo; tikhomirov@181: private boolean includeSubrepo; tikhomirov@192: private RepositoryComparator comparator; tikhomirov@181: tikhomirov@181: public HgOutgoingCommand(HgRepository hgRepo) { tikhomirov@192: localRepo = hgRepo; tikhomirov@181: } tikhomirov@181: tikhomirov@181: /** tikhomirov@192: * @param hgRemote remoteRepository to compare against tikhomirov@192: * @return this for convenience tikhomirov@192: */ tikhomirov@192: public HgOutgoingCommand against(HgRemoteRepository hgRemote) { tikhomirov@192: remoteRepo = hgRemote; tikhomirov@192: comparator = null; tikhomirov@192: return this; tikhomirov@192: } tikhomirov@192: tikhomirov@192: /** tikhomirov@192: * PLACEHOLDER, NOT IMPLEMENTED YET. tikhomirov@192: * tikhomirov@181: * Select specific branch to pull tikhomirov@181: * @return this for convenience tikhomirov@181: */ tikhomirov@181: public HgOutgoingCommand branch(String branch) { tikhomirov@181: throw HgRepository.notImplemented(); tikhomirov@181: } tikhomirov@181: tikhomirov@181: /** tikhomirov@192: * PLACEHOLDER, NOT IMPLEMENTED YET. tikhomirov@181: * tikhomirov@181: * @return this for convenience tikhomirov@181: */ tikhomirov@181: public HgOutgoingCommand subrepo(boolean include) { tikhomirov@181: includeSubrepo = include; tikhomirov@181: throw HgRepository.notImplemented(); tikhomirov@181: } tikhomirov@181: tikhomirov@192: /** tikhomirov@192: * Lightweight check for outgoing changes. tikhomirov@192: * tikhomirov@192: * @param context tikhomirov@192: * @return list on local nodes known to be missing at remote server tikhomirov@192: */ tikhomirov@181: public List executeLite(Object context) throws HgException, CancelledException { tikhomirov@192: return getComparator(context).getLocalOnlyRevisions(); tikhomirov@181: } tikhomirov@181: tikhomirov@192: /** tikhomirov@192: * Complete information about outgoing changes tikhomirov@192: * tikhomirov@192: * @param handler delegate to process changes tikhomirov@192: */ tikhomirov@192: public void executeFull(final HgLogCommand.Handler handler) throws HgException, CancelledException { tikhomirov@192: if (handler == null) { tikhomirov@192: throw new IllegalArgumentException("Delegate can't be null"); tikhomirov@192: } tikhomirov@192: getComparator(handler).visitLocalOnlyRevisions(new ChangesetTransformer(localRepo, handler)); tikhomirov@192: } tikhomirov@192: tikhomirov@192: private RepositoryComparator getComparator(Object context) throws HgException, CancelledException { tikhomirov@192: if (remoteRepo == null) { tikhomirov@192: throw new IllegalArgumentException("Shall specify remote repository to compare against"); tikhomirov@192: } tikhomirov@192: if (comparator == null) { tikhomirov@192: HgChangelog.ParentWalker pw = localRepo.getChangelog().new ParentWalker(); tikhomirov@192: pw.init(); tikhomirov@192: comparator = new RepositoryComparator(pw, remoteRepo); tikhomirov@192: comparator.compare(context); tikhomirov@192: } tikhomirov@192: return comparator; tikhomirov@181: } tikhomirov@181: }