comparison src/org/tmatesoft/hg/internal/RevlogStreamWriter.java @ 673:545b1d4cc11d

Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 12 Jul 2013 20:14:24 +0200
parents ae2d439fbed3
children 4ffc17c0b534
comparison
equal deleted inserted replaced
672:d2552e6a5af6 673:545b1d4cc11d
28 import org.tmatesoft.hg.core.SessionContext; 28 import org.tmatesoft.hg.core.SessionContext;
29 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSource; 29 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSource;
30 import org.tmatesoft.hg.internal.DataSerializer.ByteArraySerializer; 30 import org.tmatesoft.hg.internal.DataSerializer.ByteArraySerializer;
31 import org.tmatesoft.hg.internal.DataSerializer.DataSource; 31 import org.tmatesoft.hg.internal.DataSerializer.DataSource;
32 import org.tmatesoft.hg.repo.HgBundle.GroupElement; 32 import org.tmatesoft.hg.repo.HgBundle.GroupElement;
33 import org.tmatesoft.hg.repo.HgInternals;
33 import org.tmatesoft.hg.repo.HgInvalidControlFileException; 34 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
34 import org.tmatesoft.hg.repo.HgInvalidDataFormatException; 35 import org.tmatesoft.hg.repo.HgInvalidDataFormatException;
35 import org.tmatesoft.hg.repo.HgInvalidRevisionException; 36 import org.tmatesoft.hg.repo.HgInvalidRevisionException;
36 import org.tmatesoft.hg.repo.HgInvalidStateException; 37 import org.tmatesoft.hg.repo.HgInvalidStateException;
37 import org.tmatesoft.hg.repo.HgRepository; 38 import org.tmatesoft.hg.repo.HgRepository;
87 assert linkRev >= 0; 88 assert linkRev >= 0;
88 final Nodeid p1Rev = ge.firstParent(); 89 final Nodeid p1Rev = ge.firstParent();
89 int p1 = p1Rev.isNull() ? NO_REVISION : revlogRevs.revisionIndex(p1Rev); 90 int p1 = p1Rev.isNull() ? NO_REVISION : revlogRevs.revisionIndex(p1Rev);
90 final Nodeid p2Rev = ge.secondParent(); 91 final Nodeid p2Rev = ge.secondParent();
91 int p2 = p2Rev.isNull() ? NO_REVISION : revlogRevs.revisionIndex(p2Rev); 92 int p2 = p2Rev.isNull() ? NO_REVISION : revlogRevs.revisionIndex(p2Rev);
92 Patch p = new Patch(); 93 Patch p = null;
93 final byte[] patchBytes;
94 try { 94 try {
95 // XXX there's ge.rawData(), to avoid extra array wrap 95 p = HgInternals.patchFromData(ge);
96 patchBytes = ge.rawDataByteArray();
97 p.read(new ByteArrayDataAccess(patchBytes));
98 } catch (IOException ex) { 96 } catch (IOException ex) {
99 throw new HgIOException("Failed to read patch information", ex, null); 97 throw new HgIOException("Failed to read patch information", ex, null);
100 } 98 }
101 // 99 //
102 final Nodeid patchBase = ge.patchBase(); 100 final Nodeid patchBase = ge.patchBase();
107 byte[] complete = null; 105 byte[] complete = null;
108 if (patchBaseRev == lastEntryIndex && lastEntryIndex != NO_REVISION) { 106 if (patchBaseRev == lastEntryIndex && lastEntryIndex != NO_REVISION) {
109 // we may write patch from GroupElement as is 107 // we may write patch from GroupElement as is
110 int patchBaseLen = dataLength(patchBaseRev); 108 int patchBaseLen = dataLength(patchBaseRev);
111 revLen = patchBaseLen + p.patchSizeDelta(); 109 revLen = patchBaseLen + p.patchSizeDelta();
112 ds = new ByteArrayDataSource(patchBytes); 110 ds = p.new PatchDataSource();
113 } else { 111 } else {
114 // read baseRev, unless it's the pull to empty repository 112 // read baseRev, unless it's the pull to empty repository
115 try { 113 try {
116 if (lastEntryIndex == NO_REVISION) { 114 if (lastEntryIndex == NO_REVISION) {
117 complete = p.apply(new ByteArrayDataAccess(new byte[0]), -1); 115 complete = p.apply(new ByteArrayDataAccess(new byte[0]), -1);
178 } 176 }
179 // 177 //
180 DataSerializer indexFile, dataFile; 178 DataSerializer indexFile, dataFile;
181 indexFile = dataFile = null; 179 indexFile = dataFile = null;
182 try { 180 try {
183 // 181 // FIXME perhaps, not a good idea to open stream for each revision added (e.g, when we pull a lot of them)
184 indexFile = revlogStream.getIndexStreamWriter(transaction); 182 indexFile = revlogStream.getIndexStreamWriter(transaction);
185 final boolean isInlineData = revlogStream.isInlineData(); 183 final boolean isInlineData = revlogStream.isInlineData();
186 HeaderWriter revlogHeader = new HeaderWriter(isInlineData); 184 HeaderWriter revlogHeader = new HeaderWriter(isInlineData);
187 revlogHeader.length(revLen, compressedLen); 185 revlogHeader.length(revLen, compressedLen);
188 revlogHeader.nodeid(rev.toByteArray()); 186 revlogHeader.nodeid(rev.toByteArray());