Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RevlogStreamWriter.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 | 7c0d2ce340b8 |
| children | 14dac192aa26 |
comparison
equal
deleted
inserted
replaced
| 627:5153eb73b18d | 628:6526d8adbc0f |
|---|---|
| 27 import org.tmatesoft.hg.core.SessionContext; | 27 import org.tmatesoft.hg.core.SessionContext; |
| 28 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSerializer; | 28 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSerializer; |
| 29 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSource; | 29 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSource; |
| 30 import org.tmatesoft.hg.internal.DataSerializer.DataSource; | 30 import org.tmatesoft.hg.internal.DataSerializer.DataSource; |
| 31 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | 31 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
| 32 import org.tmatesoft.hg.repo.HgInvalidRevisionException; | |
| 32 import org.tmatesoft.hg.repo.HgInvalidStateException; | 33 import org.tmatesoft.hg.repo.HgInvalidStateException; |
| 34 import org.tmatesoft.hg.repo.HgRuntimeException; | |
| 33 | 35 |
| 34 /** | 36 /** |
| 35 * | 37 * |
| 36 * TODO [post-1.1] separate operation to check if index is too big and split into index+data | 38 * TODO [post-1.1] separate operation to check if index is too big and split into index+data |
| 37 * | 39 * |
| 59 transaction = tr; | 61 transaction = tr; |
| 60 } | 62 } |
| 61 | 63 |
| 62 /** | 64 /** |
| 63 * @return nodeid of added revision | 65 * @return nodeid of added revision |
| 66 * @throws HgRuntimeException | |
| 64 */ | 67 */ |
| 65 public Nodeid addRevision(DataSource content, int linkRevision, int p1, int p2) throws HgIOException { | 68 public Nodeid addRevision(DataSource content, int linkRevision, int p1, int p2) throws HgIOException, HgRuntimeException { |
| 66 lastEntryRevision = Nodeid.NULL; | 69 lastEntryRevision = Nodeid.NULL; |
| 67 int revCount = revlogStream.revisionCount(); | 70 int revCount = revlogStream.revisionCount(); |
| 68 lastEntryIndex = revCount == 0 ? NO_REVISION : revCount - 1; | 71 lastEntryIndex = revCount == 0 ? NO_REVISION : revCount - 1; |
| 69 populateLastEntry(); | 72 populateLastEntry(); |
| 70 // | 73 // |
| 136 } | 139 } |
| 137 } | 140 } |
| 138 return lastEntryRevision; | 141 return lastEntryRevision; |
| 139 } | 142 } |
| 140 | 143 |
| 141 private byte[] toByteArray(DataSource content) throws HgIOException { | 144 private byte[] toByteArray(DataSource content) throws HgIOException, HgRuntimeException { |
| 142 ByteArrayDataSerializer ba = new ByteArrayDataSerializer(); | 145 ByteArrayDataSerializer ba = new ByteArrayDataSerializer(); |
| 143 content.serialize(ba); | 146 content.serialize(ba); |
| 144 return ba.toByteArray(); | 147 return ba.toByteArray(); |
| 145 } | 148 } |
| 146 | 149 |
| 147 private Nodeid revision(int revisionIndex) { | 150 private Nodeid revision(int revisionIndex) throws HgInvalidControlFileException, HgInvalidRevisionException { |
| 148 if (revisionIndex == NO_REVISION) { | 151 if (revisionIndex == NO_REVISION) { |
| 149 return Nodeid.NULL; | 152 return Nodeid.NULL; |
| 150 } | 153 } |
| 151 Nodeid n = revisionCache.get(revisionIndex); | 154 Nodeid n = revisionCache.get(revisionIndex); |
| 152 if (n == null) { | 155 if (n == null) { |
| 154 revisionCache.put(revisionIndex, n); | 157 revisionCache.put(revisionIndex, n); |
| 155 } | 158 } |
| 156 return n; | 159 return n; |
| 157 } | 160 } |
| 158 | 161 |
| 159 private void populateLastEntry() throws HgInvalidControlFileException { | 162 private void populateLastEntry() throws HgRuntimeException { |
| 160 if (lastEntryContent != null) { | 163 if (lastEntryContent != null) { |
| 161 return; | 164 return; |
| 162 } | 165 } |
| 163 if (lastEntryIndex != NO_REVISION) { | 166 if (lastEntryIndex != NO_REVISION) { |
| 164 assert lastEntryIndex >= 0; | 167 assert lastEntryIndex >= 0; |
