Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/RevlogStreamWriter.java @ 624:507602cb4fb3
FIXMEs and TODOs: pay some technical debt
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 20 May 2013 20:34:33 +0200 |
parents | 7c0d2ce340b8 |
children | 6526d8adbc0f |
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 |
617
65c01508f002
Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
608
diff
changeset
|
25 import org.tmatesoft.hg.core.HgIOException; |
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
|
26 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
|
27 import org.tmatesoft.hg.core.SessionContext; |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
28 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSerializer; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
29 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSource; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
30 import org.tmatesoft.hg.internal.DataSerializer.DataSource; |
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
|
31 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
|
32 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
|
33 |
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 /** |
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 * |
608
e1b29756f901
Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
591
diff
changeset
|
36 * TODO [post-1.1] 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
|
37 * |
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
|
38 * @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
|
39 * @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
|
40 */ |
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
|
41 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
|
42 |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
43 private final DigestHelper dh = new DigestHelper(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
44 private final RevlogCompressor revlogDataZip; |
617
65c01508f002
Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
608
diff
changeset
|
45 private final Transaction transaction; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
46 private int lastEntryBase, lastEntryIndex; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
47 private byte[] lastEntryContent; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
48 private Nodeid lastEntryRevision; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
49 private IntMap<Nodeid> revisionCache = new IntMap<Nodeid>(32); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
50 private RevlogStream revlogStream; |
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
|
51 |
617
65c01508f002
Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
608
diff
changeset
|
52 public RevlogStreamWriter(SessionContext.Source ctxSource, RevlogStream stream, Transaction tr) { |
591
e447384f3771
CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
53 assert ctxSource != null; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
54 assert stream != null; |
617
65c01508f002
Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
608
diff
changeset
|
55 assert tr != null; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
56 |
591
e447384f3771
CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
57 revlogDataZip = new RevlogCompressor(ctxSource.getSessionContext()); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
58 revlogStream = stream; |
617
65c01508f002
Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
608
diff
changeset
|
59 transaction = tr; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
60 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
61 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
62 /** |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
63 * @return nodeid of added revision |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
64 */ |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
65 public Nodeid addRevision(DataSource content, int linkRevision, int p1, int p2) throws HgIOException { |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
66 lastEntryRevision = Nodeid.NULL; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
67 int revCount = revlogStream.revisionCount(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
68 lastEntryIndex = revCount == 0 ? NO_REVISION : revCount - 1; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
69 populateLastEntry(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
70 // |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
71 byte[] contentByteArray = toByteArray(content); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
72 Patch patch = GeneratePatchInspector.delta(lastEntryContent, contentByteArray); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
73 int patchSerializedLength = patch.serializedLength(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
74 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
75 final boolean writeComplete = preferCompleteOverPatch(patchSerializedLength, contentByteArray.length); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
76 DataSerializer.DataSource dataSource = writeComplete ? new ByteArrayDataSource(contentByteArray) : patch.new PatchDataSource(); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
77 revlogDataZip.reset(dataSource); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
78 final int compressedLen; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
79 final boolean useCompressedData = preferCompressedOverComplete(revlogDataZip.getCompressedLength(), dataSource.serializeLength()); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
80 if (useCompressedData) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
81 compressedLen= revlogDataZip.getCompressedLength(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
82 } else { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
83 // compression wasn't too effective, |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
84 compressedLen = dataSource.serializeLength() + 1 /*1 byte for 'u' - uncompressed prefix byte*/; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
85 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
86 // |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
87 Nodeid p1Rev = revision(p1); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
88 Nodeid p2Rev = revision(p2); |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
89 byte[] revisionNodeidBytes = dh.sha1(p1Rev, p2Rev, contentByteArray).asBinary(); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
90 // |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
91 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
92 DataSerializer indexFile, dataFile; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
93 indexFile = dataFile = null; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
94 try { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
95 // |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
96 indexFile = revlogStream.getIndexStreamWriter(transaction); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
97 final boolean isInlineData = revlogStream.isInlineData(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
98 HeaderWriter revlogHeader = new HeaderWriter(isInlineData); |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
99 revlogHeader.length(contentByteArray.length, compressedLen); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
100 revlogHeader.nodeid(revisionNodeidBytes); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
101 revlogHeader.linkRevision(linkRevision); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
102 revlogHeader.parents(p1, p2); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
103 revlogHeader.baseRevision(writeComplete ? lastEntryIndex+1 : lastEntryBase); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
104 long lastEntryOffset = revlogStream.newEntryOffset(); |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
105 revlogHeader.offset(lastEntryOffset); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
106 // |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
107 revlogHeader.serialize(indexFile); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
108 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
109 if (isInlineData) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
110 dataFile = indexFile; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
111 } else { |
617
65c01508f002
Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
608
diff
changeset
|
112 dataFile = revlogStream.getDataStreamWriter(transaction); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
113 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
114 if (useCompressedData) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
115 int actualCompressedLenWritten = revlogDataZip.writeCompressedData(dataFile); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
116 if (actualCompressedLenWritten != compressedLen) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
117 throw new HgInvalidStateException(String.format("Expected %d bytes of compressed data, but actually wrote %d in %s", compressedLen, actualCompressedLenWritten, revlogStream.getDataFileName())); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
118 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
119 } else { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
120 dataFile.writeByte((byte) 'u'); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
121 dataSource.serialize(dataFile); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
122 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
123 |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
124 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
125 lastEntryContent = contentByteArray; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
126 lastEntryBase = revlogHeader.baseRevision(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
127 lastEntryIndex++; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
128 lastEntryRevision = Nodeid.fromBinary(revisionNodeidBytes, 0); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
129 revisionCache.put(lastEntryIndex, lastEntryRevision); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
130 |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
131 revlogStream.revisionAdded(lastEntryIndex, lastEntryRevision, lastEntryBase, lastEntryOffset); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
132 } finally { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
133 indexFile.done(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
134 if (dataFile != null && dataFile != indexFile) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
135 dataFile.done(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
136 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
137 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
138 return lastEntryRevision; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
139 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
140 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
141 private byte[] toByteArray(DataSource content) throws HgIOException { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
142 ByteArrayDataSerializer ba = new ByteArrayDataSerializer(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
143 content.serialize(ba); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
144 return ba.toByteArray(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
145 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
146 |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
147 private Nodeid revision(int revisionIndex) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
148 if (revisionIndex == NO_REVISION) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
149 return Nodeid.NULL; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
150 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
151 Nodeid n = revisionCache.get(revisionIndex); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
152 if (n == null) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
153 n = Nodeid.fromBinary(revlogStream.nodeid(revisionIndex), 0); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
154 revisionCache.put(revisionIndex, n); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
155 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
156 return n; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
157 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
158 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
159 private void populateLastEntry() throws HgInvalidControlFileException { |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
160 if (lastEntryContent != null) { |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
161 return; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
162 } |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
163 if (lastEntryIndex != NO_REVISION) { |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
164 assert lastEntryIndex >= 0; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
165 final IOException[] failure = new IOException[1]; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
166 revlogStream.iterate(lastEntryIndex, lastEntryIndex, true, new RevlogStream.Inspector() { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
167 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
168 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
169 try { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
170 lastEntryBase = baseRevision; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
171 lastEntryRevision = Nodeid.fromBinary(nodeid, 0); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
172 lastEntryContent = data.byteArray(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
173 } catch (IOException ex) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
174 failure[0] = ex; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
175 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
176 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
177 }); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
178 if (failure[0] != null) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
179 String m = String.format("Failed to get content of most recent revision %d", lastEntryIndex); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
180 throw revlogStream.initWithDataFile(new HgInvalidControlFileException(m, failure[0], null)); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
181 } |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
182 } else { |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
183 lastEntryContent = new byte[0]; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
184 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
185 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
186 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
187 public static boolean preferCompleteOverPatch(int patchLength, int fullContentLength) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
188 return !decideWorthEffort(patchLength, fullContentLength); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
189 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
190 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
191 public static boolean preferCompressedOverComplete(int compressedLen, int fullContentLength) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
192 if (compressedLen <= 0) { // just in case, meaningless otherwise |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
193 return false; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
194 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
195 return decideWorthEffort(compressedLen, fullContentLength); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
196 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
197 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
198 // true if length obtained with effort is worth it |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
199 private static boolean decideWorthEffort(int lengthWithExtraEffort, int lengthWithoutEffort) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
200 return lengthWithExtraEffort < (/* 3/4 of original */lengthWithoutEffort - (lengthWithoutEffort >>> 2)); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
201 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
202 |
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
|
203 /*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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 |
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
|
212 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
|
213 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
|
214 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
|
215 } |
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
|
216 |
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
|
217 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
|
218 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
|
219 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
|
220 } |
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
|
221 |
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
|
222 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
|
223 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
|
224 } |
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
|
225 |
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
|
226 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
|
227 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
|
228 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
|
229 } |
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
|
230 |
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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 } |
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
|
236 |
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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 } |
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
|
242 |
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
|
243 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
|
244 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
|
245 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
|
246 } |
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
|
247 |
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
|
248 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
|
249 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
|
250 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
|
251 } |
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
|
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 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
|
254 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
|
255 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
|
256 } |
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 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
258 public void serialize(DataSerializer out) throws HgIOException { |
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
|
259 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
|
260 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
|
261 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
|
262 if (isInline) { |
608
e1b29756f901
Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
591
diff
changeset
|
263 version |= RevlogStream.INLINEDATA; |
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
|
264 } |
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
|
265 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
|
266 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
|
267 } 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
|
268 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
|
269 } |
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 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 // 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
|
278 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
|
279 |
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
|
280 // 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
|
281 // offset field always represent cumulative compressedLength |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
282 // (while physical offset in the index file with inline==true differs by n*sizeof(header), where n is entry's position in the file) |
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
|
283 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
|
284 } |
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
|
285 |
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
|
286 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
|
287 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
|
288 } |
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
|
289 } |
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
|
290 } |