annotate cmdline/org/tmatesoft/hg/console/Remote.java @ 167:86f9581f4301

Write down results of changegroup (or any other BundleFormat) wireprotocol command
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 22 Mar 2011 03:52:34 +0100
parents 643ddec3be36
children 2c3e96674e2a
rev   line source
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
3 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
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: 69
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: 69
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: 69
diff changeset
7 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
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: 69
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: 69
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: 69
diff changeset
11 * GNU General Public License for more details.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
12 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
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: 69
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: 74
diff changeset
15 * contact TMate Software at support@hg4j.com
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
17 package org.tmatesoft.hg.console;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.io.File;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.FileOutputStream;
156
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
21 import java.io.IOException;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.InputStream;
156
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
23 import java.net.HttpURLConnection;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.net.URL;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.security.cert.CertificateException;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.security.cert.X509Certificate;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.List;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.util.Map;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import java.util.prefs.Preferences;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import java.util.zip.InflaterInputStream;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import javax.net.ssl.HttpsURLConnection;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import javax.net.ssl.SSLContext;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import javax.net.ssl.TrustManager;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 import javax.net.ssl.X509TrustManager;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
167
86f9581f4301 Write down results of changegroup (or any other BundleFormat) wireprotocol command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 156
diff changeset
37 import org.tmatesoft.hg.core.Nodeid;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 import org.tmatesoft.hg.internal.ConfigFile;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
39 import org.tmatesoft.hg.internal.Internals;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 /**
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
42 * WORK IN PROGRESS, DO NOT USE
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
43 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
44 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
45 * @author TMate Software Ltd.
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 */
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 public class Remote {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 /*
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 * @see http://mercurial.selenic.com/wiki/WireProtocol
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 cmd=branches gives 4 nodeids (head, root, first parent, second parent) per line (few lines possible, per branch, perhaps?)
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 cmd=capabilities gives lookup ...subset and 3 compress methods
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 // lookup changegroupsubset unbundle=HG10GZ,HG10BZ,HG10UN
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 cmd=heads gives space-separated list of nodeids (or just one)
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 nodeids are in hex (printable) format, need to convert fromAscii()
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 cmd=branchmap
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 */
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 public static void main(String[] args) throws Exception {
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
59 ConfigFile cfg = new Internals().newConfigFile();
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 cfg.addLocation(new File(System.getProperty("user.home"), ".hgrc"));
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 String svnkitServer = cfg.getSection("paths").get("svnkit");
167
86f9581f4301 Write down results of changegroup (or any other BundleFormat) wireprotocol command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 156
diff changeset
62 URL url = new URL(svnkitServer + "?cmd=changegroup&roots=" + Nodeid.NULL.toString());
156
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
63 // URL url = new URL("http://localhost:8000/" + "?cmd=stream_out");
167
86f9581f4301 Write down results of changegroup (or any other BundleFormat) wireprotocol command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 156
diff changeset
64 // URL url = new URL(svnkitServer + "?cmd=stream_out");
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 SSLContext sslContext = SSLContext.getInstance("SSL");
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 class TrustEveryone implements X509TrustManager {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 System.out.println("checkClientTrusted " + authType);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 System.out.println("checkServerTrusted" + authType);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 public X509Certificate[] getAcceptedIssuers() {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 return new X509Certificate[0];
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 }
156
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
78 // Hack to get Base64-encoded credentials
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 Preferences tempNode = Preferences.userRoot().node("xxx");
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 tempNode.putByteArray("xxx", url.getUserInfo().getBytes());
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 String authInfo = tempNode.get("xxx", null);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 tempNode.removeNode();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 //
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 sslContext.init(null, new TrustManager[] { new TrustEveryone() }, null);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 urlConnection.addRequestProperty("User-Agent", "jhg/0.1.0");
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 urlConnection.addRequestProperty("Accept", "application/mercurial-0.1");
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 urlConnection.addRequestProperty("Authorization", "Basic " + authInfo);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 urlConnection.setSSLSocketFactory(sslContext.getSocketFactory());
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 urlConnection.connect();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 System.out.println("Response headers:");
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 final Map<String, List<String>> headerFields = urlConnection.getHeaderFields();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 for (String s : headerFields.keySet()) {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 System.out.printf("%s: %s\n", s, urlConnection.getHeaderField(s));
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 System.out.printf("Content type is %s and its length is %d\n", urlConnection.getContentType(), urlConnection.getContentLength());
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 InputStream is = urlConnection.getInputStream();
156
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
98 //
167
86f9581f4301 Write down results of changegroup (or any other BundleFormat) wireprotocol command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 156
diff changeset
99 // dump(is, -1); // simple dump, any cmd
86f9581f4301 Write down results of changegroup (or any other BundleFormat) wireprotocol command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 156
diff changeset
100 writeBundle(is, false, "HG10GZ"); // cmd=changegroup
86f9581f4301 Write down results of changegroup (or any other BundleFormat) wireprotocol command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 156
diff changeset
101 //writeBundle(is, true, "" or "HG10UN");
156
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
102 //
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
103 urlConnection.disconnect();
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
104 //
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
105 }
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
106
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
107 private static void dump(InputStream is, int limit) throws IOException {
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
108 int b;
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
109 while ((b =is.read()) != -1) {
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
110 System.out.print((char) b);
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
111 if (limit != -1) {
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
112 if (--limit < 0) {
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
113 break;
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
114 }
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
115 }
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
116 }
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
117 System.out.println();
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
118 }
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
119
167
86f9581f4301 Write down results of changegroup (or any other BundleFormat) wireprotocol command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 156
diff changeset
120 private static void writeBundle(InputStream is, boolean decompress, String header) throws IOException {
86f9581f4301 Write down results of changegroup (or any other BundleFormat) wireprotocol command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 156
diff changeset
121 InputStream zipStream = decompress ? new InflaterInputStream(is) : is;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 File tf = File.createTempFile("hg-bundle-", null);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 FileOutputStream fos = new FileOutputStream(tf);
167
86f9581f4301 Write down results of changegroup (or any other BundleFormat) wireprotocol command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 156
diff changeset
124 fos.write(header.getBytes());
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 int r;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 byte[] buf = new byte[8*1024];
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 while ((r = zipStream.read(buf)) != -1) {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 fos.write(buf, 0, r);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 fos.close();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 zipStream.close();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 System.out.println(tf);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 }