comparison src/org/tmatesoft/hg/internal/RevisionDescendants.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 2a0b09eec376
children 690e71d29bf6
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
1 /* 1 /*
2 * Copyright (c) 2012 TMate Software Ltd 2 * Copyright (c) 2012-2013 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
18 18
19 import java.util.BitSet; 19 import java.util.BitSet;
20 20
21 import org.tmatesoft.hg.core.Nodeid; 21 import org.tmatesoft.hg.core.Nodeid;
22 import org.tmatesoft.hg.repo.HgChangelog; 22 import org.tmatesoft.hg.repo.HgChangelog;
23 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
24 import org.tmatesoft.hg.repo.HgInvalidStateException; 23 import org.tmatesoft.hg.repo.HgInvalidStateException;
25 import org.tmatesoft.hg.repo.HgRepository; 24 import org.tmatesoft.hg.repo.HgRepository;
25 import org.tmatesoft.hg.repo.HgRuntimeException;
26 26
27 /** 27 /**
28 * Represent indicators which revisions are descendants of the supplied root revision 28 * Represent indicators which revisions are descendants of the supplied root revision
29 * This is sort of lightweight alternative to ParentWalker#childrenOf 29 * This is sort of lightweight alternative to ParentWalker#childrenOf
30 * 30 *
37 private final int rootRevIndex; 37 private final int rootRevIndex;
38 private final int tipRevIndex; // this is the last revision we cache to 38 private final int tipRevIndex; // this is the last revision we cache to
39 private final BitSet descendants; 39 private final BitSet descendants;
40 40
41 // in fact, may be refactored to deal not only with changelog, but any revlog (not sure what would be the usecase, though) 41 // in fact, may be refactored to deal not only with changelog, but any revlog (not sure what would be the usecase, though)
42 public RevisionDescendants(HgRepository hgRepo, int revisionIndex) { 42 public RevisionDescendants(HgRepository hgRepo, int revisionIndex) throws HgRuntimeException {
43 repo = hgRepo; 43 repo = hgRepo;
44 rootRevIndex = revisionIndex; 44 rootRevIndex = revisionIndex;
45 // even if tip moves, we still answer correctly for those isCandidate() 45 // even if tip moves, we still answer correctly for those isCandidate()
46 tipRevIndex = repo.getChangelog().getLastRevision(); 46 tipRevIndex = repo.getChangelog().getLastRevision();
47 if (revisionIndex < 0 || revisionIndex > tipRevIndex) { 47 if (revisionIndex < 0 || revisionIndex > tipRevIndex) {
49 throw new IllegalArgumentException(String.format(m, 0, tipRevIndex, revisionIndex)); 49 throw new IllegalArgumentException(String.format(m, 0, tipRevIndex, revisionIndex));
50 } 50 }
51 descendants = new BitSet(tipRevIndex - rootRevIndex + 1); 51 descendants = new BitSet(tipRevIndex - rootRevIndex + 1);
52 } 52 }
53 53
54 public void build() throws HgInvalidControlFileException { 54 public void build() throws HgRuntimeException {
55 final BitSet result = descendants; 55 final BitSet result = descendants;
56 result.set(0); 56 result.set(0);
57 if (rootRevIndex == tipRevIndex) { 57 if (rootRevIndex == tipRevIndex) {
58 return; 58 return;
59 } 59 }