annotate src/org/tmatesoft/hg/core/HgMergeCommand.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
rev   line source
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.InputStream;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import org.tmatesoft.hg.internal.Callback;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.tmatesoft.hg.internal.CsetParamKeeper;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.internal.Experimental;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.internal.ManifestRevision;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.internal.Pool;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.repo.HgChangelog;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.repo.HgParentChildMap;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.repo.HgRepository;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.tmatesoft.hg.repo.HgRepositoryLock;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import org.tmatesoft.hg.repo.HgRevisionMap;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import org.tmatesoft.hg.repo.HgRuntimeException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import org.tmatesoft.hg.util.CancelledException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 import org.tmatesoft.hg.util.Path;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 /**
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 * Merge two revisions, 'hg merge REV' counterpart
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 *
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 * @author Artem Tikhomirov
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 * @author TMate Software Ltd.
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 * @since 1.2
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 */
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 @Experimental(reason="Provisional API. Work in progress")
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 public class HgMergeCommand extends HgAbstractCommand<HgMergeCommand> {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 private final HgRepository repo;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 private int firstCset, secondCset, ancestorCset;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 public HgMergeCommand(HgRepository hgRepo) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 repo = hgRepo;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 firstCset = secondCset = ancestorCset = BAD_REVISION;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 public HgMergeCommand changeset(Nodeid changeset) throws HgBadArgumentException {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 initHeadsAndAncestor(new CsetParamKeeper(repo).set(changeset).get());
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 return this;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 public HgMergeCommand changeset(int revisionIndex) throws HgBadArgumentException {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 initHeadsAndAncestor(new CsetParamKeeper(repo).set(revisionIndex).get());
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 return this;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 public void execute(Mediator mediator) throws HgCallbackTargetException, HgRepositoryLockException, HgLibraryFailureException, CancelledException {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 if (firstCset == BAD_REVISION || secondCset == BAD_REVISION || ancestorCset == BAD_REVISION) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 throw new IllegalArgumentException("Merge heads and their ancestors are not initialized");
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 final HgRepositoryLock wdLock = repo.getWorkingDirLock();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 wdLock.acquire();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 try {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 Pool<Nodeid> cacheRevs = new Pool<Nodeid>();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 Pool<Path> cacheFiles = new Pool<Path>();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 ManifestRevision m1, m2, ma;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 m1 = new ManifestRevision(cacheRevs, cacheFiles).init(repo, firstCset);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 m2 = new ManifestRevision(cacheRevs, cacheFiles).init(repo, secondCset);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 ma = new ManifestRevision(cacheRevs, cacheFiles).init(repo, ancestorCset);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 ResolverImpl resolver = new ResolverImpl();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 for (Path f : m1.files()) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 Nodeid fileRevBase, fileRevA, fileRevB;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 if (m2.contains(f)) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 fileRevA = m1.nodeid(f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 fileRevB = m2.nodeid(f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 fileRevBase = ma.contains(f) ? ma.nodeid(f) : null;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 if (fileRevA.equals(fileRevB)) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 HgFileRevision fr = new HgFileRevision(repo, fileRevA, m1.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 mediator.same(fr, fr, resolver);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 } else if (fileRevBase == fileRevA) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 assert fileRevBase != null;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 HgFileRevision frBase = new HgFileRevision(repo, fileRevBase, ma.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 HgFileRevision frSecond= new HgFileRevision(repo, fileRevB, m2.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 mediator.fastForwardB(frBase, frSecond, resolver);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 } else if (fileRevBase == fileRevB) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 assert fileRevBase != null;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 HgFileRevision frBase = new HgFileRevision(repo, fileRevBase, ma.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 HgFileRevision frFirst = new HgFileRevision(repo, fileRevA, m1.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 mediator.fastForwardA(frBase, frFirst, resolver);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 } else {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 HgFileRevision frBase = fileRevBase == null ? null : new HgFileRevision(repo, fileRevBase, ma.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 HgFileRevision frFirst = new HgFileRevision(repo, fileRevA, m1.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 HgFileRevision frSecond= new HgFileRevision(repo, fileRevB, m2.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 mediator.resolve(frBase, frFirst, frSecond, resolver);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 } else {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 // m2 doesn't contain the file, either new in m1, or deleted in m2
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 HgFileRevision frFirst = new HgFileRevision(repo, m1.nodeid(f), m1.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 if (ma.contains(f)) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 // deleted in m2
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 HgFileRevision frBase = new HgFileRevision(repo, ma.nodeid(f), ma.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 mediator.onlyA(frBase, frFirst, resolver);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 } else {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 // new in m1
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 mediator.newInA(frFirst, resolver);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 resolver.apply();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 } // for m1 files
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 for (Path f : m2.files()) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 if (m1.contains(f)) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 continue;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 HgFileRevision frSecond= new HgFileRevision(repo, m2.nodeid(f), m2.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 // file in m2 is either new or deleted in m1
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 if (ma.contains(f)) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 // deleted in m1
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 HgFileRevision frBase = new HgFileRevision(repo, ma.nodeid(f), ma.flags(f), f);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 mediator.onlyB(frBase, frSecond, resolver);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 } else {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 // new in m2
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 mediator.newInB(frSecond, resolver);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 resolver.apply();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 } catch (HgRuntimeException ex) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 throw new HgLibraryFailureException(ex);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 } finally {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 wdLock.release();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 private void initHeadsAndAncestor(int csetIndexB) throws HgBadArgumentException {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 firstCset = secondCset = ancestorCset = BAD_REVISION;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 if (csetIndexB == HgRepository.BAD_REVISION) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 throw new HgBadArgumentException("Need valid second head for merge", null);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 // TODO cache/share parent-child map, e.g. right in HgChangelog?! #getOrCreate
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 HgParentChildMap<HgChangelog> pmap = new HgParentChildMap<HgChangelog>(repo.getChangelog());
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 pmap.init();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 final HgRevisionMap<HgChangelog> rmap = pmap.getRevisionMap();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 final Nodeid csetA = repo.getWorkingCopyParents().first();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 final Nodeid csetB = rmap.revision(csetIndexB);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 final Nodeid ancestor = pmap.ancestor(csetA, csetB);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 assert !ancestor.isNull();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 if (ancestor.equals(csetA) || ancestor.equals(csetB)) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 throw new HgBadArgumentException(String.format("Revisions %s and %s are on the same line of descent, use update instead of merge", csetA.shortNotation(), csetB.shortNotation()), null);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 firstCset = rmap.revisionIndex(csetA);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 secondCset = csetIndexB;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159 ancestorCset = rmap.revisionIndex(ancestor);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 /**
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 * This is the way client code takes part in the merge process
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 */
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 @Experimental(reason="Provisional API. Work in progress")
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 @Callback
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 public interface Mediator {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 public void same(HgFileRevision first, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 public void onlyA(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 public void onlyB(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 public void newInA(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 public void newInB(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 public void fastForwardA(HgFileRevision base, HgFileRevision first, Resolver resolver) throws HgCallbackTargetException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 public void fastForwardB(HgFileRevision base, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 public void resolve(HgFileRevision base, HgFileRevision first, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 /**
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 * Clients shall not implement this interface.
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 * They use this API from inside {@link Mediator#resolve(HgFileRevision, HgFileRevision, HgFileRevision, Resolver)}
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 */
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 @Experimental(reason="Provisional API. Work in progress")
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 public interface Resolver {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 public void use(HgFileRevision rev);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 public void use(InputStream content);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186 public void unresolved(); // record the file for later processing by 'hg resolve'
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 private static class ResolverImpl implements Resolver {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 void apply() {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 public void use(HgFileRevision rev) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 // TODO Auto-generated method stub
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 public void use(InputStream content) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 // TODO Auto-generated method stub
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 public void unresolved() {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 // TODO Auto-generated method stub
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 }