comparison src/org/tmatesoft/hg/repo/HgMergeState.java @ 423:9c9c442b5f2e

Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 23 Mar 2012 22:51:18 +0100
parents ee8264d80747
children 12f668401613
comparison
equal deleted inserted replaced
422:5d1cc7366d04 423:9c9c442b5f2e
25 import java.util.ArrayList; 25 import java.util.ArrayList;
26 import java.util.Arrays; 26 import java.util.Arrays;
27 import java.util.Collections; 27 import java.util.Collections;
28 import java.util.List; 28 import java.util.List;
29 29
30 import org.tmatesoft.hg.core.HgBadStateException;
31 import org.tmatesoft.hg.core.HgFileRevision; 30 import org.tmatesoft.hg.core.HgFileRevision;
32 import org.tmatesoft.hg.core.HgInvalidControlFileException;
33 import org.tmatesoft.hg.core.Nodeid; 31 import org.tmatesoft.hg.core.Nodeid;
34 import org.tmatesoft.hg.internal.ManifestRevision; 32 import org.tmatesoft.hg.internal.ManifestRevision;
35 import org.tmatesoft.hg.internal.Pool; 33 import org.tmatesoft.hg.internal.Pool;
36 import org.tmatesoft.hg.util.Pair; 34 import org.tmatesoft.hg.util.Pair;
37 import org.tmatesoft.hg.util.Path; 35 import org.tmatesoft.hg.util.Path;
38 import org.tmatesoft.hg.util.PathPool; 36 import org.tmatesoft.hg.util.PathPool;
39 import org.tmatesoft.hg.util.PathRewrite; 37 import org.tmatesoft.hg.util.PathRewrite;
40 38
41 /** 39 /**
42 * 40 * Access to repository's merge state
41 *
43 * @author Artem Tikhomirov 42 * @author Artem Tikhomirov
44 * @author TMate Software Ltd. 43 * @author TMate Software Ltd.
45 */ 44 */
46 public class HgMergeState { 45 public class HgMergeState {
47 private Nodeid wcp1, wcp2, stateParent; 46 private Nodeid wcp1, wcp2, stateParent;
90 89
91 HgMergeState(HgRepository hgRepo) { 90 HgMergeState(HgRepository hgRepo) {
92 repo = hgRepo; 91 repo = hgRepo;
93 } 92 }
94 93
95 public void refresh() throws HgInvalidControlFileException { 94 /**
95 * Update our knowledge about repository's merge state
96 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
97 */
98 public void refresh() throws HgRuntimeException {
96 entries = null; 99 entries = null;
97 // it's possible there are two parents but no merge/state, we shall report this case as 'merging', with proper 100 // it's possible there are two parents but no merge/state, we shall report this case as 'merging', with proper
98 // first and second parent values 101 // first and second parent values
99 stateParent = Nodeid.NULL; 102 stateParent = Nodeid.NULL;
100 Pool<Nodeid> nodeidPool = new Pool<Nodeid>(); 103 Pool<Nodeid> nodeidPool = new Pool<Nodeid>();
151 if ("u".equals(r[1])) { 154 if ("u".equals(r[1])) {
152 k = Kind.Unresolved; 155 k = Kind.Unresolved;
153 } else if ("r".equals(r[1])) { 156 } else if ("r".equals(r[1])) {
154 k = Kind.Resolved; 157 k = Kind.Resolved;
155 } else { 158 } else {
156 throw new HgBadStateException(r[1]); 159 throw new HgInvalidStateException(String.format("Unknown merge kind %s", r[1]));
157 } 160 }
158 Entry e = new Entry(k, pathPool.path(r[0]), p1, p2, ca); 161 Entry e = new Entry(k, pathPool.path(r[0]), p1, p2, ca);
159 result.add(e); 162 result.add(e);
160 } 163 }
161 entries = result.toArray(new Entry[result.size()]); 164 entries = result.toArray(new Entry[result.size()]);
182 * 185 *
183 * @return <code>true</code> when recorded merge state doesn't seem to correspond to present working copy 186 * @return <code>true</code> when recorded merge state doesn't seem to correspond to present working copy
184 */ 187 */
185 public boolean isStale() { 188 public boolean isStale() {
186 if (wcp1 == null) { 189 if (wcp1 == null) {
187 throw new HgBadStateException("Call #refresh() first"); 190 refresh();
188 } 191 }
189 return !stateParent.isNull() /*there's merge state*/ && !wcp1.equals(stateParent) /*and it doesn't match*/; 192 return !stateParent.isNull() /*there's merge state*/ && !wcp1.equals(stateParent) /*and it doesn't match*/;
190 } 193 }
191 194
192 /** 195 /**
193 * It's possible for a repository to be in a 'merging' state (@see {@link #isMerging()} without any 196 * It's possible for a repository to be in a 'merging' state (@see {@link #isMerging()} without any
194 * conflict to resolve (no merge state information file). 197 * conflict to resolve (no merge state information file).
198 *
195 * @return first parent of the working copy, never <code>null</code> 199 * @return first parent of the working copy, never <code>null</code>
196 */ 200 */
197 public Nodeid getFirstParent() { 201 public Nodeid getFirstParent() {
198 if (wcp1 == null) { 202 if (wcp1 == null) {
199 throw new HgBadStateException("Call #refresh() first"); 203 refresh();
200 } 204 }
201 return wcp1; 205 return wcp1;
202 } 206 }
203 207
204 /** 208 /**
205 * @return second parent of the working copy, never <code>null</code> 209 * @return second parent of the working copy, never <code>null</code>
206 */ 210 */
207 public Nodeid getSecondParent() { 211 public Nodeid getSecondParent() {
208 if (wcp2 == null) { 212 if (wcp2 == null) {
209 throw new HgBadStateException("Call #refresh() first"); 213 refresh();
210 } 214 }
211 return wcp2; 215 return wcp2;
212 } 216 }
213 217
214 /** 218 /**
215 * @return revision of the merge state or {@link Nodeid#NULL} if there's no merge state 219 * @return revision of the merge state or {@link Nodeid#NULL} if there's no merge state
216 */ 220 */
217 public Nodeid getStateParent() { 221 public Nodeid getStateParent() {
218 if (stateParent == null) { 222 if (stateParent == null) {
219 throw new HgBadStateException("Call #refresh() first"); 223 refresh();
220 } 224 }
221 return stateParent; 225 return stateParent;
222 } 226 }
223 227
224 /** 228 /**