Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/RevlogStreamWriter.java @ 534:243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 04 Feb 2013 18:00:55 +0100 |
parents | e6f72c9829a6 |
children | dd4f6311af52 |
rev | line source |
---|---|
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.internal.Internals.REVLOGV1_RECORD_SIZE; |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.io.IOException; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.nio.ByteBuffer; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import org.tmatesoft.hg.core.Nodeid; |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
26 import org.tmatesoft.hg.core.SessionContext; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
27 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
28 import org.tmatesoft.hg.repo.HgInvalidStateException; |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 /** |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 * |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
32 * TODO separate operation to check if index is too big and split into index+data |
532
688c1ab113bb
Introduce explicit reference to base patch in bundle's group element, use it when cloning to fix defect when few revisions list null,null parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
530
diff
changeset
|
33 * |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 * @author Artem Tikhomirov |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 * @author TMate Software Ltd. |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 */ |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 public class RevlogStreamWriter { |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
40 /*XXX public because HgCloneCommand uses it*/ |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
41 public static class HeaderWriter implements DataSerializer.DataSource { |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 private final ByteBuffer header; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 private final boolean isInline; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 private long offset; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 private int length, compressedLength; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 private int baseRev, linkRev, p1, p2; |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
47 private byte[] nodeid; |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 public HeaderWriter(boolean inline) { |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 isInline = inline; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 header = ByteBuffer.allocate(REVLOGV1_RECORD_SIZE); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 public HeaderWriter offset(long offset) { |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 this.offset = offset; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 return this; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 |
532
688c1ab113bb
Introduce explicit reference to base patch in bundle's group element, use it when cloning to fix defect when few revisions list null,null parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
530
diff
changeset
|
59 public int baseRevision() { |
688c1ab113bb
Introduce explicit reference to base patch in bundle's group element, use it when cloning to fix defect when few revisions list null,null parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
530
diff
changeset
|
60 return baseRev; |
688c1ab113bb
Introduce explicit reference to base patch in bundle's group element, use it when cloning to fix defect when few revisions list null,null parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
530
diff
changeset
|
61 } |
688c1ab113bb
Introduce explicit reference to base patch in bundle's group element, use it when cloning to fix defect when few revisions list null,null parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
530
diff
changeset
|
62 |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 public HeaderWriter baseRevision(int baseRevision) { |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 this.baseRev = baseRevision; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 return this; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 public HeaderWriter length(int len, int compressedLen) { |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 this.length = len; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 this.compressedLength = compressedLen; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 return this; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 public HeaderWriter parents(int parent1, int parent2) { |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 p1 = parent1; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 p2 = parent2; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 return this; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 public HeaderWriter linkRevision(int linkRevision) { |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
81 linkRev = linkRevision; |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 return this; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 public HeaderWriter nodeid(Nodeid n) { |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
86 nodeid = n.toByteArray(); |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 return this; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 } |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
89 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
90 public HeaderWriter nodeid(byte[] nodeidBytes) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
91 nodeid = nodeidBytes; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
92 return this; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
93 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
94 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
95 public void serialize(DataSerializer out) throws IOException { |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 header.clear(); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 if (offset == 0) { |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 int version = 1 /* RevlogNG */; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 if (isInline) { |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 final int INLINEDATA = 1 << 16; // FIXME extract constant |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 version |= INLINEDATA; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 header.putInt(version); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 header.putInt(0); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } else { |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 header.putLong(offset << 16); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 header.putInt(compressedLength); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 header.putInt(length); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 header.putInt(baseRev); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 header.putInt(linkRev); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 header.putInt(p1); |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 header.putInt(p2); |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
114 header.put(nodeid); |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 // assume 12 bytes left are zeros |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
116 out.write(header.array(), 0, header.capacity()); |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 // regardless whether it's inline or separate data, |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 // offset field always represent cumulative compressedLength |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 // (while offset in the index file with inline==true differs by n*sizeof(header), where n is entry's position in the file) |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 offset += compressedLength; |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 } |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
123 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
124 public int serializeLength() { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
125 return header.capacity(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
126 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
127 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
128 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
129 private final DigestHelper dh = new DigestHelper(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
130 private final RevlogCompressor revlogDataZip; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
131 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
132 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
133 public RevlogStreamWriter(SessionContext ctx, RevlogStream stream) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
134 revlogDataZip = new RevlogCompressor(ctx); |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
137 private int lastEntryBase, lastEntryIndex; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
138 private byte[] lastEntryContent; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
139 private Nodeid lastEntryRevision; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
140 private IntMap<Nodeid> revisionCache = new IntMap<Nodeid>(32); |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
532
diff
changeset
|
141 |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
532
diff
changeset
|
142 public void addRevision(byte[] content, int linkRevision, int p1, int p2) { |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
143 int revCount = revlogStream.revisionCount(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
144 lastEntryIndex = revCount == 0 ? NO_REVISION : revCount - 1; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
145 populateLastEntry(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
146 // |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
532
diff
changeset
|
147 PatchGenerator pg = new PatchGenerator(); |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
148 Patch patch = pg.delta(lastEntryContent, content); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
149 int patchSerializedLength = patch.serializedLength(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
150 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
151 final boolean writeComplete = preferCompleteOverPatch(patchSerializedLength, content.length); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
152 DataSerializer.DataSource dataSource = writeComplete ? new DataSerializer.ByteArrayDataSource(content) : patch.new PatchDataSource(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
153 revlogDataZip.reset(dataSource); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
154 final int compressedLen; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
155 final boolean useUncompressedData = preferCompressedOverComplete(revlogDataZip.getCompressedLength(), dataSource.serializeLength()); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
156 if (useUncompressedData) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
157 // compression wasn't too effective, |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
158 compressedLen = dataSource.serializeLength() + 1 /*1 byte for 'u' - uncompressed prefix byte*/; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
159 } else { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
160 compressedLen= revlogDataZip.getCompressedLength(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
161 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
162 // |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
163 Nodeid p1Rev = revision(p1); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
164 Nodeid p2Rev = revision(p2); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
165 byte[] revisionNodeidBytes = dh.sha1(p1Rev, p2Rev, content).asBinary(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
166 // |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
167 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
168 DataSerializer indexFile, dataFile, activeFile; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
169 indexFile = dataFile = activeFile = null; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
170 try { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
171 // |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
172 activeFile = indexFile = revlogStream.getIndexStreamWriter(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
173 final boolean isInlineData = revlogStream.isInlineData(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
174 HeaderWriter revlogHeader = new HeaderWriter(isInlineData); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
175 revlogHeader.length(content.length, compressedLen); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
176 revlogHeader.nodeid(revisionNodeidBytes); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
177 revlogHeader.linkRevision(linkRevision); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
178 revlogHeader.parents(p1, p2); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
179 revlogHeader.baseRevision(writeComplete ? lastEntryIndex+1 : lastEntryBase); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
180 // |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
181 revlogHeader.serialize(indexFile); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
182 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
183 if (isInlineData) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
184 dataFile = indexFile; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
185 } else { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
186 dataFile = revlogStream.getDataStreamWriter(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
187 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
188 activeFile = dataFile; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
189 if (useUncompressedData) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
190 dataFile.writeByte((byte) 'u'); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
191 dataSource.serialize(dataFile); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
192 } else { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
193 int actualCompressedLenWritten = revlogDataZip.writeCompressedData(dataFile); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
194 if (actualCompressedLenWritten != compressedLen) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
195 throw new HgInvalidStateException(String.format("Expected %d bytes of compressed data, but actually wrote %d in %s", compressedLen, actualCompressedLenWritten, revlogStream.getDataFileName())); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
196 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
197 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
198 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
199 lastEntryContent = content; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
200 lastEntryBase = revlogHeader.baseRevision(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
201 lastEntryIndex++; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
202 lastEntryRevision = Nodeid.fromBinary(revisionNodeidBytes, 0); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
203 revisionCache.put(lastEntryIndex, lastEntryRevision); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
204 } catch (IOException ex) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
205 String m = String.format("Failed to write revision %d", lastEntryIndex+1, null); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
206 HgInvalidControlFileException t = new HgInvalidControlFileException(m, ex, null); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
207 if (activeFile == dataFile) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
208 throw revlogStream.initWithDataFile(t); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
209 } else { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
210 throw revlogStream.initWithIndexFile(t); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
211 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
212 } finally { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
213 indexFile.done(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
214 if (dataFile != null && dataFile != indexFile) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
215 dataFile.done(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
216 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
217 } |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
532
diff
changeset
|
218 } |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
532
diff
changeset
|
219 |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
220 private RevlogStream revlogStream; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
221 private Nodeid revision(int revisionIndex) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
222 if (revisionIndex == NO_REVISION) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
223 return Nodeid.NULL; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
224 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
225 Nodeid n = revisionCache.get(revisionIndex); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
226 if (n == null) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
227 n = Nodeid.fromBinary(revlogStream.nodeid(revisionIndex), 0); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
228 revisionCache.put(revisionIndex, n); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
229 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
230 return n; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
231 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
232 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
233 private void populateLastEntry() throws HgInvalidControlFileException { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
234 if (lastEntryIndex != NO_REVISION && lastEntryContent == null) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
235 assert lastEntryIndex >= 0; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
236 final IOException[] failure = new IOException[1]; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
237 revlogStream.iterate(lastEntryIndex, lastEntryIndex, true, new RevlogStream.Inspector() { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
238 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
239 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
240 try { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
241 lastEntryBase = baseRevision; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
242 lastEntryRevision = Nodeid.fromBinary(nodeid, 0); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
243 lastEntryContent = data.byteArray(); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
244 } catch (IOException ex) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
245 failure[0] = ex; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
246 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
247 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
248 }); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
249 if (failure[0] != null) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
250 String m = String.format("Failed to get content of most recent revision %d", lastEntryIndex); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
251 throw revlogStream.initWithDataFile(new HgInvalidControlFileException(m, failure[0], null)); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
252 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
253 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
254 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
255 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
256 public static boolean preferCompleteOverPatch(int patchLength, int fullContentLength) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
257 return !decideWorthEffort(patchLength, fullContentLength); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
258 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
259 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
260 public static boolean preferCompressedOverComplete(int compressedLen, int fullContentLength) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
261 if (compressedLen <= 0) { // just in case, meaningless otherwise |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
262 return false; |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
263 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
264 return decideWorthEffort(compressedLen, fullContentLength); |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
265 } |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
266 |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
267 // true if length obtained with effort is worth it |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
268 private static boolean decideWorthEffort(int lengthWithExtraEffort, int lengthWithoutEffort) { |
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
269 return lengthWithExtraEffort < (/* 3/4 of original */lengthWithoutEffort - (lengthWithoutEffort >>> 2)); |
530
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
270 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
271 } |