annotate src/org/tmatesoft/hg/internal/remote/SshConnector.java @ 686:f1f095e42555

Annotated file is not always changed in the latest changeset, need to find out last changest it was changed at (iow, diffed to with BlameHelper)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 25 Jul 2013 22:12:14 +0200
parents 9897cbfd2790
children 9859fcea475d
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;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.Closeable;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.EOFException;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.File;
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;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.io.IOException;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.io.InputStream;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.io.InputStreamReader;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.io.OutputStream;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.net.URL;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import java.util.ArrayList;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import java.util.Arrays;
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.HashSet;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import java.util.List;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 import java.util.Set;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
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.internal.Internals;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 import org.tmatesoft.hg.repo.HgBundle;
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.HgRemoteRepository.Range;
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.repo.HgRuntimeException;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 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
45
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 import ch.ethz.ssh2.Connection;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 import ch.ethz.ssh2.ConnectionInfo;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 import ch.ethz.ssh2.Session;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 import ch.ethz.ssh2.StreamGobbler;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50
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 * Remote repository via SSH
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 *
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 * @author Artem Tikhomirov
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 * @author TMate Software Ltd.
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 */
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 public class SshConnector {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 private SessionContext sessionCtx;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 private URL url;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 private Connection conn;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 private Session session;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 private int sessionUse;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 private StreamGobbler remoteErr, remoteOut;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 private OutputStream remoteIn;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 public void connect(URL url, SessionContext sessionContext, Object globalConfig) throws HgRemoteConnectionException {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 sessionCtx = sessionContext;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 this.url = url;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 try {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 conn = new Connection(url.getHost(), url.getPort() == -1 ? 22 : url.getPort());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 conn.connect();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 } catch (IOException ex) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 throw new HgRemoteConnectionException("Failed to establish connection");
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 try {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 conn.authenticateWithPublicKey(System.getProperty("user.name"), new File(System.getProperty("user.home"), ".ssh/id_rsa"), null);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 ConnectionInfo ci = conn.getConnectionInfo();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 System.out.printf("%s %s %s %d %s %s %s\n", ci.clientToServerCryptoAlgorithm, ci.clientToServerMACAlgorithm, ci.keyExchangeAlgorithm, ci.keyExchangeCounter, ci.serverHostKeyAlgorithm, ci.serverToClientCryptoAlgorithm, ci.serverToClientMACAlgorithm);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 } catch (IOException ex) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 throw new HgRemoteConnectionException("Failed to authenticate", ex).setServerInfo(getLocation());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 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
86 if (session != null) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 forceSessionClose();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 if (conn != null) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 conn.close();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 conn = null;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 }
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 sessionBegin() throws HgRemoteConnectionException {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 if (sessionUse > 0) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 assert session != null;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 sessionUse++;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 return;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 try {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 session = conn.openSession();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 session.execCommand(String.format("hg -R %s serve --stdio", url.getPath()));
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 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
105 remoteOut = new StreamGobbler(session.getStdout());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 sessionUse = 1;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 } catch (IOException ex) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 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
109 }
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
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 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
113 assert sessionUse > 0;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 assert session != null;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 if (sessionUse > 1) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 sessionUse--;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 return;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 forceSessionClose();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 }
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 public String getLocation() {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 return "";
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 public InputStream heads() throws HgRemoteConnectionException {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 return executeCommand("heads", Collections.<Parameter>emptyList());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 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
131 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
132 for (Range r : ranges) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 r.append(sb).append(' ');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 if (!ranges.isEmpty()) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 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
137 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 return executeCommand("between", Collections.singletonList(new Parameter("pairs", sb.toString())));
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 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
142 String l = join(nodes, ' ');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 return executeCommand("branches", Collections.singletonList(new Parameter("nodes", l)));
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 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
147 String l = join(roots, ' ');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 return executeCommand("changegroup", Collections.singletonList(new Parameter("roots", l)));
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 public void unbundle(HgBundle bundle, List<Nodeid> remoteHeads) throws HgRemoteConnectionException, HgRuntimeException {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 String l = join(remoteHeads, ' ');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 Collections.singletonList(new Parameter("heads", l));
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 throw Internals.notImplemented();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 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
158 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
159 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
160 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
161 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
162 p.add(new Parameter("new", newValue));
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 return executeCommand("pushkey", p);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 }
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 public InputStream listkeys(String namespace, String actionName) throws HgRemoteConnectionException, HgRuntimeException {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 return executeCommand("listkeys", Collections.singletonList(new Parameter("namespace", namespace)));
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 }
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 Set<String> initCapabilities() throws HgRemoteConnectionException {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 try {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 final String CMD_CAPABILITIES = "capabilities";
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 final String CMD_HEADS = "heads";
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 final String CMD_HELLO = "hello";
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 consume(remoteOut);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 consume(remoteErr);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 remoteIn.write(CMD_HELLO.getBytes());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 remoteIn.write('\n');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 remoteIn.write(CMD_CAPABILITIES.getBytes()); // see http connector for
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 remoteIn.write('\n');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 remoteIn.write(CMD_HEADS.getBytes());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 remoteIn.write('\n');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 checkError();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 int responseLen = readResponseLength();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186 checkError();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 FilterStream s = new FilterStream(remoteOut, responseLen);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 BufferedReader r = new BufferedReader(new InputStreamReader(s));
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 String line;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 while ((line = r.readLine()) != null) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 if (line.startsWith(CMD_CAPABILITIES) && line.length() > (CMD_CAPABILITIES.length()+1)) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 line = line.substring(CMD_CAPABILITIES.length());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 if (line.charAt(0) == ':') {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 String[] caps = line.substring(CMD_CAPABILITIES.length() + 1).split("\\s");
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 return new HashSet<String>(Arrays.asList(caps));
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 r.close();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 consume(remoteOut);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 checkError();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 return Collections.emptySet();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 } catch (IOException ex) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 throw new HgRemoteConnectionException("Failed to initiate dialog with server", ex).setRemoteCommand("hello").setServerInfo(getLocation());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 } catch (HgRemoteConnectionException ex) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 ex.setRemoteCommand("hello").setServerInfo(getLocation());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 throw ex;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 private InputStream executeCommand(String cmd, List<Parameter> parameters) throws HgRemoteConnectionException {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212 try {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 consume(remoteOut);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214 consume(remoteErr);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215 remoteIn.write(cmd.getBytes());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 remoteIn.write('\n');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217 for (Parameter p : parameters) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 remoteIn.write(p.name().getBytes());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 remoteIn.write(' ');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 remoteIn.write(String.valueOf(p.size()).getBytes());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221 remoteIn.write('\n');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
222 remoteIn.write(p.data());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223 remoteIn.write('\n');
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225 checkError();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226 int responseLen = readResponseLength();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
227 checkError();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 return new FilterStream(remoteOut, responseLen);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
229 } catch (IOException ex) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 throw new HgRemoteConnectionException("Communication failure", ex).setRemoteCommand(cmd).setServerInfo(getLocation());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
231 } catch (HgRemoteConnectionException ex) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
232 ex.setRemoteCommand(cmd).setServerInfo(getLocation());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
233 throw ex;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
234 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
235 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
236
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
237 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
238 while (is.available() > 0) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 is.read();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 private void checkError() throws IOException, HgRemoteConnectionException {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 if (remoteErr.available() > 0) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
245 StringBuilder sb = new StringBuilder();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
246 int c;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
247 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
248 sb.append((char)c);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
249 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
250 throw new HgRemoteConnectionException(sb.toString());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
251 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
252 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
253
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
254 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
255 int c;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
256 StringBuilder sb = new StringBuilder();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
257 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
258 if (c == '\n') {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
259 break;
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 sb.append((char) c);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
262 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
263 if (c == -1) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
264 throw new EOFException();
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 try {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
267 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
268 } catch (NumberFormatException ex) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
269 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
270 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
271 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
272
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
273
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
274 private void forceSessionClose() {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
275 if (session != null) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
276 closeQuietly(remoteErr);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
277 closeQuietly(remoteOut);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
278 remoteErr = remoteOut = null;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
279 closeQuietly(remoteIn);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
280 remoteIn = null;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
281 session.close();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
282 session = null;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
283 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
284 sessionUse = 0;
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
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
287 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
288 try {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
289 if (c != null) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
290 c.close();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
291 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
292 } catch (IOException ex) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
293 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
294 }
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 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
298 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
299 for (Nodeid n : values) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
300 sb.append(n.toString());
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
301 sb.append(sep);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
302 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
303 if (!values.isEmpty()) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
304 // strip last space
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
305 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
306 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
307 return sb.toString();
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
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
310 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
311 private final String name;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
312 private final byte[] data;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
313
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
314 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
315 assert paramName != null;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
316 assert paramValue != null;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
317 name = paramName;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
318 data = paramValue.getBytes();
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 public String name() {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
322 return name;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
323 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
324 public int size() {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
325 return data.length;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
326 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
327 public byte[] data() {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
328 return data;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
329 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
330 }
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 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
333 private int length;
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 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
336 super(is);
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
337 length = initialLength;
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
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
340 @Override
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
341 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
342 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
343 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
344 @Override
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
345 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
346 if (length == 0) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
347 return -1;
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 int r = super.read();
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
350 if (r >= 0) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
351 length--;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
352 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
353 return r;
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 @Override
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
356 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
357 if (length == 0) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
358 return -1;
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 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
361 if (r >= 0) {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
362 assert r <= length;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
363 length -= r;
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 return r;
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
366 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
367 @Override
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
368 public void close() throws IOException {
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
369 // 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
370 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
371 }
9897cbfd2790 Towards ssh remote repositories: use ganymed library for ssh transport
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
372 }