annotate src/org/tmatesoft/hg/repo/HgMergeState.java @ 455:281cfb60e2ef smartgit3

Added option to turn detection of copied files off during status operation
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 18 Jun 2012 20:26:59 +0200
parents 2fadf8695f8a
children ee8264d80747
rev   line source
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
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.BufferedReader;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.File;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.FileReader;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.io.IOException;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.ArrayList;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.util.Arrays;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.Collections;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.util.List;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.core.HgBadStateException;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.tmatesoft.hg.core.HgFileRevision;
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
32 import org.tmatesoft.hg.core.HgInvalidControlFileException;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import org.tmatesoft.hg.core.Nodeid;
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
34 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
35 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
36 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
37 import org.tmatesoft.hg.util.Path;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 import org.tmatesoft.hg.util.PathPool;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 import org.tmatesoft.hg.util.PathRewrite;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 /**
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 *
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 * @author Artem Tikhomirov
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 * @author TMate Software Ltd.
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 */
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 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
47 private Nodeid wcp1, wcp2, stateParent;
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 public enum Kind {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 Resolved, Unresolved;
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
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 public static class Entry {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 private final Kind state;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 private final HgFileRevision parent1;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 private final HgFileRevision parent2;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 private final HgFileRevision ancestor;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 private final Path wcFile;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 /*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
61 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
62 throw new IllegalArgumentException();
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 state = s;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 wcFile = actualCopy;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 parent1 = p1;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 parent2 = p2;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 ancestor = ca;
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
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 public Kind getState() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 return state;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 public Path getActualFile() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 return wcFile;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 public HgFileRevision getFirstParent() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 return parent1;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 public HgFileRevision getSecondParent() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 return parent2;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 public HgFileRevision getCommonAncestor() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 return ancestor;
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 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 private final HgRepository repo;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 private Entry[] entries;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 HgMergeState(HgRepository hgRepo) {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 repo = hgRepo;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
95 public void refresh() throws HgInvalidControlFileException {
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 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
97 // 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
98 // 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
99 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
100 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
101 Pool<Path> fnamePool = new Pool<Path>();
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 Pair<Nodeid, Nodeid> wcParents = repo.getWorkingCopyParents();
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 wcp1 = nodeidPool.unify(wcParents.first()); wcp2 = nodeidPool.unify(wcParents.second());
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 final File f = new File(repo.getRepositoryRoot(), "merge/state");
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 if (!f.canRead()) {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 // empty state
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 return;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 }
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
109 try {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
110 ArrayList<Entry> result = new ArrayList<Entry>();
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
111 // FIXME need to settle use of Pool<Path> and PathPool
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
112 // latter is pool that can create objects on demand, former is just cache
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
113 PathPool pathPool = new PathPool(new PathRewrite.Empty());
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
114 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
115 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
116 if (!wcp2.isNull()) {
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
117 final int rp2 = repo.getChangelog().getRevisionIndex(wcp2);
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
118 repo.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
119 }
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
120 BufferedReader br = new BufferedReader(new FileReader(f));
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
121 String s = br.readLine();
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
122 stateParent = nodeidPool.unify(Nodeid.fromAscii(s));
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
123 final int rp1 = repo.getChangelog().getRevisionIndex(stateParent);
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
124 repo.getManifest().walk(rp1, rp1, m1);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
125 while ((s = br.readLine()) != null) {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
126 String[] r = s.split("\\00");
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
127 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
128 Nodeid nidP1 = m1.nodeid(p1fname);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
129 Nodeid nidCA = nodeidPool.unify(Nodeid.fromAscii(r[5]));
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
130 HgFileRevision p1 = new HgFileRevision(repo, nidP1, p1fname);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
131 HgFileRevision ca;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
132 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
133 ca = p1;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
134 } else {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
135 ca = new HgFileRevision(repo, nidCA, 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
136 }
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
137 HgFileRevision p2;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
138 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
139 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
140 Nodeid nidP2 = m2.nodeid(p2fname);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
141 if (nidP2 == null) {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
142 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
143 nidP2 = NULL;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
144 }
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
145 p2 = new HgFileRevision(repo, nidP2, p2fname);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
146 } else {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
147 // 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
148 p2 = ca;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
149 }
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
150 final Kind k;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
151 if ("u".equals(r[1])) {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
152 k = Kind.Unresolved;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
153 } 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
154 k = Kind.Resolved;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
155 } else {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
156 throw new HgBadStateException(r[1]);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
157 }
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
158 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
159 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
160 }
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
161 entries = result.toArray(new Entry[result.size()]);
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
162 br.close();
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
163 pathPool.clear();
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
164 } catch (IOException ex) {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 341
diff changeset
165 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
166 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 }
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
168
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
169 /**
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
170 * 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
171 * 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
172 * 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
173 * @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
174 */
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
175 public boolean isMerging() {
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
176 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
177 }
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
178
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
179 /**
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
180 * 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
181 * 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
182 *
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
183 * @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
184 */
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
185 public boolean isStale() {
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
186 if (wcp1 == null) {
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
187 throw new HgBadStateException("Call #refresh() first");
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
188 }
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).
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
195 * @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
196 */
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 public Nodeid getFirstParent() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 if (wcp1 == null) {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 throw new HgBadStateException("Call #refresh() first");
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 return wcp1;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203
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
204 /**
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 * @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
206 */
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 public Nodeid getSecondParent() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 if (wcp2 == null) {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 throw new HgBadStateException("Call #refresh() first");
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 return wcp2;
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213
336
f74e36b7344b Do not fail with HgBadStateException when there are no merge state
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
214 /**
f74e36b7344b Do not fail with HgBadStateException when there are no merge state
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
215 * @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
216 */
270
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
217 public Nodeid getStateParent() {
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
218 if (stateParent == null) {
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
219 throw new HgBadStateException("Call #refresh() first");
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
220 }
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
221 return stateParent;
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
222 }
c6450b0b1fd5 Avoid IAE:nullid when looking into stale merge/state file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 249
diff changeset
223
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
224 /**
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
225 * List of conflicts as recorded in the merge state information file.
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
226 * Note, this information is valid unless {@link #isStale()} is <code>true</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
227 *
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
228 * @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
229 */
231
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 public List<Entry> getConflicts() {
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
231 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
232 }
1792b37650f2 Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
233 }