Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/remote/SshConnector.java @ 699:a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 08 Aug 2013 19:18:50 +0200 |
parents | 822f3a83ff57 |
children |
rev | line source |
---|---|
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal.remote; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.io.BufferedReader; |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
20 import java.io.ByteArrayInputStream; |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.io.Closeable; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.io.EOFException; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.io.FilterInputStream; |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
24 import java.io.FilterOutputStream; |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.io.IOException; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.io.InputStream; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.io.InputStreamReader; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import java.io.OutputStream; |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
29 import java.io.SequenceInputStream; |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import java.util.ArrayList; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import java.util.Collection; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import java.util.Collections; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import java.util.List; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
35 import org.tmatesoft.hg.auth.HgAuthFailedException; |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
36 import org.tmatesoft.hg.auth.HgAuthenticator; |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 import org.tmatesoft.hg.core.HgRemoteConnectionException; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 import org.tmatesoft.hg.core.Nodeid; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 import org.tmatesoft.hg.core.SessionContext; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 import org.tmatesoft.hg.repo.HgRemoteRepository.Range; |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
41 import org.tmatesoft.hg.repo.HgRemoteRepository.RemoteDescriptor; |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 import org.tmatesoft.hg.repo.HgRuntimeException; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 import org.tmatesoft.hg.util.LogFacility.Severity; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 |
696
5b5d199e2eb3
Replaced ganymed ssh2 library with trilead
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
45 import com.trilead.ssh2.Connection; |
5b5d199e2eb3
Replaced ganymed ssh2 library with trilead
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
46 import com.trilead.ssh2.Session; |
5b5d199e2eb3
Replaced ganymed ssh2 library with trilead
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
687
diff
changeset
|
47 import com.trilead.ssh2.StreamGobbler; |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 /** |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 * Remote repository via SSH |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 * |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 * @author Artem Tikhomirov |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 * @author TMate Software Ltd. |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 */ |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
55 public class SshConnector extends ConnectorBase { |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
56 private RemoteDescriptor rd; |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 private SessionContext sessionCtx; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 private Connection conn; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 private Session session; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 private int sessionUse; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 private StreamGobbler remoteErr, remoteOut; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 private OutputStream remoteIn; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
65 public void init(RemoteDescriptor remote, SessionContext sessionContext, Object globalConfig) throws HgRuntimeException { |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
66 rd = remote; |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 sessionCtx = sessionContext; |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
68 setURI(remote.getURI()); |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
69 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
70 |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
71 public void connect() throws HgAuthFailedException, HgRemoteConnectionException, HgRuntimeException { |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 try { |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
73 conn = new Connection(uri.getHost(), uri.getPort() == -1 ? 22 : uri.getPort()); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 conn.connect(); |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
75 authenticateClient(); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 } catch (IOException ex) { |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
77 throw new HgRemoteConnectionException("Failed to establish connection").setServerInfo(getServerLocation()); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 } |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
79 } |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
80 |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
81 private void authenticateClient() throws HgAuthFailedException { |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
82 SshAuthMethod m = new SshAuthMethod(conn); |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
83 if (uri.getUserInfo() != null) { |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
84 try { |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
85 m.tryWithUserInfo(uri.getUserInfo()); |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
86 return; |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
87 } catch (HgAuthFailedException ex) { |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
88 // FALL-THROUGH to try with Authenticator |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
89 } |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 } |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
91 HgAuthenticator auth = sessionCtx.getAuthenticator(rd); |
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
92 auth.authenticate(rd, m); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 public void disconnect() throws HgRemoteConnectionException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 if (session != null) { |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
97 doSessionClose(); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 if (conn != null) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 conn.close(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 conn = null; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 public void sessionBegin() throws HgRemoteConnectionException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 if (sessionUse > 0) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 assert session != null; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 sessionUse++; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 return; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 try { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 session = conn.openSession(); |
698
822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
697
diff
changeset
|
113 final String path = uri.getPath(); |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
114 session.execCommand(String.format("hg -R %s serve --stdio", path.charAt(0) == '/' ? path.substring(1) : path)); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 remoteErr = new StreamGobbler(session.getStderr()); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 remoteOut = new StreamGobbler(session.getStdout()); |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
117 remoteIn = session.getStdin(); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 sessionUse = 1; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 } catch (IOException ex) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 throw new HgRemoteConnectionException("Failed to create ssh session", ex); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 public void sessionEnd() throws HgRemoteConnectionException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 assert sessionUse > 0; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 assert session != null; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 if (sessionUse > 1) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 sessionUse--; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 return; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 } |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
131 doSessionClose(); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
134 public String getCapabilities() throws HgRemoteConnectionException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
135 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
136 consume(remoteOut); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
137 consume(remoteErr); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
138 remoteIn.write(CMD_HELLO.getBytes()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
139 remoteIn.write('\n'); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
140 remoteIn.write(CMD_CAPABILITIES.getBytes()); // see http connector for details |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
141 remoteIn.write('\n'); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
142 remoteIn.write(CMD_HEADS.getBytes()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
143 remoteIn.write('\n'); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
144 checkError(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
145 int responseLen = readResponseLength(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
146 checkError(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
147 FilterStream s = new FilterStream(remoteOut, responseLen); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
148 BufferedReader r = new BufferedReader(new InputStreamReader(s)); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
149 String line; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
150 while ((line = r.readLine()) != null) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
151 if (line.startsWith(CMD_CAPABILITIES) && line.length() > (CMD_CAPABILITIES.length()+1)) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
152 line = line.substring(CMD_CAPABILITIES.length()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
153 if (line.charAt(0) == ':') { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
154 return line.substring(CMD_CAPABILITIES.length() + 1); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
155 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
156 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
157 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
158 r.close(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
159 consume(remoteOut); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
160 checkError(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
161 return new String(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
162 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
163 throw new HgRemoteConnectionException("Failed to initiate dialog with server", ex).setRemoteCommand(CMD_HELLO).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
164 } |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 public InputStream heads() throws HgRemoteConnectionException { |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
168 return executeCommand("heads", Collections.<Parameter>emptyList(), true); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 public InputStream between(Collection<Range> ranges) throws HgRemoteConnectionException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 StringBuilder sb = new StringBuilder(ranges.size() * 82); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 for (Range r : ranges) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 r.append(sb).append(' '); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 if (!ranges.isEmpty()) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 sb.setLength(sb.length() - 1); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 } |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
179 return executeCommand("between", Collections.singletonList(new Parameter("pairs", sb.toString())), true); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 public InputStream branches(List<Nodeid> nodes) throws HgRemoteConnectionException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 String l = join(nodes, ' '); |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
184 return executeCommand("branches", Collections.singletonList(new Parameter("nodes", l)), true); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
185 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 public InputStream changegroup(List<Nodeid> roots) throws HgRemoteConnectionException, HgRuntimeException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 String l = join(roots, ' '); |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
189 InputStream cg = executeCommand("changegroup", Collections.singletonList(new Parameter("roots", l)), false); |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
190 InputStream prefix = new ByteArrayInputStream("HG10UN".getBytes()); |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
191 return new SequenceInputStream(prefix, cg); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
194 public OutputStream unbundle(long outputLen, List<Nodeid> remoteHeads) throws HgRemoteConnectionException, HgRuntimeException { |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 String l = join(remoteHeads, ' '); |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
196 try { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
197 consume(remoteOut); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
198 consume(remoteErr); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
199 remoteIn.write(CMD_UNBUNDLE.getBytes()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
200 remoteIn.write('\n'); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
201 writeParameters(Collections.singletonList(new Parameter("heads", l))); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
202 checkError(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
203 return new FilterOutputStream(remoteIn) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
204 @Override |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
205 public void close() throws IOException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
206 out.flush(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
207 @SuppressWarnings("unused") |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
208 int responseLen = readResponseLength(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
209 checkError(); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
210 // XXX perhaps, need to return responseLen to caller? |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
211 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
212 }; |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
213 } catch (IOException ex) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
214 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand(CMD_UNBUNDLE).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
215 } |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
216 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
217 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
218 public InputStream pushkey(String opName, String namespace, String key, String oldValue, String newValue) throws HgRemoteConnectionException, HgRuntimeException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
219 ArrayList<Parameter> p = new ArrayList<Parameter>(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
220 p.add(new Parameter("namespace", namespace)); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
221 p.add(new Parameter("key", key)); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
222 p.add(new Parameter("old", oldValue)); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
223 p.add(new Parameter("new", newValue)); |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
224 return executeCommand("pushkey", p, true); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
225 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
226 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
227 public InputStream listkeys(String namespace, String actionName) throws HgRemoteConnectionException, HgRuntimeException { |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
228 return executeCommand("listkeys", Collections.singletonList(new Parameter("namespace", namespace)), true); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
229 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
230 |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
231 private InputStream executeCommand(String cmd, List<Parameter> parameters, boolean expectResponseLength) throws HgRemoteConnectionException { |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
232 try { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
233 consume(remoteOut); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
234 consume(remoteErr); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
235 remoteIn.write(cmd.getBytes()); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
236 remoteIn.write('\n'); |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
237 writeParameters(parameters); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
238 checkError(); |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
239 if (expectResponseLength) { |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
240 int responseLen = readResponseLength(); |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
241 checkError(); |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
242 return new FilterStream(remoteOut, responseLen); |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
243 } else { |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
244 return new FilterStream(remoteOut, Integer.MAX_VALUE); |
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
245 } |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
246 } catch (IOException ex) { |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
247 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand(cmd).setServerInfo(getServerLocation()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
248 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
249 } |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
250 |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
251 private void writeParameters(List<Parameter> parameters) throws IOException { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
252 for (Parameter p : parameters) { |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
253 remoteIn.write(p.name().getBytes()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
254 remoteIn.write(' '); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
255 remoteIn.write(String.valueOf(p.size()).getBytes()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
256 remoteIn.write('\n'); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
257 remoteIn.write(p.data()); |
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
258 remoteIn.write('\n'); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
259 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
260 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
261 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
262 private void consume(InputStream is) throws IOException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
263 while (is.available() > 0) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
264 is.read(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
265 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
266 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
267 |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
268 private void checkError() throws IOException { |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
269 if (remoteErr.available() > 0) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
270 StringBuilder sb = new StringBuilder(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
271 int c; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
272 while ((c = remoteErr.read()) != -1) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
273 sb.append((char)c); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
274 } |
687
9859fcea475d
Towards ssh remote repositories: refactor HgRemoteRepository - move http related code to HttpConnector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
685
diff
changeset
|
275 throw new IOException(sb.toString()); |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
276 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
277 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
278 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
279 private int readResponseLength() throws IOException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
280 int c; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
281 StringBuilder sb = new StringBuilder(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
282 while ((c = remoteOut.read()) != -1) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
283 if (c == '\n') { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
284 break; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
285 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
286 sb.append((char) c); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
287 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
288 if (c == -1) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
289 throw new EOFException(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
290 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
291 try { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
292 return Integer.parseInt(sb.toString()); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
293 } catch (NumberFormatException ex) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
294 throw new IOException(String.format("Expected response length instead of %s", sb)); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
295 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
296 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
297 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
298 |
699
a483b2b68a2e
Provisional APIs and respective implementation for http, https and ssh remote repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
698
diff
changeset
|
299 private void doSessionClose() { |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
300 if (session != null) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
301 closeQuietly(remoteErr); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
302 closeQuietly(remoteOut); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
303 remoteErr = remoteOut = null; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
304 closeQuietly(remoteIn); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
305 remoteIn = null; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
306 session.close(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
307 session = null; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
308 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
309 sessionUse = 0; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
310 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
311 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
312 private void closeQuietly(Closeable c) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
313 try { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
314 if (c != null) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
315 c.close(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
316 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
317 } catch (IOException ex) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
318 sessionCtx.getLog().dump(getClass(), Severity.Warn, ex, null); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
319 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
320 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
321 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
322 private static String join(List<Nodeid> values, char sep) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
323 StringBuilder sb = new StringBuilder(values.size() * 41); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
324 for (Nodeid n : values) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
325 sb.append(n.toString()); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
326 sb.append(sep); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
327 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
328 if (!values.isEmpty()) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
329 // strip last space |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
330 sb.setLength(sb.length() - 1); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
331 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
332 return sb.toString(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
333 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
334 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
335 private static final class Parameter { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
336 private final String name; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
337 private final byte[] data; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
338 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
339 public Parameter(String paramName, String paramValue) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
340 assert paramName != null; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
341 assert paramValue != null; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
342 name = paramName; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
343 data = paramValue.getBytes(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
344 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
345 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
346 public String name() { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
347 return name; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
348 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
349 public int size() { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
350 return data.length; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
351 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
352 public byte[] data() { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
353 return data; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
354 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
355 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
356 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
357 private static final class FilterStream extends FilterInputStream { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
358 private int length; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
359 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
360 public FilterStream(InputStream is, int initialLength) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
361 super(is); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
362 length = initialLength; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
363 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
364 |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
365 @Override |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
366 public int available() throws IOException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
367 return Math.min(super.available(), length); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
368 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
369 @Override |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
370 public int read() throws IOException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
371 if (length == 0) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
372 return -1; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
373 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
374 int r = super.read(); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
375 if (r >= 0) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
376 length--; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
377 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
378 return r; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
379 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
380 @Override |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
381 public int read(byte[] b, int off, int len) throws IOException { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
382 if (length == 0) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
383 return -1; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
384 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
385 int r = super.read(b, off, Math.min(len, length)); |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
386 if (r >= 0) { |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
387 assert r <= length; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
388 length -= r; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
389 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
390 return r; |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
391 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
392 @Override |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
393 public void close() throws IOException { |
697
24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
696
diff
changeset
|
394 length = 0; |
685
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
395 // INTENTIONALLY DOES NOT CLOSE THE STREAM |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
396 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
397 } |
9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
398 } |