Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/RevlogStreamWriter.java @ 661:5d8798772cca
Merge branch smartgit-4.5 (no actual changes, merely to denote branch is inactive
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 10 Jul 2013 11:48:55 +0200 |
parents | 4fd317a2fecf |
children | 46b56864b483 |
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; |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
28 import org.tmatesoft.hg.internal.DataSerializer.ByteArrayDataSource; |
645
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
29 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
|
30 import org.tmatesoft.hg.internal.DataSerializer.DataSource; |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgBundle.GroupElement; |
534
243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
32 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
|
33 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
|
34 import org.tmatesoft.hg.repo.HgInvalidStateException; |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
35 import org.tmatesoft.hg.repo.HgRepository; |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
618
diff
changeset
|
36 import org.tmatesoft.hg.repo.HgRuntimeException; |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
37 import org.tmatesoft.hg.util.Pair; |
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 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces 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 /** |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces 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 * |
608
e1b29756f901
Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
591
diff
changeset
|
41 * 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
|
42 * |
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
|
43 * @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
|
44 * @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
|
45 */ |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 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
|
47 |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
48 private final DigestHelper dh = new DigestHelper(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
49 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
|
50 private final Transaction transaction; |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
51 private int lastEntryBase, lastEntryIndex, lastEntryActualLen; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
52 // record revision and its full content |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
53 // the name might be misleading, it does not necessarily match lastEntryIndex |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
54 private Pair<Integer, byte[]> lastFullContent; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
55 private Nodeid lastEntryRevision; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
56 private IntMap<Nodeid> revisionCache = new IntMap<Nodeid>(32); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
57 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
|
58 |
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 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
|
60 assert ctxSource != null; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
61 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
|
62 assert tr != null; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
63 |
591
e447384f3771
CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
544
diff
changeset
|
64 revlogDataZip = new RevlogCompressor(ctxSource.getSessionContext()); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
65 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
|
66 transaction = tr; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
67 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
68 |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
69 public Pair<Integer,Nodeid> addPatchRevision(GroupElement ge, RevisionToIndexMap clogRevs, RevisionToIndexMap revlogRevs) throws HgIOException, HgRuntimeException { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
70 populateLastEntryIndex(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
71 // |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
72 final Nodeid nodeRev = ge.node(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
73 final Nodeid csetRev = ge.cset(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
74 int linkRev; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
75 if (nodeRev.equals(csetRev)) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
76 linkRev = lastEntryIndex+1; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
77 } else { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
78 linkRev = clogRevs.revisionIndex(csetRev); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
79 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
80 assert linkRev >= 0; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
81 final Nodeid p1Rev = ge.firstParent(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
82 int p1 = p1Rev.isNull() ? NO_REVISION : revlogRevs.revisionIndex(p1Rev); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
83 final Nodeid p2Rev = ge.secondParent(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
84 int p2 = p2Rev.isNull() ? NO_REVISION : revlogRevs.revisionIndex(p2Rev); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
85 Patch p = new Patch(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
86 final byte[] patchBytes; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
87 try { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
88 // XXX there's ge.rawData(), to avoid extra array wrap |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
89 patchBytes = ge.rawDataByteArray(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
90 p.read(new ByteArrayDataAccess(patchBytes)); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
91 } catch (IOException ex) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
92 throw new HgIOException("Failed to read patch information", ex, null); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
93 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
94 // |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
95 final Nodeid patchBase = ge.patchBase(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
96 int patchBaseRev = patchBase.isNull() ? NO_REVISION : revlogRevs.revisionIndex(patchBase); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
97 int baseRev = lastEntryIndex == NO_REVISION ? 0 : revlogStream.baseRevision(patchBaseRev); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
98 int revLen; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
99 DataSource ds; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
100 byte[] complete = null; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
101 if (patchBaseRev == lastEntryIndex && lastEntryIndex != NO_REVISION) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
102 // we may write patch from GroupElement as is |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
103 int patchBaseLen = dataLength(patchBaseRev); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
104 revLen = patchBaseLen + p.patchSizeDelta(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
105 ds = new ByteArrayDataSource(patchBytes); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
106 } else { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
107 // read baseRev, unless it's the pull to empty repository |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
108 try { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
109 if (lastEntryIndex == NO_REVISION) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
110 complete = p.apply(new ByteArrayDataAccess(new byte[0]), -1); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
111 baseRev = 0; // it's done above, but doesn't hurt |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
112 } else { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
113 ReadContentInspector insp = new ReadContentInspector().read(revlogStream, baseRev); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
114 complete = p.apply(new ByteArrayDataAccess(insp.content), -1); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
115 baseRev = lastEntryIndex + 1; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
116 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
117 ds = new ByteArrayDataSource(complete); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
118 revLen = complete.length; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
119 } catch (IOException ex) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
120 // unlikely to happen, as ByteArrayDataSource doesn't throw IOException |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
121 throw new HgIOException("Failed to reconstruct revision", ex, null); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
122 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
123 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
124 doAdd(nodeRev, p1, p2, linkRev, baseRev, revLen, ds); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
125 if (complete != null) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
126 lastFullContent = new Pair<Integer, byte[]>(lastEntryIndex, complete); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
127 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
128 return new Pair<Integer, Nodeid>(lastEntryIndex, lastEntryRevision); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
129 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
130 |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
131 /** |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
132 * @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
|
133 * @throws HgRuntimeException |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
134 */ |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
135 public Pair<Integer,Nodeid> addRevision(DataSource content, int linkRevision, int p1, int p2) throws HgIOException, HgRuntimeException { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
136 populateLastEntryIndex(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
137 populateLastEntryContent(); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
138 // |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
139 byte[] contentByteArray = toByteArray(content); |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
140 Patch patch = GeneratePatchInspector.delta(lastFullContent.second(), contentByteArray); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
141 int patchSerializedLength = patch.serializedLength(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
142 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
143 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
|
144 DataSerializer.DataSource dataSource = writeComplete ? new ByteArrayDataSource(contentByteArray) : patch.new PatchDataSource(); |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
145 // |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
146 Nodeid p1Rev = revision(p1); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
147 Nodeid p2Rev = revision(p2); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
148 Nodeid newRev = Nodeid.fromBinary(dh.sha1(p1Rev, p2Rev, contentByteArray).asBinary(), 0); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
149 doAdd(newRev, p1, p2, linkRevision, writeComplete ? lastEntryIndex+1 : lastEntryBase, contentByteArray.length, dataSource); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
150 lastFullContent = new Pair<Integer, byte[]>(lastEntryIndex, contentByteArray); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
151 return new Pair<Integer, Nodeid>(lastEntryIndex, lastEntryRevision); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
152 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
153 |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
154 private Nodeid doAdd(Nodeid rev, int p1, int p2, int linkRevision, int baseRevision, int revLen, DataSerializer.DataSource dataSource) throws HgIOException, HgRuntimeException { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
155 assert linkRevision >= 0; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
156 assert baseRevision >= 0; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
157 assert p1 == NO_REVISION || p1 >= 0; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
158 assert p2 == NO_REVISION || p2 >= 0; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
159 assert !rev.isNull(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
160 assert revLen >= 0; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
161 revlogDataZip.reset(dataSource); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
162 final int compressedLen; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
163 final boolean useCompressedData = preferCompressedOverComplete(revlogDataZip.getCompressedLength(), dataSource.serializeLength()); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
164 if (useCompressedData) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
165 compressedLen= revlogDataZip.getCompressedLength(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
166 } else { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
167 // compression wasn't too effective, |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
168 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
|
169 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
170 // |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
171 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
|
172 indexFile = dataFile = null; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
173 try { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
174 // |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
175 indexFile = revlogStream.getIndexStreamWriter(transaction); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
176 final boolean isInlineData = revlogStream.isInlineData(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
177 HeaderWriter revlogHeader = new HeaderWriter(isInlineData); |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
178 revlogHeader.length(revLen, compressedLen); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
179 revlogHeader.nodeid(rev.toByteArray()); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
180 revlogHeader.linkRevision(linkRevision); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
181 revlogHeader.parents(p1, p2); |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
182 revlogHeader.baseRevision(baseRevision); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
183 long lastEntryOffset = revlogStream.newEntryOffset(); |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
184 revlogHeader.offset(lastEntryOffset); |
538
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 revlogHeader.serialize(indexFile); |
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 if (isInlineData) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
189 dataFile = indexFile; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
190 } 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
|
191 dataFile = revlogStream.getDataStreamWriter(transaction); |
538
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 if (useCompressedData) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
194 int actualCompressedLenWritten = revlogDataZip.writeCompressedData(dataFile); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
195 if (actualCompressedLenWritten != compressedLen) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
196 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
|
197 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
198 } else { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
199 dataFile.writeByte((byte) 'u'); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
200 dataSource.serialize(dataFile); |
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 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
203 lastEntryBase = revlogHeader.baseRevision(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
204 lastEntryIndex++; |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
205 lastEntryActualLen = revLen; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
206 lastEntryRevision = rev; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
207 revisionCache.put(lastEntryIndex, lastEntryRevision); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
208 |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
209 revlogStream.revisionAdded(lastEntryIndex, lastEntryRevision, lastEntryBase, lastEntryOffset); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
210 } finally { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
211 indexFile.done(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
212 if (dataFile != null && dataFile != indexFile) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
213 dataFile.done(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
214 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
215 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
216 return lastEntryRevision; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
217 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
218 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
618
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 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
|
223 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
224 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
618
diff
changeset
|
225 private Nodeid revision(int revisionIndex) throws HgInvalidControlFileException, HgInvalidRevisionException { |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
226 if (revisionIndex == NO_REVISION) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
227 return Nodeid.NULL; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
228 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
229 Nodeid n = revisionCache.get(revisionIndex); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
230 if (n == null) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
231 n = Nodeid.fromBinary(revlogStream.nodeid(revisionIndex), 0); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
232 revisionCache.put(revisionIndex, n); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
233 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
234 return n; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
235 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
236 |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
237 private int dataLength(int revisionIndex) throws HgInvalidControlFileException, HgInvalidRevisionException { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
238 assert revisionIndex >= 0; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
239 if (revisionIndex == lastEntryIndex) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
240 return lastEntryActualLen; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
241 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
242 if (lastFullContent != null && lastFullContent.first() == revisionIndex) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
243 return lastFullContent.second().length; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
244 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
245 return revlogStream.dataLength(revisionIndex); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
246 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
247 |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
248 private void populateLastEntryIndex() throws HgRuntimeException { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
249 int revCount = revlogStream.revisionCount(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
250 lastEntryIndex = revCount == 0 ? NO_REVISION : revCount - 1; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
251 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
252 |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
253 private void populateLastEntryContent() throws HgRuntimeException { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
254 if (lastFullContent != null && lastFullContent.first() == lastEntryIndex) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
255 // we have last entry cached |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
256 return; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
257 } |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
258 lastEntryRevision = Nodeid.NULL; |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
259 if (lastEntryIndex != NO_REVISION) { |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
260 ReadContentInspector insp = new ReadContentInspector().read(revlogStream, lastEntryIndex); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
261 lastEntryBase = insp.baseRev; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
262 lastEntryRevision = insp.rev; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
263 lastFullContent = new Pair<Integer, byte[]>(lastEntryIndex, insp.content); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
264 } else { |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
265 lastFullContent = new Pair<Integer, byte[]>(lastEntryIndex, new byte[0]); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
266 } |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
267 assert lastFullContent.first() == lastEntryIndex; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
268 assert lastFullContent.second() != null; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
269 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
270 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
271 public static boolean preferCompleteOverPatch(int patchLength, int fullContentLength) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
272 return !decideWorthEffort(patchLength, fullContentLength); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
273 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
274 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
275 public static boolean preferCompressedOverComplete(int compressedLen, int fullContentLength) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
276 if (compressedLen <= 0) { // just in case, meaningless otherwise |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
277 return false; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
278 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
279 return decideWorthEffort(compressedLen, fullContentLength); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
280 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
281 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
282 // true if length obtained with effort is worth it |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
283 private static boolean decideWorthEffort(int lengthWithExtraEffort, int lengthWithoutEffort) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
284 return lengthWithExtraEffort < (/* 3/4 of original */lengthWithoutEffort - (lengthWithoutEffort >>> 2)); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
285 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
286 |
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
|
287 /*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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
296 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
|
297 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
|
298 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
|
299 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
300 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
305 |
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
|
306 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
|
307 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
|
308 } |
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
|
309 |
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
|
310 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
|
311 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
|
312 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
|
313 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
314 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 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
|
319 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
320 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
321 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
|
322 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
|
323 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
|
324 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
|
325 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
326 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
327 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
|
328 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
|
329 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
|
330 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
331 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 } |
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
|
336 |
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
|
337 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
|
338 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
|
339 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
|
340 } |
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
|
341 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
349 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
|
350 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
|
351 } 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
|
352 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
|
353 } |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 // 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
|
362 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
|
363 |
0f6fa88e2162
Towards commit command: refactor clone, extract pieces to reuse. Describe a defect discovered when bundle has few patches with 0,0 parents
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
364 // 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
|
365 // offset field always represent cumulative compressedLength |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
366 // (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
|
367 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
|
368 } |
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
|
369 |
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
|
370 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
|
371 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
|
372 } |
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
|
373 } |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
374 |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
375 // XXX part of HgRevisionMap contract, need public counterparts (along with IndexToRevisionMap) |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
376 public interface RevisionToIndexMap { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
377 |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
378 /** |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
379 * @return {@link HgRepository#NO_REVISION} if unknown revision |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
380 */ |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
381 int revisionIndex(Nodeid revision); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
382 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
383 |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
384 private static class ReadContentInspector implements RevlogStream.Inspector { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
385 public int baseRev; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
386 public Nodeid rev; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
387 public byte[] content; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
388 private IOException failure; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
389 |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
390 public ReadContentInspector read(RevlogStream rs, int revIndex) throws HgInvalidControlFileException { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
391 assert revIndex >= 0; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
392 rs.iterate(revIndex, revIndex, true, this); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
393 if (failure != null) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
394 String m = String.format("Failed to get content of revision %d", revIndex); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
395 throw rs.initWithDataFile(new HgInvalidControlFileException(m, failure, null)); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
396 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
397 return this; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
398 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
399 |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
400 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
401 try { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
402 baseRev = baseRevision; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
403 rev = Nodeid.fromBinary(nodeid, 0); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
404 content = data.byteArray(); |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
405 } catch (IOException ex) { |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
406 failure = ex; |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
407 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
408 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
409 } |
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
645
diff
changeset
|
410 } |