comparison src/org/tmatesoft/hg/repo/HgBundle.java @ 628:6526d8adbc0f

Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 22 May 2013 15:52:31 +0200
parents 5daa42067e7c
children 14dac192aa26
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
141 a6f39e595b2b54f56304470269a936ead77f5725 9429c7bd1920fab164a9d2b621d38d57bcb49ae0 30bd389788464287cee22ccff54c330a4b715de5 a6f39e595b2b54f56304470269a936ead77f5725; patches:3 141 a6f39e595b2b54f56304470269a936ead77f5725 9429c7bd1920fab164a9d2b621d38d57bcb49ae0 30bd389788464287cee22ccff54c330a4b715de5 a6f39e595b2b54f56304470269a936ead77f5725; patches:3
142 fd4f2c98995beb051070630c272a9be87bef617d 30bd389788464287cee22ccff54c330a4b715de5 0000000000000000000000000000000000000000 fd4f2c98995beb051070630c272a9be87bef617d; patches:3 142 fd4f2c98995beb051070630c272a9be87bef617d 30bd389788464287cee22ccff54c330a4b715de5 0000000000000000000000000000000000000000 fd4f2c98995beb051070630c272a9be87bef617d; patches:3
143 143
144 To recreate 30bd..e5, one have to take content of 9429..e0, not its p1 f1db..5e 144 To recreate 30bd..e5, one have to take content of 9429..e0, not its p1 f1db..5e
145 */ 145 */
146 public boolean element(GroupElement ge) { 146 public boolean element(GroupElement ge) throws HgRuntimeException {
147 emptyChangelog = false; 147 emptyChangelog = false;
148 HgChangelog changelog = hgRepo.getChangelog(); 148 HgChangelog changelog = hgRepo.getChangelog();
149 try { 149 try {
150 if (prevRevContent == null) { 150 if (prevRevContent == null) {
151 if (ge.firstParent().isNull() && ge.secondParent().isNull()) { 151 if (ge.firstParent().isNull() && ge.secondParent().isNull()) {
192 } 192 }
193 193
194 // callback to minimize amount of Strings and Nodeids instantiated 194 // callback to minimize amount of Strings and Nodeids instantiated
195 @Callback 195 @Callback
196 public interface Inspector { 196 public interface Inspector {
197 void changelogStart(); 197 void changelogStart() throws HgRuntimeException;
198 198
199 void changelogEnd(); 199 void changelogEnd() throws HgRuntimeException;
200 200
201 void manifestStart(); 201 void manifestStart() throws HgRuntimeException;
202 202
203 void manifestEnd(); 203 void manifestEnd() throws HgRuntimeException;
204 204
205 void fileStart(String name); 205 void fileStart(String name) throws HgRuntimeException;
206 206
207 void fileEnd(String name); 207 void fileEnd(String name) throws HgRuntimeException;
208 208
209 /** 209 /**
210 * XXX desperately need exceptions here 210 * XXX desperately need exceptions here
211 * @param element data element, instance might be reused, don't keep a reference to it or its raw data 211 * @param element data element, instance might be reused, don't keep a reference to it or its raw data
212 * @return <code>true</code> to continue 212 * @return <code>true</code> to continue
213 */ 213 */
214 boolean element(GroupElement element); 214 boolean element(GroupElement element) throws HgRuntimeException;
215 } 215 }
216 216
217 /** 217 /**
218 * @param inspector callback to visit changelog entries 218 * @param inspector callback to visit changelog entries
219 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> 219 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
353 lifecycle.finish(flowControl); 353 lifecycle.finish(flowControl);
354 } 354 }
355 flowControl = null; 355 flowControl = null;
356 } 356 }
357 357
358 private void internalInspectChangelog(DataAccess da, Inspector inspector) throws IOException { 358 private void internalInspectChangelog(DataAccess da, Inspector inspector) throws IOException, HgRuntimeException {
359 if (da.isEmpty()) { 359 if (da.isEmpty()) {
360 return; 360 return;
361 } 361 }
362 inspector.changelogStart(); 362 inspector.changelogStart();
363 if (flowControl.isStopped()) { 363 if (flowControl.isStopped()) {
368 return; 368 return;
369 } 369 }
370 inspector.changelogEnd(); 370 inspector.changelogEnd();
371 } 371 }
372 372
373 private void internalInspectManifest(DataAccess da, Inspector inspector) throws IOException { 373 private void internalInspectManifest(DataAccess da, Inspector inspector) throws IOException, HgRuntimeException {
374 if (da.isEmpty()) { 374 if (da.isEmpty()) {
375 return; 375 return;
376 } 376 }
377 inspector.manifestStart(); 377 inspector.manifestStart();
378 if (flowControl.isStopped()) { 378 if (flowControl.isStopped()) {
383 return; 383 return;
384 } 384 }
385 inspector.manifestEnd(); 385 inspector.manifestEnd();
386 } 386 }
387 387
388 private void internalInspectFiles(DataAccess da, Inspector inspector) throws IOException { 388 private void internalInspectFiles(DataAccess da, Inspector inspector) throws IOException, HgRuntimeException {
389 while (!da.isEmpty()) { 389 while (!da.isEmpty()) {
390 int fnameLen = da.readInt(); 390 int fnameLen = da.readInt();
391 if (fnameLen <= 4) { 391 if (fnameLen <= 4) {
392 break; // null chunk, the last one. 392 break; // null chunk, the last one.
393 } 393 }
404 } 404 }
405 inspector.fileEnd(name); 405 inspector.fileEnd(name);
406 } 406 }
407 } 407 }
408 408
409 private static void readGroup(DataAccess da, Inspector inspector) throws IOException { 409 private static void readGroup(DataAccess da, Inspector inspector) throws IOException, HgRuntimeException {
410 int len = da.readInt(); 410 int len = da.readInt();
411 boolean good2go = true; 411 boolean good2go = true;
412 Nodeid prevNodeid = Nodeid.NULL; 412 Nodeid prevNodeid = Nodeid.NULL;
413 while (len > 4 && !da.isEmpty() && good2go) { 413 while (len > 4 && !da.isEmpty() && good2go) {
414 byte[] nb = new byte[80]; 414 byte[] nb = new byte[80];