Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RevlogStream.java @ 295:981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Fri, 16 Sep 2011 05:35:32 +0200 |
| parents | b11f6a08f748 |
| children | e7ca6f16d074 |
comparison
equal
deleted
inserted
replaced
| 294:32890bab7209 | 295:981f9f50bb6c |
|---|---|
| 77 public int revisionCount() { | 77 public int revisionCount() { |
| 78 initOutline(); | 78 initOutline(); |
| 79 return baseRevisions.length; | 79 return baseRevisions.length; |
| 80 } | 80 } |
| 81 | 81 |
| 82 /** | |
| 83 * @throws HgBadStateException if internal read operation failed | |
| 84 */ | |
| 82 public int dataLength(int revision) { | 85 public int dataLength(int revision) { |
| 83 // XXX in fact, use of iterate() instead of this implementation may be quite reasonable. | 86 // XXX in fact, use of iterate() instead of this implementation may be quite reasonable. |
| 84 // | 87 // |
| 85 final int indexSize = revisionCount(); | 88 final int indexSize = revisionCount(); |
| 86 DataAccess daIndex = getIndexStream(); | 89 DataAccess daIndex = getIndexStream(); |
| 92 daIndex.seek(recordOffset + 12); // 6+2+4 | 95 daIndex.seek(recordOffset + 12); // 6+2+4 |
| 93 int actualLen = daIndex.readInt(); | 96 int actualLen = daIndex.readInt(); |
| 94 return actualLen; | 97 return actualLen; |
| 95 } catch (IOException ex) { | 98 } catch (IOException ex) { |
| 96 ex.printStackTrace(); // log error. FIXME better handling | 99 ex.printStackTrace(); // log error. FIXME better handling |
| 97 throw new IllegalStateException(ex); | 100 throw new HgBadStateException(ex); |
| 98 } finally { | 101 } finally { |
| 99 daIndex.done(); | 102 daIndex.done(); |
| 100 } | 103 } |
| 101 } | 104 } |
| 102 | 105 |
| 106 /** | |
| 107 * @throws HgBadStateException if internal read operation failed | |
| 108 */ | |
| 103 public byte[] nodeid(int revision) { | 109 public byte[] nodeid(int revision) { |
| 104 final int indexSize = revisionCount(); | 110 final int indexSize = revisionCount(); |
| 105 if (revision == TIP) { | 111 if (revision == TIP) { |
| 106 revision = indexSize - 1; | 112 revision = indexSize - 1; |
| 107 } | 113 } |
| 115 byte[] rv = new byte[20]; | 121 byte[] rv = new byte[20]; |
| 116 daIndex.readBytes(rv, 0, 20); | 122 daIndex.readBytes(rv, 0, 20); |
| 117 return rv; | 123 return rv; |
| 118 } catch (IOException ex) { | 124 } catch (IOException ex) { |
| 119 ex.printStackTrace(); | 125 ex.printStackTrace(); |
| 120 throw new IllegalStateException(); | 126 throw new HgBadStateException(); |
| 121 } finally { | 127 } finally { |
| 122 daIndex.done(); | 128 daIndex.done(); |
| 123 } | 129 } |
| 124 } | 130 } |
| 125 | 131 |
| 132 /** | |
| 133 * Get link field from the index record. | |
| 134 * @throws HgBadStateException if internal read operation failed | |
| 135 */ | |
| 126 public int linkRevision(int revision) { | 136 public int linkRevision(int revision) { |
| 127 final int last = revisionCount() - 1; | 137 final int last = revisionCount() - 1; |
| 128 if (revision == TIP) { | 138 if (revision == TIP) { |
| 129 revision = last; | 139 revision = last; |
| 130 } | 140 } |
| 137 daIndex.seek(recordOffset + 20); | 147 daIndex.seek(recordOffset + 20); |
| 138 int linkRev = daIndex.readInt(); | 148 int linkRev = daIndex.readInt(); |
| 139 return linkRev; | 149 return linkRev; |
| 140 } catch (IOException ex) { | 150 } catch (IOException ex) { |
| 141 ex.printStackTrace(); | 151 ex.printStackTrace(); |
| 142 throw new IllegalStateException(); | 152 throw new HgBadStateException(); |
| 143 } finally { | 153 } finally { |
| 144 daIndex.done(); | 154 daIndex.done(); |
| 145 } | 155 } |
| 146 } | 156 } |
| 147 | 157 |
