comparison src/org/tmatesoft/hg/internal/BundleGenerator.java @ 668:d25f0324a27a

Delete bundle with push/pull changes once command completes successfully. Test for bundle generator
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 11 Jul 2013 18:41:40 +0200
parents fba85bc1dfb8
children 52af7f62e731
comparison
equal deleted inserted replaced
667:fba85bc1dfb8 668:d25f0324a27a
33 33
34 import org.tmatesoft.hg.core.HgIOException; 34 import org.tmatesoft.hg.core.HgIOException;
35 import org.tmatesoft.hg.core.Nodeid; 35 import org.tmatesoft.hg.core.Nodeid;
36 import org.tmatesoft.hg.internal.DataSerializer.OutputStreamSerializer; 36 import org.tmatesoft.hg.internal.DataSerializer.OutputStreamSerializer;
37 import org.tmatesoft.hg.internal.Patch.PatchDataSource; 37 import org.tmatesoft.hg.internal.Patch.PatchDataSource;
38 import org.tmatesoft.hg.repo.HgBundle;
39 import org.tmatesoft.hg.repo.HgChangelog; 38 import org.tmatesoft.hg.repo.HgChangelog;
40 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; 39 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
41 import org.tmatesoft.hg.repo.HgDataFile; 40 import org.tmatesoft.hg.repo.HgDataFile;
42 import org.tmatesoft.hg.repo.HgInternals;
43 import org.tmatesoft.hg.repo.HgInvalidControlFileException; 41 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
44 import org.tmatesoft.hg.repo.HgLookup;
45 import org.tmatesoft.hg.repo.HgManifest; 42 import org.tmatesoft.hg.repo.HgManifest;
46 import org.tmatesoft.hg.repo.HgRepository;
47 import org.tmatesoft.hg.repo.HgRuntimeException; 43 import org.tmatesoft.hg.repo.HgRuntimeException;
48 44
49 /** 45 /**
50 * @see http://mercurial.selenic.com/wiki/BundleFormat 46 * @see http://mercurial.selenic.com/wiki/BundleFormat
51 * @author Artem Tikhomirov 47 * @author Artem Tikhomirov
141 } 137 }
142 }); 138 });
143 return files; 139 return files;
144 } 140 }
145 141
146
147 public static void main(String[] args) throws Exception {
148 final HgLookup hgLookup = new HgLookup();
149 HgRepository hgRepo = hgLookup.detectFromWorkingDir();
150 BundleGenerator bg = new BundleGenerator(HgInternals.getImplementationRepo(hgRepo));
151 ArrayList<Nodeid> l = new ArrayList<Nodeid>();
152 l.add(Nodeid.fromAscii("9ef1fab9f5e3d51d70941121dc27410e28069c2d")); // 640
153 l.add(Nodeid.fromAscii("2f33f102a8fa59274a27ebbe1c2903cecac6c5d5")); // 639
154 l.add(Nodeid.fromAscii("d074971287478f69ab0a64176ce2284d8c1e91c3")); // 638
155 File bundleFile = bg.create(l);
156 HgBundle b = hgLookup.loadBundle(bundleFile);
157 // Bundle.dump(b); // FIXME dependency from dependant code
158 }
159
160 private static class ChunkGenerator implements RevlogStream.Inspector { 142 private static class ChunkGenerator implements RevlogStream.Inspector {
161 143
162 private final DataSerializer ds; 144 private final DataSerializer ds;
163 private final IntMap<Nodeid> parentMap; 145 private final IntMap<Nodeid> parentMap;
164 private final IntMap<Nodeid> clogMap; 146 private final IntMap<Nodeid> clogMap;
220 nextContent = null; 202 nextContent = null;
221 PatchDataSource pds = p.new PatchDataSource(); 203 PatchDataSource pds = p.new PatchDataSource();
222 int len = pds.serializeLength() + 84; 204 int len = pds.serializeLength() + 84;
223 ds.writeInt(len); 205 ds.writeInt(len);
224 ds.write(nodeid, 0, Nodeid.SIZE); 206 ds.write(nodeid, 0, Nodeid.SIZE);
225 // TODO assert parents match those in previous group elements
226 if (parent1Revision != NO_REVISION) { 207 if (parent1Revision != NO_REVISION) {
227 ds.writeByte(parentMap.get(parent1Revision).toByteArray()); 208 ds.writeByte(parentMap.get(parent1Revision).toByteArray());
228 } else { 209 } else {
229 ds.writeByte(Nodeid.NULL.toByteArray()); 210 ds.writeByte(Nodeid.NULL.toByteArray());
230 } 211 }