annotate src/org/tmatesoft/hg/repo/HgMergeState.java @ 707:42b88709e41d

Merge: support 'unresolved' resolution with MergeStateBuilder
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Aug 2013 19:22:59 +0200
parents b4242b7e7dfe
children 4ffc17c0b534
rev   line source
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
2 * Copyright (c) 2011-2013 TMate Software Ltd
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.repo;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
19 import static org.tmatesoft.hg.core.Nodeid.NULL;
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
20
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.File;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.ArrayList;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.Arrays;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.util.Collections;
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
25 import java.util.Iterator;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.util.List;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.core.HgFileRevision;
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
29 import org.tmatesoft.hg.core.HgIOException;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.core.Nodeid;
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
31 import org.tmatesoft.hg.internal.Internals;
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
32 import org.tmatesoft.hg.internal.LineReader;
248
3fbfce107f94 Issue 8: Means to find out information about given file at specific changeset. Inner ManifestRevisionInspector got promoted to ManifestRevision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 231
diff changeset
33 import org.tmatesoft.hg.internal.ManifestRevision;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import org.tmatesoft.hg.internal.Pool;
284
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 270
diff changeset
35 import org.tmatesoft.hg.util.Pair;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 import org.tmatesoft.hg.util.Path;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 import org.tmatesoft.hg.util.PathRewrite;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 /**
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
40 * Access to repository's merge state
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
41 *
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 * @author Artem Tikhomirov
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 * @author TMate Software Ltd.
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 */
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 public class HgMergeState {
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
46 private Nodeid wcp1, wcp2, stateParent;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 public enum Kind {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 Resolved, Unresolved;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 public static class Entry {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 private final Kind state;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 private final HgFileRevision parent1;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 private final HgFileRevision parent2;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 private final HgFileRevision ancestor;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 private final Path wcFile;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 /*package-local*/Entry(Kind s, Path actualCopy, HgFileRevision p1, HgFileRevision p2, HgFileRevision ca) {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 if (p1 == null || p2 == null || ca == null || actualCopy == null) {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 throw new IllegalArgumentException();
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 state = s;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 wcFile = actualCopy;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 parent1 = p1;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 parent2 = p2;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 ancestor = ca;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 public Kind getState() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 return state;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 public Path getActualFile() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 return wcFile;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 public HgFileRevision getFirstParent() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 return parent1;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 public HgFileRevision getSecondParent() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 return parent2;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 public HgFileRevision getCommonAncestor() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 return ancestor;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
87 private final Internals repo;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 private Entry[] entries;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
90 HgMergeState(Internals internalRepo) {
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
91 repo = internalRepo;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
94 /**
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
95 * Update our knowledge about repository's merge state
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
96 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
97 */
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
98 public void refresh() throws HgRuntimeException {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
99 final HgRepository hgRepo = repo.getRepo();
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 entries = null;
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
101 // it's possible there are two parents but no merge/state, we shall report this case as 'merging', with proper
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
102 // first and second parent values
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
103 stateParent = Nodeid.NULL;
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
104 Pool<Nodeid> nodeidPool = new Pool<Nodeid>();
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
105 Pool<Path> fnamePool = new Pool<Path>();
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
106 Pair<Nodeid, Nodeid> wcParents = hgRepo.getWorkingCopyParents();
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
107 wcp1 = nodeidPool.unify(wcParents.first()); wcp2 = nodeidPool.unify(wcParents.second());
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
108 final File f = repo.getRepositoryFile(HgRepositoryFiles.MergeState);
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 if (!f.canRead()) {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 // empty state
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 return;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 }
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
113 try {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
114 ArrayList<Entry> result = new ArrayList<Entry>();
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
115 // pipe (already normalized) names from mergestate through same pool of filenames as use manifest revisions
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
116 Path.Source pathPool = new Path.SimpleSource(new PathRewrite.Empty(), fnamePool);
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
117 final ManifestRevision m1 = new ManifestRevision(nodeidPool, fnamePool);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
118 final ManifestRevision m2 = new ManifestRevision(nodeidPool, fnamePool);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
119 if (!wcp2.isNull()) {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
120 final int rp2 = hgRepo.getChangelog().getRevisionIndex(wcp2);
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
121 hgRepo.getManifest().walk(rp2, rp2, m2);
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
122 }
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
123 LineReader lr = new LineReader(f, repo.getLog());
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
124 Iterator<String> lines = lr.read(new LineReader.SimpleLineCollector(), new ArrayList<String>()).iterator();
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
125 String s = lines.next();
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
126 stateParent = nodeidPool.unify(Nodeid.fromAscii(s));
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
127 final int rp1 = hgRepo.getChangelog().getRevisionIndex(stateParent);
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
128 hgRepo.getManifest().walk(rp1, rp1, m1);
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
129 while (lines.hasNext()) {
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
130 String[] r = s.split("\\00");
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
131 Path p1fname = pathPool.path(r[3]);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
132 Nodeid nidP1 = m1.nodeid(p1fname);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
133 Nodeid nidCA = nodeidPool.unify(Nodeid.fromAscii(r[5]));
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
134 HgFileRevision p1 = new HgFileRevision(hgRepo, nidP1, m1.flags(p1fname), p1fname);
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
135 HgFileRevision ca;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
136 if (nidCA == nidP1 && r[3].equals(r[4])) {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
137 ca = p1;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
138 } else {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
139 ca = new HgFileRevision(hgRepo, nidCA, null, pathPool.path(r[4]));
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
140 }
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
141 HgFileRevision p2;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
142 if (!wcp2.isNull() || !r[6].equals(r[4])) {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
143 final Path p2fname = pathPool.path(r[6]);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
144 Nodeid nidP2 = m2.nodeid(p2fname);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
145 if (nidP2 == null) {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
146 assert false : "There's not enough information (or I don't know where to look) in merge/state to find out what's the second parent";
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
147 nidP2 = NULL;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
148 }
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
149 p2 = new HgFileRevision(hgRepo, nidP2, m2.flags(p2fname), p2fname);
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
150 } else {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
151 // no second parent known. no idea what to do here, assume linear merge, use common ancestor as parent
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
152 p2 = ca;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
153 }
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
154 final Kind k;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
155 if ("u".equals(r[1])) {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
156 k = Kind.Unresolved;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
157 } else if ("r".equals(r[1])) {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
158 k = Kind.Resolved;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
159 } else {
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
160 throw new HgInvalidStateException(String.format("Unknown merge kind %s", r[1]));
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
161 }
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
162 Entry e = new Entry(k, pathPool.path(r[0]), p1, p2, ca);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
163 result.add(e);
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
164 }
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
165 entries = result.toArray(new Entry[result.size()]);
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
166 } catch (HgIOException ex) {
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
167 throw new HgInvalidControlFileException("Merge state read failed", ex, f);
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 }
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
170
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
171 /**
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
172 * Repository is in 'merging' state when changeset to be committed got two parents.
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
173 * This method doesn't tell whether there are (un)resolved conflicts in the working copy,
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
174 * use {@link #getConflicts()} (which makes sense only when {@link #isStale()} is <code>false</code>).
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
175 * @return <code>true</code> when repository is being merged
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
176 */
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
177 public boolean isMerging() {
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
178 return !getFirstParent().isNull() && !getSecondParent().isNull() && !isStale();
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
179 }
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
180
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
181 /**
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
182 * Merge state file may not match actual working copy due to rollback or undo operations.
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
183 * Value of {@link #getConflicts()} is reasonable iff this method returned <code>false</code>.
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
184 *
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
185 * @return <code>true</code> when recorded merge state doesn't seem to correspond to present working copy
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
186 */
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
187 public boolean isStale() {
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
188 assert wcp1 != null;
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
189 return !stateParent.isNull() /*there's merge state*/ && !wcp1.equals(stateParent) /*and it doesn't match*/;
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
190 }
336
f74e36b7344b Do not fail with HgBadStateException when there are no merge state
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
191
f74e36b7344b Do not fail with HgBadStateException when there are no merge state
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
192 /**
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
193 * It's possible for a repository to be in a 'merging' state (@see {@link #isMerging()} without any
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
194 * conflict to resolve (no merge state information file).
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
195 *
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
196 * @return first parent of the working copy, never <code>null</code>
336
f74e36b7344b Do not fail with HgBadStateException when there are no merge state
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
197 */
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 public Nodeid getFirstParent() {
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
199 assert wcp1 != null;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 return wcp1;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
203 /**
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
204 * @return second parent of the working copy, never <code>null</code>
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
205 */
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 public Nodeid getSecondParent() {
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
207 assert wcp2 != null;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 return wcp2;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210
336
f74e36b7344b Do not fail with HgBadStateException when there are no merge state
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
211 /**
f74e36b7344b Do not fail with HgBadStateException when there are no merge state
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
212 * @return revision of the merge state or {@link Nodeid#NULL} if there's no merge state
f74e36b7344b Do not fail with HgBadStateException when there are no merge state
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
213 */
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
214 public Nodeid getStateParent() {
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
215 assert stateParent != null;
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
216 return stateParent;
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
217 }
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
218
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
219 /**
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
220 * List of conflicts as recorded in the merge state information file.
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
221 * Note, this information is not valid unless {@link #isStale()} is <code>true</code>.
341
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
222 *
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
223 * @return non-<code>null</code> list with both resolved and unresolved conflicts.
75c452fdd76a Merging state not detected when there's no conflicts to resolve (no merge/state file)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 336
diff changeset
224 */
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225 public List<Entry> getConflicts() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226 return entries == null ? Collections.<Entry>emptyList() : Arrays.asList(entries);
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
227 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 }