summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.ssh.apache
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2020-08-02 19:22:05 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2020-10-29 00:36:21 +0100
commitf802f06e7fd5a98f256b7b7727598491f563bf2f (patch)
treef4573000d9c41bbba588340fcf65d6729073a4aa /org.eclipse.jgit.ssh.apache
parent679977c931500b7c8240021f84267f9e213fc800 (diff)
downloadjgit-f802f06e7fd5a98f256b7b7727598491f563bf2f.tar.gz
jgit-f802f06e7fd5a98f256b7b7727598491f563bf2f.zip
Client-side protocol V2 support for fetching
Make all transports request protocol V2 when fetching. Depending on the transport, set the GIT_PROTOCOL environment variable (file and ssh), pass the Git-Protocol header (http), or set the hidden "\0version=2\0" (git anon). We'll fall back to V0 if the server doesn't reply with a version 2 answer. A user can control which protocol the client requests via the git config protocol.version; if not set, JGit requests protocol V2 for fetching. Pushing always uses protocol V0 still. In the API, there is only a new Transport.openFetch() version that takes a collection of RefSpecs plus additional patterns to construct the Ref prefixes for the "ls-refs" command in protocol V2. If none are given, the server will still advertise all refs, even in protocol V2. BasePackConnection.readAdvertisedRefs() handles falling back to protocol V0. It newly returns true if V0 was used and the advertised refs were read, and false if V2 is used and an explicit "ls-refs" is needed. (This can't be done transparently inside readAdvertisedRefs() because a "stateless RPC" transport like TransportHttp may need to open a new connection for writing.) BasePackFetchConnection implements the changes needed for the protocol V2 "fetch" command (simplified ACK handling, delimiters, section headers). In TransportHttp, change readSmartHeaders() to also recognize the "version 2" packet line as a valid smart server indication. Adapt tests, and run all the HTTP tests not only with both HTTP connection factories (JDK and Apache HttpClient) but also with both protocol V0 and V2. Do the same for the SSH transport tests. Bug: 553083 Change-Id: Ice9866aa78020f5ca8f397cde84dc224bf5d41b4 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.ssh.apache')
-rw-r--r--org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java17
1 files changed, 13 insertions, 4 deletions
diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java
index 0fb0610b99..5a50cc8f27 100644
--- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java
+++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java
@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -53,7 +54,7 @@ import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.transport.sshd.JGitSshClient;
import org.eclipse.jgit.internal.transport.sshd.SshdText;
import org.eclipse.jgit.transport.FtpChannel;
-import org.eclipse.jgit.transport.RemoteSession;
+import org.eclipse.jgit.transport.RemoteSession2;
import org.eclipse.jgit.transport.SshConstants;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.StringUtils;
@@ -61,11 +62,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * An implementation of {@link RemoteSession} based on Apache MINA sshd.
+ * An implementation of {@link org.eclipse.jgit.transport.RemoteSession
+ * RemoteSession} based on Apache MINA sshd.
*
* @since 5.2
*/
-public class SshdSession implements RemoteSession {
+public class SshdSession implements RemoteSession2 {
private static final Logger LOG = LoggerFactory
.getLogger(SshdSession.class);
@@ -290,8 +292,15 @@ public class SshdSession implements RemoteSession {
@Override
public Process exec(String commandName, int timeout) throws IOException {
+ return exec(commandName, Collections.emptyMap(), timeout);
+ }
+
+ @Override
+ public Process exec(String commandName, Map<String, String> environment,
+ int timeout) throws IOException {
@SuppressWarnings("resource")
- ChannelExec exec = session.createExecChannel(commandName);
+ ChannelExec exec = session.createExecChannel(commandName, null,
+ environment);
if (timeout <= 0) {
try {
exec.open().verify();