diff options
author | Markus Duft <markus.duft@ssi-schaefer.com> | 2018-03-08 08:29:03 +0100 |
---|---|---|
committer | Markus Duft <markus.duft@ssi-schaefer.com> | 2018-03-12 07:53:35 +0100 |
commit | 4ca9bb5ab98c73ecc1be2d6983f46c477c53dc99 (patch) | |
tree | 6b4d0710c92c15fef704f77d65f64a280f49a4de /org.eclipse.jgit.lfs | |
parent | e00f59b7fe7467a930457962326ce5fd0ec63537 (diff) | |
download | jgit-4ca9bb5ab98c73ecc1be2d6983f46c477c53dc99.tar.gz jgit-4ca9bb5ab98c73ecc1be2d6983f46c477c53dc99.zip |
Introduce SshSupport to centralize SSH related utility code
As discussed with Thomas here:
https://git.eclipse.org/r/#/c/83506/31/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java@349
Move the code from ConfigureGerritAfterCloneTask to SshSupport and
eliminate the slightly modified copy of the code from
LfsConnectionFactory. Separate EGit commit will eliminate the code from
ConfigureGerritAfterCloneTask.
Change-Id: Ifb5adb1342e0fc1f2a70cddf693408d4e0ef7906
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
Diffstat (limited to 'org.eclipse.jgit.lfs')
-rw-r--r-- | org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java | 52 |
1 files changed, 6 insertions, 46 deletions
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java index 5d8268b73e..25a70c745a 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java @@ -47,9 +47,7 @@ import static org.eclipse.jgit.util.HttpSupport.HDR_ACCEPT; import static org.eclipse.jgit.util.HttpSupport.HDR_ACCEPT_ENCODING; import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.net.ProxySelector; import java.net.URL; import java.text.SimpleDateFormat; @@ -66,20 +64,17 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.transport.HttpConfig; import org.eclipse.jgit.transport.HttpTransport; -import org.eclipse.jgit.transport.RemoteSession; -import org.eclipse.jgit.transport.SshSessionFactory; import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.http.HttpConnection; -import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.HttpSupport; -import org.eclipse.jgit.util.io.MessageWriter; -import org.eclipse.jgit.util.io.StreamCopyThread; +import org.eclipse.jgit.util.SshSupport; /** * Provides means to get a valid LFS connection for a given repository. */ public class LfsConnectionFactory { + private static final int SSH_AUTH_TIMEOUT_SECONDS = 5; private static final String SCHEME_HTTPS = "https"; //$NON-NLS-1$ private static final String SCHEME_SSH = "ssh"; //$NON-NLS-1$ private static final Map<String, AuthCache> sshAuthCache = new TreeMap<>(); @@ -193,10 +188,11 @@ public class LfsConnectionFactory { // discover and authenticate; git-lfs does "ssh // -p <port> -- <host> git-lfs-authenticate // <project> <upload/download>" - String json = runSshCommand(u.setPath(""), //$NON-NLS-1$ - db.getFS(), + String json = SshSupport.runSshCommand(u.setPath(""), //$NON-NLS-1$ + null, db.getFS(), "git-lfs-authenticate " + extractProjectName(u) + " " //$NON-NLS-1$//$NON-NLS-2$ - + purpose); + + purpose, + SSH_AUTH_TIMEOUT_SECONDS); action = Protocol.gson().fromJson(json, Protocol.ExpiringAction.class); @@ -253,42 +249,6 @@ public class LfsConnectionFactory { } } - private static String runSshCommand(URIish sshUri, FS fs, String command) - throws IOException { - RemoteSession session = null; - Process process = null; - StreamCopyThread errorThread = null; - try (MessageWriter stderr = new MessageWriter()) { - session = SshSessionFactory.getInstance().getSession(sshUri, null, - fs, 5_000); - process = session.exec(command, 0); - errorThread = new StreamCopyThread(process.getErrorStream(), - stderr.getRawStream()); - errorThread.start(); - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(process.getInputStream(), - org.eclipse.jgit.lib.Constants.CHARSET))) { - return reader.readLine(); - } - } finally { - if (process != null) { - process.destroy(); - } - if (errorThread != null) { - try { - errorThread.halt(); - } catch (InterruptedException e) { - // Stop waiting and return anyway. - } finally { - errorThread = null; - } - } - if (session != null) { - SshSessionFactory.getInstance().releaseSession(session); - } - } - } - /** * @param operation * the operation to perform, e.g. Protocol.OPERATION_DOWNLOAD |