comparison src/org/tmatesoft/hg/repo/HgChangelog.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 46f29b73e51e
children a937e63b6e02
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
51 51
52 /* package-local */HgChangelog(HgRepository hgRepo, RevlogStream content) { 52 /* package-local */HgChangelog(HgRepository hgRepo, RevlogStream content) {
53 super(hgRepo, content, true); 53 super(hgRepo, content, true);
54 } 54 }
55 55
56 public void all(final HgChangelog.Inspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { 56 /**
57 * Iterate over whole changelog
58 * @param inspector callback to process entries
59 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
60 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
61 */
62 public void all(final HgChangelog.Inspector inspector) throws HgRuntimeException {
57 range(0, getLastRevision(), inspector); 63 range(0, getLastRevision(), inspector);
58 } 64 }
59 65
60 public void range(int start, int end, final HgChangelog.Inspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { 66 /**
67 * Iterate over changelog part
68 * @param start first changelog entry to process
69 * @param end last changelog entry to process
70 * @param inspector callback to process entries
71 * @throws HgInvalidRevisionException if any supplied revision doesn't identify revision from this revlog. <em>Runtime exception</em>
72 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
73 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
74 */
75 public void range(int start, int end, final HgChangelog.Inspector inspector) throws HgRuntimeException {
61 if (inspector == null) { 76 if (inspector == null) {
62 throw new IllegalArgumentException(); 77 throw new IllegalArgumentException();
63 } 78 }
64 content.iterate(start, end, true, new RawCsetParser(inspector)); 79 content.iterate(start, end, true, new RawCsetParser(inspector));
65 } 80 }
66 81
67 public List<RawChangeset> range(int start, int end) throws HgInvalidRevisionException, HgInvalidControlFileException { 82 /**
83 * @see #range(int, int, Inspector)
84 * @return changeset entry objects, never <code>null</code>
85 * @throws HgInvalidRevisionException if any supplied revision doesn't identify revision from this revlog. <em>Runtime exception</em>
86 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
87 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
88 */
89 public List<RawChangeset> range(int start, int end) throws HgRuntimeException {
68 final RawCsetCollector c = new RawCsetCollector(end - start + 1); 90 final RawCsetCollector c = new RawCsetCollector(end - start + 1);
69 range(start, end, c); 91 range(start, end, c);
70 return c.result; 92 return c.result;
71 } 93 }
72 94
73 /** 95 /**
74 * Access individual revisions. Note, regardless of supplied revision order, inspector gets 96 * Access individual revisions. Note, regardless of supplied revision order, inspector gets
75 * changesets strictly in the order they are in the changelog. 97 * changesets strictly in the order they are in the changelog.
76 * @param inspector callback to get changesets 98 * @param inspector callback to get changesets
77 * @param revisions revisions to read, unrestricted ordering. 99 * @param revisions revisions to read, unrestricted ordering.
78 */ 100 * @throws HgInvalidRevisionException if any supplied revision doesn't identify revision from this revlog <em>Runtime exception</em>
79 public void range(final HgChangelog.Inspector inspector, final int... revisions) throws HgInvalidRevisionException, HgInvalidControlFileException { 101 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
102 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
103 */
104 public void range(final HgChangelog.Inspector inspector, final int... revisions) throws HgRuntimeException {
80 Arrays.sort(revisions); 105 Arrays.sort(revisions);
81 rangeInternal(inspector, revisions); 106 rangeInternal(inspector, revisions);
82 } 107 }
83 108
84 /** 109 /**
85 * Friends-only version of {@link #range(Inspector, int...)}, when callers know array is sorted 110 * Friends-only version of {@link #range(Inspector, int...)}, when callers know array is sorted
86 */ 111 */
87 /*package-local*/ void rangeInternal(HgChangelog.Inspector inspector, int[] sortedRevisions) throws HgInvalidRevisionException, HgInvalidControlFileException { 112 /*package-local*/ void rangeInternal(HgChangelog.Inspector inspector, int[] sortedRevisions) throws HgRuntimeException {
88 if (sortedRevisions == null || sortedRevisions.length == 0) { 113 if (sortedRevisions == null || sortedRevisions.length == 0) {
89 return; 114 return;
90 } 115 }
91 if (inspector == null) { 116 if (inspector == null) {
92 throw new IllegalArgumentException(); 117 throw new IllegalArgumentException();
93 } 118 }
94 content.iterate(sortedRevisions, true, new RawCsetParser(inspector)); 119 content.iterate(sortedRevisions, true, new RawCsetParser(inspector));
95 } 120 }
96 121
97 /** 122 /**
98 * @throws HgInvalidRevisionException if supplied nodeid doesn't identify any revision from this revlog 123 * Get changeset entry object
99 * @throws HgInvalidControlFileException if access to revlog index/data entry failed 124 * @throws HgInvalidRevisionException if supplied nodeid doesn't identify any revision from this revlog. <em>Runtime exception</em>
100 */ 125 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em>
101 public RawChangeset changeset(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { 126 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em>
127 */
128 public RawChangeset changeset(Nodeid nid) throws HgRuntimeException {
102 int x = getRevisionIndex(nid); 129 int x = getRevisionIndex(nid);
103 return range(x, x).get(0); 130 return range(x, x).get(0);
104 } 131 }
105 132
106 @Callback 133 @Callback
111 * 138 *
112 * @param revisionIndex index of revision being inspected, local to the inspected object 139 * @param revisionIndex index of revision being inspected, local to the inspected object
113 * @param nodeid revision being inspected 140 * @param nodeid revision being inspected
114 * @param cset changeset raw data 141 * @param cset changeset raw data
115 */ 142 */
116 void next(int revisionIndex, Nodeid nodeid, RawChangeset cset); 143 void next(int revisionIndex, Nodeid nodeid, RawChangeset cset) throws HgRuntimeException;
117 } 144 }
118 145
119 /** 146 /**
120 * Entry in the Changelog 147 * Entry in the Changelog
121 */ 148 */
394 } else { 421 } else {
395 lifecycleStub = null; 422 lifecycleStub = null;
396 } 423 }
397 } 424 }
398 425
399 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { 426 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) throws HgRuntimeException {
400 try { 427 try {
401 byte[] data = da.byteArray(); 428 byte[] data = da.byteArray();
402 cset.init(data, 0, data.length, usersPool); 429 cset.init(data, 0, data.length, usersPool);
403 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse 430 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse
404 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); 431 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset);