tikhomirov@384: /* tikhomirov@384: * Copyright (c) 2012 TMate Software Ltd tikhomirov@384: * tikhomirov@384: * This program is free software; you can redistribute it and/or modify tikhomirov@384: * it under the terms of the GNU General Public License as published by tikhomirov@384: * the Free Software Foundation; version 2 of the License. tikhomirov@384: * tikhomirov@384: * This program is distributed in the hope that it will be useful, tikhomirov@384: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@384: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@384: * GNU General Public License for more details. tikhomirov@384: * tikhomirov@384: * For information on how to redistribute this software under tikhomirov@384: * the terms of a license other than GNU General Public License tikhomirov@384: * contact TMate Software at support@hg4j.com tikhomirov@384: */ tikhomirov@538: package org.tmatesoft.hg.internal; tikhomirov@384: tikhomirov@384: import java.io.ByteArrayOutputStream; tikhomirov@384: tikhomirov@384: import org.tmatesoft.hg.core.Nodeid; tikhomirov@384: tikhomirov@384: /** tikhomirov@384: * Create binary manifest entry ready to write down into 00manifest.i tikhomirov@384: *
Usage: tikhomirov@384: *
tikhomirov@384: * ManifestEntryBuilder mb = new ManifestEntryBuilder(); tikhomirov@384: * mb.reset().add("file1", file1.getRevision(r1)); tikhomirov@384: * mb.add("file2", file2.getRevision(r2)); tikhomirov@384: * byte[] manifestRecordData = mb.build(); tikhomirov@384: * byte[] manifestRevlogHeader = buildRevlogHeader(..., sha1(parents, manifestRecordData), manifestRecordData.length); tikhomirov@384: * manifestIndexOutputStream.write(manifestRevlogHeader); tikhomirov@384: * manifestIndexOutputStream.write(manifestRecordData); tikhomirov@384: *tikhomirov@384: * tikhomirov@384: * @author Artem Tikhomirov tikhomirov@384: * @author TMate Software Ltd. tikhomirov@384: */ tikhomirov@384: public class ManifestEntryBuilder { tikhomirov@384: private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); tikhomirov@384: tikhomirov@384: tikhomirov@384: public ManifestEntryBuilder reset() { tikhomirov@384: buffer.reset(); tikhomirov@384: return this; tikhomirov@384: } tikhomirov@384: public ManifestEntryBuilder add(String fname, Nodeid revision) { tikhomirov@384: byte[] b = fname.getBytes(); tikhomirov@384: buffer.write(b, 0, b.length); tikhomirov@384: buffer.write('\0'); tikhomirov@384: b = revision.toString().getBytes(); tikhomirov@384: buffer.write(b, 0, b.length); tikhomirov@384: buffer.write('\n'); tikhomirov@384: return this; tikhomirov@384: } tikhomirov@384: tikhomirov@384: public byte[] build() { tikhomirov@384: return buffer.toByteArray(); tikhomirov@384: } tikhomirov@384: tikhomirov@384: }