comparison cmdline/org/tmatesoft/hg/console/Merge.java @ 704:7743a9c10bfa

Merge command introduced
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 14 Aug 2013 20:07:26 +0200
parents
children b4242b7e7dfe
comparison
equal deleted inserted replaced
703:7839ff0bfd78 704:7743a9c10bfa
1 /*
2 * Copyright (c) 2013 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.console;
18
19 import java.util.Arrays;
20 import java.util.HashSet;
21
22 import org.tmatesoft.hg.core.HgCallbackTargetException;
23 import org.tmatesoft.hg.core.HgFileRevision;
24 import org.tmatesoft.hg.core.HgMergeCommand;
25 import org.tmatesoft.hg.core.HgMergeCommand.Resolver;
26 import org.tmatesoft.hg.core.HgRepoFacade;
27 import org.tmatesoft.hg.core.Nodeid;
28
29 /**
30 * Command-line frontend for merge command, 'hg merge' counterpart.
31 * @author Artem Tikhomirov
32 * @author TMate Software Ltd.
33 */
34 public class Merge {
35
36 public static void main(String[] args) throws Exception {
37 Options cmdLineOpts = Options.parse(args, new HashSet<String>(Arrays.asList("--dry-run")));
38 HgRepoFacade hgRepo = new HgRepoFacade();
39 if (!hgRepo.init(cmdLineOpts.findRepository())) {
40 System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation());
41 return;
42 }
43 HgMergeCommand.Mediator m = null;
44 if (cmdLineOpts.getBoolean("--dry-run") || Boolean.TRUE.booleanValue()) {
45 m = new Dump();
46 }
47 final String revParam = cmdLineOpts.getSingle("-r", "--rev");
48 final HgMergeCommand cmd = hgRepo.createMergeCommand();
49 if (revParam.trim().length() == Nodeid.SIZE_ASCII) {
50 cmd.changeset(Nodeid.fromAscii(revParam.trim()));
51 } else {
52 cmd.changeset(Integer.parseInt(revParam));
53 }
54 cmd.execute(m);
55 }
56
57 static class Dump implements HgMergeCommand.Mediator {
58
59 public void same(HgFileRevision first, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException {
60 System.out.printf("Unchanged %s:%s", first.getPath(), first.getRevision().shortNotation());
61 }
62
63 public void onlyA(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
64 System.out.printf("Left in first trunk only %s:%s", rev.getPath(), rev.getRevision().shortNotation());
65
66 }
67
68 public void onlyB(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
69 System.out.printf("Left in second trunk only %s:%s\n", rev.getPath(), rev.getRevision().shortNotation());
70 }
71
72 public void newInA(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
73 System.out.printf("Introduced in first trunk %s:%s\n", rev.getPath(), rev.getRevision().shortNotation());
74 }
75
76 public void newInB(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
77 System.out.printf("Introduced in second trunk %s:%s\n", rev.getPath(), rev.getRevision().shortNotation());
78 }
79
80 public void fastForwardA(HgFileRevision base, HgFileRevision first, Resolver resolver) throws HgCallbackTargetException {
81 System.out.printf("Changed in first trunk only %s: %s..%s\n", first.getPath(), base.getRevision().shortNotation(), first.getRevision().shortNotation());
82 }
83
84 public void fastForwardB(HgFileRevision base, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException {
85 System.out.printf("Changed in second trunk only %s: %s..%s\n", second.getPath(), base.getRevision().shortNotation(), second.getRevision().shortNotation());
86 }
87
88 public void resolve(HgFileRevision base, HgFileRevision first, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException {
89 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());
90 }
91 }
92 }