comparison src/org/tmatesoft/hg/repo/HgManifest.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/HgManifest.java@9429c7bd1920 src/com/tmate/hgkit/ll/HgManifest.java@a3a2e5deb320
children e2115da4cf6a
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;
20
21 import org.tmatesoft.hg.core.HgBadStateException;
19 import org.tmatesoft.hg.core.Nodeid; 22 import org.tmatesoft.hg.core.Nodeid;
23 import org.tmatesoft.hg.internal.DataAccess;
20 import org.tmatesoft.hg.internal.RevlogStream; 24 import org.tmatesoft.hg.internal.RevlogStream;
21 25
22 26
23 /** 27 /**
24 * 28 *
34 public void walk(int start, int end, final Inspector inspector) { 38 public void walk(int start, int end, final Inspector inspector) {
35 RevlogStream.Inspector insp = new RevlogStream.Inspector() { 39 RevlogStream.Inspector insp = new RevlogStream.Inspector() {
36 40
37 private boolean gtg = true; // good to go 41 private boolean gtg = true; // good to go
38 42
39 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { 43 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) {
40 if (!gtg) { 44 if (!gtg) {
41 return; 45 return;
42 } 46 }
43 gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid, true)); 47 try {
44 int i; 48 gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid, true));
45 String fname = null; 49 int i;
46 String flags = null; 50 String fname = null;
47 Nodeid nid = null; 51 String flags = null;
48 for (i = 0; gtg && i < actualLen; i++) { 52 Nodeid nid = null;
49 int x = i; 53 byte[] data = da.byteArray();
50 for( ; data[i] != '\n' && i < actualLen; i++) { 54 for (i = 0; gtg && i < actualLen; i++) {
51 if (fname == null && data[i] == 0) { 55 int x = i;
52 fname = new String(data, x, i - x); 56 for( ; data[i] != '\n' && i < actualLen; i++) {
53 x = i+1; 57 if (fname == null && data[i] == 0) {
58 fname = new String(data, x, i - x);
59 x = i+1;
60 }
54 } 61 }
62 if (i < actualLen) {
63 assert data[i] == '\n';
64 int nodeidLen = i - x < 40 ? i-x : 40;
65 nid = Nodeid.fromAscii(data, x, nodeidLen);
66 if (nodeidLen + x < i) {
67 // 'x' and 'l' for executable bits and symlinks?
68 // hg --debug manifest shows 644 for each regular file in my repo
69 flags = new String(data, x + nodeidLen, i-x-nodeidLen);
70 }
71 gtg = gtg && inspector.next(nid, fname, flags);
72 }
73 nid = null;
74 fname = flags = null;
55 } 75 }
56 if (i < actualLen) { 76 gtg = gtg && inspector.end(revisionNumber);
57 assert data[i] == '\n'; 77 } catch (IOException ex) {
58 int nodeidLen = i - x < 40 ? i-x : 40; 78 throw new HgBadStateException(ex);
59 nid = Nodeid.fromAscii(data, x, nodeidLen);
60 if (nodeidLen + x < i) {
61 // 'x' and 'l' for executable bits and symlinks?
62 // hg --debug manifest shows 644 for each regular file in my repo
63 flags = new String(data, x + nodeidLen, i-x-nodeidLen);
64 }
65 gtg = gtg && inspector.next(nid, fname, flags);
66 }
67 nid = null;
68 fname = flags = null;
69 } 79 }
70 gtg = gtg && inspector.end(revisionNumber);
71 } 80 }
72 }; 81 };
73 content.iterate(start, end, true, insp); 82 content.iterate(start, end, true, insp);
74 } 83 }
75 84