comparison src/org/tmatesoft/hg/internal/RevlogStream.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 99ad1e3a4e4d
children 1deea2f33218
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
34 import org.tmatesoft.hg.repo.HgInternals; 34 import org.tmatesoft.hg.repo.HgInternals;
35 import org.tmatesoft.hg.repo.HgInvalidControlFileException; 35 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
36 import org.tmatesoft.hg.repo.HgInvalidRevisionException; 36 import org.tmatesoft.hg.repo.HgInvalidRevisionException;
37 import org.tmatesoft.hg.repo.HgInvalidStateException; 37 import org.tmatesoft.hg.repo.HgInvalidStateException;
38 import org.tmatesoft.hg.repo.HgRepository; 38 import org.tmatesoft.hg.repo.HgRepository;
39 import org.tmatesoft.hg.repo.HgRuntimeException;
39 import org.tmatesoft.hg.util.Adaptable; 40 import org.tmatesoft.hg.util.Adaptable;
40 41
41 42
42 /** 43 /**
43 * ? Single RevlogStream per file per repository with accessor to record access session (e.g. with back/forward operations), 44 * ? Single RevlogStream per file per repository with accessor to record access session (e.g. with back/forward operations),
148 // system data under store/data) and system-only revlogs (like changelog and manifest), there's no 149 // system data under store/data) and system-only revlogs (like changelog and manifest), there's no
149 // easy way to supply human-friendly name of the active file (independent from whether it's index of data) 150 // easy way to supply human-friendly name of the active file (independent from whether it's index of data)
150 return inline ? indexFile.getPath() : getDataFile().getPath(); 151 return inline ? indexFile.getPath() : getDataFile().getPath();
151 } 152 }
152 153
153 public boolean isInlineData() { 154 public boolean isInlineData() throws HgInvalidControlFileException {
154 initOutline(); 155 initOutline();
155 return inline; 156 return inline;
156 } 157 }
157 158
158 public int revisionCount() { 159 public int revisionCount() throws HgInvalidControlFileException {
159 initOutline(); 160 initOutline();
160 return baseRevisions.length; 161 return baseRevisions.length;
161 } 162 }
162 163
163 /** 164 /**
269 270
270 /** 271 /**
271 * @return value suitable for the corresponding field in the new revision's header, not physical offset in the file 272 * @return value suitable for the corresponding field in the new revision's header, not physical offset in the file
272 * (which is different in case of inline revlogs) 273 * (which is different in case of inline revlogs)
273 */ 274 */
274 public long newEntryOffset() { 275 public long newEntryOffset() throws HgInvalidControlFileException {
275 if (revisionCount() == 0) { 276 if (revisionCount() == 0) {
276 return 0; 277 return 0;
277 } 278 }
278 DataAccess daIndex = getIndexStream(true); 279 DataAccess daIndex = getIndexStream(true);
279 int lastRev = revisionCount() - 1; 280 int lastRev = revisionCount() - 1;
289 } finally { 290 } finally {
290 daIndex.done(); 291 daIndex.done();
291 } 292 }
292 } 293 }
293 294
294 // should be possible to use TIP, ALL, or -1, -2, -n notation of Hg 295 /**
295 // ? boolean needsNodeid 296 * should be possible to use TIP, ALL, or -1, -2, -n notation of Hg
296 public void iterate(int start, int end, boolean needData, Inspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { 297 * ? boolean needsNodeid
298 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
299 */
300 public void iterate(int start, int end, boolean needData, Inspector inspector) throws HgRuntimeException {
297 initOutline(); 301 initOutline();
298 final int indexSize = revisionCount(); 302 final int indexSize = revisionCount();
299 if (indexSize == 0) { 303 if (indexSize == 0) {
300 return; 304 return;
301 } 305 }
324 * Effective alternative to {@link #iterate(int, int, boolean, Inspector) batch read}, when only few selected 328 * Effective alternative to {@link #iterate(int, int, boolean, Inspector) batch read}, when only few selected
325 * revisions are of interest. 329 * revisions are of interest.
326 * @param sortedRevisions revisions to walk, in ascending order. 330 * @param sortedRevisions revisions to walk, in ascending order.
327 * @param needData whether inspector needs access to header only 331 * @param needData whether inspector needs access to header only
328 * @param inspector callback to process entries 332 * @param inspector callback to process entries
329 */ 333 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
330 public void iterate(int[] sortedRevisions, boolean needData, Inspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException /*REVISIT - too general exception*/ { 334 */
335 public void iterate(int[] sortedRevisions, boolean needData, Inspector inspector) throws HgRuntimeException {
331 final int indexSize = revisionCount(); 336 final int indexSize = revisionCount();
332 if (indexSize == 0 || sortedRevisions.length == 0) { 337 if (indexSize == 0 || sortedRevisions.length == 0) {
333 return; 338 return;
334 } 339 }
335 if (sortedRevisions[0] > indexSize) { 340 if (sortedRevisions[0] > indexSize) {
440 */ 445 */
441 private int getIndexOffsetInt(int revisionIndex) { 446 private int getIndexOffsetInt(int revisionIndex) {
442 return inline ? indexRecordOffset[revisionIndex] : revisionIndex * REVLOGV1_RECORD_SIZE; 447 return inline ? indexRecordOffset[revisionIndex] : revisionIndex * REVLOGV1_RECORD_SIZE;
443 } 448 }
444 449
445 private int checkRevisionIndex(int revisionIndex) throws HgInvalidRevisionException { 450 private int checkRevisionIndex(int revisionIndex) throws HgInvalidControlFileException, HgInvalidRevisionException {
446 final int last = revisionCount() - 1; 451 final int last = revisionCount() - 1;
447 if (revisionIndex == TIP) { 452 if (revisionIndex == TIP) {
448 revisionIndex = last; 453 revisionIndex = last;
449 } 454 }
450 if (revisionIndex < 0 || revisionIndex > last) { 455 if (revisionIndex < 0 || revisionIndex > last) {
720 } 725 }
721 return userDataAccess; 726 return userDataAccess;
722 } 727 }
723 728
724 // may be invoked few times per instance life 729 // may be invoked few times per instance life
725 public boolean range(int start, int end) throws IOException { 730 public boolean range(int start, int end) throws IOException, HgRuntimeException {
726 int i; 731 int i;
727 // it (i.e. replace with i >= start) 732 // it (i.e. replace with i >= start)
728 if (needData && (i = getBaseRevision(start)) < start) { 733 if (needData && (i = getBaseRevision(start)) < start) {
729 // if lastRevisionRead in [baseRevision(start), start) can reuse lastUserData 734 // if lastRevisionRead in [baseRevision(start), start) can reuse lastUserData
730 // doesn't make sense to reuse if lastRevisionRead == start (too much to change in the cycle below). 735 // doesn't make sense to reuse if lastRevisionRead == start (too much to change in the cycle below).
848 * @param parent2Revision index of second parent revision in this revlog, or {@link HgRepository#NO_REVISION} 853 * @param parent2Revision index of second parent revision in this revlog, or {@link HgRepository#NO_REVISION}
849 * @param nodeid 20-byte buffer, shared between invocations 854 * @param nodeid 20-byte buffer, shared between invocations
850 * @param data access to revision content of actualLen size, or <code>null</code> if no data has been requested with 855 * @param data access to revision content of actualLen size, or <code>null</code> if no data has been requested with
851 * {@link RevlogStream#iterate(int[], boolean, Inspector)} 856 * {@link RevlogStream#iterate(int[], boolean, Inspector)}
852 */ 857 */
853 void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[/*20*/] nodeid, DataAccess data); 858 void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[/*20*/] nodeid, DataAccess data) throws HgRuntimeException;
854 } 859 }
855 860
856 public interface Observer { 861 public interface Observer {
857 // notify observer of invalidate/reload event in the stream 862 // notify observer of invalidate/reload event in the stream
858 public void reloaded(RevlogStream src); 863 public void reloaded(RevlogStream src);