annotate src/org/tmatesoft/hg/internal/RevlogStreamWriter.java @ 657:6334b0267103

ParentChildMap can supply RevisionMap. Refactor ArrayHelper to keep most of sorted/reverse index magic inside
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 04 Jul 2013 20:27:45 +0200
parents 14dac192aa26
children 4fd317a2fecf
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;
645
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
28 import org.tmatesoft.hg.internal.DataSerializer.ByteArraySerializer;
618
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;
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
32 import org.tmatesoft.hg.repo.HgInvalidRevisionException;
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
33 import org.tmatesoft.hg.repo.HgInvalidStateException;
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
34 import org.tmatesoft.hg.repo.HgRuntimeException;
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
35
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 *
608
e1b29756f901 Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
38 * 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
39 *
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
40 * @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
41 * @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
42 */
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 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
44
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
45 private final DigestHelper dh = new DigestHelper();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
46 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
47 private final Transaction transaction;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
48 private int lastEntryBase, lastEntryIndex;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
49 private byte[] lastEntryContent;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
50 private Nodeid lastEntryRevision;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
51 private IntMap<Nodeid> revisionCache = new IntMap<Nodeid>(32);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
52 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
53
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
54 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
55 assert ctxSource != null;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
56 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
57 assert tr != null;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
58
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
59 revlogDataZip = new RevlogCompressor(ctxSource.getSessionContext());
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
60 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
61 transaction = tr;
538
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
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
64 /**
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
65 * @return nodeid of added revision
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
66 * @throws HgRuntimeException
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
67 */
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
68 public Nodeid addRevision(DataSource content, int linkRevision, int p1, int p2) throws HgIOException, HgRuntimeException {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
69 lastEntryRevision = Nodeid.NULL;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
70 int revCount = revlogStream.revisionCount();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
71 lastEntryIndex = revCount == 0 ? NO_REVISION : revCount - 1;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
72 populateLastEntry();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
73 //
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
74 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
75 Patch patch = GeneratePatchInspector.delta(lastEntryContent, contentByteArray);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
76 int patchSerializedLength = patch.serializedLength();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
77
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
78 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
79 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
80 revlogDataZip.reset(dataSource);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
81 final int compressedLen;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
82 final boolean useCompressedData = preferCompressedOverComplete(revlogDataZip.getCompressedLength(), dataSource.serializeLength());
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
83 if (useCompressedData) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
84 compressedLen= revlogDataZip.getCompressedLength();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
85 } else {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
86 // compression wasn't too effective,
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
87 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
88 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
89 //
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
90 Nodeid p1Rev = revision(p1);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
91 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
92 byte[] revisionNodeidBytes = dh.sha1(p1Rev, p2Rev, contentByteArray).asBinary();
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
93 //
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
94
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
95 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
96 indexFile = dataFile = null;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
97 try {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
98 //
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 indexFile = revlogStream.getIndexStreamWriter(transaction);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
100 final boolean isInlineData = revlogStream.isInlineData();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
101 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
102 revlogHeader.length(contentByteArray.length, compressedLen);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
103 revlogHeader.nodeid(revisionNodeidBytes);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
104 revlogHeader.linkRevision(linkRevision);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
105 revlogHeader.parents(p1, p2);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
106 revlogHeader.baseRevision(writeComplete ? lastEntryIndex+1 : lastEntryBase);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
107 long lastEntryOffset = revlogStream.newEntryOffset();
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
108 revlogHeader.offset(lastEntryOffset);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
109 //
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
110 revlogHeader.serialize(indexFile);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
111
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
112 if (isInlineData) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
113 dataFile = indexFile;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
114 } 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
115 dataFile = revlogStream.getDataStreamWriter(transaction);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
116 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
117 if (useCompressedData) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
118 int actualCompressedLenWritten = revlogDataZip.writeCompressedData(dataFile);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
119 if (actualCompressedLenWritten != compressedLen) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
120 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
121 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
122 } else {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
123 dataFile.writeByte((byte) 'u');
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
124 dataSource.serialize(dataFile);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
125 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
126
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
127
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
128 lastEntryContent = contentByteArray;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
129 lastEntryBase = revlogHeader.baseRevision();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
130 lastEntryIndex++;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
131 lastEntryRevision = Nodeid.fromBinary(revisionNodeidBytes, 0);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
132 revisionCache.put(lastEntryIndex, lastEntryRevision);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
133
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
134 revlogStream.revisionAdded(lastEntryIndex, lastEntryRevision, lastEntryBase, lastEntryOffset);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
135 } finally {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
136 indexFile.done();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
137 if (dataFile != null && dataFile != indexFile) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
138 dataFile.done();
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 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
141 return lastEntryRevision;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
142 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
143
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
144 private byte[] toByteArray(DataSource content) throws HgIOException, HgRuntimeException {
645
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
145 ByteArraySerializer ba = new ByteArraySerializer();
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
146 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
147 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
148 }
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
149
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
150 private Nodeid revision(int revisionIndex) throws HgInvalidControlFileException, HgInvalidRevisionException {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
151 if (revisionIndex == NO_REVISION) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
152 return Nodeid.NULL;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
153 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
154 Nodeid n = revisionCache.get(revisionIndex);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
155 if (n == null) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
156 n = Nodeid.fromBinary(revlogStream.nodeid(revisionIndex), 0);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
157 revisionCache.put(revisionIndex, n);
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 return n;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
160 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
161
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
162 private void populateLastEntry() throws HgRuntimeException {
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
163 if (lastEntryContent != null) {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
164 return;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
165 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
166 if (lastEntryIndex != NO_REVISION) {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
167 assert lastEntryIndex >= 0;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
168 final IOException[] failure = new IOException[1];
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
169 revlogStream.iterate(lastEntryIndex, lastEntryIndex, true, new RevlogStream.Inspector() {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
170
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
171 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
172 try {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
173 lastEntryBase = baseRevision;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
174 lastEntryRevision = Nodeid.fromBinary(nodeid, 0);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
175 lastEntryContent = data.byteArray();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
176 } catch (IOException ex) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
177 failure[0] = ex;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
178 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
179 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
180 });
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
181 if (failure[0] != null) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
182 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
183 throw revlogStream.initWithDataFile(new HgInvalidControlFileException(m, failure[0], null));
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
184 }
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
185 } else {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
186 lastEntryContent = new byte[0];
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
187 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
188 }
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 public static boolean preferCompleteOverPatch(int patchLength, int fullContentLength) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
191 return !decideWorthEffort(patchLength, fullContentLength);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
192 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
193
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
194 public static boolean preferCompressedOverComplete(int compressedLen, int fullContentLength) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
195 if (compressedLen <= 0) { // just in case, meaningless otherwise
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
196 return false;
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 return decideWorthEffort(compressedLen, fullContentLength);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
199 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
200
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
201 // true if length obtained with effort is worth it
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
202 private static boolean decideWorthEffort(int lengthWithExtraEffort, int lengthWithoutEffort) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
203 return lengthWithExtraEffort < (/* 3/4 of original */lengthWithoutEffort - (lengthWithoutEffort >>> 2));
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
204 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 534
diff changeset
205
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
206 /*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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214
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 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
216 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
217 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
218 }
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
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 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
221 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
222 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
223 }
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
224
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
225 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
226 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
227 }
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
228
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
229 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
230 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
231 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
232 }
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
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 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
235 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
236 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
237 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
238 }
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
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 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
241 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
242 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
243 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
244 }
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
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 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
247 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
248 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
249 }
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
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 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
252 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
253 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
254 }
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
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 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
257 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
258 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
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
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
261 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
262 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
263 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
264 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
265 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
266 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
267 }
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.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
269 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
270 } 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
271 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
272 }
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(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
274 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
275 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
276 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
277 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
278 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
279 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
280 // 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
281 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
282
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 // 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
284 // offset field always represent cumulative compressedLength
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
285 // (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
286 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
287 }
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
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 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
290 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
291 }
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
292 }
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
293 }