comparison src/org/tmatesoft/hg/repo/HgMergeState.java @ 336:f74e36b7344b

Do not fail with HgBadStateException when there are no merge state
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 11 Nov 2011 05:56:09 +0100
parents 6dbbc53fc46d
children 75c452fdd76a
comparison
equal deleted inserted replaced
335:3d41dc148d14 336:f74e36b7344b
91 repo = hgRepo; 91 repo = hgRepo;
92 } 92 }
93 93
94 public void refresh() throws IOException/*XXX it's unlikely caller can do anything reasonable about IOException */ { 94 public void refresh() throws IOException/*XXX it's unlikely caller can do anything reasonable about IOException */ {
95 entries = null; 95 entries = null;
96 wcp1 = wcp2 = stateParent = Nodeid.NULL;
96 final File f = new File(repo.getRepositoryRoot(), "merge/state"); 97 final File f = new File(repo.getRepositoryRoot(), "merge/state");
97 if (!f.canRead()) { 98 if (!f.canRead()) {
98 // empty state 99 // empty state
99 return; 100 return;
100 } 101 }
170 if (wcp1 == null) { 171 if (wcp1 == null) {
171 throw new HgBadStateException("Call #refresh() first"); 172 throw new HgBadStateException("Call #refresh() first");
172 } 173 }
173 return !wcp1.equals(stateParent); 174 return !wcp1.equals(stateParent);
174 } 175 }
175 176
177 /**
178 * FIXME decide what to return if there's no merge state altogether (perhaps, separate method to check that)
179 * @return never <code>null</code>
180 */
176 public Nodeid getFirstParent() { 181 public Nodeid getFirstParent() {
177 if (wcp1 == null) { 182 if (wcp1 == null) {
178 throw new HgBadStateException("Call #refresh() first"); 183 throw new HgBadStateException("Call #refresh() first");
179 } 184 }
180 return wcp1; 185 return wcp1;
185 throw new HgBadStateException("Call #refresh() first"); 190 throw new HgBadStateException("Call #refresh() first");
186 } 191 }
187 return wcp2; 192 return wcp2;
188 } 193 }
189 194
195 /**
196 * @return revision of the merge state or {@link Nodeid#NULL} if there's no merge state
197 */
190 public Nodeid getStateParent() { 198 public Nodeid getStateParent() {
191 if (stateParent == null) { 199 if (stateParent == null) {
192 throw new HgBadStateException("Call #refresh() first"); 200 throw new HgBadStateException("Call #refresh() first");
193 } 201 }
194 return stateParent; 202 return stateParent;