Mercurial > hg4j
annotate src/org/tmatesoft/hg/core/HgCloneCommand.java @ 274:9fb50c04f03c
Use Nodeid.isNull check instead of NULL.equals
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 25 Aug 2011 03:57:39 +0200 |
parents | 883f1efbcf27 |
children | a415fe296a50 |
rev | line source |
---|---|
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.core; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.core.Nodeid.NULL; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import static org.tmatesoft.hg.internal.RequiresFile.*; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.io.ByteArrayOutputStream; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.io.File; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.io.FileOutputStream; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.io.IOException; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.nio.ByteBuffer; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.util.ArrayList; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import java.util.Collections; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import java.util.LinkedList; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import java.util.TreeMap; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import java.util.zip.DeflaterOutputStream; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import org.tmatesoft.hg.internal.ByteArrayDataAccess; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 import org.tmatesoft.hg.internal.DataAccess; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import org.tmatesoft.hg.internal.DigestHelper; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 import org.tmatesoft.hg.internal.Internals; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 import org.tmatesoft.hg.repo.HgBundle; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 import org.tmatesoft.hg.repo.HgBundle.GroupElement; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 import org.tmatesoft.hg.repo.HgLookup; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 import org.tmatesoft.hg.repo.HgRemoteRepository; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 import org.tmatesoft.hg.repo.HgRepository; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 import org.tmatesoft.hg.util.CancelledException; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 import org.tmatesoft.hg.util.PathRewrite; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 /** |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 * WORK IN PROGRESS, DO NOT USE |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 * |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 * @author Artem Tikhomirov |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 * @author TMate Software Ltd. |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 */ |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 public class HgCloneCommand { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 private File destination; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 private HgRemoteRepository srcRepo; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 public HgCloneCommand() { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 |
204
883f1efbcf27
Add clone,incoming and outging tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
59 /** |
883f1efbcf27
Add clone,incoming and outging tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
60 * @param folder location to become root of the repository (i.e. where <em>.hg</em> folder would reside). Either |
883f1efbcf27
Add clone,incoming and outging tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
61 * shall not exist or be empty otherwise. |
883f1efbcf27
Add clone,incoming and outging tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
62 * @return <code>this</code> for convenience |
883f1efbcf27
Add clone,incoming and outging tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
63 */ |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 public HgCloneCommand destination(File folder) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 destination = folder; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 return this; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 public HgCloneCommand source(HgRemoteRepository hgRemote) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 srcRepo = hgRemote; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 return this; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 public HgRepository execute() throws HgException, CancelledException { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 if (destination == null) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 throw new HgBadArgumentException("Destination not set", null); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 if (srcRepo == null || srcRepo.isInvalid()) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 throw new HgBadArgumentException("Bad source repository", null); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 if (destination.exists()) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 if (!destination.isDirectory()) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 throw new HgBadArgumentException(String.format("%s is not a directory", destination), null); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } else if (destination.list().length > 0) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 throw new HgBadArgumentException(String.format("% shall be empty", destination), null); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } else { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 destination.mkdirs(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 // if cloning remote repo, which can stream and no revision is specified - |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 // can use 'stream_out' wireproto |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 // |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 // pull all changes from the very beginning |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 // XXX consult getContext() if by any chance has a bundle ready, if not, then read and register |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 HgBundle completeChanges = srcRepo.getChanges(Collections.singletonList(NULL)); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 WriteDownMate mate = new WriteDownMate(destination); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 try { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 // instantiate new repo in the destdir |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 mate.initEmptyRepository(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 // pull changes |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 completeChanges.inspectAll(mate); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 mate.complete(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 } catch (IOException ex) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 throw new HgException(ex); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } finally { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 completeChanges.unlink(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 return new HgLookup().detect(destination); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 // 1. process changelog, memorize nodeids to index |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 // 2. process manifest, using map from step 3, collect manifest nodeids |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 // 3. process every file, using map from 3, and consult set from step 4 to ensure repo is correct |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 private static class WriteDownMate implements HgBundle.Inspector { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 private final File hgDir; |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
117 private final PathRewrite storagePathHelper; |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 private FileOutputStream indexFile; |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
119 private String filename; // human-readable name of the file being written, for log/exception purposes |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 private final TreeMap<Nodeid, Integer> changelogIndexes = new TreeMap<Nodeid, Integer>(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 private boolean collectChangelogIndexes = false; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 private int base = -1; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 private long offset = 0; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 private DataAccess prevRevContent; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 private final DigestHelper dh = new DigestHelper(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 private final ArrayList<Nodeid> revisionSequence = new ArrayList<Nodeid>(); // last visited nodes first |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 private final LinkedList<String> fncacheFiles = new LinkedList<String>(); |
202
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
190
diff
changeset
|
131 private Internals implHelper; |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 public WriteDownMate(File destDir) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 hgDir = new File(destDir, ".hg"); |
202
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
190
diff
changeset
|
135 implHelper = new Internals(); |
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
190
diff
changeset
|
136 implHelper.setStorageConfig(1, STORE | FNCACHE | DOTENCODE); |
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
190
diff
changeset
|
137 storagePathHelper = implHelper.buildDataFilesHelper(); |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 public void initEmptyRepository() throws IOException { |
202
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
190
diff
changeset
|
141 implHelper.initEmptyRepository(hgDir); |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 public void complete() throws IOException { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 FileOutputStream fncacheFile = new FileOutputStream(new File(hgDir, "store/fncache")); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 for (String s : fncacheFiles) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 fncacheFile.write(s.getBytes()); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 fncacheFile.write(0x0A); // http://mercurial.selenic.com/wiki/fncacheRepoFormat |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 fncacheFile.close(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 public void changelogStart() { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 try { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 base = -1; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 offset = 0; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 revisionSequence.clear(); |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
158 indexFile = new FileOutputStream(new File(hgDir, filename = "store/00changelog.i")); |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 collectChangelogIndexes = true; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 } catch (IOException ex) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 throw new HgBadStateException(ex); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 public void changelogEnd() { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 try { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 if (prevRevContent != null) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 prevRevContent.done(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 prevRevContent = null; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 collectChangelogIndexes = false; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 indexFile.close(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 indexFile = null; |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
174 filename = null; |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 } catch (IOException ex) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 throw new HgBadStateException(ex); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 public void manifestStart() { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 try { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 base = -1; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 offset = 0; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
184 revisionSequence.clear(); |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
185 indexFile = new FileOutputStream(new File(hgDir, filename = "store/00manifest.i")); |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 } catch (IOException ex) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 throw new HgBadStateException(ex); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 public void manifestEnd() { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 try { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 if (prevRevContent != null) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
194 prevRevContent.done(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 prevRevContent = null; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
196 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
197 indexFile.close(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 indexFile = null; |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
199 filename = null; |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
200 } catch (IOException ex) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 throw new HgBadStateException(ex); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
202 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
203 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
204 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 public void fileStart(String name) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
206 try { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
207 base = -1; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
208 offset = 0; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
209 revisionSequence.clear(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
210 fncacheFiles.add("data/" + name + ".i"); // FIXME this is pure guess, |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
211 // need to investigate more how filenames are kept in fncache |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
212 File file = new File(hgDir, filename = storagePathHelper.rewrite(name)); |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
213 file.getParentFile().mkdirs(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
214 indexFile = new FileOutputStream(file); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
215 } catch (IOException ex) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
216 throw new HgBadStateException(ex); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
217 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
218 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
219 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
220 public void fileEnd(String name) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
221 try { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
222 if (prevRevContent != null) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
223 prevRevContent.done(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
224 prevRevContent = null; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
225 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
226 indexFile.close(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
227 indexFile = null; |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
228 filename = null; |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
229 } catch (IOException ex) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
230 throw new HgBadStateException(ex); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
231 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
232 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
233 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
234 private int knownRevision(Nodeid p) { |
274
9fb50c04f03c
Use Nodeid.isNull check instead of NULL.equals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
204
diff
changeset
|
235 if (p.isNull()) { |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
236 return -1; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
237 } else { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
238 for (int i = revisionSequence.size() - 1; i >= 0; i--) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
239 if (revisionSequence.get(i).equals(p)) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
240 return i; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
241 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
242 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
243 } |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
244 throw new HgBadStateException(String.format("Can't find index of %s for file %s", p.shortNotation(), filename)); |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
245 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
246 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
247 public boolean element(GroupElement ge) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
248 try { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
249 assert indexFile != null; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
250 boolean writeComplete = false; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
251 Nodeid p1 = ge.firstParent(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
252 Nodeid p2 = ge.secondParent(); |
274
9fb50c04f03c
Use Nodeid.isNull check instead of NULL.equals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
204
diff
changeset
|
253 if (p1.isNull() && p2.isNull() /* or forced flag, does REVIDX_PUNCHED_FLAG indicate that? */) { |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
254 prevRevContent = new ByteArrayDataAccess(new byte[0]); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
255 writeComplete = true; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
256 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
257 byte[] content = ge.apply(prevRevContent); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
258 byte[] calculated = dh.sha1(p1, p2, content).asBinary(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
259 final Nodeid node = ge.node(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
260 if (!node.equalsTo(calculated)) { |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
261 throw new HgBadStateException(String.format("Checksum failed: expected %s, calculated %s. File %s", node, calculated, filename)); |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
262 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
263 final int link; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
264 if (collectChangelogIndexes) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
265 changelogIndexes.put(node, revisionSequence.size()); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
266 link = revisionSequence.size(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
267 } else { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
268 Integer csRev = changelogIndexes.get(ge.cset()); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
269 if (csRev == null) { |
190
9b99d27aeddc
More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
270 throw new HgBadStateException(String.format("Changelog doesn't contain revision %s of %s", ge.cset().shortNotation(), filename)); |
186
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
271 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
272 link = csRev.intValue(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
273 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
274 final int p1Rev = knownRevision(p1), p2Rev = knownRevision(p2); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
275 DataAccess patchContent = ge.rawData(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
276 writeComplete = writeComplete || patchContent.length() >= (/* 3/4 of actual */content.length - (content.length >>> 2)); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
277 if (writeComplete) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
278 base = revisionSequence.size(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
279 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
280 final byte[] sourceData = writeComplete ? content : patchContent.byteArray(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
281 final byte[] data; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
282 ByteArrayOutputStream bos = new ByteArrayOutputStream(content.length); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
283 DeflaterOutputStream dos = new DeflaterOutputStream(bos); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
284 dos.write(sourceData); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
285 dos.close(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
286 final byte[] compressedData = bos.toByteArray(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
287 dos = null; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
288 bos = null; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
289 final Byte dataPrefix; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
290 if (compressedData.length >= (sourceData.length - (sourceData.length >>> 2))) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
291 // compression wasn't too effective, |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
292 data = sourceData; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
293 dataPrefix = 'u'; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
294 } else { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
295 data = compressedData; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
296 dataPrefix = null; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
297 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
298 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
299 ByteBuffer header = ByteBuffer.allocate(64 /* REVLOGV1_RECORD_SIZE */); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
300 if (offset == 0) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
301 final int INLINEDATA = 1 << 16; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
302 header.putInt(1 /* RevlogNG */ | INLINEDATA); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
303 header.putInt(0); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
304 } else { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
305 header.putLong(offset << 16); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
306 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
307 final int compressedLen = data.length + (dataPrefix == null ? 0 : 1); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
308 header.putInt(compressedLen); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
309 header.putInt(content.length); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
310 header.putInt(base); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
311 header.putInt(link); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
312 header.putInt(p1Rev); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
313 header.putInt(p2Rev); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
314 header.put(node.toByteArray()); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
315 // assume 12 bytes left are zeros |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
316 indexFile.write(header.array()); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
317 if (dataPrefix != null) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
318 indexFile.write(dataPrefix.byteValue()); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
319 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
320 indexFile.write(data); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
321 // |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
322 offset += compressedLen; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
323 revisionSequence.add(node); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
324 prevRevContent.done(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
325 prevRevContent = new ByteArrayDataAccess(content); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
326 } catch (IOException ex) { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
327 throw new HgBadStateException(ex); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
328 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
329 return true; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
330 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
331 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
332 |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
333 } |