Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/BundleGenerator.java @ 644:1deea2f33218
Push: phase1 - prepare bundle with changes
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 19 Jun 2013 16:04:24 +0200 |
parents | |
children | 14dac192aa26 |
rev | line source |
---|---|
644
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.io.File; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.io.FileOutputStream; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.io.IOException; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.io.OutputStream; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.util.ArrayList; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.util.Arrays; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import java.util.Collection; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import java.util.Collections; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import java.util.Comparator; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import java.util.List; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import org.tmatesoft.hg.console.Bundle; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 import org.tmatesoft.hg.core.HgIOException; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import org.tmatesoft.hg.core.Nodeid; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 import org.tmatesoft.hg.internal.Patch.PatchDataSource; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 import org.tmatesoft.hg.repo.HgBundle; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 import org.tmatesoft.hg.repo.HgChangelog; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 import org.tmatesoft.hg.repo.HgDataFile; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 import org.tmatesoft.hg.repo.HgInternals; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 import org.tmatesoft.hg.repo.HgLookup; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 import org.tmatesoft.hg.repo.HgManifest; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 import org.tmatesoft.hg.repo.HgRepository; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 import org.tmatesoft.hg.repo.HgRuntimeException; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 /** |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 * @see http://mercurial.selenic.com/wiki/BundleFormat |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 * @author Artem Tikhomirov |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 * @author TMate Software Ltd. |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 */ |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 public class BundleGenerator { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 private final Internals repo; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 public BundleGenerator(Internals hgRepo) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 repo = hgRepo; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 public File create(List<Nodeid> changesets) throws HgIOException, IOException { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 final HgChangelog clog = repo.getRepo().getChangelog(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 final HgManifest manifest = repo.getRepo().getManifest(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 IntVector clogRevsVector = new IntVector(changesets.size(), 0); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 for (Nodeid n : changesets) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 clogRevsVector.add(clog.getRevisionIndex(n)); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 clogRevsVector.sort(true); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 final int[] clogRevs = clogRevsVector.toArray(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 System.out.printf("Changelog: %s\n", Arrays.toString(clogRevs)); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 final IntMap<Nodeid> clogMap = new IntMap<Nodeid>(changesets.size()); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 final IntVector manifestRevs = new IntVector(changesets.size(), 0); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 final List<HgDataFile> files = new ArrayList<HgDataFile>(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 clog.range(new HgChangelog.Inspector() { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 public void next(int revisionIndex, Nodeid nodeid, RawChangeset cset) throws HgRuntimeException { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 clogMap.put(revisionIndex, nodeid); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 manifestRevs.add(manifest.getRevisionIndex(cset.manifest())); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 for (String f : cset.files()) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 HgDataFile df = repo.getRepo().getFileNode(f); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 if (!files.contains(df)) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 files.add(df); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 }, clogRevs); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 manifestRevs.sort(true); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 System.out.printf("Manifest: %s\n", Arrays.toString(manifestRevs.toArray(true))); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 /////////////// |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 for (HgDataFile df : sortedByName(files)) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 RevlogStream s = repo.getImplAccess().getStream(df); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 final IntVector fileRevs = new IntVector(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 s.iterate(0, TIP, false, new RevlogStream.Inspector() { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) throws HgRuntimeException { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 if (Arrays.binarySearch(clogRevs, linkRevision) >= 0) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 fileRevs.add(revisionIndex); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 }); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 fileRevs.sort(true); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 System.out.printf("%s: %s\n", df.getPath(), Arrays.toString(fileRevs.toArray(true))); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 if (Boolean.FALSE.booleanValue()) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 return null; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 /////////////// |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 // |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 final File bundleFile = File.createTempFile("hg4j-", "bundle"); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 final OutputStreamSerializer outRaw = new OutputStreamSerializer(new FileOutputStream(bundleFile)); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 outRaw.write("HG10UN".getBytes(), 0, 6); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 // |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 RevlogStream clogStream = repo.getImplAccess().getChangelogStream(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 new ChunkGenerator(outRaw, clogMap).iterate(clogStream, clogRevs); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 outRaw.writeInt(0); // null chunk for changelog group |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 // |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 RevlogStream manifestStream = repo.getImplAccess().getManifestStream(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 new ChunkGenerator(outRaw, clogMap).iterate(manifestStream, manifestRevs.toArray(true)); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 outRaw.writeInt(0); // null chunk for manifest group |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 // |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 for (HgDataFile df : sortedByName(files)) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 RevlogStream s = repo.getImplAccess().getStream(df); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 final IntVector fileRevs = new IntVector(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 s.iterate(0, TIP, false, new RevlogStream.Inspector() { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) throws HgRuntimeException { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 if (Arrays.binarySearch(clogRevs, linkRevision) >= 0) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 fileRevs.add(revisionIndex); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 }); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 fileRevs.sort(true); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 if (!fileRevs.isEmpty()) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 // although BundleFormat page says "filename length, filename" for a file, |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 // in fact there's a sort of 'filename chunk', i.e. filename length field includes |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 // not only length of filename, but also length of the field itseld, i.e. filename.length+sizeof(int) |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 byte[] fnameBytes = df.getPath().toString().getBytes(); // FIXME check encoding in native hg (and fix accordingly in HgBundle) |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 outRaw.writeInt(fnameBytes.length + 4); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 outRaw.writeByte(fnameBytes); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 new ChunkGenerator(outRaw, clogMap).iterate(s, fileRevs.toArray(true)); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 outRaw.writeInt(0); // null chunk for file group |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 outRaw.done(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 //return new HgBundle(repo.getSessionContext(), repo.getDataAccess(), bundleFile); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 return bundleFile; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 private static Collection<HgDataFile> sortedByName(List<HgDataFile> files) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 Collections.sort(files, new Comparator<HgDataFile>() { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 public int compare(HgDataFile o1, HgDataFile o2) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 return o1.getPath().compareTo(o2.getPath()); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 }); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 return files; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 public static void main(String[] args) throws Exception { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 final HgLookup hgLookup = new HgLookup(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 HgRepository hgRepo = hgLookup.detectFromWorkingDir(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 BundleGenerator bg = new BundleGenerator(HgInternals.getImplementationRepo(hgRepo)); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 ArrayList<Nodeid> l = new ArrayList<Nodeid>(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 l.add(Nodeid.fromAscii("9ef1fab9f5e3d51d70941121dc27410e28069c2d")); // 640 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 l.add(Nodeid.fromAscii("2f33f102a8fa59274a27ebbe1c2903cecac6c5d5")); // 639 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 l.add(Nodeid.fromAscii("d074971287478f69ab0a64176ce2284d8c1e91c3")); // 638 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 File bundleFile = bg.create(l); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 HgBundle b = hgLookup.loadBundle(bundleFile); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 // Bundle.dump(b); // FIXME dependency from dependant code |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 private static class ChunkGenerator implements RevlogStream.Inspector { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 private final DataSerializer ds; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 private final IntMap<Nodeid> parentMap; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 private final IntMap<Nodeid> clogMap; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 private byte[] prevContent; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 private int startParent; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 public ChunkGenerator(DataSerializer dataSerializer, IntMap<Nodeid> clogNodeidMap) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 ds = dataSerializer; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 parentMap = new IntMap<Nodeid>(clogNodeidMap.size());; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 clogMap = clogNodeidMap; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
184 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
185 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 public void iterate(RevlogStream s, int[] revisions) throws HgRuntimeException { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 int[] p = s.parents(revisions[0], new int[2]); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 startParent = p[0]; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 int[] revs2read; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 if (startParent == NO_REVISION) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 revs2read = revisions; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 prevContent = new byte[0]; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 } else { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
194 revs2read = new int[revisions.length + 1]; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 revs2read[0] = startParent; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
196 System.arraycopy(revisions, 0, revs2read, 1, revisions.length); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
197 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 s.iterate(revs2read, true, this); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
199 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
200 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) throws HgRuntimeException { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
202 try { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
203 parentMap.put(revisionIndex, Nodeid.fromBinary(nodeid, 0)); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
204 byte[] nextContent = data.byteArray(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 data.done(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
206 if (revisionIndex == startParent) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
207 prevContent = nextContent; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
208 return; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
209 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
210 Patch p = GeneratePatchInspector.delta(prevContent, nextContent); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
211 prevContent = nextContent; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
212 nextContent = null; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
213 PatchDataSource pds = p.new PatchDataSource(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
214 int len = pds.serializeLength() + 84; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
215 ds.writeInt(len); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
216 ds.write(nodeid, 0, Nodeid.SIZE); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
217 // TODO assert parents match those in previous group elements |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
218 if (parent1Revision != NO_REVISION) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
219 ds.writeByte(parentMap.get(parent1Revision).toByteArray()); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
220 } else { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
221 ds.writeByte(Nodeid.NULL.toByteArray()); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
222 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
223 if (parent2Revision != NO_REVISION) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
224 ds.writeByte(parentMap.get(parent2Revision).toByteArray()); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
225 } else { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
226 ds.writeByte(Nodeid.NULL.toByteArray()); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
227 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
228 ds.writeByte(clogMap.get(linkRevision).toByteArray()); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
229 pds.serialize(ds); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
230 } catch (IOException ex) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
231 // XXX odd to have object with IOException to use where no checked exception is allowed |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
232 throw new HgInvalidControlFileException(ex.getMessage(), ex, null); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
233 } catch (HgIOException ex) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
234 throw new HgInvalidControlFileException(ex, true); // XXX any way to refactor ChunkGenerator not to get checked exception here? |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
235 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
236 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
237 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
238 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
239 private static class OutputStreamSerializer extends DataSerializer { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
240 private final OutputStream out; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
241 public OutputStreamSerializer(OutputStream outputStream) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
242 out = outputStream; |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
243 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
244 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
245 @Override |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
246 public void write(byte[] data, int offset, int length) throws HgIOException { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
247 try { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
248 out.write(data, offset, length); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
249 } catch (IOException ex) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
250 throw new HgIOException(ex.getMessage(), ex, null); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
251 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
252 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
253 |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
254 @Override |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
255 public void done() throws HgIOException { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
256 try { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
257 out.close(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
258 super.done(); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
259 } catch (IOException ex) { |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
260 throw new HgIOException(ex.getMessage(), ex, null); |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
261 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
262 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
263 } |
1deea2f33218
Push: phase1 - prepare bundle with changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
264 } |