annotate test/org/tmatesoft/hg/tools/ManifestEntryBuilder.java @ 476:c02b5710d9ac

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