tikhomirov@704: /* tikhomirov@704: * Copyright (c) 2013 TMate Software Ltd tikhomirov@704: * tikhomirov@704: * This program is free software; you can redistribute it and/or modify tikhomirov@704: * it under the terms of the GNU General Public License as published by tikhomirov@704: * the Free Software Foundation; version 2 of the License. tikhomirov@704: * tikhomirov@704: * This program is distributed in the hope that it will be useful, tikhomirov@704: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@704: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@704: * GNU General Public License for more details. tikhomirov@704: * tikhomirov@704: * For information on how to redistribute this software under tikhomirov@704: * the terms of a license other than GNU General Public License tikhomirov@704: * contact TMate Software at support@hg4j.com tikhomirov@704: */ tikhomirov@704: package org.tmatesoft.hg.console; tikhomirov@704: tikhomirov@704: import java.util.Arrays; tikhomirov@704: import java.util.HashSet; tikhomirov@704: tikhomirov@704: import org.tmatesoft.hg.core.HgCallbackTargetException; tikhomirov@704: import org.tmatesoft.hg.core.HgFileRevision; tikhomirov@704: import org.tmatesoft.hg.core.HgMergeCommand; tikhomirov@704: import org.tmatesoft.hg.core.HgMergeCommand.Resolver; tikhomirov@704: import org.tmatesoft.hg.core.HgRepoFacade; tikhomirov@704: import org.tmatesoft.hg.core.Nodeid; tikhomirov@704: tikhomirov@704: /** tikhomirov@704: * Command-line frontend for merge command, 'hg merge' counterpart. tikhomirov@704: * @author Artem Tikhomirov tikhomirov@704: * @author TMate Software Ltd. tikhomirov@704: */ tikhomirov@704: public class Merge { tikhomirov@704: tikhomirov@704: public static void main(String[] args) throws Exception { tikhomirov@704: Options cmdLineOpts = Options.parse(args, new HashSet(Arrays.asList("--dry-run"))); tikhomirov@704: HgRepoFacade hgRepo = new HgRepoFacade(); tikhomirov@704: if (!hgRepo.init(cmdLineOpts.findRepository())) { tikhomirov@704: System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation()); tikhomirov@704: return; tikhomirov@704: } tikhomirov@704: HgMergeCommand.Mediator m = null; tikhomirov@704: if (cmdLineOpts.getBoolean("--dry-run") || Boolean.TRUE.booleanValue()) { tikhomirov@704: m = new Dump(); tikhomirov@704: } tikhomirov@704: final String revParam = cmdLineOpts.getSingle("-r", "--rev"); tikhomirov@704: final HgMergeCommand cmd = hgRepo.createMergeCommand(); tikhomirov@704: if (revParam.trim().length() == Nodeid.SIZE_ASCII) { tikhomirov@704: cmd.changeset(Nodeid.fromAscii(revParam.trim())); tikhomirov@704: } else { tikhomirov@704: cmd.changeset(Integer.parseInt(revParam)); tikhomirov@704: } tikhomirov@704: cmd.execute(m); tikhomirov@704: } tikhomirov@704: tikhomirov@704: static class Dump implements HgMergeCommand.Mediator { tikhomirov@704: tikhomirov@704: public void same(HgFileRevision first, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException { tikhomirov@704: System.out.printf("Unchanged %s:%s", first.getPath(), first.getRevision().shortNotation()); tikhomirov@704: } tikhomirov@704: tikhomirov@704: public void onlyA(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException { tikhomirov@704: System.out.printf("Left in first trunk only %s:%s", rev.getPath(), rev.getRevision().shortNotation()); tikhomirov@704: tikhomirov@704: } tikhomirov@704: tikhomirov@704: public void onlyB(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException { tikhomirov@704: System.out.printf("Left in second trunk only %s:%s\n", rev.getPath(), rev.getRevision().shortNotation()); tikhomirov@704: } tikhomirov@704: tikhomirov@704: public void newInA(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException { tikhomirov@704: System.out.printf("Introduced in first trunk %s:%s\n", rev.getPath(), rev.getRevision().shortNotation()); tikhomirov@704: } tikhomirov@704: tikhomirov@704: public void newInB(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException { tikhomirov@704: System.out.printf("Introduced in second trunk %s:%s\n", rev.getPath(), rev.getRevision().shortNotation()); tikhomirov@704: } tikhomirov@704: tikhomirov@704: public void fastForwardA(HgFileRevision base, HgFileRevision first, Resolver resolver) throws HgCallbackTargetException { tikhomirov@704: System.out.printf("Changed in first trunk only %s: %s..%s\n", first.getPath(), base.getRevision().shortNotation(), first.getRevision().shortNotation()); tikhomirov@704: } tikhomirov@704: tikhomirov@704: public void fastForwardB(HgFileRevision base, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException { tikhomirov@704: System.out.printf("Changed in second trunk only %s: %s..%s\n", second.getPath(), base.getRevision().shortNotation(), second.getRevision().shortNotation()); tikhomirov@704: } tikhomirov@704: tikhomirov@704: public void resolve(HgFileRevision base, HgFileRevision first, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException { tikhomirov@704: System.out.printf("Changed in boths trunks %s: %s and %s from %s\n", first.getPath(), first.getRevision().shortNotation(), second.getRevision().shortNotation(), base.getRevision().shortNotation()); tikhomirov@704: } tikhomirov@704: } tikhomirov@704: }