Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/RevlogStream.java @ 347:8da7ade36c57
Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 22 Nov 2011 05:25:57 +0100 |
parents | 694ebabb5cb3 |
children | 5f9073eabf06 |
comparison
equal
deleted
inserted
replaced
346:6d2c6b2469fc | 347:8da7ade36c57 |
---|---|
22 import java.io.File; | 22 import java.io.File; |
23 import java.io.IOException; | 23 import java.io.IOException; |
24 import java.util.zip.Inflater; | 24 import java.util.zip.Inflater; |
25 | 25 |
26 import org.tmatesoft.hg.core.HgBadStateException; | 26 import org.tmatesoft.hg.core.HgBadStateException; |
27 import org.tmatesoft.hg.core.HgInvalidRevisionException; | |
27 import org.tmatesoft.hg.core.Nodeid; | 28 import org.tmatesoft.hg.core.Nodeid; |
28 import org.tmatesoft.hg.repo.HgInternals; | 29 import org.tmatesoft.hg.repo.HgInternals; |
29 import org.tmatesoft.hg.repo.HgRepository; | 30 import org.tmatesoft.hg.repo.HgRepository; |
30 | 31 |
31 | 32 |
103 } | 104 } |
104 | 105 |
105 /** | 106 /** |
106 * @throws HgBadStateException if internal read operation failed | 107 * @throws HgBadStateException if internal read operation failed |
107 */ | 108 */ |
108 public byte[] nodeid(int revision) { | 109 public byte[] nodeid(int revision) throws HgInvalidRevisionException { |
109 final int indexSize = revisionCount(); | 110 final int indexSize = revisionCount(); |
110 if (revision == TIP) { | 111 if (revision == TIP) { |
111 revision = indexSize - 1; | 112 revision = indexSize - 1; |
112 } | 113 } |
113 if (revision < 0 || revision >= indexSize) { | 114 if (revision < 0 || revision >= indexSize) { |
114 throw new IllegalArgumentException(Integer.toString(revision)); | 115 throw new HgInvalidRevisionException(revision).setRevisionIndex(revision, 0, indexSize); |
115 } | 116 } |
116 DataAccess daIndex = getIndexStream(); | 117 DataAccess daIndex = getIndexStream(); |
117 try { | 118 try { |
118 int recordOffset = getIndexOffsetInt(revision); | 119 int recordOffset = getIndexOffsetInt(revision); |
119 daIndex.seek(recordOffset + 32); | 120 daIndex.seek(recordOffset + 32); |
189 | 190 |
190 private final int REVLOGV1_RECORD_SIZE = 64; | 191 private final int REVLOGV1_RECORD_SIZE = 64; |
191 | 192 |
192 // should be possible to use TIP, ALL, or -1, -2, -n notation of Hg | 193 // should be possible to use TIP, ALL, or -1, -2, -n notation of Hg |
193 // ? boolean needsNodeid | 194 // ? boolean needsNodeid |
194 public void iterate(int start, int end, boolean needData, Inspector inspector) { | 195 public void iterate(int start, int end, boolean needData, Inspector inspector) throws HgInvalidRevisionException { |
195 initOutline(); | 196 initOutline(); |
196 final int indexSize = revisionCount(); | 197 final int indexSize = revisionCount(); |
197 if (indexSize == 0) { | 198 if (indexSize == 0) { |
198 return; | 199 return; |
199 } | 200 } |
222 * revisions are of interest. | 223 * revisions are of interest. |
223 * @param sortedRevisions revisions to walk, in ascending order. | 224 * @param sortedRevisions revisions to walk, in ascending order. |
224 * @param needData whether inspector needs access to header only | 225 * @param needData whether inspector needs access to header only |
225 * @param inspector callback to process entries | 226 * @param inspector callback to process entries |
226 */ | 227 */ |
227 public void iterate(int[] sortedRevisions, boolean needData, Inspector inspector) { | 228 public void iterate(int[] sortedRevisions, boolean needData, Inspector inspector) throws HgInvalidRevisionException { |
228 final int indexSize = revisionCount(); | 229 final int indexSize = revisionCount(); |
229 if (indexSize == 0 || sortedRevisions.length == 0) { | 230 if (indexSize == 0 || sortedRevisions.length == 0) { |
230 return; | 231 return; |
231 } | 232 } |
232 if (sortedRevisions[0] > indexSize || sortedRevisions[sortedRevisions.length - 1] > indexSize) { | 233 if (sortedRevisions[0] > indexSize) { |
233 throw new IllegalArgumentException(String.format("Can't iterate [%d, %d] in range [0..%d]", sortedRevisions[0], sortedRevisions[sortedRevisions.length - 1], indexSize)); | 234 throw new HgInvalidRevisionException(String.format("Can't iterate [%d, %d] in range [0..%d]", sortedRevisions[0], sortedRevisions[sortedRevisions.length - 1], indexSize), null, sortedRevisions[0]); |
235 } | |
236 if (sortedRevisions[sortedRevisions.length - 1] > indexSize) { | |
237 throw new HgInvalidRevisionException(String.format("Can't iterate [%d, %d] in range [0..%d]", sortedRevisions[0], sortedRevisions[sortedRevisions.length - 1], indexSize), null, sortedRevisions[sortedRevisions.length - 1]); | |
234 } | 238 } |
235 | 239 |
236 ReaderN1 r = new ReaderN1(needData, inspector); | 240 ReaderN1 r = new ReaderN1(needData, inspector); |
237 try { | 241 try { |
238 r.start(sortedRevisions.length); | 242 r.start(sortedRevisions.length); |