comparison src/com/tmate/hgkit/ll/RevlogStream.java @ 36:205f9b59b400

Strip parsing logic out from console frontend
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 13 Jan 2011 23:31:39 +0100
parents 6061aa826a9e
children e45e75e22523
comparison
equal deleted inserted replaced
35:6061aa826a9e 36:205f9b59b400
188 if (baseRevision != i) { // XXX not sure if this is the right way to detect a patch 188 if (baseRevision != i) { // XXX not sure if this is the right way to detect a patch
189 // this is a patch 189 // this is a patch
190 LinkedList<PatchRecord> patches = new LinkedList<PatchRecord>(); 190 LinkedList<PatchRecord> patches = new LinkedList<PatchRecord>();
191 int patchElementIndex = 0; 191 int patchElementIndex = 0;
192 do { 192 do {
193 final int x = patchElementIndex; // shorthand 193 PatchRecord pr = PatchRecord.read(data, patchElementIndex);
194 int p1 = ((data[x] & 0xFF)<< 24) | ((data[x+1] & 0xFF) << 16) | ((data[x+2] & 0xFF) << 8) | (data[x+3] & 0xFF); 194 patches.add(pr);
195 int p2 = ((data[x+4] & 0xFF) << 24) | ((data[x+5] & 0xFF) << 16) | ((data[x+6] & 0xFF) << 8) | (data[x+7] & 0xFF); 195 patchElementIndex += 12 + pr.len;
196 int len = ((data[x+8] & 0xFF) << 24) | ((data[x+9] & 0xFF) << 16) | ((data[x+10] & 0xFF) << 8) | (data[x+11] & 0xFF);
197 patchElementIndex += 12 + len;
198 patches.add(new PatchRecord(p1, p2, len, data, x+12));
199 } while (patchElementIndex < data.length); 196 } while (patchElementIndex < data.length);
200 // 197 //
201 byte[] baseRevContent = lastData; 198 byte[] baseRevContent = lastData;
202 data = apply(baseRevContent, actualLen, patches); 199 data = apply(baseRevContent, actualLen, patches);
203 } 200 }
303 System.arraycopy(tempBuf, 0, rv, 0, destIndex); 300 System.arraycopy(tempBuf, 0, rv, 0, destIndex);
304 return rv; 301 return rv;
305 } 302 }
306 303
307 // @see http://mercurial.selenic.com/wiki/BundleFormat, in Changelog group description 304 // @see http://mercurial.selenic.com/wiki/BundleFormat, in Changelog group description
308 static class PatchRecord { // copy of struct frag from mpatch.c 305 /*package-local*/ static class PatchRecord { // copy of struct frag from mpatch.c
309 int start, end, len; 306 int start, end, len;
310 byte[] data; 307 byte[] data;
311 308
312 public PatchRecord(int p1, int p2, int len, byte[] src, int srcOffset) { 309 // TODO consider PatchRecord that only records data position (absolute in data source), and acquires data as needed
313 start = p1; 310 private PatchRecord(int p1, int p2, int length, byte[] src) {
314 end = p2; 311 start = p1;
315 this.len = len; 312 end = p2;
316 data = new byte[len]; 313 len = length;
317 System.arraycopy(src, srcOffset, data, 0, len); 314 data = src;
318 } 315 }
316
317 /*package-local*/ static PatchRecord read(byte[] data, int offset) {
318 final int x = offset; // shorthand
319 int p1 = ((data[x] & 0xFF)<< 24) | ((data[x+1] & 0xFF) << 16) | ((data[x+2] & 0xFF) << 8) | (data[x+3] & 0xFF);
320 int p2 = ((data[x+4] & 0xFF) << 24) | ((data[x+5] & 0xFF) << 16) | ((data[x+6] & 0xFF) << 8) | (data[x+7] & 0xFF);
321 int len = ((data[x+8] & 0xFF) << 24) | ((data[x+9] & 0xFF) << 16) | ((data[x+10] & 0xFF) << 8) | (data[x+11] & 0xFF);
322 byte[] dataCopy = new byte[len];
323 System.arraycopy(data, x+12, dataCopy, 0, len);
324 return new PatchRecord(p1, p2, len, dataCopy);
325 }
326
327 /*package-local*/ static PatchRecord read(DataAccess da) throws IOException {
328 int p1 = da.readInt();
329 int p2 = da.readInt();
330 int len = da.readInt();
331 byte[] src = new byte[len];
332 da.readBytes(src, 0, len);
333 return new PatchRecord(p1, p2, len, src);
334 }
335
336
319 } 337 }
320 } 338 }