Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgDataFile.java @ 366:189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Fri, 16 Dec 2011 04:43:18 +0100 |
| parents | f2c11fe7f3e9 |
| children | 2fadf8695f8a |
comparison
equal
deleted
inserted
replaced
| 365:3572fcb06473 | 366:189dc6dc1c3e |
|---|---|
| 125 * | 125 * |
| 126 * @param sink where to pipe content to | 126 * @param sink where to pipe content to |
| 127 * @throws HgDataStreamException to indicate troubles reading repository file | 127 * @throws HgDataStreamException to indicate troubles reading repository file |
| 128 * @throws CancelledException if operation was cancelled | 128 * @throws CancelledException if operation was cancelled |
| 129 */ | 129 */ |
| 130 public void workingCopy(ByteChannel sink) throws HgDataStreamException, CancelledException { | 130 public void workingCopy(ByteChannel sink) throws HgDataStreamException, HgInvalidControlFileException, CancelledException { |
| 131 File f = getRepo().getFile(this); | 131 File f = getRepo().getFile(this); |
| 132 if (f.exists()) { | 132 if (f.exists()) { |
| 133 final CancelSupport cs = CancelSupport.Factory.get(sink); | 133 final CancelSupport cs = CancelSupport.Factory.get(sink); |
| 134 final ProgressSupport progress = ProgressSupport.Factory.get(sink); | 134 final ProgressSupport progress = ProgressSupport.Factory.get(sink); |
| 135 final long flength = f.length(); | 135 final long flength = f.length(); |
| 188 // } while (left > 0); | 188 // } while (left > 0); |
| 189 // progressSupport.done(); // XXX shall specify whether #done() is invoked always or only if completed successfully. | 189 // progressSupport.done(); // XXX shall specify whether #done() is invoked always or only if completed successfully. |
| 190 // } | 190 // } |
| 191 | 191 |
| 192 /*XXX not sure distinct method contentWithFilters() is the best way to do, perhaps, callers shall add filters themselves?*/ | 192 /*XXX not sure distinct method contentWithFilters() is the best way to do, perhaps, callers shall add filters themselves?*/ |
| 193 public void contentWithFilters(int revision, ByteChannel sink) throws HgDataStreamException, CancelledException, HgInvalidRevisionException { | 193 public void contentWithFilters(int revision, ByteChannel sink) throws HgDataStreamException, HgInvalidControlFileException, CancelledException, HgInvalidRevisionException { |
| 194 if (revision == WORKING_COPY) { | 194 if (revision == WORKING_COPY) { |
| 195 workingCopy(sink); // pass un-mangled sink | 195 workingCopy(sink); // pass un-mangled sink |
| 196 } else { | 196 } else { |
| 197 content(revision, new FilterByteChannel(sink, getRepo().getFiltersFromRepoToWorkingDir(getPath()))); | 197 content(revision, new FilterByteChannel(sink, getRepo().getFiltersFromRepoToWorkingDir(getPath()))); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 // for data files need to check heading of the file content for possible metadata | 201 // for data files need to check heading of the file content for possible metadata |
| 202 // @see http://mercurial.selenic.com/wiki/FileFormats#data.2BAC8- | 202 // @see http://mercurial.selenic.com/wiki/FileFormats#data.2BAC8- |
| 203 public void content(int revision, ByteChannel sink) throws HgDataStreamException, CancelledException, HgInvalidRevisionException { | 203 public void content(int revision, ByteChannel sink) throws HgDataStreamException, HgInvalidControlFileException, CancelledException, HgInvalidRevisionException { |
| 204 if (revision == TIP) { | 204 if (revision == TIP) { |
| 205 revision = getLastRevision(); | 205 revision = getLastRevision(); |
| 206 } | 206 } |
| 207 if (revision == WORKING_COPY) { | 207 if (revision == WORKING_COPY) { |
| 208 // sink is supposed to come into workingCopy without filters | 208 // sink is supposed to come into workingCopy without filters |
| 275 | 275 |
| 276 /** | 276 /** |
| 277 * @deprecated use {@link HgLogCommand#execute(org.tmatesoft.hg.core.HgChangesetTreeHandler)} instead | 277 * @deprecated use {@link HgLogCommand#execute(org.tmatesoft.hg.core.HgChangesetTreeHandler)} instead |
| 278 */ | 278 */ |
| 279 @Deprecated | 279 @Deprecated |
| 280 public void history(HgChangelog.TreeInspector inspector) { | 280 public void history(HgChangelog.TreeInspector inspector) throws HgInvalidControlFileException{ |
| 281 final CancelSupport cancelSupport = CancelSupport.Factory.get(inspector); | 281 final CancelSupport cancelSupport = CancelSupport.Factory.get(inspector); |
| 282 try { | 282 try { |
| 283 final boolean[] needsSorting = { false }; | 283 final boolean[] needsSorting = { false }; |
| 284 final HistoryNode[] completeHistory = new HistoryNode[getRevisionCount()]; | 284 final HistoryNode[] completeHistory = new HistoryNode[getRevisionCount()]; |
| 285 final int[] commitRevisions = new int[completeHistory.length]; | 285 final int[] commitRevisions = new int[completeHistory.length]; |
| 357 } catch (CancelledException ex) { | 357 } catch (CancelledException ex) { |
| 358 return; | 358 return; |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 public void history(HgChangelog.Inspector inspector) { | 362 public void history(HgChangelog.Inspector inspector) throws HgInvalidControlFileException { |
| 363 history(0, getLastRevision(), inspector); | 363 history(0, getLastRevision(), inspector); |
| 364 } | 364 } |
| 365 | 365 |
| 366 public void history(int start, int end, HgChangelog.Inspector inspector) throws HgInvalidRevisionException { | 366 public void history(int start, int end, HgChangelog.Inspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { |
| 367 if (!exists()) { | 367 if (!exists()) { |
| 368 throw new IllegalStateException("Can't get history of invalid repository file node"); | 368 throw new IllegalStateException("Can't get history of invalid repository file node"); |
| 369 } | 369 } |
| 370 final int last = getLastRevision(); | 370 final int last = getLastRevision(); |
| 371 if (end == TIP) { | 371 if (end == TIP) { |
| 482 throw new CancelledException(); | 482 throw new CancelledException(); |
| 483 } | 483 } |
| 484 }); | 484 }); |
| 485 } catch (CancelledException ex) { | 485 } catch (CancelledException ex) { |
| 486 // it's ok, we did that | 486 // it's ok, we did that |
| 487 } catch (HgInvalidControlFileException ex) { | |
| 488 throw new HgDataStreamException(getPath(), ex); | |
| 487 } | 489 } |
| 488 } | 490 } |
| 489 | 491 |
| 490 private static final class MetadataEntry { | 492 private static final class MetadataEntry { |
| 491 private final String entry; | 493 private final String entry; |
| 579 fname = file; | 581 fname = file; |
| 580 delegate = chain; | 582 delegate = chain; |
| 581 setCancelSupport(CancelSupport.Factory.get(chain)); | 583 setCancelSupport(CancelSupport.Factory.get(chain)); |
| 582 } | 584 } |
| 583 | 585 |
| 584 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { | 586 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) throws HgException { |
| 585 try { | 587 try { |
| 586 final int daLength = data.length(); | 588 final int daLength = data.length(); |
| 587 if (daLength < 4 || data.readByte() != 1 || data.readByte() != 10) { | 589 if (daLength < 4 || data.readByte() != 1 || data.readByte() != 10) { |
| 588 metadata.recordNone(revisionNumber); | 590 metadata.recordNone(revisionNumber); |
| 589 data.reset(); | 591 data.reset(); |
