comparison src/org/tmatesoft/hg/internal/RevlogStreamWriter.java @ 664:ae2d439fbed3

Utilize transaction when writing fncache. Better HgIOException
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 10 Jul 2013 19:33:51 +0200
parents 46b56864b483
children 545b1d4cc11d
comparison
equal deleted inserted replaced
663:46b56864b483 664:ae2d439fbed3
18 18
19 import static org.tmatesoft.hg.internal.Internals.REVLOGV1_RECORD_SIZE; 19 import static org.tmatesoft.hg.internal.Internals.REVLOGV1_RECORD_SIZE;
20 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; 20 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION;
21 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; 21 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
22 22
23 import java.io.File;
24 import java.io.IOException; 23 import java.io.IOException;
25 import java.nio.ByteBuffer; 24 import java.nio.ByteBuffer;
26 25
27 import org.tmatesoft.hg.core.HgIOException; 26 import org.tmatesoft.hg.core.HgIOException;
28 import org.tmatesoft.hg.core.Nodeid; 27 import org.tmatesoft.hg.core.Nodeid;
30 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSource; 29 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSource;
31 import org.tmatesoft.hg.internal.DataSerializer.ByteArraySerializer; 30 import org.tmatesoft.hg.internal.DataSerializer.ByteArraySerializer;
32 import org.tmatesoft.hg.internal.DataSerializer.DataSource; 31 import org.tmatesoft.hg.internal.DataSerializer.DataSource;
33 import org.tmatesoft.hg.repo.HgBundle.GroupElement; 32 import org.tmatesoft.hg.repo.HgBundle.GroupElement;
34 import org.tmatesoft.hg.repo.HgInvalidControlFileException; 33 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
34 import org.tmatesoft.hg.repo.HgInvalidDataFormatException;
35 import org.tmatesoft.hg.repo.HgInvalidRevisionException; 35 import org.tmatesoft.hg.repo.HgInvalidRevisionException;
36 import org.tmatesoft.hg.repo.HgInvalidStateException; 36 import org.tmatesoft.hg.repo.HgInvalidStateException;
37 import org.tmatesoft.hg.repo.HgRepository; 37 import org.tmatesoft.hg.repo.HgRepository;
38 import org.tmatesoft.hg.repo.HgRuntimeException; 38 import org.tmatesoft.hg.repo.HgRuntimeException;
39 import org.tmatesoft.hg.util.Pair; 39 import org.tmatesoft.hg.util.Pair;
124 } 124 }
125 ds = new ByteArrayDataSource(complete); 125 ds = new ByteArrayDataSource(complete);
126 revLen = complete.length; 126 revLen = complete.length;
127 } catch (IOException ex) { 127 } catch (IOException ex) {
128 // unlikely to happen, as ByteArrayDataSource throws IOException only in case of programming errors 128 // unlikely to happen, as ByteArrayDataSource throws IOException only in case of programming errors
129 // FIXME next approach to get indexFile is awful: 129 // hence, throwing rt exception here makes more sense here than HgIOException (even that latter is in throws)
130 File indexFile = revlogStream.initWithIndexFile(new HgInvalidControlFileException("", ex, null)).getFile(); 130 throw new HgInvalidDataFormatException("Failed to reconstruct revision", ex);
131 throw new HgIOException("Failed to reconstruct revision", ex, indexFile);
132 } 131 }
133 } 132 }
134 doAdd(nodeRev, p1, p2, linkRev, baseRev, revLen, ds); 133 doAdd(nodeRev, p1, p2, linkRev, baseRev, revLen, ds);
135 if (complete != null) { 134 if (complete != null) {
136 lastFullContent = new Pair<Integer, byte[]>(lastEntryIndex, complete); 135 lastFullContent = new Pair<Integer, byte[]>(lastEntryIndex, complete);
262 private void populateLastEntryIndex() throws HgRuntimeException { 261 private void populateLastEntryIndex() throws HgRuntimeException {
263 int revCount = revlogStream.revisionCount(); 262 int revCount = revlogStream.revisionCount();
264 lastEntryIndex = revCount == 0 ? NO_REVISION : revCount - 1; 263 lastEntryIndex = revCount == 0 ? NO_REVISION : revCount - 1;
265 } 264 }
266 265
267 private void populateLastEntryContent() throws HgRuntimeException { 266 private void populateLastEntryContent() throws HgIOException, HgRuntimeException {
268 if (lastFullContent != null && lastFullContent.first() == lastEntryIndex) { 267 if (lastFullContent != null && lastFullContent.first() == lastEntryIndex) {
269 // we have last entry cached 268 // we have last entry cached
270 return; 269 return;
271 } 270 }
272 lastEntryRevision = Nodeid.NULL; 271 lastEntryRevision = Nodeid.NULL;
399 public int baseRev; 398 public int baseRev;
400 public Nodeid rev; 399 public Nodeid rev;
401 public byte[] content; 400 public byte[] content;
402 private IOException failure; 401 private IOException failure;
403 402
404 public ReadContentInspector read(RevlogStream rs, int revIndex) throws HgInvalidControlFileException { 403 public ReadContentInspector read(RevlogStream rs, int revIndex) throws HgIOException, HgRuntimeException {
405 assert revIndex >= 0; 404 assert revIndex >= 0;
406 rs.iterate(revIndex, revIndex, true, this); 405 rs.iterate(revIndex, revIndex, true, this);
407 if (failure != null) { 406 if (failure != null) {
408 String m = String.format("Failed to get content of revision %d", revIndex); 407 String m = String.format("Failed to get content of revision %d", revIndex);
409 throw rs.initWithDataFile(new HgInvalidControlFileException(m, failure, null)); 408 throw rs.initWithIndexFile(new HgIOException(m, failure, null));
410 } 409 }
411 return this; 410 return this;
412 } 411 }
413 412
414 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { 413 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) {