comparison src/org/tmatesoft/hg/repo/Revlog.java @ 405:866fc3b597a0

Add an explicit constant instead of -1 to indicate 'no revision' case
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 14 Mar 2012 22:49:32 +0100
parents 2747b0723867
children d30083c80d52
comparison
equal deleted inserted replaced
403:2747b0723867 405:866fc3b597a0
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; 19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION;
20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; 21 import static org.tmatesoft.hg.repo.HgRepository.TIP;
21 22
22 import java.io.IOException; 23 import java.io.IOException;
23 import java.nio.ByteBuffer; 24 import java.nio.ByteBuffer;
24 import java.util.ArrayList; 25 import java.util.ArrayList;
226 throw e; 227 throw e;
227 } 228 }
228 } 229 }
229 230
230 /** 231 /**
231 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query? 232 * Fills supplied arguments with information about revision parents.
232 * 233 *
233 * @param revision - revision to query parents, or {@link HgRepository#TIP} 234 * @param revision - revision to query parents, or {@link HgRepository#TIP}
234 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1}) 235 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1}), {@link HgRepository#NO_REVISION} indicates parent not set
235 * @param parent1 - byte[20] or null, if parent's nodeid is not needed 236 * @param parent1 - byte[20] or null, if parent's nodeid is not needed
236 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed 237 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed
237 * @throws HgInvalidRevisionException 238 * @throws HgInvalidRevisionException
239 * @throws HgInvalidControlFileException FIXME
238 * @throws IllegalArgumentException 240 * @throws IllegalArgumentException
239 */ 241 */
240 public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) throws HgInvalidRevisionException, HgInvalidControlFileException { 242 public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) throws HgInvalidRevisionException, HgInvalidControlFileException {
241 if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) { 243 if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) {
242 throw new HgInvalidRevisionException(revision); 244 throw new HgInvalidRevisionException(revision);
263 System.arraycopy(nodeid, nodeid.length > 20 ? nodeid.length - 20 : 0, this.nodeid, 0, 20); 265 System.arraycopy(nodeid, nodeid.length > 20 ? nodeid.length - 20 : 0, this.nodeid, 0, 20);
264 } 266 }
265 }; 267 };
266 ParentCollector pc = new ParentCollector(); 268 ParentCollector pc = new ParentCollector();
267 content.iterate(revision, revision, false, pc); 269 content.iterate(revision, revision, false, pc);
268 parentRevisions[0] = pc.p1; 270 // although next code looks odd (NO_REVISION *is* -1), it's safer to be explicit
269 parentRevisions[1] = pc.p2; 271 parentRevisions[0] = pc.p1 == -1 ? NO_REVISION : pc.p1;
272 parentRevisions[1] = pc.p2 == -1 ? NO_REVISION : pc.p2;
270 if (parent1 != null) { 273 if (parent1 != null) {
271 if (parentRevisions[0] == -1) { 274 if (parentRevisions[0] == NO_REVISION) {
272 Arrays.fill(parent1, 0, 20, (byte) 0); 275 Arrays.fill(parent1, 0, 20, (byte) 0);
273 } else { 276 } else {
274 content.iterate(parentRevisions[0], parentRevisions[0], false, pc); 277 content.iterate(parentRevisions[0], parentRevisions[0], false, pc);
275 System.arraycopy(pc.nodeid, 0, parent1, 0, 20); 278 System.arraycopy(pc.nodeid, 0, parent1, 0, 20);
276 } 279 }
277 } 280 }
278 if (parent2 != null) { 281 if (parent2 != null) {
279 if (parentRevisions[1] == -1) { 282 if (parentRevisions[1] == NO_REVISION) {
280 Arrays.fill(parent2, 0, 20, (byte) 0); 283 Arrays.fill(parent2, 0, 20, (byte) 0);
281 } else { 284 } else {
282 content.iterate(parentRevisions[1], parentRevisions[1], false, pc); 285 content.iterate(parentRevisions[1], parentRevisions[1], false, pc);
283 System.arraycopy(pc.nodeid, 0, parent2, 0, 20); 286 System.arraycopy(pc.nodeid, 0, parent2, 0, 20);
284 } 287 }