Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/RevlogStream.java @ 80:4222b04f34ee
Follow history of a file
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 25 Jan 2011 03:54:32 +0100 |
parents | c677e1593919 |
children | 61eedab3eb3e |
comparison
equal
deleted
inserted
replaced
79:5f9635c01681 | 80:4222b04f34ee |
---|---|
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@svnkit.com | 15 * contact TMate Software at support@svnkit.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.TIP; | 20 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
20 | 21 |
21 import java.io.File; | 22 import java.io.File; |
22 import java.io.IOException; | 23 import java.io.IOException; |
23 import java.util.ArrayList; | 24 import java.util.ArrayList; |
26 import java.util.List; | 27 import java.util.List; |
27 import java.util.zip.DataFormatException; | 28 import java.util.zip.DataFormatException; |
28 import java.util.zip.Inflater; | 29 import java.util.zip.Inflater; |
29 | 30 |
30 import org.tmatesoft.hg.core.Nodeid; | 31 import org.tmatesoft.hg.core.Nodeid; |
32 import org.tmatesoft.hg.repo.HgRepository; | |
31 | 33 |
32 | 34 |
33 /** | 35 /** |
34 * ? Single RevlogStream per file per repository with accessor to record access session (e.g. with back/forward operations), | 36 * ? Single RevlogStream per file per repository with accessor to record access session (e.g. with back/forward operations), |
35 * or numerous RevlogStream with separate representation of the underlaying data (cached, lazy ChunkStream)? | 37 * or numerous RevlogStream with separate representation of the underlaying data (cached, lazy ChunkStream)? |
87 } finally { | 89 } finally { |
88 daIndex.done(); | 90 daIndex.done(); |
89 } | 91 } |
90 } | 92 } |
91 | 93 |
94 public byte[] nodeid(int revision) { | |
95 final int indexSize = revisionCount(); | |
96 if (revision == TIP) { | |
97 revision = indexSize - 1; | |
98 } | |
99 if (revision < 0 || revision >= indexSize) { | |
100 throw new IllegalArgumentException(Integer.toString(revision)); | |
101 } | |
102 DataAccess daIndex = getIndexStream(); | |
103 try { | |
104 int recordOffset = inline ? (int) index.get(revision).offset : revision * REVLOGV1_RECORD_SIZE; | |
105 daIndex.seek(recordOffset + 32); | |
106 byte[] rv = new byte[20]; | |
107 daIndex.readBytes(rv, 0, 20); | |
108 return rv; | |
109 } catch (IOException ex) { | |
110 ex.printStackTrace(); | |
111 throw new IllegalStateException(); | |
112 } finally { | |
113 } | |
114 } | |
115 | |
92 // Perhaps, RevlogStream should be limited to use of plain int revisions for access, | 116 // Perhaps, RevlogStream should be limited to use of plain int revisions for access, |
93 // while Nodeids should be kept on the level up, in Revlog. Guess, Revlog better keep | 117 // while Nodeids should be kept on the level up, in Revlog. Guess, Revlog better keep |
94 // map of nodeids, and once this comes true, we may get rid of this method. | 118 // map of nodeids, and once this comes true, we may get rid of this method. |
95 // Unlike its counterpart, Revlog#getLocalRevisionNumber, doesn't fail with exception if node not found, | 119 // Unlike its counterpart, {@link Revlog#getLocalRevisionNumber()}, doesn't fail with exception if node not found, |
96 // returns a predefined constant instead | 120 /** |
121 * @return integer in [0..revisionCount()) or {@link HgRepository#BAD_REVISION} if not found | |
122 */ | |
97 public int findLocalRevisionNumber(Nodeid nodeid) { | 123 public int findLocalRevisionNumber(Nodeid nodeid) { |
98 // XXX this one may be implemented with iterate() once there's mechanism to stop iterations | 124 // XXX this one may be implemented with iterate() once there's mechanism to stop iterations |
99 final int indexSize = revisionCount(); | 125 final int indexSize = revisionCount(); |
100 DataAccess daIndex = getIndexStream(); | 126 DataAccess daIndex = getIndexStream(); |
101 try { | 127 try { |
114 ex.printStackTrace(); // log error. FIXME better handling | 140 ex.printStackTrace(); // log error. FIXME better handling |
115 throw new IllegalStateException(ex); | 141 throw new IllegalStateException(ex); |
116 } finally { | 142 } finally { |
117 daIndex.done(); | 143 daIndex.done(); |
118 } | 144 } |
119 return Integer.MIN_VALUE; | 145 return BAD_REVISION; |
120 } | 146 } |
121 | 147 |
122 | 148 |
123 private final int REVLOGV1_RECORD_SIZE = 64; | 149 private final int REVLOGV1_RECORD_SIZE = 64; |
124 | 150 |