comparison src/org/tmatesoft/hg/internal/RevlogStream.java @ 644:1deea2f33218

Push: phase1 - prepare bundle with changes
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 19 Jun 2013 16:04:24 +0200
parents 6526d8adbc0f
children bcbcc318f250
comparison
equal deleted inserted replaced
643:a8ce405da1f5 644:1deea2f33218
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.internal; 17 package org.tmatesoft.hg.internal;
18 18
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; 19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION;
20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; 21 import static org.tmatesoft.hg.repo.HgRepository.TIP;
21 import static org.tmatesoft.hg.internal.Internals.REVLOGV1_RECORD_SIZE; 22 import static org.tmatesoft.hg.internal.Internals.REVLOGV1_RECORD_SIZE;
22 23
23 import java.io.File; 24 import java.io.File;
24 import java.io.IOException; 25 import java.io.IOException;
232 * @throws HgInvalidRevisionException if revisionIndex argument doesn't represent a valid record in the revlog 233 * @throws HgInvalidRevisionException if revisionIndex argument doesn't represent a valid record in the revlog
233 */ 234 */
234 public int baseRevision(int revisionIndex) throws HgInvalidControlFileException, HgInvalidRevisionException { 235 public int baseRevision(int revisionIndex) throws HgInvalidControlFileException, HgInvalidRevisionException {
235 revisionIndex = checkRevisionIndex(revisionIndex); 236 revisionIndex = checkRevisionIndex(revisionIndex);
236 return getBaseRevision(revisionIndex); 237 return getBaseRevision(revisionIndex);
238 }
239
240 /**
241 * Read indexes of parent revisions
242 * @param revisionIndex index of child revision
243 * @param parents array to hold return value, length >= 2
244 * @return value of <code>parents</code> parameter for convenience
245 * @throws HgInvalidControlFileException if attempt to read index file failed
246 * @throws HgInvalidRevisionException if revisionIndex argument doesn't represent a valid record in the revlog
247 */
248 public int[] parents(int revisionIndex, int[] parents) throws HgInvalidControlFileException, HgInvalidRevisionException {
249 assert parents.length > 1;
250 revisionIndex = checkRevisionIndex(revisionIndex);
251 DataAccess daIndex = getIndexStream(true);
252 try {
253 int recordOffset = getIndexOffsetInt(revisionIndex);
254 daIndex.seek(recordOffset + 24);
255 int p1 = daIndex.readInt();
256 int p2 = daIndex.readInt();
257 // although NO_REVISION == -1, it doesn't hurt to ensure this
258 parents[0] = p1 == -1 ? NO_REVISION : p1;
259 parents[1] = p2 == -1 ? NO_REVISION : p2;
260 return parents;
261 } catch (IOException ex) {
262 throw new HgInvalidControlFileException("Parents lookup failed", ex, indexFile).setRevisionIndex(revisionIndex);
263 } finally {
264 daIndex.done();
265 }
237 } 266 }
238 267
239 // Perhaps, RevlogStream should be limited to use of plain int revisions for access, 268 // Perhaps, RevlogStream should be limited to use of plain int revisions for access,
240 // while Nodeids should be kept on the level up, in Revlog. Guess, Revlog better keep 269 // while Nodeids should be kept on the level up, in Revlog. Guess, Revlog better keep
241 // map of nodeids, and once this comes true, we may get rid of this method. 270 // map of nodeids, and once this comes true, we may get rid of this method.