Mercurial > hg4j
comparison 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 |
comparison
equal
deleted
inserted
replaced
166:1d0654be1466 | 167:86f9581f4301 |
---|---|
32 import javax.net.ssl.HttpsURLConnection; | 32 import javax.net.ssl.HttpsURLConnection; |
33 import javax.net.ssl.SSLContext; | 33 import javax.net.ssl.SSLContext; |
34 import javax.net.ssl.TrustManager; | 34 import javax.net.ssl.TrustManager; |
35 import javax.net.ssl.X509TrustManager; | 35 import javax.net.ssl.X509TrustManager; |
36 | 36 |
37 import org.tmatesoft.hg.core.Nodeid; | |
37 import org.tmatesoft.hg.internal.ConfigFile; | 38 import org.tmatesoft.hg.internal.ConfigFile; |
38 import org.tmatesoft.hg.internal.Internals; | 39 import org.tmatesoft.hg.internal.Internals; |
39 | 40 |
40 /** | 41 /** |
41 * WORK IN PROGRESS, DO NOT USE | 42 * WORK IN PROGRESS, DO NOT USE |
56 */ | 57 */ |
57 public static void main(String[] args) throws Exception { | 58 public static void main(String[] args) throws Exception { |
58 ConfigFile cfg = new Internals().newConfigFile(); | 59 ConfigFile cfg = new Internals().newConfigFile(); |
59 cfg.addLocation(new File(System.getProperty("user.home"), ".hgrc")); | 60 cfg.addLocation(new File(System.getProperty("user.home"), ".hgrc")); |
60 String svnkitServer = cfg.getSection("paths").get("svnkit"); | 61 String svnkitServer = cfg.getSection("paths").get("svnkit"); |
61 // URL url = new URL(svnkitServer + "?cmd=changegroup&roots=a78c980749e3ccebb47138b547e9b644a22797a9"); | 62 URL url = new URL(svnkitServer + "?cmd=changegroup&roots=" + Nodeid.NULL.toString()); |
62 // URL url = new URL("http://localhost:8000/" + "?cmd=stream_out"); | 63 // URL url = new URL("http://localhost:8000/" + "?cmd=stream_out"); |
63 URL url = new URL(svnkitServer + "?cmd=stream_out"); | 64 // URL url = new URL(svnkitServer + "?cmd=stream_out"); |
64 | 65 |
65 SSLContext sslContext = SSLContext.getInstance("SSL"); | 66 SSLContext sslContext = SSLContext.getInstance("SSL"); |
66 class TrustEveryone implements X509TrustManager { | 67 class TrustEveryone implements X509TrustManager { |
67 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { | 68 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
68 System.out.println("checkClientTrusted " + authType); | 69 System.out.println("checkClientTrusted " + authType); |
93 System.out.printf("%s: %s\n", s, urlConnection.getHeaderField(s)); | 94 System.out.printf("%s: %s\n", s, urlConnection.getHeaderField(s)); |
94 } | 95 } |
95 System.out.printf("Content type is %s and its length is %d\n", urlConnection.getContentType(), urlConnection.getContentLength()); | 96 System.out.printf("Content type is %s and its length is %d\n", urlConnection.getContentType(), urlConnection.getContentLength()); |
96 InputStream is = urlConnection.getInputStream(); | 97 InputStream is = urlConnection.getInputStream(); |
97 // | 98 // |
98 dump(is, -1); // simple dump, any cmd | 99 // dump(is, -1); // simple dump, any cmd |
99 // writeBundle(is); // cmd=changegroup | 100 writeBundle(is, false, "HG10GZ"); // cmd=changegroup |
101 //writeBundle(is, true, "" or "HG10UN"); | |
100 // | 102 // |
101 urlConnection.disconnect(); | 103 urlConnection.disconnect(); |
102 // | 104 // |
103 } | 105 } |
104 | 106 |
113 } | 115 } |
114 } | 116 } |
115 System.out.println(); | 117 System.out.println(); |
116 } | 118 } |
117 | 119 |
118 private static void writeBundle(InputStream is) throws IOException { | 120 private static void writeBundle(InputStream is, boolean decompress, String header) throws IOException { |
119 InflaterInputStream zipStream = new InflaterInputStream(is); | 121 InputStream zipStream = decompress ? new InflaterInputStream(is) : is; |
120 File tf = File.createTempFile("hg-bundle-", null); | 122 File tf = File.createTempFile("hg-bundle-", null); |
121 FileOutputStream fos = new FileOutputStream(tf); | 123 FileOutputStream fos = new FileOutputStream(tf); |
124 fos.write(header.getBytes()); | |
122 int r; | 125 int r; |
123 byte[] buf = new byte[8*1024]; | 126 byte[] buf = new byte[8*1024]; |
124 while ((r = zipStream.read(buf)) != -1) { | 127 while ((r = zipStream.read(buf)) != -1) { |
125 fos.write(buf, 0, r); | 128 fos.write(buf, 0, r); |
126 } | 129 } |