annotate src/org/tmatesoft/hg/repo/HgRemoteRepository.java @ 177:e10225daface

Use POST for long between queries. Batch between queries (pass multiple pairs to a server) to minimize number thereof
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 02 Apr 2011 23:05:28 +0200
parents a8df7162ec75
children 62665d8f0686
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 /*
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
2 * Copyright (c) 2011 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
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;
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
20 import java.io.IOException;
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
21 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
22 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
23 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
24 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
25 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
26 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
27 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
28 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
29 import java.security.cert.X509Certificate;
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.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
31 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
32 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
33 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
34 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
35 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
36 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
37 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
38 import java.util.prefs.Preferences;
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
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 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
41 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
42 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
43 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
44
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
45 import org.tmatesoft.hg.core.HgBadStateException;
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
46 import org.tmatesoft.hg.core.HgException;
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
47 import org.tmatesoft.hg.core.Nodeid;
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
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
49 /**
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
50 * 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
51 *
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
52 * @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
53 *
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
54 * @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
55 * @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
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 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
58
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
59 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
60 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
61 private final String 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
62
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
63 HgRemoteRepository(URL url) throws HgException {
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
64 if (url == 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
65 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
66 }
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 this.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
68 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
69 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
70 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
71 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
72 public void checkClientTrusted(X509Certificate[] chain, String authType) throws 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
73 System.out.println("checkClientTrusted " + authType);
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
74 }
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 public void checkServerTrusted(X509Certificate[] chain, String authType) throws 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
76 System.out.println("checkServerTrusted" + authType);
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 }
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
78 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
79 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
80 }
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 };
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 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
83 } catch (Exception ex) {
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 throw new HgException(ex);
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 }
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
86 } 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
87 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
88 }
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 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
90 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
91 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
92 // 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
93 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
94 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
95 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
96 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
97 } catch (BackingStoreException ex) {
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 ex.printStackTrace();
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 // 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
100 }
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
101 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
102 } 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
103 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
104 }
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
105 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
106
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
107 public List<Nodeid> heads() {
172
87f40938c9b2 Configuration handling out of HgLookup (bad idea to use URL to pass keys)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
108 return Collections.singletonList(Nodeid.fromAscii("71ddbf8603e8e09d54ac9c5fe4bb5ae824589f1d"));
87f40938c9b2 Configuration handling out of HgLookup (bad idea to use URL to pass keys)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 171
diff changeset
109 // return Collections.emptyList();
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
110 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
111
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
112 public List<Nodeid> between(Nodeid tip, Nodeid base) throws HgException {
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
113 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
114 // 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
115 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
116 }
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
117
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
118 /**
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
119 * @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
120 * @return map, where keys are input instances, values are corresponding server reply
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
121 * @throws HgException
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
122 */
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
123 public Map<Range, List<Nodeid>> between(Collection<Range> ranges) throws HgException {
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
124 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
125 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
126 }
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
127 // 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 }
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
137 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
138 // 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
139 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
140 }
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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 } 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
156 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
157 }
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
158 System.out.printf("%d ranges, method:%s \n", ranges.size(), c.getRequestMethod());
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
159 System.out.printf("Query (%d bytes):%s\n", u.getQuery().length(), u.getQuery());
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
160 System.out.println("Response headers:");
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
161 final Map<String, List<String>> headerFields = c.getHeaderFields();
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
162 for (String s : headerFields.keySet()) {
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
163 System.out.printf("%s: %s\n", s, c.getHeaderField(s));
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
164 }
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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 // 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
178 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
179 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
180 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
181 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
182 }
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 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
184 } 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
185 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
186 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
187 }
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 // 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
189 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
190 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
191 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
192 }
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 } 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
194 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
195 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
196 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
197 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
198 }
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 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
200 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
201 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
202 }
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 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
204 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
205 }
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
206 }
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
207 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
208 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
209 } catch (MalformedURLException ex) {
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
210 throw new HgException(ex);
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
211 } catch (IOException ex) {
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
212 throw new HgException(ex);
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
213 }
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
214 }
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
215
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
216 public List<RemoteBranch> branches(List<Nodeid> nodes) {
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
217 return Collections.emptyList();
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
218 }
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
219
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
220 // WireProtocol wiki: roots = a list of the latest nodes on every service side changeset branch that both the client and server know about.
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
221 public HgBundle getChanges(List<Nodeid> roots) throws HgException {
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
222 return new HgLookup().loadBundle(new File("/temp/hg/hg-bundle-000000000000-gz.tmp"));
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
223 }
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
224
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 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
226 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
227 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
228 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
229 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
230 }
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
231 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
232 ((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
233 }
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
234 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
235 }
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
236
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
237 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
238 /**
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
239 * 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
240 */
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
241 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
242 /**
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
243 * 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
244 */
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
245 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
246
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
247 /**
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
248 * @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
249 * @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
250 */
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
251 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
252 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
253 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
254 }
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
255 }
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
256 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
257 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
258
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
259 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
260 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
261 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
262 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
263 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
264 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
265
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
266 @Override
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
267 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
268 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
269 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
270 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
271 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
272 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
273 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
274 RemoteBranch o = (RemoteBranch) obj;
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
275 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
276 }
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
277 }
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
278 }