annotate src/org/tmatesoft/hg/repo/HgBundle.java @ 667:fba85bc1dfb8

Refactoring: move all encoding/decoding operations into single place, EncodingHelper
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 11 Jul 2013 17:54:08 +0200
parents 46b56864b483
children 545b1d4cc11d
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>
parents: 51 154
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>
parents: 51 154
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;
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
34 import org.tmatesoft.hg.internal.EncodingHelper;
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
35 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
36 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
37 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
38 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
39 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
40 import org.tmatesoft.hg.internal.Patch;
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
41 import org.tmatesoft.hg.repo.HgChangelog.ChangesetParser;
154
ba2bf656f00f Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
42 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
43 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>
parents: 51 154
diff changeset
44 import org.tmatesoft.hg.util.CancelledException;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
45
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 /**
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
47 * 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
48 *
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 * @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
50 *
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
51 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
52 * @author TMate Software Ltd.
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 */
467
51d682cf9cdc Cleaned experimental tag and updated comments/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 427
diff changeset
54 @Experimental(reason="API is not stable")
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 public class HgBundle {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 private final File bundleFile;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 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
59 private final SessionContext ctx;
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
60 private final EncodingHelper fnDecorer;
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
61 private Lifecycle.BasicCallback flowControl;
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62
645
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
63 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
64 ctx = sessionContext;
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 accessProvider = dap;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 bundleFile = bundle;
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
67 fnDecorer = Internals.buildFileNameEncodingHelper(new SessionContext.SourcePrim(ctx));
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69
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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 }
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
79 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
80 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
81 }
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 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
83 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
84 }
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 // "...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
86 } 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
87 da.reset();
39
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
88 }
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
89 }
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
90 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
91 }
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
92
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
93 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
94 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
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 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
97 }
44a34baabea0 Clone refactored 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 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
99 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
100 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
101 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
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 }
44a34baabea0 Clone refactored 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
104 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
105 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
106 }
44a34baabea0 Clone refactored 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
107
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
108 /**
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
109 * 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
110 * @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
111 * @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
112 */
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
113 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
114 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
115 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
116 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
117 private DataAccess prevRevContent;
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
118 private int revisionIndex;
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
119 private ChangesetParser csetBuilder;
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
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 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
122 emptyChangelog = true;
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
123 revisionIndex = 0;
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
124 csetBuilder = new ChangesetParser(hgRepo, true);
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
125 }
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 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
128 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
129 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
130 }
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
131 }
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
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 /*
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 * 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
135 * (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
136 * 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
137 * 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
138 *
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 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
140 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
141 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
142 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
143 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
144 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
145 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
146
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 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
148 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
149 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
150 > 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
151 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
152 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
153
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 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
155 */
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
156 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
157 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
158 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
159 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
160 if (prevRevContent == null) {
274
9fb50c04f03c Use Nodeid.isNull check instead of NULL.equals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 186
diff changeset
161 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
162 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
163 } 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
164 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
165 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
166 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
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 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
169 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
170 // 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
171 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
172 }
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 //
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 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
176 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
177 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
178 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
179 }
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 ByteArrayDataAccess csetDataAccess = new ByteArrayDataAccess(csetContent);
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
181 RawChangeset cs = csetBuilder.parse(csetDataAccess);
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
182 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
183 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
184 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
185 } 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
186 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
187 } 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
188 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
189 } 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
190 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
191 }
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 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
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
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
195 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
196 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
197 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
198 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
199
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 };
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
201 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
202 }
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
203
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 // 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
205 @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
206 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
207 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
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 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
210
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
211 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
212
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
213 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
214
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
215 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
216
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
217 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
218
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 /**
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
220 * 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
221 * @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
222 * @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
223 */
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
224 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
225 }
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
226
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
227 /**
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
228 * @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
229 * @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
230 * @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
231 */
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
232 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
233 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
234 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
235 }
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
236 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
237 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
238 try {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
239 da = getDataStream();
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
240 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
241 } catch (IOException ex) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
242 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
243 } finally {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
244 if (da != null) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
245 da.done();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
246 }
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
247 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
248 }
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
249 }
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
250
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
251 /**
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
252 * @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
253 * @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
254 * @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
255 */
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
256 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
257 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
258 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
259 }
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
260 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
261 DataAccess da = null;
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
262 try {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
263 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
264 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
265 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
266 }
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
267 skipGroup(da); // changelog
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
268 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
269 } catch (IOException ex) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
270 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
271 } finally {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
272 if (da != null) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
273 da.done();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
274 }
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
275 lifecycleTearDown(lifecycle);
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
276 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
277 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
278
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
279 /**
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
280 * @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
281 * @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
282 * @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
283 */
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
284 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
285 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
286 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
287 }
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
288 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
289 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
290 try {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
291 da = getDataStream();
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
292 if (da.isEmpty()) {
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
293 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
294 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
295 skipGroup(da); // changelog
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
296 if (da.isEmpty()) {
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
297 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
298 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
299 skipGroup(da); // manifest
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
300 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
301 } catch (IOException ex) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
302 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
303 } finally {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
304 if (da != null) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
305 da.done();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
306 }
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
307 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
308 }
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
309 }
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
310
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
311 /**
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
312 * @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
313 * @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
314 * @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
315 */
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
316 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
317 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
318 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
319 }
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
320 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
321 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
322 try {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
323 da = getDataStream();
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
324 internalInspectChangelog(da, inspector);
513
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
325 if (flowControl.isStopped()) {
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
326 return;
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
327 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
328 internalInspectManifest(da, inspector);
513
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
329 if (flowControl.isStopped()) {
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
330 return;
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
331 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
332 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
333 } catch (IOException ex) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
334 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
335 } finally {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
336 if (da != null) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
337 da.done();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
338 }
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
339 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
340 }
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
341 }
512
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
342
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
343 // 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
344 // 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
345 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
346 // 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
347 // 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
348 // 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
349 // 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
350 if (flowControl != null) {
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
351 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
352 }
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
353 flowControl = new Lifecycle.BasicCallback();
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
354 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
355 if (lifecycle != null) {
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
356 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
357 }
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
358 return lifecycle;
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
359 }
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
360
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
361 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
362 if (lifecycle != null) {
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
363 lifecycle.finish(flowControl);
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
364 }
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
365 flowControl = null;
10ca3ede8367 Issue 39: Progress and Cancel support for Clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 467
diff changeset
366 }
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
367
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
368 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
369 if (da.isEmpty()) {
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
370 return;
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
371 }
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
372 inspector.changelogStart();
513
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
373 if (flowControl.isStopped()) {
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
374 return;
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
375 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
376 readGroup(da, inspector);
513
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
377 if (flowControl.isStopped()) {
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
378 return;
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
379 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
380 inspector.changelogEnd();
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
381 }
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
382
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
383 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
384 if (da.isEmpty()) {
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
385 return;
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
386 }
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
387 inspector.manifestStart();
513
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
388 if (flowControl.isStopped()) {
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
389 return;
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
390 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
391 readGroup(da, inspector);
513
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
392 if (flowControl.isStopped()) {
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
393 return;
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
394 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
395 inspector.manifestEnd();
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
396 }
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
397
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
398 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
399 while (!da.isEmpty()) {
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
400 int fnameLen = da.readInt();
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
401 if (fnameLen <= 4) {
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
402 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
403 }
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
404 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
405 da.readBytes(fnameBuf, 0, fnameBuf.length);
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
406 String name = fnDecorer.fromBundle(fnameBuf, 0, fnameBuf.length);
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
407 inspector.fileStart(name);
513
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
408 if (flowControl.isStopped()) {
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
409 return;
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
410 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
411 readGroup(da, inspector);
513
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
412 if (flowControl.isStopped()) {
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
413 return;
a41d955dc360 Issue 39: HgCloneCommand doesn't use CancelSupport/ProgressSupport handlers
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 512
diff changeset
414 }
182
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
415 inspector.fileEnd(name);
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
416 }
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
417 }
f26ffe04ced0 Refactor HgBundle to dispatch changes found through callback
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
418
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 606
diff changeset
419 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
420 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
421 boolean good2go = true;
663
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
422 Nodeid prevNodeid = 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
423 while (len > 4 && !da.isEmpty() && good2go) {
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
424 byte[] nb = new byte[80];
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
425 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
426 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
427 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
428 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
429 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
430 // 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
431 // 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
432 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
433 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
434 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
435 /// 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
436 // 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
437 prevNodeid = ge.node();
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
438 len = da.isEmpty() ? 0 : da.readInt();
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
439 }
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
440 // 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
441 // 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
442 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
443 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
444 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
445 }
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
446 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
447
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
448 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
449 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
450 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
451 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
452 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
453 }
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
454 }
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
455
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
456 @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
457 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
458 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
459 private final DataAccess dataAccess;
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
460 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
461 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
462
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
463 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
464 assert fourNodeids != null && fourNodeids.length == 80;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
465 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
466 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
467 dataAccess = rawDataAccess;
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
468 }
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
469
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
470 /**
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
471 * <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
472 * @return node revision, never <code>null</code>
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
473 */
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
474 public Nodeid node() {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
475 return Nodeid.fromBinary(header, 0);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
476 }
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
477
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
478 /**
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
479 * <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
480 * @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
481 */
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
482 public Nodeid firstParent() {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
483 return Nodeid.fromBinary(header, 20);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
484 }
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
485
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
486 /**
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
487 * <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
488 * @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
489 */
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
490 public Nodeid secondParent() {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
491 return Nodeid.fromBinary(header, 40);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
492 }
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
493
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
494 /**
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
495 * <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
496 * @return changeset revision, never <code>null</code>
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
497 */
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
498 public Nodeid cset() {
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
499 return Nodeid.fromBinary(header, 60);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
500 }
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
501
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
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 * 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
504 * @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
505 */
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
506 public Nodeid patchBase() {
663
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
507 return deltaBase == null ? firstParent() : deltaBase;
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
508 }
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
509
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
510 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
511 return rawData().byteArray();
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
512 }
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
513
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
514 public byte[] apply(byte[] baseContent) throws IOException {
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
515 return apply(new ByteArrayDataAccess(baseContent));
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
516 }
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
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
518 /*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
519 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
520 }
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
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
522 /*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
523 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
524 dataAccess.reset();
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
525 patches = new Patch();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
526 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
527 }
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
528 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
529 }
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
530
358
fc8bc2f1edbe Clean internal classes from public API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
531 /*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
532 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
533 }
357
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
534
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
535 public String toString() {
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
536 int patchCount;
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
537 try {
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
538 patchCount = patch().count();
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
539 } catch (IOException ex) {
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
540 ex.printStackTrace();
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
541 patchCount = -1;
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
542 }
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
543 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
544 }
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
545 }
645
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
546
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
547 @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
548 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
549
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
550 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
551 FileInputStream fis = null;
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
552 try {
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
553 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
554 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
555 int r;
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
556 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
557 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
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 } catch (IOException ex) {
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
561 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
562 } finally {
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 645
diff changeset
563 new FileUtils(HgBundle.this.ctx.getLog(), this).closeQuietly(fis, HgBundle.this.bundleFile);
645
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
564 }
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
565 }
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
566
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
567 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
568 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
569 }
14dac192aa26 Push: phase2 - upload bundle with changes to remote server
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
570 }
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
571 }