Mercurial > hg4j
comparison test/org/tmatesoft/hg/tools/ManifestEntryBuilder.java @ 384:4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 13 Feb 2012 13:20:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
383:994b5813a925 | 384:4b97847d0b2d |
---|---|
1 /* | |
2 * Copyright (c) 2012 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.tools; | |
18 | |
19 import java.io.ByteArrayOutputStream; | |
20 | |
21 import org.tmatesoft.hg.core.Nodeid; | |
22 | |
23 /** | |
24 * Create binary manifest entry ready to write down into 00manifest.i | |
25 * <p>Usage: | |
26 * <pre> | |
27 * ManifestEntryBuilder mb = new ManifestEntryBuilder(); | |
28 * mb.reset().add("file1", file1.getRevision(r1)); | |
29 * mb.add("file2", file2.getRevision(r2)); | |
30 * byte[] manifestRecordData = mb.build(); | |
31 * byte[] manifestRevlogHeader = buildRevlogHeader(..., sha1(parents, manifestRecordData), manifestRecordData.length); | |
32 * manifestIndexOutputStream.write(manifestRevlogHeader); | |
33 * manifestIndexOutputStream.write(manifestRecordData); | |
34 * </pre> | |
35 * | |
36 * @author Artem Tikhomirov | |
37 * @author TMate Software Ltd. | |
38 */ | |
39 public class ManifestEntryBuilder { | |
40 private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | |
41 | |
42 | |
43 public ManifestEntryBuilder reset() { | |
44 buffer.reset(); | |
45 return this; | |
46 } | |
47 public ManifestEntryBuilder add(String fname, Nodeid revision) { | |
48 byte[] b = fname.getBytes(); | |
49 buffer.write(b, 0, b.length); | |
50 buffer.write('\0'); | |
51 b = revision.toString().getBytes(); | |
52 buffer.write(b, 0, b.length); | |
53 buffer.write('\n'); | |
54 return this; | |
55 } | |
56 | |
57 public byte[] build() { | |
58 return buffer.toByteArray(); | |
59 } | |
60 | |
61 } |