Mercurial > jhg
annotate src/org/tmatesoft/hg/repo/HgBundle.java @ 645:14dac192aa26
Push: phase2 - upload bundle with changes to remote server
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 20 Jun 2013 19:15:09 +0200 |
parents | 6526d8adbc0f |
children | 12a4f60ea972 |
rev | line source |
---|---|
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
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:
526
diff
changeset
|
2 * Copyright (c) 2011-2013 TMate Software Ltd |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
13 * For information on how to redistribute this software under |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
102
a3a2e5deb320
Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
17 package org.tmatesoft.hg.repo; |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.io.File; |
645
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
20 import java.io.FileInputStream; |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.io.IOException; |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
22 import java.util.ConcurrentModificationException; |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 |
645
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
24 import org.tmatesoft.hg.core.HgIOException; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
25 import org.tmatesoft.hg.core.Nodeid; |
357
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
26 import org.tmatesoft.hg.core.SessionContext; |
157
d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
27 import org.tmatesoft.hg.internal.ByteArrayChannel; |
d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
28 import org.tmatesoft.hg.internal.ByteArrayDataAccess; |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
29 import org.tmatesoft.hg.internal.Callback; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
30 import org.tmatesoft.hg.internal.DataAccess; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
31 import org.tmatesoft.hg.internal.DataAccessProvider; |
645
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
32 import org.tmatesoft.hg.internal.DataSerializer; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
33 import org.tmatesoft.hg.internal.DigestHelper; |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
34 import org.tmatesoft.hg.internal.Experimental; |
645
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
35 import org.tmatesoft.hg.internal.FileUtils; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
36 import org.tmatesoft.hg.internal.InflaterDataAccess; |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
513
diff
changeset
|
37 import org.tmatesoft.hg.internal.Internals; |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
38 import org.tmatesoft.hg.internal.Lifecycle; |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
39 import org.tmatesoft.hg.internal.Patch; |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
129
diff
changeset
|
40 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
41 import org.tmatesoft.hg.util.Adaptable; |
157
d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
42 import org.tmatesoft.hg.util.CancelledException; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
43 |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 /** |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
45 * WORK IN PROGRESS |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
46 * |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 * @see http://mercurial.selenic.com/wiki/BundleFormat |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
48 * |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
49 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
50 * @author TMate Software Ltd. |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 */ |
467
51d682cf9cdc
Cleaned experimental tag and updated comments/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
52 @Experimental(reason="API is not stable") |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 public class HgBundle { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 private final File bundleFile; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 private final DataAccessProvider accessProvider; |
645
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
57 private final SessionContext ctx; |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
58 private Lifecycle.BasicCallback flowControl; |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 |
645
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
60 HgBundle(SessionContext sessionContext, DataAccessProvider dap, File bundle) { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
61 ctx = sessionContext; |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 accessProvider = dap; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 bundleFile = bundle; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
66 private DataAccess getDataStream() throws IOException { |
606
5daa42067e7c
Avoid mmap files when only few bytes are to be read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
534
diff
changeset
|
67 DataAccess da = accessProvider.createReader(bundleFile, false); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
68 byte[] signature = new byte[6]; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
69 if (da.length() > 6) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
70 da.readBytes(signature, 0, 6); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
71 if (signature[0] == 'H' && signature[1] == 'G' && signature[2] == '1' && signature[3] == '0') { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
72 if (signature[4] == 'G' && signature[5] == 'Z') { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
73 return new InflaterDataAccess(da, 6, da.length() - 6); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
74 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
75 if (signature[4] == 'B' && signature[5] == 'Z') { |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
513
diff
changeset
|
76 throw Internals.notImplemented(); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
77 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
78 if (signature[4] != 'U' || signature[5] != 'N') { |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
79 throw new HgInvalidStateException(String.format("Bad bundle signature: %s", String.valueOf(signature))); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
80 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
81 // "...UN", fall-through |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
82 } else { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
83 da.reset(); |
39
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
84 } |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
85 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
86 return da; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
87 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
88 |
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:
182
diff
changeset
|
89 private int uses = 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:
182
diff
changeset
|
90 public HgBundle 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:
182
diff
changeset
|
91 uses++; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
92 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:
182
diff
changeset
|
93 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
94 public void 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:
182
diff
changeset
|
95 uses--; |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
96 if (uses == 0 && bundleFile != 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:
182
diff
changeset
|
97 bundleFile.deleteOnExit(); |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
98 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
99 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
100 public boolean inUse() { |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
101 return uses > 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:
182
diff
changeset
|
102 } |
44a34baabea0
Clone refactored into a command. HgBundle needs means to control its lifecycle, to be deleted when no longer needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
182
diff
changeset
|
103 |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
104 /** |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
105 * Get changes recorded in the bundle that are missing from the supplied repository. |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
106 * @param hgRepo repository that shall possess base revision for this bundle |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
107 * @param inspector callback to get each changeset found |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
108 */ |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
109 public void changes(final HgRepository hgRepo, final HgChangelog.Inspector inspector) throws HgRuntimeException { |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
110 Inspector bundleInsp = new Inspector() { |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
111 DigestHelper dh = new DigestHelper(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
112 boolean emptyChangelog = true; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
113 private DataAccess prevRevContent; |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
114 private int revisionIndex; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
115 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
116 public void changelogStart() { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
117 emptyChangelog = true; |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
118 revisionIndex = 0; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
119 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
120 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
121 public void changelogEnd() { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
122 if (emptyChangelog) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
123 throw new IllegalStateException("No changelog group in the bundle"); // XXX perhaps, just be silent and/or log? |
42
92c3d0920d58
Real integrity check, with exception. DigestHelper refactored to accomodate new needs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
41
diff
changeset
|
124 } |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
125 } |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
126 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
127 /* |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
128 * Despite that BundleFormat wiki says: "Each Changelog entry patches the result of all previous patches |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
129 * (the previous, or parent patch of a given patch p is the patch that has a node equal to p's p1 field)", |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
130 * it seems not to hold true. Instead, each entry patches previous one, regardless of whether the one |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
131 * before is its parent (i.e. ge.firstParent()) or not. |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
132 * |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
133 Actual state in the changelog.i |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
134 Index Offset Flags Packed Actual Base Rev Link Rev Parent1 Parent2 nodeid |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
135 50: 9212 0 209 329 48 50 49 -1 f1db8610da62a3e0beb8d360556ee1fd6eb9885e |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
136 51: 9421 0 278 688 48 51 50 -1 9429c7bd1920fab164a9d2b621d38d57bcb49ae0 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
137 52: 9699 0 154 179 52 52 50 -1 30bd389788464287cee22ccff54c330a4b715de5 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
138 53: 9853 0 133 204 52 53 51 52 a6f39e595b2b54f56304470269a936ead77f5725 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
139 54: 9986 0 156 182 54 54 52 -1 fd4f2c98995beb051070630c272a9be87bef617d |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
140 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
141 Excerpt from bundle (nodeid, p1, p2, cs): |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
142 f1db8610da62a3e0beb8d360556ee1fd6eb9885e 26e3eeaa39623de552b45ee1f55c14f36460f220 0000000000000000000000000000000000000000 f1db8610da62a3e0beb8d360556ee1fd6eb9885e; patches:4 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
143 9429c7bd1920fab164a9d2b621d38d57bcb49ae0 f1db8610da62a3e0beb8d360556ee1fd6eb9885e 0000000000000000000000000000000000000000 9429c7bd1920fab164a9d2b621d38d57bcb49ae0; patches:3 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
144 > 30bd389788464287cee22ccff54c330a4b715de5 f1db8610da62a3e0beb8d360556ee1fd6eb9885e 0000000000000000000000000000000000000000 30bd389788464287cee22ccff54c330a4b715de5; patches:3 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
145 a6f39e595b2b54f56304470269a936ead77f5725 9429c7bd1920fab164a9d2b621d38d57bcb49ae0 30bd389788464287cee22ccff54c330a4b715de5 a6f39e595b2b54f56304470269a936ead77f5725; patches:3 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
146 fd4f2c98995beb051070630c272a9be87bef617d 30bd389788464287cee22ccff54c330a4b715de5 0000000000000000000000000000000000000000 fd4f2c98995beb051070630c272a9be87bef617d; patches:3 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
147 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
148 To recreate 30bd..e5, one have to take content of 9429..e0, not its p1 f1db..5e |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
149 */ |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
150 public boolean element(GroupElement ge) throws HgRuntimeException { |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
151 emptyChangelog = false; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
152 HgChangelog changelog = hgRepo.getChangelog(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
153 try { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
154 if (prevRevContent == null) { |
274
9fb50c04f03c
Use Nodeid.isNull check instead of NULL.equals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
186
diff
changeset
|
155 if (ge.firstParent().isNull() && ge.secondParent().isNull()) { |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
156 prevRevContent = new ByteArrayDataAccess(new byte[0]); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
157 } else { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
158 final Nodeid base = ge.firstParent(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
159 if (!changelog.isKnown(base) /*only first parent, that's Bundle contract*/) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
160 throw new IllegalStateException(String.format("Revision %s needs a parent %s, which is missing in the supplied repo %s", ge.node().shortNotation(), base.shortNotation(), hgRepo.toString())); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
161 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
162 ByteArrayChannel bac = new ByteArrayChannel(); |
418
528b6780a8bd
A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
383
diff
changeset
|
163 changelog.rawContent(base, bac); // TODO post-1.0 get DataAccess directly, to avoid |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
164 // extra byte[] (inside ByteArrayChannel) duplication just for the sake of subsequent ByteArrayDataChannel wrap. |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
165 prevRevContent = new ByteArrayDataAccess(bac.toArray()); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
166 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
167 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
168 // |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
169 byte[] csetContent = ge.apply(prevRevContent); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
170 dh = dh.sha1(ge.firstParent(), ge.secondParent(), csetContent); // XXX ge may give me access to byte[] content of nodeid directly, perhaps, I don't need DH to be friend of Nodeid? |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
171 if (!ge.node().equalsTo(dh.asBinary())) { |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
172 throw new HgInvalidStateException(String.format("Integrity check failed on %s, node: %s", bundleFile, ge.node().shortNotation())); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
173 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
174 ByteArrayDataAccess csetDataAccess = new ByteArrayDataAccess(csetContent); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
175 RawChangeset cs = RawChangeset.parse(csetDataAccess); |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
176 inspector.next(revisionIndex++, ge.node(), cs); |
170
71ddbf8603e8
Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
169
diff
changeset
|
177 prevRevContent.done(); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
178 prevRevContent = csetDataAccess.reset(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
179 } catch (CancelledException ex) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
180 return false; |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
181 } catch (IOException ex) { |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
182 throw new HgInvalidFileException("Invalid bundle file", ex, bundleFile); // TODO post-1.0 revisit exception handling |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
183 } catch (HgInvalidDataFormatException ex) { |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
184 throw new HgInvalidControlFileException("Invalid bundle file", ex, bundleFile); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
185 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
186 return true; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
187 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
188 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
189 public void manifestStart() {} |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
190 public void manifestEnd() {} |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
191 public void fileStart(String name) {} |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
192 public void fileEnd(String name) {} |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
193 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
194 }; |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
195 inspectChangelog(bundleInsp); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
196 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
197 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
198 // callback to minimize amount of Strings and Nodeids instantiated |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
199 @Callback |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
200 public interface Inspector { |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
201 void changelogStart() throws HgRuntimeException; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
202 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
203 void changelogEnd() throws HgRuntimeException; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
204 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
205 void manifestStart() throws HgRuntimeException; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
206 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
207 void manifestEnd() throws HgRuntimeException; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
208 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
209 void fileStart(String name) throws HgRuntimeException; |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
210 |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
211 void fileEnd(String name) throws HgRuntimeException; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
212 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
213 /** |
170
71ddbf8603e8
Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
169
diff
changeset
|
214 * XXX desperately need exceptions here |
71ddbf8603e8
Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
169
diff
changeset
|
215 * @param element data element, instance might be reused, don't keep a reference to it or its raw data |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
216 * @return <code>true</code> to continue |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
217 */ |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
218 boolean element(GroupElement element) throws HgRuntimeException; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
219 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
220 |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
221 /** |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
222 * @param inspector callback to visit changelog entries |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
223 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
224 * @throws IllegalArgumentException if inspector argument is null |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
225 */ |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
226 public void inspectChangelog(Inspector inspector) throws HgRuntimeException { |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
227 if (inspector == null) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
228 throw new IllegalArgumentException(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
229 } |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
230 final Lifecycle lifecycle = lifecycleSetUp(inspector); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
231 DataAccess da = null; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
232 try { |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
233 da = getDataStream(); |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
234 internalInspectChangelog(da, inspector); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
235 } catch (IOException ex) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
236 throw new HgInvalidFileException("Bundle.inspectChangelog failed", ex, bundleFile); |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
237 } finally { |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
238 if (da != null) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
239 da.done(); |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
240 } |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
241 lifecycleTearDown(lifecycle); |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
242 } |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
243 } |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
244 |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
245 /** |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
246 * @param inspector callback to visit manifest entries |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
247 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
248 * @throws IllegalArgumentException if inspector argument is null |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
249 */ |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
250 public void inspectManifest(Inspector inspector) throws HgRuntimeException { |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
251 if (inspector == null) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
252 throw new IllegalArgumentException(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
253 } |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
254 final Lifecycle lifecycle = lifecycleSetUp(inspector); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
255 DataAccess da = null; |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
256 try { |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
257 da = getDataStream(); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
258 if (da.isEmpty()) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
259 return; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
260 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
261 skipGroup(da); // changelog |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
262 internalInspectManifest(da, inspector); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
263 } catch (IOException ex) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
264 throw new HgInvalidFileException("Bundle.inspectManifest failed", ex, bundleFile); |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
265 } finally { |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
266 if (da != null) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
267 da.done(); |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
268 } |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
269 lifecycleTearDown(lifecycle); |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
270 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
271 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
272 |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
273 /** |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
274 * @param inspector callback to visit file entries |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
275 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
276 * @throws IllegalArgumentException if inspector argument is null |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
277 */ |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
278 public void inspectFiles(Inspector inspector) throws HgRuntimeException { |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
279 if (inspector == null) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
280 throw new IllegalArgumentException(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
281 } |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
282 final Lifecycle lifecycle = lifecycleSetUp(inspector); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
283 DataAccess da = null; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
284 try { |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
285 da = getDataStream(); |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
286 if (da.isEmpty()) { |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
287 return; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
288 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
289 skipGroup(da); // changelog |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
290 if (da.isEmpty()) { |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
291 return; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
292 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
293 skipGroup(da); // manifest |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
294 internalInspectFiles(da, inspector); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
295 } catch (IOException ex) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
296 throw new HgInvalidFileException("Bundle.inspectFiles failed", ex, bundleFile); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
297 } finally { |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
298 if (da != null) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
299 da.done(); |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
300 } |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
301 lifecycleTearDown(lifecycle); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
302 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
303 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
304 |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
305 /** |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
306 * @param inspector visit complete bundle (changelog, manifest and file entries) |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
307 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
308 * @throws IllegalArgumentException if inspector argument is null |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
309 */ |
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
418
diff
changeset
|
310 public void inspectAll(Inspector inspector) throws HgRuntimeException { |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
311 if (inspector == null) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
312 throw new IllegalArgumentException(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
313 } |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
314 final Lifecycle lifecycle = lifecycleSetUp(inspector); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
315 DataAccess da = null; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
316 try { |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
317 da = getDataStream(); |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
318 internalInspectChangelog(da, inspector); |
513
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
319 if (flowControl.isStopped()) { |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
320 return; |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
321 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
322 internalInspectManifest(da, inspector); |
513
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
323 if (flowControl.isStopped()) { |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
324 return; |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
325 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
326 internalInspectFiles(da, inspector); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
327 } catch (IOException ex) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
328 throw new HgInvalidFileException("Bundle.inspectAll failed", ex, bundleFile); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
329 } finally { |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
330 if (da != null) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
331 da.done(); |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
274
diff
changeset
|
332 } |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
333 lifecycleTearDown(lifecycle); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
334 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
335 } |
512
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
336 |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
337 // initialize flowControl, check for concurrent usage, starts lifecyle, if any |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
338 // return non-null only if inspector is interested in lifecycle events |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
339 private Lifecycle lifecycleSetUp(Inspector inspector) throws ConcurrentModificationException { |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
340 // Don't need flowControl in case Inspector doesn't implement Lifecycle, |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
341 // however is handy not to expect it == null inside internalInspect* |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
342 // XXX Once there's need to make this class thread-safe, |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
343 // shall move flowControl to thread-local state. |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
344 if (flowControl != null) { |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
345 throw new ConcurrentModificationException("HgBundle is in use and not thread-safe yet"); |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
346 } |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
347 flowControl = new Lifecycle.BasicCallback(); |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
348 final Lifecycle lifecycle = Adaptable.Factory.getAdapter(inspector, Lifecycle.class, null); |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
349 if (lifecycle != null) { |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
350 lifecycle.start(-1, flowControl, flowControl); |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
351 } |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
352 return lifecycle; |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
353 } |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
354 |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
355 private void lifecycleTearDown(Lifecycle lifecycle) { |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
356 if (lifecycle != null) { |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
357 lifecycle.finish(flowControl); |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
358 } |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
359 flowControl = null; |
10ca3ede8367
Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
360 } |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
361 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
362 private void internalInspectChangelog(DataAccess da, Inspector inspector) throws IOException, HgRuntimeException { |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
363 if (da.isEmpty()) { |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
364 return; |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
365 } |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
366 inspector.changelogStart(); |
513
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
367 if (flowControl.isStopped()) { |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
368 return; |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
369 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
370 readGroup(da, inspector); |
513
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
371 if (flowControl.isStopped()) { |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
372 return; |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
373 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
374 inspector.changelogEnd(); |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
375 } |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
376 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
377 private void internalInspectManifest(DataAccess da, Inspector inspector) throws IOException, HgRuntimeException { |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
378 if (da.isEmpty()) { |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
379 return; |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
380 } |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
381 inspector.manifestStart(); |
513
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
382 if (flowControl.isStopped()) { |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
383 return; |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
384 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
385 readGroup(da, inspector); |
513
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
386 if (flowControl.isStopped()) { |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
387 return; |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
388 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
389 inspector.manifestEnd(); |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
390 } |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
391 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
392 private void internalInspectFiles(DataAccess da, Inspector inspector) throws IOException, HgRuntimeException { |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
393 while (!da.isEmpty()) { |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
394 int fnameLen = da.readInt(); |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
395 if (fnameLen <= 4) { |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
396 break; // null chunk, the last one. |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
397 } |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
398 byte[] fnameBuf = new byte[fnameLen - 4]; |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
399 da.readBytes(fnameBuf, 0, fnameBuf.length); |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
400 String name = new String(fnameBuf); |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
401 inspector.fileStart(name); |
513
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
402 if (flowControl.isStopped()) { |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
403 return; |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
404 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
405 readGroup(da, inspector); |
513
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
406 if (flowControl.isStopped()) { |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
407 return; |
a41d955dc360
Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
512
diff
changeset
|
408 } |
182
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
409 inspector.fileEnd(name); |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
410 } |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
411 } |
f26ffe04ced0
Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
412 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
606
diff
changeset
|
413 private static void readGroup(DataAccess da, Inspector inspector) throws IOException, HgRuntimeException { |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
414 int len = da.readInt(); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
415 boolean good2go = true; |
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:
526
diff
changeset
|
416 Nodeid prevNodeid = Nodeid.NULL; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
417 while (len > 4 && !da.isEmpty() && good2go) { |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
418 byte[] nb = new byte[80]; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
419 da.readBytes(nb, 0, 80); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
420 int dataLength = len - 84 /* length field + 4 nodeids */; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
421 byte[] data = new byte[dataLength]; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
422 da.readBytes(data, 0, dataLength); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
423 DataAccess slice = new ByteArrayDataAccess(data); // XXX in fact, may pass a slicing DataAccess. |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
424 // Just need to make sure that we seek to proper location afterwards (where next GroupElement starts), |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
425 // regardless whether that slice has read it or not. |
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:
526
diff
changeset
|
426 GroupElement ge = new GroupElement(nb, prevNodeid, slice); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
427 good2go = inspector.element(ge); |
170
71ddbf8603e8
Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
169
diff
changeset
|
428 slice.done(); // BADA doesn't implement done(), but it could (e.g. free array) |
71ddbf8603e8
Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
169
diff
changeset
|
429 /// and we'd better tell it we are not going to use it any more. However, it's important to ensure Inspector |
71ddbf8603e8
Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
169
diff
changeset
|
430 // implementations out there do not retain GroupElement.rawData() |
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:
526
diff
changeset
|
431 prevNodeid = ge.node(); |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
432 len = da.isEmpty() ? 0 : da.readInt(); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
433 } |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
434 // need to skip up to group end if inspector told he don't want to continue with the group, |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
435 // because outer code may try to read next group immediately as we return back. |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
436 while (len > 4 && !da.isEmpty()) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
437 da.skip(len - 4 /* length field */); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
438 len = da.isEmpty() ? 0 : da.readInt(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
439 } |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
440 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
441 |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
442 private static void skipGroup(DataAccess da) throws IOException { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
443 int len = da.readInt(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
444 while (len > 4 && !da.isEmpty()) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
445 da.skip(len - 4); // sizeof(int) |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
446 len = da.isEmpty() ? 0 : da.readInt(); |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
447 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
448 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
449 |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
450 @Experimental(reason="Cumbersome API, rawData and apply with byte[] perhaps need replacement with ByteChannel/ByteBuffer, and better Exceptions. Perhaps, shall split into interface and impl") |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
451 public static class GroupElement { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
452 private final byte[] header; // byte[80] takes 120 bytes, 4 Nodeids - 192 |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
453 private final DataAccess dataAccess; |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
454 private Patch patches; |
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:
526
diff
changeset
|
455 private final Nodeid deltaBase; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
456 |
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:
526
diff
changeset
|
457 GroupElement(byte[] fourNodeids, Nodeid deltaBaseRev, DataAccess rawDataAccess) { |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
458 assert fourNodeids != null && fourNodeids.length == 80; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
459 header = fourNodeids; |
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:
526
diff
changeset
|
460 deltaBase = deltaBaseRev; |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
461 dataAccess = rawDataAccess; |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
462 } |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
463 |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
464 /** |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
465 * <b>node</b> field of the group element |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
466 * @return node revision, never <code>null</code> |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
467 */ |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
468 public Nodeid node() { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
469 return Nodeid.fromBinary(header, 0); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
470 } |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
471 |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
472 /** |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
473 * <b>p1</b> <i>(parent 1)</i> field of the group element |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
474 * @return revision of parent 1, never <code>null</code> |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
475 */ |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
476 public Nodeid firstParent() { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
477 return Nodeid.fromBinary(header, 20); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
478 } |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
479 |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
480 /** |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
481 * <b>p2</b> <i>(parent 2)</i> field of the group element |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
482 * @return revision of parent 2, never <code>null</code> |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
483 */ |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
484 public Nodeid secondParent() { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
485 return Nodeid.fromBinary(header, 40); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
486 } |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
487 |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
488 /** |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
489 * <b>cs</b> <i>(changeset link)</i> field of the group element |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
490 * @return changeset revision, never <code>null</code> |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
491 */ |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
492 public Nodeid cset() { |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
493 return Nodeid.fromBinary(header, 60); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
494 } |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
495 |
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:
526
diff
changeset
|
496 /** |
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:
526
diff
changeset
|
497 * Revision this element keeps patches against. For the patches of the very first revision returns {@link Nodeid#NULL}. |
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:
526
diff
changeset
|
498 * @return revision of delta base, never <code>null</code> |
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:
526
diff
changeset
|
499 */ |
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:
526
diff
changeset
|
500 public Nodeid patchBase() { |
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:
526
diff
changeset
|
501 return deltaBase; |
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:
526
diff
changeset
|
502 } |
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:
526
diff
changeset
|
503 |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
504 public byte[] rawDataByteArray() throws IOException { // XXX IOException or HgInvalidFileException? |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
505 return rawData().byteArray(); |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
506 } |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
507 |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
508 public byte[] apply(byte[] baseContent) throws IOException { |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
509 return apply(new ByteArrayDataAccess(baseContent)); |
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
510 } |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
511 |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
512 /*package-local*/ DataAccess rawData() { |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
513 return dataAccess; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
514 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
515 |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
516 /*package-local*/ Patch patch() throws IOException { |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
517 if (patches == null) { |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
518 dataAccess.reset(); |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
519 patches = new Patch(); |
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
520 patches.read(dataAccess); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
521 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
522 return patches; |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
523 } |
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
524 |
358
fc8bc2f1edbe
Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
357
diff
changeset
|
525 /*package-local*/ byte[] apply(DataAccess baseContent) throws IOException { |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
526 return patch().apply(baseContent, -1); |
169
8c8e3f372fa1
Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
527 } |
357
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
528 |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
529 public String toString() { |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
530 int patchCount; |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
531 try { |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
532 patchCount = patch().count(); |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
533 } catch (IOException ex) { |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
534 ex.printStackTrace(); |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
535 patchCount = -1; |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
536 } |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
537 return String.format("%s %s %s %s; patches:%d\n", node().shortNotation(), firstParent().shortNotation(), secondParent().shortNotation(), cset().shortNotation(), patchCount); |
dfb8405d996f
Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
538 } |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
539 } |
645
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
540 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
541 @Experimental(reason="Work in progress, not an API") |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
542 public class BundleSerializer implements DataSerializer.DataSource { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
543 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
544 public void serialize(DataSerializer out) throws HgIOException, HgRuntimeException { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
545 FileInputStream fis = null; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
546 try { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
547 fis = new FileInputStream(HgBundle.this.bundleFile); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
548 byte[] buffer = new byte[8*1024]; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
549 int r; |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
550 while ((r = fis.read(buffer, 0, buffer.length)) > 0) { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
551 out.write(buffer, 0, r); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
552 } |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
553 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
554 } catch (IOException ex) { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
555 throw new HgIOException("Failed to serialize bundle", HgBundle.this.bundleFile); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
556 } finally { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
557 new FileUtils(HgBundle.this.ctx.getLog()).closeQuietly(fis, HgBundle.this.bundleFile); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
558 } |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
559 } |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
560 |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
561 public int serializeLength() throws HgRuntimeException { |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
562 return Internals.ltoi(HgBundle.this.bundleFile.length()); |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
563 } |
14dac192aa26
Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
564 } |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
565 } |