annotate src/org/tmatesoft/hg/repo/HgRemoteRepository.java @ 407:30922c728341 smartgit3

Better multiline log printout; options to tune default log output
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Mar 2012 12:51:03 +0100
parents 994b5813a925
children bb278ccf9866
rev   line source
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:
diff changeset
1 /*
407
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
2 * Copyright (c) 2011-2012 TMate Software Ltd
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:
diff changeset
3 *
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:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
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:
diff changeset
5 * it under the terms of the GNU General Public License as published by
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:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
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:
diff changeset
7 *
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:
diff changeset
8 * This program is distributed in the hope that it will be useful,
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:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
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:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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:
diff changeset
11 * GNU General Public License for more details.
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:
diff changeset
12 *
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:
diff changeset
13 * For information on how to redistribute this software under
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:
diff changeset
14 * the terms of a license other than GNU General Public License
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:
diff changeset
15 * contact TMate Software at support@hg4j.com
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:
diff changeset
16 */
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:
diff changeset
17 package org.tmatesoft.hg.repo;
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:
diff changeset
18
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:
diff changeset
19 import java.io.File;
179
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
20 import java.io.FileOutputStream;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
21 import java.io.IOException;
179
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
22 import java.io.InputStream;
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
23 import java.io.InputStreamReader;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
24 import java.io.OutputStream;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
25 import java.io.StreamTokenizer;
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
26 import java.net.HttpURLConnection;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
27 import java.net.MalformedURLException;
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
28 import java.net.URL;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
29 import java.net.URLConnection;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
30 import java.security.cert.CertificateException;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
31 import java.security.cert.X509Certificate;
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
32 import java.util.ArrayList;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
33 import java.util.Collection;
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
34 import java.util.Collections;
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
35 import java.util.Iterator;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
36 import java.util.LinkedHashMap;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
37 import java.util.LinkedList;
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:
diff changeset
38 import java.util.List;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
39 import java.util.Map;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
40 import java.util.prefs.BackingStoreException;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
41 import java.util.prefs.Preferences;
179
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
42 import java.util.zip.InflaterInputStream;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
43
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
44 import javax.net.ssl.HttpsURLConnection;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
45 import javax.net.ssl.SSLContext;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
46 import javax.net.ssl.TrustManager;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
47 import javax.net.ssl.X509TrustManager;
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:
diff changeset
48
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
49 import org.tmatesoft.hg.core.HgBadArgumentException;
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
50 import org.tmatesoft.hg.core.HgBadStateException;
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
51 import org.tmatesoft.hg.core.HgInvalidFileException;
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
52 import org.tmatesoft.hg.core.HgRemoteConnectionException;
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:
diff changeset
53 import org.tmatesoft.hg.core.Nodeid;
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
54 import org.tmatesoft.hg.core.SessionContext;
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:
diff changeset
55
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:
diff changeset
56 /**
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:
diff changeset
57 * WORK IN PROGRESS, DO NOT USE
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:
diff changeset
58 *
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:
diff changeset
59 * @see http://mercurial.selenic.com/wiki/WireProtocol
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:
diff changeset
60 *
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:
diff changeset
61 * @author Artem Tikhomirov
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:
diff changeset
62 * @author TMate Software Ltd.
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:
diff changeset
63 */
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:
diff changeset
64 public class HgRemoteRepository {
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
65
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
66 private final URL url;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
67 private final SSLContext sslContext;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
68 private final String authInfo;
407
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
69 private final boolean debug;
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: 184
diff changeset
70 private HgLookup lookupHelper;
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
71 private final SessionContext sessionContext;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
72
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
73 HgRemoteRepository(SessionContext ctx, URL url) throws HgBadArgumentException {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
74 if (url == null || ctx == null) {
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
75 throw new IllegalArgumentException();
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
76 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
77 this.url = url;
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
78 sessionContext = ctx;
407
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
79 Object debugProp = ctx.getProperty("hg4j.remote.debug", false);
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
80 debug = debugProp instanceof Boolean ? ((Boolean) debugProp).booleanValue() : Boolean.parseBoolean(String.valueOf(debugProp));
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
81 if ("https".equals(url.getProtocol())) {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
82 try {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
83 sslContext = SSLContext.getInstance("SSL");
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
84 class TrustEveryone implements X509TrustManager {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
85 public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
207
1bf0a5af2d5d Conditional debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
86 if (debug) {
1bf0a5af2d5d Conditional debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
87 System.out.println("checkClientTrusted:" + authType);
1bf0a5af2d5d Conditional debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
88 }
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
89 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
90 public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
207
1bf0a5af2d5d Conditional debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
91 if (debug) {
1bf0a5af2d5d Conditional debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
92 System.out.println("checkServerTrusted:" + authType);
1bf0a5af2d5d Conditional debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
93 }
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
94 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
95 public X509Certificate[] getAcceptedIssuers() {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
96 return new X509Certificate[0];
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
97 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
98 };
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
99 sslContext.init(null, new TrustManager[] { new TrustEveryone() }, null);
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
100 } catch (Exception ex) {
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
101 throw new HgBadArgumentException("Can't initialize secure connection", ex);
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
102 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
103 } else {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
104 sslContext = null;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
105 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
106 if (url.getUserInfo() != null) {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
107 String ai = null;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
108 try {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
109 // Hack to get Base64-encoded credentials
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
110 Preferences tempNode = Preferences.userRoot().node("xxx");
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
111 tempNode.putByteArray("xxx", url.getUserInfo().getBytes());
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
112 ai = tempNode.get("xxx", null);
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
113 tempNode.removeNode();
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
114 } catch (BackingStoreException ex) {
357
dfb8405d996f Clean debug stacktraces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
115 sessionContext.getLog().info(getClass(), ex, null);
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
116 // IGNORE
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
117 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
118 authInfo = ai;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
119 } else {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
120 authInfo = null;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
121 }
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
122 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
123
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
124 public boolean isInvalid() throws HgRemoteConnectionException {
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
125 // say hello to server, check response
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
126 if (Boolean.FALSE.booleanValue()) {
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
127 throw HgRepository.notImplemented();
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
128 }
383
994b5813a925 Few comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
129 return false; // FIXME implement remote repository hello/check
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
130 }
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
131
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
132 /**
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
133 * @return human-readable address of the server, without user credentials or any other security information
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
134 */
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
135 public String getLocation() {
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
136 if (url.getUserInfo() == null) {
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
137 return url.toExternalForm();
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
138 }
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
139 if (url.getPort() != -1) {
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
140 return String.format("%s://%s:%d%s", url.getProtocol(), url.getHost(), url.getPort(), url.getPath());
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
141 } else {
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
142 return String.format("%s://%s%s", url.getProtocol(), url.getHost(), url.getPath());
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
143 }
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
144 }
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 179
diff changeset
145
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
146 public List<Nodeid> heads() throws HgRemoteConnectionException {
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
147 try {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
148 URL u = new URL(url, url.getPath() + "?cmd=heads");
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
149 HttpURLConnection c = setupConnection(u.openConnection());
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
150 c.connect();
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
151 if (debug) {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
152 dumpResponseHeader(u, c);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
153 }
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
154 InputStreamReader is = new InputStreamReader(c.getInputStream(), "US-ASCII");
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
155 StreamTokenizer st = new StreamTokenizer(is);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
156 st.ordinaryChars('0', '9');
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
157 st.wordChars('0', '9');
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
158 st.eolIsSignificant(false);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
159 LinkedList<Nodeid> parseResult = new LinkedList<Nodeid>();
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
160 while (st.nextToken() != StreamTokenizer.TT_EOF) {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
161 parseResult.add(Nodeid.fromAscii(st.sval));
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
162 }
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
163 return parseResult;
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
164 } catch (MalformedURLException ex) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
165 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand("heads").setServerInfo(getLocation());
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
166 } catch (IOException ex) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
167 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand("heads").setServerInfo(getLocation());
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
168 }
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
169 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
170
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
171 public List<Nodeid> between(Nodeid tip, Nodeid base) throws HgRemoteConnectionException {
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
172 Range r = new Range(base, tip);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
173 // XXX shall handle errors like no range key in the returned map, not sure how.
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
174 return between(Collections.singletonList(r)).get(r);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
175 }
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
176
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
177 /**
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
178 * @param ranges
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
179 * @return map, where keys are input instances, values are corresponding server reply
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
180 * @throws HgRemoteConnectionException
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
181 */
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
182 public Map<Range, List<Nodeid>> between(Collection<Range> ranges) throws HgRemoteConnectionException {
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
183 if (ranges.isEmpty()) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
184 return Collections.emptyMap();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
185 }
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
186 // if fact, shall do other way round, this method shall send
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
187 LinkedHashMap<Range, List<Nodeid>> rv = new LinkedHashMap<HgRemoteRepository.Range, List<Nodeid>>(ranges.size() * 4 / 3);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
188 StringBuilder sb = new StringBuilder(20 + ranges.size() * 82);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
189 sb.append("pairs=");
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
190 for (Range r : ranges) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
191 sb.append(r.end.toString());
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
192 sb.append('-');
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
193 sb.append(r.start.toString());
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
194 sb.append('+');
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
195 }
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
196 if (sb.charAt(sb.length() - 1) == '+') {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
197 // strip last space
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
198 sb.setLength(sb.length() - 1);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
199 }
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
200 try {
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
201 boolean usePOST = ranges.size() > 3;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
202 URL u = new URL(url, url.getPath() + "?cmd=between" + (usePOST ? "" : '&' + sb.toString()));
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
203 HttpURLConnection c = setupConnection(u.openConnection());
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
204 if (usePOST) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
205 c.setRequestMethod("POST");
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
206 c.setRequestProperty("Content-Length", String.valueOf(sb.length()/*nodeids are ASCII, bytes == characters */));
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
207 c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
208 c.setDoOutput(true);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
209 c.connect();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
210 OutputStream os = c.getOutputStream();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
211 os.write(sb.toString().getBytes());
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
212 os.flush();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
213 os.close();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
214 } else {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
215 c.connect();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
216 }
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
217 if (debug) {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
218 System.out.printf("%d ranges, method:%s \n", ranges.size(), c.getRequestMethod());
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
219 dumpResponseHeader(u, c);
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
220 }
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
221 InputStreamReader is = new InputStreamReader(c.getInputStream(), "US-ASCII");
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
222 StreamTokenizer st = new StreamTokenizer(is);
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
223 st.ordinaryChars('0', '9');
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
224 st.wordChars('0', '9');
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
225 st.eolIsSignificant(true);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
226 Iterator<Range> rangeItr = ranges.iterator();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
227 LinkedList<Nodeid> currRangeList = null;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
228 Range currRange = null;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
229 boolean possiblyEmptyNextLine = true;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
230 while (st.nextToken() != StreamTokenizer.TT_EOF) {
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
231 if (st.ttype == StreamTokenizer.TT_EOL) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
232 if (possiblyEmptyNextLine) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
233 // newline follows newline;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
234 assert currRange == null;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
235 assert currRangeList == null;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
236 if (!rangeItr.hasNext()) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
237 throw new HgBadStateException();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
238 }
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
239 rv.put(rangeItr.next(), Collections.<Nodeid>emptyList());
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
240 } else {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
241 if (currRange == null || currRangeList == null) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
242 throw new HgBadStateException();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
243 }
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
244 // indicate next range value is needed
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
245 currRange = null;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
246 currRangeList = null;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
247 possiblyEmptyNextLine = true;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
248 }
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
249 } else {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
250 possiblyEmptyNextLine = false;
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
251 if (currRange == null) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
252 if (!rangeItr.hasNext()) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
253 throw new HgBadStateException();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
254 }
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
255 currRange = rangeItr.next();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
256 currRangeList = new LinkedList<Nodeid>();
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
257 rv.put(currRange, currRangeList);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
258 }
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
259 Nodeid nid = Nodeid.fromAscii(st.sval);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
260 currRangeList.addLast(nid);
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
261 }
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
262 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
263 is.close();
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
264 return rv;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
265 } catch (MalformedURLException ex) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
266 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand("between").setServerInfo(getLocation());
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
267 } catch (IOException ex) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
268 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand("between").setServerInfo(getLocation());
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
269 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
270 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
271
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
272 public List<RemoteBranch> branches(List<Nodeid> nodes) throws HgRemoteConnectionException {
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
273 StringBuilder sb = new StringBuilder(20 + nodes.size() * 41);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
274 sb.append("nodes=");
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
275 for (Nodeid n : nodes) {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
276 sb.append(n.toString());
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
277 sb.append('+');
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
278 }
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
279 if (sb.charAt(sb.length() - 1) == '+') {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
280 // strip last space
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
281 sb.setLength(sb.length() - 1);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
282 }
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
283 try {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
284 URL u = new URL(url, url.getPath() + "?cmd=branches&" + sb.toString());
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
285 HttpURLConnection c = setupConnection(u.openConnection());
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
286 c.connect();
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
287 if (debug) {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
288 dumpResponseHeader(u, c);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
289 }
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
290 InputStreamReader is = new InputStreamReader(c.getInputStream(), "US-ASCII");
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
291 StreamTokenizer st = new StreamTokenizer(is);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
292 st.ordinaryChars('0', '9');
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
293 st.wordChars('0', '9');
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
294 st.eolIsSignificant(false);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
295 ArrayList<Nodeid> parseResult = new ArrayList<Nodeid>(nodes.size() * 4);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
296 while (st.nextToken() != StreamTokenizer.TT_EOF) {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
297 parseResult.add(Nodeid.fromAscii(st.sval));
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
298 }
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
299 if (parseResult.size() != nodes.size() * 4) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
300 throw new HgRemoteConnectionException(String.format("Bad number of nodeids in result (shall be factor 4), expected %d, got %d", nodes.size()*4, parseResult.size()));
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
301 }
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
302 ArrayList<RemoteBranch> rv = new ArrayList<RemoteBranch>(nodes.size());
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
303 for (int i = 0; i < nodes.size(); i++) {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
304 RemoteBranch rb = new RemoteBranch(parseResult.get(i*4), parseResult.get(i*4 + 1), parseResult.get(i*4 + 2), parseResult.get(i*4 + 3));
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
305 rv.add(rb);
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
306 }
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
307 return rv;
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
308 } catch (MalformedURLException ex) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
309 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand("branches").setServerInfo(getLocation());
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
310 } catch (IOException ex) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
311 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand("branches").setServerInfo(getLocation());
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
312 }
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
313 }
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:
diff changeset
314
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: 184
diff changeset
315 /*
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 190
diff changeset
316 * XXX need to describe behavior when roots arg is empty; our RepositoryComparator code currently returns empty lists when
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 190
diff changeset
317 * no common elements found, which in turn means we need to query changes starting with NULL nodeid.
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 190
diff changeset
318 *
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: 184
diff changeset
319 * WireProtocol wiki: roots = a list of the latest nodes on every service side changeset branch that both the client and server know about.
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: 184
diff changeset
320 *
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: 184
diff changeset
321 * Perhaps, shall be named 'changegroup'
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: 184
diff changeset
322
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: 184
diff changeset
323 * Changegroup:
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: 184
diff changeset
324 * http://mercurial.selenic.com/wiki/Merge
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: 184
diff changeset
325 * http://mercurial.selenic.com/wiki/WireProtocol
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: 184
diff changeset
326 *
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: 184
diff changeset
327 * according to latter, bundleformat data is sent through zlib
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: 184
diff changeset
328 * (there's no header like HG10?? with the server output, though,
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: 184
diff changeset
329 * as one may expect according to http://mercurial.selenic.com/wiki/BundleFormat)
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: 184
diff changeset
330 */
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
331 public HgBundle getChanges(List<Nodeid> roots) throws HgRemoteConnectionException, HgInvalidFileException {
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 190
diff changeset
332 List<Nodeid> _roots = roots.isEmpty() ? Collections.singletonList(Nodeid.NULL) : roots;
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 190
diff changeset
333 StringBuilder sb = new StringBuilder(20 + _roots.size() * 41);
179
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
334 sb.append("roots=");
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 190
diff changeset
335 for (Nodeid n : _roots) {
179
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
336 sb.append(n.toString());
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
337 sb.append('+');
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
338 }
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
339 if (sb.charAt(sb.length() - 1) == '+') {
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
340 // strip last space
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
341 sb.setLength(sb.length() - 1);
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
342 }
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
343 try {
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
344 URL u = new URL(url, url.getPath() + "?cmd=changegroup&" + sb.toString());
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
345 HttpURLConnection c = setupConnection(u.openConnection());
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
346 c.connect();
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
347 if (debug) {
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
348 dumpResponseHeader(u, c);
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
349 }
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
350 File tf = writeBundle(c.getInputStream(), false, "HG10GZ" /*didn't see any other that zip*/);
190
9b99d27aeddc More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 186
diff changeset
351 if (debug) {
210
6a2481866491 Wrong parent assignment when building branch chain
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 207
diff changeset
352 System.out.printf("Wrote bundle %s for roots %s\n", tf, sb);
190
9b99d27aeddc More debug printouts
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 186
diff changeset
353 }
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: 184
diff changeset
354 return getLookupHelper().loadBundle(tf);
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
355 } catch (MalformedURLException ex) { // XXX in fact, this exception might be better to be re-thrown as RuntimeEx,
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
356 // as there's little user can do about this issue (URLs are constructed by our code)
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
357 throw new HgRemoteConnectionException("Bad URL", ex).setRemoteCommand("changegroup").setServerInfo(getLocation());
179
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
358 } catch (IOException ex) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 210
diff changeset
359 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand("changegroup").setServerInfo(getLocation());
179
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
360 }
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:
diff changeset
361 }
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: 184
diff changeset
362
203
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
363 @Override
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
364 public String toString() {
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
365 return getClass().getSimpleName() + '[' + getLocation() + ']';
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
366 }
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
367
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: 184
diff changeset
368 private HgLookup getLookupHelper() {
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: 184
diff changeset
369 if (lookupHelper == null) {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 274
diff changeset
370 lookupHelper = new HgLookup(sessionContext);
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: 184
diff changeset
371 }
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: 184
diff changeset
372 return lookupHelper;
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: 184
diff changeset
373 }
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
374
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
375 private HttpURLConnection setupConnection(URLConnection urlConnection) {
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
376 urlConnection.setRequestProperty("User-Agent", "hg4j/0.5.0");
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
377 urlConnection.addRequestProperty("Accept", "application/mercurial-0.1");
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
378 if (authInfo != null) {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
379 urlConnection.addRequestProperty("Authorization", "Basic " + authInfo);
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
380 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
381 if (sslContext != null) {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
382 ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslContext.getSocketFactory());
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
383 }
177
e10225daface Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 176
diff changeset
384 return (HttpURLConnection) urlConnection;
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
385 }
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
386
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
387 private void dumpResponseHeader(URL u, HttpURLConnection c) {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
388 System.out.printf("Query (%d bytes):%s\n", u.getQuery().length(), u.getQuery());
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
389 System.out.println("Response headers:");
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
390 final Map<String, List<String>> headerFields = c.getHeaderFields();
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
391 for (String s : headerFields.keySet()) {
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
392 System.out.printf("%s: %s\n", s, c.getHeaderField(s));
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
393 }
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
394 }
179
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
395
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
396 private static File writeBundle(InputStream is, boolean decompress, String header) throws IOException {
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
397 InputStream zipStream = decompress ? new InflaterInputStream(is) : is;
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
398 File tf = File.createTempFile("hg-bundle-", null);
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
399 FileOutputStream fos = new FileOutputStream(tf);
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
400 fos.write(header.getBytes());
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
401 int r;
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
402 byte[] buf = new byte[8*1024];
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
403 while ((r = zipStream.read(buf)) != -1) {
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
404 fos.write(buf, 0, r);
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
405 }
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
406 fos.close();
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
407 zipStream.close();
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
408 return tf;
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
409 }
da426c2fe1ec Support for changegroup wire command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 178
diff changeset
410
178
62665d8f0686 Complete logic to discover all branches missing locally. Most of wire protocol in HgRemoteRepository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 177
diff changeset
411
176
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
412 public static final class Range {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
413 /**
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
414 * Root of the range, earlier revision
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
415 */
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
416 public final Nodeid start;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
417 /**
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
418 * Head of the range, later revision.
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
419 */
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
420 public final Nodeid end;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
421
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
422 /**
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
423 * @param from - root/base revision
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
424 * @param to - head/tip revision
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
425 */
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
426 public Range(Nodeid from, Nodeid to) {
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
427 start = from;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
428 end = to;
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
429 }
a8df7162ec75 Extracting complete branch using remote between call to detect incoming changes is done. Arguments reorderd in remote repo to better match Hg server ideology, not my mental convenience
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
430 }
184
ec1820f64d2b Complete incoming cmdline client, with both lite (revisions) and complete (full changeset) information dump
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 181
diff changeset
431
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
432 public static final class RemoteBranch {
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
433 public final Nodeid head, root, p1, p2;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
434
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
435 public RemoteBranch(Nodeid h, Nodeid r, Nodeid parent1, Nodeid parent2) {
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
436 head = h;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
437 root = r;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
438 p1 = parent1;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
439 p2 = parent2;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
440 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
441
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
442 @Override
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
443 public boolean equals(Object obj) {
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
444 if (this == obj) {
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
445 return true;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
446 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
447 if (false == obj instanceof RemoteBranch) {
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
448 return false;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
449 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
450 RemoteBranch o = (RemoteBranch) obj;
274
9fb50c04f03c Use Nodeid.isNull check instead of NULL.equals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
451 // in fact, p1 and p2 are not supposed to be null, ever (at least for RemoteBranch created from server output)
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
452 return head.equals(o.head) && root.equals(o.root) && (p1 == null && o.p1 == null || p1.equals(o.p1)) && (p2 == null && o.p2 == null || p2.equals(o.p2));
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
453 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
454 }
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:
diff changeset
455 }