comparison src/org/tmatesoft/hg/repo/HgChangelog.java @ 354:5f9073eabf06

Propagate errors with exceptions up to a end client
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 01 Dec 2011 05:21:40 +0100
parents 694ebabb5cb3
children 150500515714
comparison
equal deleted inserted replaced
353:0f3687e79f5a 354:5f9073eabf06
30 import java.util.Locale; 30 import java.util.Locale;
31 import java.util.Map; 31 import java.util.Map;
32 import java.util.TimeZone; 32 import java.util.TimeZone;
33 33
34 import org.tmatesoft.hg.core.HgBadStateException; 34 import org.tmatesoft.hg.core.HgBadStateException;
35 import org.tmatesoft.hg.core.HgInvalidControlFileException;
36 import org.tmatesoft.hg.core.HgInvalidRevisionException;
35 import org.tmatesoft.hg.core.Nodeid; 37 import org.tmatesoft.hg.core.Nodeid;
36 import org.tmatesoft.hg.internal.DataAccess; 38 import org.tmatesoft.hg.internal.DataAccess;
37 import org.tmatesoft.hg.internal.IterateControlMediator; 39 import org.tmatesoft.hg.internal.IterateControlMediator;
38 import org.tmatesoft.hg.internal.Lifecycle; 40 import org.tmatesoft.hg.internal.Lifecycle;
39 import org.tmatesoft.hg.internal.Pool; 41 import org.tmatesoft.hg.internal.Pool;
52 54
53 /* package-local */HgChangelog(HgRepository hgRepo, RevlogStream content) { 55 /* package-local */HgChangelog(HgRepository hgRepo, RevlogStream content) {
54 super(hgRepo, content); 56 super(hgRepo, content);
55 } 57 }
56 58
57 public void all(final HgChangelog.Inspector inspector) { 59 public void all(final HgChangelog.Inspector inspector) throws HgInvalidRevisionException {
58 range(0, getLastRevision(), inspector); 60 range(0, getLastRevision(), inspector);
59 } 61 }
60 62
61 public void range(int start, int end, final HgChangelog.Inspector inspector) { 63 public void range(int start, int end, final HgChangelog.Inspector inspector) throws HgInvalidRevisionException {
62 if (inspector == null) { 64 if (inspector == null) {
63 throw new IllegalArgumentException(); 65 throw new IllegalArgumentException();
64 } 66 }
65 content.iterate(start, end, true, new RawCsetParser(inspector)); 67 content.iterate(start, end, true, new RawCsetParser(inspector));
66 } 68 }
67 69
68 public List<RawChangeset> range(int start, int end) { 70 public List<RawChangeset> range(int start, int end) throws HgInvalidRevisionException {
69 final RawCsetCollector c = new RawCsetCollector(end - start + 1); 71 final RawCsetCollector c = new RawCsetCollector(end - start + 1);
70 range(start, end, c); 72 range(start, end, c);
71 return c.result; 73 return c.result;
72 } 74 }
73 75
75 * Access individual revisions. Note, regardless of supplied revision order, inspector gets 77 * Access individual revisions. Note, regardless of supplied revision order, inspector gets
76 * changesets strictly in the order they are in the changelog. 78 * changesets strictly in the order they are in the changelog.
77 * @param inspector callback to get changesets 79 * @param inspector callback to get changesets
78 * @param revisions revisions to read, unrestricted ordering. 80 * @param revisions revisions to read, unrestricted ordering.
79 */ 81 */
80 public void range(final HgChangelog.Inspector inspector, final int... revisions) { 82 public void range(final HgChangelog.Inspector inspector, final int... revisions) throws HgInvalidRevisionException {
81 Arrays.sort(revisions); 83 Arrays.sort(revisions);
82 rangeInternal(inspector, revisions); 84 rangeInternal(inspector, revisions);
83 } 85 }
84 86
85 /** 87 /**
86 * Friends-only version of {@link #range(Inspector, int...)}, when callers know array is sorted 88 * Friends-only version of {@link #range(Inspector, int...)}, when callers know array is sorted
87 */ 89 */
88 /*package-local*/ void rangeInternal(HgChangelog.Inspector inspector, int[] sortedRevisions) { 90 /*package-local*/ void rangeInternal(HgChangelog.Inspector inspector, int[] sortedRevisions) throws HgInvalidRevisionException {
89 if (sortedRevisions == null || sortedRevisions.length == 0) { 91 if (sortedRevisions == null || sortedRevisions.length == 0) {
90 return; 92 return;
91 } 93 }
92 if (inspector == null) { 94 if (inspector == null) {
93 throw new IllegalArgumentException(); 95 throw new IllegalArgumentException();
94 } 96 }
95 content.iterate(sortedRevisions, true, new RawCsetParser(inspector)); 97 content.iterate(sortedRevisions, true, new RawCsetParser(inspector));
96 } 98 }
97 99
98 public RawChangeset changeset(Nodeid nid) { 100 /**
101 * @throws HgInvalidRevisionException if supplied nodeid doesn't identify any revision from this revlog
102 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
103 */
104 public RawChangeset changeset(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException {
99 int x = getLocalRevision(nid); 105 int x = getLocalRevision(nid);
100 return range(x, x).get(0); 106 return range(x, x).get(0);
101 } 107 }
102 108
103 public interface Inspector { 109 public interface Inspector {