annotate src/org/tmatesoft/hg/core/HgMergeCommand.java @ 706:cd5c87d96315

Merge: tests for mediator notifications
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Aug 2013 14:54:09 +0200
parents b4242b7e7dfe
children 42b88709e41d
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
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
21 import java.io.File;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
22 import java.io.FileInputStream;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
23 import java.io.IOException;
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.io.InputStream;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.internal.Callback;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.internal.CsetParamKeeper;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
28 import org.tmatesoft.hg.internal.DirstateBuilder;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
29 import org.tmatesoft.hg.internal.DirstateReader;
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.internal.Experimental;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
31 import org.tmatesoft.hg.internal.FileUtils;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
32 import org.tmatesoft.hg.internal.Internals;
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import org.tmatesoft.hg.internal.ManifestRevision;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
34 import org.tmatesoft.hg.internal.MergeStateBuilder;
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 import org.tmatesoft.hg.internal.Pool;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
36 import org.tmatesoft.hg.internal.Transaction;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
37 import org.tmatesoft.hg.internal.WorkingDirFileWriter;
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 import org.tmatesoft.hg.repo.HgChangelog;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 import org.tmatesoft.hg.repo.HgParentChildMap;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 import org.tmatesoft.hg.repo.HgRepository;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 import org.tmatesoft.hg.repo.HgRepositoryLock;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 import org.tmatesoft.hg.repo.HgRevisionMap;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 import org.tmatesoft.hg.repo.HgRuntimeException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 import org.tmatesoft.hg.util.CancelledException;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 import org.tmatesoft.hg.util.Path;
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 /**
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 * Merge two revisions, 'hg merge REV' counterpart
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 * @author Artem Tikhomirov
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 * @author TMate Software Ltd.
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 * @since 1.2
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 @Experimental(reason="Provisional API. Work in progress")
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 public class HgMergeCommand extends HgAbstractCommand<HgMergeCommand> {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 private final HgRepository repo;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 private int firstCset, secondCset, ancestorCset;
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(HgRepository hgRepo) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 repo = hgRepo;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 firstCset = secondCset = ancestorCset = BAD_REVISION;
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 HgMergeCommand changeset(Nodeid changeset) throws HgBadArgumentException {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 initHeadsAndAncestor(new CsetParamKeeper(repo).set(changeset).get());
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 return this;
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
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 public HgMergeCommand changeset(int revisionIndex) throws HgBadArgumentException {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 initHeadsAndAncestor(new CsetParamKeeper(repo).set(revisionIndex).get());
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 return this;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
75 public void execute(Mediator mediator) throws HgCallbackTargetException, HgRepositoryLockException, HgIOException, HgLibraryFailureException, CancelledException {
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 if (firstCset == BAD_REVISION || secondCset == BAD_REVISION || ancestorCset == BAD_REVISION) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 throw new IllegalArgumentException("Merge heads and their ancestors are not initialized");
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 final HgRepositoryLock wdLock = repo.getWorkingDirLock();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 wdLock.acquire();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 try {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 Pool<Nodeid> cacheRevs = new Pool<Nodeid>();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 Pool<Path> cacheFiles = new Pool<Path>();
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
84
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
85 Internals implRepo = Internals.getInstance(repo);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
86 final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
87 dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource(repo.getSessionContext().getPathFactory(), cacheFiles)));
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
88 final HgChangelog clog = repo.getChangelog();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
89 dirstateBuilder.parents(clog.getRevision(firstCset), clog.getRevision(secondCset));
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
90 //
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
91 MergeStateBuilder mergeStateBuilder = new MergeStateBuilder(implRepo);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
92
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 ManifestRevision m1, m2, ma;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 m1 = new ManifestRevision(cacheRevs, cacheFiles).init(repo, firstCset);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 m2 = new ManifestRevision(cacheRevs, cacheFiles).init(repo, secondCset);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 ma = new ManifestRevision(cacheRevs, cacheFiles).init(repo, ancestorCset);
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
97 Transaction transaction = implRepo.getTransactionFactory().create(repo);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
98 ResolverImpl resolver = new ResolverImpl(implRepo, dirstateBuilder, mergeStateBuilder);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
99 try {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
100 for (Path f : m1.files()) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
101 Nodeid fileRevBase, fileRevA, fileRevB;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
102 if (m2.contains(f)) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
103 fileRevA = m1.nodeid(f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
104 fileRevB = m2.nodeid(f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
105 fileRevBase = ma.contains(f) ? ma.nodeid(f) : null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
106 if (fileRevA.equals(fileRevB)) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
107 HgFileRevision fr = new HgFileRevision(repo, fileRevA, m1.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
108 resolver.presentState(f, fr, fr);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
109 mediator.same(fr, resolver);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
110 } else if (fileRevBase == fileRevA) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
111 assert fileRevBase != null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
112 HgFileRevision frBase = new HgFileRevision(repo, fileRevBase, ma.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
113 HgFileRevision frSecond= new HgFileRevision(repo, fileRevB, m2.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
114 resolver.presentState(f, frBase, frSecond);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
115 mediator.fastForwardB(frBase, frSecond, resolver);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
116 } else if (fileRevBase == fileRevB) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
117 assert fileRevBase != null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
118 HgFileRevision frBase = new HgFileRevision(repo, fileRevBase, ma.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
119 HgFileRevision frFirst = new HgFileRevision(repo, fileRevA, m1.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
120 resolver.presentState(f, frFirst, frBase);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
121 mediator.fastForwardA(frBase, frFirst, resolver);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
122 } else {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
123 HgFileRevision frBase = fileRevBase == null ? null : new HgFileRevision(repo, fileRevBase, ma.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
124 HgFileRevision frFirst = new HgFileRevision(repo, fileRevA, m1.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
125 HgFileRevision frSecond= new HgFileRevision(repo, fileRevB, m2.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
126 resolver.presentState(f, frFirst, frSecond);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
127 mediator.resolve(frBase, frFirst, frSecond, resolver);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
128 }
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 } else {
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
130 // m2 doesn't contain the file, either new in m1, or deleted in m2
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
131 HgFileRevision frFirst = new HgFileRevision(repo, m1.nodeid(f), m1.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
132 resolver.presentState(f, frFirst, null);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
133 if (ma.contains(f)) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
134 // deleted in m2
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
135 HgFileRevision frBase = new HgFileRevision(repo, ma.nodeid(f), ma.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
136 mediator.onlyA(frBase, frFirst, resolver);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
137 } else {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
138 // new in m1
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
139 mediator.newInA(frFirst, resolver);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
140 }
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 }
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
142 resolver.apply();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
143 } // for m1 files
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
144 for (Path f : m2.files()) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
145 if (m1.contains(f)) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
146 continue;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
147 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
148 HgFileRevision frSecond= new HgFileRevision(repo, m2.nodeid(f), m2.flags(f), f);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
149 // file in m2 is either new or deleted in m1
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
150 resolver.presentState(f, null, frSecond);
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 if (ma.contains(f)) {
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
152 // deleted in m1
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 HgFileRevision frBase = new HgFileRevision(repo, ma.nodeid(f), ma.flags(f), f);
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
154 mediator.onlyB(frBase, frSecond, resolver);
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 } else {
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
156 // new in m2
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
157 mediator.newInB(frSecond, resolver);
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 }
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
159 resolver.apply();
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 }
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
161 resolver.serializeChanged(transaction);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
162 transaction.commit();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
163 } catch (HgRuntimeException ex) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
164 transaction.rollback();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
165 throw ex;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
166 } catch (HgIOException ex) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
167 transaction.rollback();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
168 throw ex;
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 } catch (HgRuntimeException ex) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 throw new HgLibraryFailureException(ex);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 } finally {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 wdLock.release();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 }
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 private void initHeadsAndAncestor(int csetIndexB) throws HgBadArgumentException {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 firstCset = secondCset = ancestorCset = BAD_REVISION;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 if (csetIndexB == HgRepository.BAD_REVISION) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 throw new HgBadArgumentException("Need valid second head for merge", null);
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 // 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
183 HgParentChildMap<HgChangelog> pmap = new HgParentChildMap<HgChangelog>(repo.getChangelog());
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 pmap.init();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 final HgRevisionMap<HgChangelog> rmap = pmap.getRevisionMap();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186 final Nodeid csetA = repo.getWorkingCopyParents().first();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 final Nodeid csetB = rmap.revision(csetIndexB);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 final Nodeid ancestor = pmap.ancestor(csetA, csetB);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 assert !ancestor.isNull();
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 if (ancestor.equals(csetA) || ancestor.equals(csetB)) {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 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
192 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 firstCset = rmap.revisionIndex(csetA);
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 secondCset = csetIndexB;
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 ancestorCset = rmap.revisionIndex(ancestor);
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
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 /**
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
199 * This is the way client code takes part in the merge process.
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
200 * It's advised to subclass {@link MediatorBase} unless special treatment for regular cases is desired
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 */
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 @Experimental(reason="Provisional API. Work in progress")
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 @Callback
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 public interface Mediator {
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
205 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
206 * file revisions are identical in both heads
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
207 */
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
208 public void same(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
209 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
210 * file left in first/left/A trunk only, deleted in second/right/B trunk
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
211 */
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212 public void onlyA(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
213 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
214 * file left in second/right/B trunk only, deleted in first/left/A trunk
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
215 */
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 public void onlyB(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
217 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
218 * file is missing in ancestor revision and second/right/B trunk, introduced in first/left/A trunk
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
219 */
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 public void newInA(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
221 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
222 * file is missing in ancestor revision and first/left/A trunk, introduced in second/right/B trunk
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
223 */
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 public void newInB(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
225 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
226 * file was changed in first/left/A trunk, unchanged in second/right/B trunk
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
227 */
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 public void fastForwardA(HgFileRevision base, HgFileRevision first, Resolver resolver) throws HgCallbackTargetException;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
229 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
230 * file was changed in second/right/B trunk, unchanged in first/left/A trunk
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
231 */
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
232 public void fastForwardB(HgFileRevision base, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException;
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
233 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
234 * File changed (or added, if base is <code>null</code>) in both trunks
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
235 */
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
236 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
237 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
238
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 /**
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 * Clients shall not implement this interface.
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 * 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
242 */
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 @Experimental(reason="Provisional API. Work in progress")
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 public interface Resolver {
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
245 public void use(HgFileRevision rev);
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
246 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
247 * Replace current revision with stream content.
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
248 * Note, callers are not expected to {@link InputStream#close()} this stream.
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
249 * It will be {@link InputStream#close() closed} at <b>Hg4J</b>'s discretion
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
250 * not necessarily during invocation of this method. IOW, the library may decide to
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
251 * use this stream not right away, at some point of time later, and streams supplied
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
252 * shall respect this.
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
253 *
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
254 * @param content New content to replace current revision, shall not be <code>null</code>
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
255 * @throws IOException propagated exceptions from content
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
256 */
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
257 public void use(InputStream content) throws IOException;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
258 public void forget(HgFileRevision rev);
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
259 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
260 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
261
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
262 /**
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
263 * Base mediator implementation, with regular resolution
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
264 */
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
265 @Experimental(reason="Provisional API. Work in progress")
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
266 public abstract class MediatorBase implements Mediator {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
267 public void same(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
268 resolver.use(rev);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
269 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
270 public void onlyA(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
271 resolver.use(rev);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
272 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
273 public void onlyB(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
274 resolver.use(rev);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
275 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
276 public void newInA(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
277 resolver.use(rev);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
278 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
279 public void newInB(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
280 resolver.use(rev);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
281 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
282 public void fastForwardA(HgFileRevision base, HgFileRevision first, Resolver resolver) throws HgCallbackTargetException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
283 resolver.use(first);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
284 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
285 public void fastForwardB(HgFileRevision base, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
286 resolver.use(second);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
287 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
288 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
289
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
290 private static class ResolverImpl implements Resolver {
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
291
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
292 private final Internals repo;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
293 private final DirstateBuilder dirstateBuilder;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
294 private final MergeStateBuilder mergeStateBuilder;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
295 private boolean changedDirstate;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
296 private HgFileRevision revA;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
297 private HgFileRevision revB;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
298 private Path file;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
299 // resolutions:
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
300 private HgFileRevision resolveUse, resolveForget;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
301 private File resolveContent;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
302 private boolean resolveMarkUnresolved;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
303
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
304 public ResolverImpl(Internals implRepo, DirstateBuilder dirstateBuilder, MergeStateBuilder mergeStateBuilder) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
305 repo = implRepo;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
306 this.dirstateBuilder = dirstateBuilder;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
307 this.mergeStateBuilder = mergeStateBuilder;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
308 changedDirstate = false;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
309 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
310
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
311 void serializeChanged(Transaction tr) throws HgIOException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
312 if (changedDirstate) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
313 dirstateBuilder.serialize(tr);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
314 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
315 mergeStateBuilder.serialize(tr);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
316 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
317
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
318 void presentState(Path p, HgFileRevision revA, HgFileRevision revB) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
319 assert revA != null || revB != null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
320 file = p;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
321 this.revA = revA;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
322 this.revB = revB;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
323 resolveUse = resolveForget = null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
324 resolveContent = null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
325 resolveMarkUnresolved = false;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
326 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
327
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
328 void apply() throws HgIOException, HgRuntimeException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
329 if (resolveMarkUnresolved) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
330 mergeStateBuilder.unresolved(file);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
331 } else if (resolveForget != null) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
332 if (resolveForget == revA) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
333 changedDirstate = true;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
334 dirstateBuilder.recordRemoved(file);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
335 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
336 } else if (resolveUse != null) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
337 if (resolveUse != revA) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
338 changedDirstate = true;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
339 final WorkingDirFileWriter fw = new WorkingDirFileWriter(repo);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
340 fw.processFile(resolveUse);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
341 if (resolveUse == revB) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
342 dirstateBuilder.recordMergedFromP2(file);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
343 } else {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
344 dirstateBuilder.recordMerged(file, fw.fmode(), fw.mtime(), fw.bytesWritten());
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
345 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
346 } // if resolution is to use revA, nothing to do
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
347 } else if (resolveContent != null) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
348 changedDirstate = true;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
349 // FIXME write content to file using transaction?
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
350 InputStream is;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
351 try {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
352 is = new FileInputStream(resolveContent);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
353 } catch (IOException ex) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
354 throw new HgIOException("Failed to read temporary content", ex, resolveContent);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
355 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
356 final WorkingDirFileWriter fw = new WorkingDirFileWriter(repo);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
357 fw.processFile(file, is, revA == null ? revB.getFileFlags() : revA.getFileFlags());
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
358 // XXX if presentState(null, fileOnlyInB), and use(InputStream) - i.e.
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
359 // resolution is to add file with supplied content - shall I put 'Merged', MergedFromP2 or 'Added' into dirstate?
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
360 if (revA == null && revB != null) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
361 dirstateBuilder.recordMergedFromP2(file);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
362 } else {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
363 dirstateBuilder.recordMerged(file, fw.fmode(), fw.mtime(), fw.bytesWritten());
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
364 }
706
cd5c87d96315 Merge: tests for mediator notifications
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
365 } // else no resolution was chosen, fine with that
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
366 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
367
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
368 public void use(HgFileRevision rev) {
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
369 if (rev == null) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
370 throw new IllegalArgumentException();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
371 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
372 assert resolveContent == null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
373 assert resolveForget == null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
374 resolveUse = rev;
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
375 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
376
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
377 public void use(InputStream content) throws IOException {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
378 if (content == null) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
379 throw new IllegalArgumentException();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
380 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
381 assert resolveUse == null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
382 assert resolveForget == null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
383 try {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
384 // cache new contents just to fail fast if there are troubles with content
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
385 final FileUtils fileUtils = new FileUtils(repo.getLog(), this);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
386 resolveContent = fileUtils.createTempFile();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
387 fileUtils.write(content, resolveContent);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
388 } finally {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
389 content.close();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
390 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
391 // do not care deleting file in case of failure to allow analyze of the issue
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
392 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
393
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
394 public void forget(HgFileRevision rev) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
395 if (rev == null) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
396 throw new IllegalArgumentException();
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
397 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
398 if (rev != revA || rev != revB) {
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
399 throw new IllegalArgumentException("Can't forget revision which doesn't represent actual state in either merged trunk");
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
400 }
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
401 assert resolveUse == null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
402 assert resolveContent == null;
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
403 resolveForget = rev;
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
404 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
405
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
406 public void unresolved() {
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 704
diff changeset
407 resolveMarkUnresolved = true;
704
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
408 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
409 }
7743a9c10bfa Merge command introduced
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
410 }