if (clogRevs.length == 0) {
// nothing to write
return bundleFile;
}
final FileOutputStream osBundle = new FileOutputStream(bundleFile);
final OutputStreamSerializer outRaw = new OutputStreamSerializer(osBundle);
outRaw.write("HG10UN".getBytes(), 0, 6);
//
RevlogStream clogStream = repo.getImplAccess().getChangelogStream();
new ChunkGenerator(outRaw, clogMap).iterate(clogStream, clogRevs);
outRaw.writeInt(0); // null chunk for changelog group
//
RevlogStream manifestStream = repo.getImplAccess().getManifestStream();
new ChunkGenerator(outRaw, clogMap).iterate(manifestStream, manifestRevs.toArray(true));
outRaw.writeInt(0); // null chunk for manifest group
//
EncodingHelper fnEncoder = repo.buildFileNameEncodingHelper();
for (HgDataFile df : sortedByName(files)) {
RevlogStream s = repo.getImplAccess().getStream(df);
final IntVector fileRevs = new IntVector();
s.iterate(0, TIP, false, new RevlogStream.Inspector() {
public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) throws HgRuntimeException {
if (Arrays.binarySearch(clogRevs, linkRevision) >= 0) {
fileRevs.add(revisionIndex);
}
}
});
fileRevs.sort(true);
if (!fileRevs.isEmpty()) {
// although BundleFormat page says "filename length, filename" for a file,
// in fact there's a sort of 'filename chunk', i.e. filename length field includes
// not only length of filename, but also length of the field itseld, i.e. filename.length+sizeof(int)
byte[] fnameBytes = fnEncoder.toBundle(df.getPath());
outRaw.writeInt(fnameBytes.length + 4);
outRaw.writeByte(fnameBytes);
new ChunkGenerator(outRaw, clogMap).iterate(s, fileRevs.toArray(true));
outRaw.writeInt(0); // null chunk for file group
}
}
outRaw.writeInt(0); // null chunk to indicate no more files (although BundleFormat page doesn't mention this)
outRaw.done();
osBundle.flush();
osBundle.close();
//return new HgBundle(repo.getSessionContext(), repo.getDataAccess(), bundleFile);
return bundleFile;
}