Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgChangelog.java @ 157:d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 09 Mar 2011 05:22:17 +0100 |
parents | src/com/tmate/hgkit/ll/Changelog.java@9429c7bd1920 src/com/tmate/hgkit/ll/Changelog.java@ba2bf656f00f |
children | 9423235ca77b |
comparison
equal
deleted
inserted
replaced
156:643ddec3be36 | 157:d5268ca7715b |
---|---|
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@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 java.io.IOException; | |
19 import java.io.UnsupportedEncodingException; | 20 import java.io.UnsupportedEncodingException; |
20 import java.util.ArrayList; | 21 import java.util.ArrayList; |
21 import java.util.Arrays; | 22 import java.util.Arrays; |
22 import java.util.Calendar; | 23 import java.util.Calendar; |
23 import java.util.Collections; | 24 import java.util.Collections; |
28 import java.util.Locale; | 29 import java.util.Locale; |
29 import java.util.Map; | 30 import java.util.Map; |
30 import java.util.TimeZone; | 31 import java.util.TimeZone; |
31 | 32 |
32 import org.tmatesoft.hg.core.Nodeid; | 33 import org.tmatesoft.hg.core.Nodeid; |
34 import org.tmatesoft.hg.internal.DataAccess; | |
33 import org.tmatesoft.hg.internal.RevlogStream; | 35 import org.tmatesoft.hg.internal.RevlogStream; |
34 | 36 |
35 /** | 37 /** |
36 * Representation of the Mercurial changelog file (list of ChangeSets) | 38 * Representation of the Mercurial changelog file (list of ChangeSets) |
37 * | 39 * |
49 } | 51 } |
50 | 52 |
51 public void range(int start, int end, final HgChangelog.Inspector inspector) { | 53 public void range(int start, int end, final HgChangelog.Inspector inspector) { |
52 RevlogStream.Inspector i = new RevlogStream.Inspector() { | 54 RevlogStream.Inspector i = new RevlogStream.Inspector() { |
53 | 55 |
54 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | 56 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { |
55 RawChangeset cset = RawChangeset.parse(data, 0, data.length); | 57 RawChangeset cset = RawChangeset.parse(da); |
56 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse | 58 // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse |
57 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); | 59 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); |
58 } | 60 } |
59 }; | 61 }; |
60 content.iterate(start, end, true, i); | 62 content.iterate(start, end, true, i); |
62 | 64 |
63 public List<RawChangeset> range(int start, int end) { | 65 public List<RawChangeset> range(int start, int end) { |
64 final ArrayList<RawChangeset> rv = new ArrayList<RawChangeset>(end - start + 1); | 66 final ArrayList<RawChangeset> rv = new ArrayList<RawChangeset>(end - start + 1); |
65 RevlogStream.Inspector i = new RevlogStream.Inspector() { | 67 RevlogStream.Inspector i = new RevlogStream.Inspector() { |
66 | 68 |
67 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | 69 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { |
68 RawChangeset cset = RawChangeset.parse(data, 0, data.length); | 70 RawChangeset cset = RawChangeset.parse(da); |
69 rv.add(cset); | 71 rv.add(cset); |
70 } | 72 } |
71 }; | 73 }; |
72 content.iterate(start, end, true, i); | 74 content.iterate(start, end, true, i); |
73 return rv; | 75 return rv; |
77 if (revisions == null || revisions.length == 0) { | 79 if (revisions == null || revisions.length == 0) { |
78 return; | 80 return; |
79 } | 81 } |
80 RevlogStream.Inspector i = new RevlogStream.Inspector() { | 82 RevlogStream.Inspector i = new RevlogStream.Inspector() { |
81 | 83 |
82 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { | 84 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { |
83 if (Arrays.binarySearch(revisions, revisionNumber) >= 0) { | 85 if (Arrays.binarySearch(revisions, revisionNumber) >= 0) { |
84 RawChangeset cset = RawChangeset.parse(data, 0, data.length); | 86 RawChangeset cset = RawChangeset.parse(da); |
85 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); | 87 inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); |
86 } | 88 } |
87 } | 89 } |
88 }; | 90 }; |
89 Arrays.sort(revisions); | 91 Arrays.sort(revisions); |
196 } catch (CloneNotSupportedException ex) { | 198 } catch (CloneNotSupportedException ex) { |
197 throw new InternalError(ex.toString()); | 199 throw new InternalError(ex.toString()); |
198 } | 200 } |
199 } | 201 } |
200 | 202 |
201 public static RawChangeset parse(byte[] data, int offset, int length) { | 203 public static RawChangeset parse(DataAccess da) { |
202 RawChangeset rv = new RawChangeset(); | 204 try { |
203 rv.init(data, offset, length); | 205 byte[] data = da.byteArray(); |
204 return rv; | 206 RawChangeset rv = new RawChangeset(); |
207 rv.init(data, 0, data.length); | |
208 return rv; | |
209 } catch (IOException ex) { | |
210 throw new IllegalArgumentException(ex); // FIXME better handling of IOExc | |
211 } | |
205 } | 212 } |
206 | 213 |
207 /* package-local */void init(byte[] data, int offset, int length) { | 214 /* package-local */void init(byte[] data, int offset, int length) { |
208 final int bufferEndIndex = offset + length; | 215 final int bufferEndIndex = offset + length; |
209 final byte lineBreak = (byte) '\n'; | 216 final byte lineBreak = (byte) '\n'; |