comparison src/org/tmatesoft/hg/repo/Revlog.java @ 394:f52ca9530774 v0.8.0

Resolve FIXMEs: more consistent exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 22 Feb 2012 03:10:55 +0100
parents 728708de3597
children 2747b0723867
comparison
equal deleted inserted replaced
393:728708de3597 394:f52ca9530774
175 } 175 }
176 return true; 176 return true;
177 } 177 }
178 178
179 /** 179 /**
180 * Access to revision data as is (decompressed, but otherwise unprocessed, i.e. not parsed for e.g. changeset or manifest entries) 180 * Access to revision data as is, equivalent to <code>rawContent(getRevisionIndex(nodeid), sink)</code>
181 * @param nodeid 181 *
182 */ 182 * @param nodeid revision to retrieve
183 protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { 183 * @param sink data destination
184 *
185 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog
186 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
187 * @throws CancelledException if content retrieval operation was cancelled
188 *
189 * @see #rawContent(int, ByteChannel)
190 */
191 protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgInvalidControlFileException, CancelledException, HgInvalidRevisionException {
184 rawContent(getRevisionIndex(nodeid), sink); 192 rawContent(getRevisionIndex(nodeid), sink);
185 } 193 }
186 194
187 /** 195 /**
188 * @param fileRevisionIndex - index of this file change (not a changelog revision index), non-negative. From predefined constants, only {@link HgRepository#TIP} makes sense. 196 * Access to revision data as is (decompressed, but otherwise unprocessed, i.e. not parsed for e.g. changeset or manifest entries).
189 * FIXME is it necessary to have IOException along with HgException here? 197 *
190 */ 198 * @param fileRevisionIndex index of this revlog change (not a changelog revision index), non-negative. From predefined constants, only {@link HgRepository#TIP} makes sense.
191 protected void rawContent(int fileRevisionIndex, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { 199 * @param sink data destination
200 *
201 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog
202 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
203 * @throws CancelledException if content retrieval operation was cancelled
204 */
205 protected void rawContent(int fileRevisionIndex, ByteChannel sink) throws HgInvalidControlFileException, CancelledException, HgInvalidRevisionException {
192 if (sink == null) { 206 if (sink == null) {
193 throw new IllegalArgumentException(); 207 throw new IllegalArgumentException();
194 } 208 }
195 ContentPipe insp = new ContentPipe(sink, 0, repo.getContext().getLog()); 209 try {
196 insp.checkCancelled(); 210 ContentPipe insp = new ContentPipe(sink, 0, repo.getContext().getLog());
197 content.iterate(fileRevisionIndex, fileRevisionIndex, true, insp); 211 insp.checkCancelled();
198 insp.checkFailed(); 212 content.iterate(fileRevisionIndex, fileRevisionIndex, true, insp);
213 insp.checkFailed();
214 } catch (IOException ex) {
215 HgInvalidControlFileException e = new HgInvalidControlFileException(String.format("Access to revision %d content failed", fileRevisionIndex), ex, null);
216 e.setRevisionIndex(fileRevisionIndex);
217 // FIXME e.setFileName(content.getIndexFile() or this.getHumanFriendlyPath()) - shall decide whether
218 // protected abstract getPath() with impl in HgDataFile, HgManifest and HgChangelog or path is data of either Revlog or RevlogStream
219 // Do the same (add file name) below
220 throw e;
221 } catch (HgInvalidControlFileException ex) {
222 throw ex;
223 } catch (HgException ex) {
224 HgInvalidControlFileException e = new HgInvalidControlFileException(ex.getClass().getSimpleName(), ex, null);
225 e.setRevisionIndex(fileRevisionIndex);
226 throw e;
227 }
199 } 228 }
200 229
201 /** 230 /**
202 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query? 231 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query?
203 * 232 *
583 protected void recordFailure(Exception ex) { 612 protected void recordFailure(Exception ex) {
584 assert failure == null; 613 assert failure == null;
585 failure = ex; 614 failure = ex;
586 } 615 }
587 616
617 // TODO consider if IOException in addition to HgException is of any real utility
588 public void checkFailed() throws HgException, IOException, CancelledException { 618 public void checkFailed() throws HgException, IOException, CancelledException {
589 if (failure == null) { 619 if (failure == null) {
590 return; 620 return;
591 } 621 }
592 if (failure instanceof IOException) { 622 if (failure instanceof IOException) {