comparison src/org/tmatesoft/hg/core/HgStatusCommand.java @ 360:150500515714

Report non-critical errors during status operation to handler/inspector
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 08 Dec 2011 22:19:27 +0100
parents 33eaed1ad130
children 2fadf8695f8a
comparison
equal deleted inserted replaced
359:1d9bcab9c50f 360:150500515714
28 import org.tmatesoft.hg.repo.HgRepository; 28 import org.tmatesoft.hg.repo.HgRepository;
29 import org.tmatesoft.hg.repo.HgStatusCollector; 29 import org.tmatesoft.hg.repo.HgStatusCollector;
30 import org.tmatesoft.hg.repo.HgStatusInspector; 30 import org.tmatesoft.hg.repo.HgStatusInspector;
31 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; 31 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector;
32 import org.tmatesoft.hg.util.Path; 32 import org.tmatesoft.hg.util.Path;
33 import org.tmatesoft.hg.util.Status;
33 34
34 /** 35 /**
35 * Command to obtain file status information, 'hg status' counterpart. 36 * Command to obtain file status information, 'hg status' counterpart.
36 * 37 *
37 * @author Artem Tikhomirov 38 * @author Artem Tikhomirov
162 * @param handler callback to get status information 163 * @param handler callback to get status information
163 * @throws IOException if there are (further unspecified) errors while walking working copy 164 * @throws IOException if there are (further unspecified) errors while walking working copy
164 * @throws IllegalArgumentException if handler is <code>null</code> 165 * @throws IllegalArgumentException if handler is <code>null</code>
165 * @throws ConcurrentModificationException if this command already runs (i.e. being used from another thread) 166 * @throws ConcurrentModificationException if this command already runs (i.e. being used from another thread)
166 */ 167 */
167 public void execute(Handler statusHandler) throws CancellationException, HgException, IOException { 168 public void execute(HgStatusHandler statusHandler) throws CancellationException, HgException, IOException {
168 if (statusHandler == null) { 169 if (statusHandler == null) {
169 throw new IllegalArgumentException(); 170 throw new IllegalArgumentException();
170 } 171 }
171 if (mediator.busy()) { 172 if (mediator.busy()) {
172 throw new ConcurrentModificationException(); 173 throw new ConcurrentModificationException();
187 sc.change(endRevision, mediator); 188 sc.change(endRevision, mediator);
188 } else { 189 } else {
189 sc.walk(startRevision, endRevision, mediator); 190 sc.walk(startRevision, endRevision, mediator);
190 } 191 }
191 } 192 }
193 } catch (HgCallbackTargetException.Wrap ex) {
194 // seems too general to catch RuntimeException, i.e.
195 // unless catch is for very narrow piece of code, it's better not to catch any RTE (which may happen elsewhere, not only in handler)
196 // XXX Perhaps, need more detailed explanation in handlers that are expected to throw Wrap/RTE (i.e. HgChangesetHandler)
197 throw new HgCallbackTargetException(ex).setRevisionNumber(endRevision);
192 } finally { 198 } finally {
193 mediator.done(); 199 mediator.done();
194 } 200 }
195 } 201 }
196 202
197 public interface Handler { 203 /**
204 * @deprecated replaced with {@link HgStatusHandler}
205 */
206 @Deprecated
207 public interface Handler extends HgStatusHandler{
198 void handleStatus(HgStatus s); 208 void handleStatus(HgStatus s);
199 } 209 }
200 210
201 private class Mediator implements HgStatusInspector { 211 private class Mediator implements HgStatusInspector {
202 boolean needModified; 212 boolean needModified;
205 boolean needUnknown; 215 boolean needUnknown;
206 boolean needMissing; 216 boolean needMissing;
207 boolean needClean; 217 boolean needClean;
208 boolean needIgnored; 218 boolean needIgnored;
209 boolean needCopies; 219 boolean needCopies;
210 Handler handler; 220 HgStatusHandler handler;
211 private ChangelogHelper logHelper; 221 private ChangelogHelper logHelper;
212 222
213 Mediator() { 223 Mediator() {
214 } 224 }
215 225
216 public void start(Handler h, ChangelogHelper changelogHelper) { 226 public void start(HgStatusHandler h, ChangelogHelper changelogHelper) {
217 handler = h; 227 handler = h;
218 logHelper = changelogHelper; 228 logHelper = changelogHelper;
219 } 229 }
220 230
221 public void done() { 231 public void done() {
266 public void ignored(Path fname) { 276 public void ignored(Path fname) {
267 if (needIgnored) { 277 if (needIgnored) {
268 handler.handleStatus(new HgStatus(Ignored, fname, logHelper)); 278 handler.handleStatus(new HgStatus(Ignored, fname, logHelper));
269 } 279 }
270 } 280 }
281
282 public void invalid(Path fname, Exception ex) {
283 handler.handleError(fname, new Status(Status.Kind.ERROR, "Failed to get file status", ex));
284 }
271 } 285 }
272 } 286 }