Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/Revlog.java @ 77:c677e1593919
Moved RevlogStream implementation into .internal
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 24 Jan 2011 05:33:47 +0100 |
parents | 6f1b88693d48 |
children | 4222b04f34ee |
comparison
equal
deleted
inserted
replaced
76:658fa6b3a371 | 77:c677e1593919 |
---|---|
25 import java.util.LinkedHashSet; | 25 import java.util.LinkedHashSet; |
26 import java.util.Map; | 26 import java.util.Map; |
27 import java.util.Set; | 27 import java.util.Set; |
28 | 28 |
29 import org.tmatesoft.hg.core.Nodeid; | 29 import org.tmatesoft.hg.core.Nodeid; |
30 import org.tmatesoft.hg.internal.RevlogStream; | |
30 | 31 |
31 | 32 |
32 /** | 33 /** |
33 * | 34 * |
34 * @author Artem Tikhomirov | 35 * @author Artem Tikhomirov |
90 /** | 91 /** |
91 * @param revision - repo-local index of this file change (not a changelog revision number!) | 92 * @param revision - repo-local index of this file change (not a changelog revision number!) |
92 */ | 93 */ |
93 public byte[] content(int revision) { | 94 public byte[] content(int revision) { |
94 final byte[][] dataPtr = new byte[1][]; | 95 final byte[][] dataPtr = new byte[1][]; |
95 Revlog.Inspector insp = new Revlog.Inspector() { | 96 RevlogStream.Inspector insp = new RevlogStream.Inspector() { |
96 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | 97 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { |
97 dataPtr[0] = data; | 98 dataPtr[0] = data; |
98 } | 99 } |
99 }; | 100 }; |
100 content.iterate(revision, revision, true, insp); | 101 content.iterate(revision, revision, true, insp); |
121 throw new IllegalArgumentException(parent1.toString()); | 122 throw new IllegalArgumentException(parent1.toString()); |
122 } | 123 } |
123 if (parent2 != null && parent2.length < 20) { | 124 if (parent2 != null && parent2.length < 20) { |
124 throw new IllegalArgumentException(parent2.toString()); | 125 throw new IllegalArgumentException(parent2.toString()); |
125 } | 126 } |
126 class ParentCollector implements Revlog.Inspector { | 127 class ParentCollector implements RevlogStream.Inspector { |
127 public int p1 = -1; | 128 public int p1 = -1; |
128 public int p2 = -1; | 129 public int p2 = -1; |
129 public byte[] nodeid; | 130 public byte[] nodeid; |
130 | 131 |
131 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | 132 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { |
156 System.arraycopy(pc.nodeid, 0, parent2, 0, 20); | 157 System.arraycopy(pc.nodeid, 0, parent2, 0, 20); |
157 } | 158 } |
158 } | 159 } |
159 } | 160 } |
160 | 161 |
161 // FIXME byte[] data might be too expensive, for few usecases it may be better to have intermediate Access object (when we don't need full data | |
162 // instantly - e.g. calculate hash, or comparing two revisions | |
163 // XXX seems that RevlogStream is better place for this class. | |
164 public interface Inspector { | |
165 // XXX boolean retVal to indicate whether to continue? | |
166 // TODO specify nodeid and data length, and reuse policy (i.e. if revlog stream doesn't reuse nodeid[] for each call) | |
167 void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[/*20*/] nodeid, byte[] data); | |
168 } | |
169 | |
170 /* | 162 /* |
171 * XXX think over if it's better to do either: | 163 * XXX think over if it's better to do either: |
172 * pw = getChangelog().new ParentWalker(); pw.init() and pass pw instance around as needed | 164 * pw = getChangelog().new ParentWalker(); pw.init() and pass pw instance around as needed |
173 * or | 165 * or |
174 * add Revlog#getParentWalker(), static class, make cons() and #init package-local, and keep SoftReference to allow walker reuse. | 166 * add Revlog#getParentWalker(), static class, make cons() and #init package-local, and keep SoftReference to allow walker reuse. |
190 final int revisionCount = stream.revisionCount(); | 182 final int revisionCount = stream.revisionCount(); |
191 firstParent = new HashMap<Nodeid, Nodeid>(revisionCount); | 183 firstParent = new HashMap<Nodeid, Nodeid>(revisionCount); |
192 secondParent = new HashMap<Nodeid, Nodeid>(firstParent.size() >> 1); // assume branches/merges are less frequent | 184 secondParent = new HashMap<Nodeid, Nodeid>(firstParent.size() >> 1); // assume branches/merges are less frequent |
193 allNodes = new LinkedHashSet<Nodeid>(); | 185 allNodes = new LinkedHashSet<Nodeid>(); |
194 | 186 |
195 Inspector insp = new Inspector() { | 187 RevlogStream.Inspector insp = new RevlogStream.Inspector() { |
196 final Nodeid[] sequentialRevisionNodeids = new Nodeid[revisionCount]; | 188 final Nodeid[] sequentialRevisionNodeids = new Nodeid[revisionCount]; |
197 int ix = 0; | 189 int ix = 0; |
198 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | 190 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { |
199 if (ix != revisionNumber) { | 191 if (ix != revisionNumber) { |
200 // XXX temp code, just to make sure I understand what's going on here | 192 // XXX temp code, just to make sure I understand what's going on here |