annotate cmdline/org/tmatesoft/hg/console/Remote.java @ 161:9423235ca77b

Record possible value (and knowledge source) for extras field
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 09 Mar 2011 13:34:50 +0100
parents 643ddec3be36
children 86f9581f4301
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
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
37 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
38 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
39
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 /**
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
41 * WORK IN PROGRESS, DO NOT USE
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
42 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
43 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 69
diff changeset
44 * @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
45 */
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 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
47
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 * @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
50 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
51 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
52 // 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
53 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
54 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
55 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
56 */
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 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
58 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
59 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
60 String svnkitServer = cfg.getSection("paths").get("svnkit");
156
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
61 // URL url = new URL(svnkitServer + "?cmd=changegroup&roots=a78c980749e3ccebb47138b547e9b644a22797a9");
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
62 // URL url = new URL("http://localhost:8000/" + "?cmd=stream_out");
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
63 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
64
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 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
66 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
67 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
68 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
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
70 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
71 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
72 }
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 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
74 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
75 }
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 }
156
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
77 // 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
78 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
79 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
80 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
81 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
82 //
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 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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94 }
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 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
96 InputStream is = urlConnection.getInputStream();
156
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
97 //
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
98 dump(is, -1); // simple dump, any cmd
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
99 // writeBundle(is); // cmd=changegroup
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
100 //
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
101 urlConnection.disconnect();
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 }
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 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
106 int b;
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
107 while ((b =is.read()) != -1) {
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
108 System.out.print((char) b);
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
109 if (limit != -1) {
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
110 if (--limit < 0) {
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
111 break;
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
112 }
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
113 }
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 System.out.println();
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
643ddec3be36 Investigate pull/clone functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
118 private static void writeBundle(InputStream is) throws 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
119 InflaterInputStream zipStream = new InflaterInputStream(is);
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
120 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
121 FileOutputStream fos = new FileOutputStream(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
122 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
123 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
124 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
125 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
126 }
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 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
128 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
129 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
130 }
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 }