comparison src/org/tmatesoft/hg/repo/HgBundle.java @ 329:694ebabb5cb3

Refactor revlog patch mechanism, towards patch merging
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 13 Oct 2011 03:30:50 +0200
parents 981f9f50bb6c
children 5f9073eabf06
comparison
equal deleted inserted replaced
328:a674b8590362 329:694ebabb5cb3
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import java.io.File; 19 import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.util.LinkedList; 21 import java.util.LinkedList;
22 import java.util.List;
23 22
24 import org.tmatesoft.hg.core.HgBadStateException; 23 import org.tmatesoft.hg.core.HgBadStateException;
25 import org.tmatesoft.hg.core.HgException; 24 import org.tmatesoft.hg.core.HgException;
26 import org.tmatesoft.hg.core.HgInvalidFileException; 25 import org.tmatesoft.hg.core.HgInvalidFileException;
27 import org.tmatesoft.hg.core.Nodeid; 26 import org.tmatesoft.hg.core.Nodeid;
29 import org.tmatesoft.hg.internal.ByteArrayDataAccess; 28 import org.tmatesoft.hg.internal.ByteArrayDataAccess;
30 import org.tmatesoft.hg.internal.DataAccess; 29 import org.tmatesoft.hg.internal.DataAccess;
31 import org.tmatesoft.hg.internal.DataAccessProvider; 30 import org.tmatesoft.hg.internal.DataAccessProvider;
32 import org.tmatesoft.hg.internal.DigestHelper; 31 import org.tmatesoft.hg.internal.DigestHelper;
33 import org.tmatesoft.hg.internal.InflaterDataAccess; 32 import org.tmatesoft.hg.internal.InflaterDataAccess;
34 import org.tmatesoft.hg.internal.RevlogStream; 33 import org.tmatesoft.hg.internal.Patch;
35 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; 34 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
36 import org.tmatesoft.hg.util.CancelledException; 35 import org.tmatesoft.hg.util.CancelledException;
37 36
38 /** 37 /**
39 * @see http://mercurial.selenic.com/wiki/BundleFormat 38 * @see http://mercurial.selenic.com/wiki/BundleFormat
237 public void fileEnd(String name) { 236 public void fileEnd(String name) {
238 } 237 }
239 238
240 public boolean element(GroupElement ge) { 239 public boolean element(GroupElement ge) {
241 try { 240 try {
242 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches().size()); 241 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patch().count());
243 } catch (Exception ex) { 242 } catch (Exception ex) {
244 ex.printStackTrace(); // FIXME 243 ex.printStackTrace(); // FIXME
245 } 244 }
246 return true; 245 return true;
247 } 246 }
395 da.skip(len - 4); // sizeof(int) 394 da.skip(len - 4); // sizeof(int)
396 len = da.isEmpty() ? 0 : da.readInt(); 395 len = da.isEmpty() ? 0 : da.readInt();
397 } 396 }
398 } 397 }
399 398
399 // FIXME GroupElement exposes some internal API!!! (DataAccess)
400 public static class GroupElement { 400 public static class GroupElement {
401 private final byte[] header; // byte[80] takes 120 bytes, 4 Nodeids - 192 401 private final byte[] header; // byte[80] takes 120 bytes, 4 Nodeids - 192
402 private final DataAccess dataAccess; 402 private final DataAccess dataAccess;
403 private List<RevlogStream.PatchRecord> patches; 403 private Patch patches;
404 404
405 GroupElement(byte[] fourNodeids, DataAccess rawDataAccess) { 405 GroupElement(byte[] fourNodeids, DataAccess rawDataAccess) {
406 assert fourNodeids != null && fourNodeids.length == 80; 406 assert fourNodeids != null && fourNodeids.length == 80;
407 header = fourNodeids; 407 header = fourNodeids;
408 dataAccess = rawDataAccess; 408 dataAccess = rawDataAccess;
430 430
431 public DataAccess rawData() { 431 public DataAccess rawData() {
432 return dataAccess; 432 return dataAccess;
433 } 433 }
434 434
435 public List<RevlogStream.PatchRecord> patches() throws IOException { 435 /*package-local*/ Patch patch() throws IOException {
436 if (patches == null) { 436 if (patches == null) {
437 dataAccess.reset(); 437 dataAccess.reset();
438 LinkedList<RevlogStream.PatchRecord> p = new LinkedList<RevlogStream.PatchRecord>(); 438 patches = new Patch();
439 while (!dataAccess.isEmpty()) { 439 patches.read(dataAccess);
440 RevlogStream.PatchRecord pr = RevlogStream.PatchRecord.read(dataAccess);
441 p.add(pr);
442 }
443 patches = p;
444 } 440 }
445 return patches; 441 return patches;
446 } 442 }
447 443
448 public byte[] apply(DataAccess baseContent) throws IOException { 444 public byte[] apply(DataAccess baseContent) throws IOException {
449 return RevlogStream.apply(baseContent, -1, patches()); 445 return patch().apply(baseContent, -1);
450 } 446 }
451 } 447 }
452 } 448 }