aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/transport
diff options
context:
space:
mode:
authorMarc Strapetz <marc.strapetz@syntevo.com>2010-04-20 21:01:19 +0200
committerShawn O. Pearce <spearce@spearce.org>2010-06-04 19:08:58 -0700
commit936e4ab2f2ad4847e22483b26eb61f0c8e56b70c (patch)
tree731290ad8d049ca21e3a483a346ebb36c4fcac15 /org.eclipse.jgit/src/org/eclipse/jgit/transport
parent92eedd667dd75cda762b2ac758dcd1845b05886c (diff)
downloadjgit-936e4ab2f2ad4847e22483b26eb61f0c8e56b70c.tar.gz
jgit-936e4ab2f2ad4847e22483b26eb61f0c8e56b70c.zip
Repository can be configured with FS
On Windows, FS_Win32_Cygwin has been used if a Cygwin Git installation is present in the PATH. Assuming that the user works with the Cygwin Git installation may result in unnecessary overhead if he actually does not. Applications built on top of jgit may have more knowledge on the actually used Git client (Cygwin or not) and hence should be able to configure which FS to use accordingly. Change-Id: Ifc4278078b298781d55cf5421e9647a21fa5db24
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConfigSessionFactory.java66
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/SshTransport.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java13
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java6
9 files changed, 65 insertions, 52 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java
index 39c7ae8f01..aa2e2521c2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java
@@ -63,6 +63,7 @@ import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
+import org.eclipse.jgit.util.FS;
/** Basic daemon for the anonymous <code>git://</code> transport protocol. */
public class Daemon {
@@ -368,7 +369,7 @@ public class Daemon {
}
for (final File baseDir : exportBase) {
- final File gitdir = FileKey.resolve(new File(baseDir, name));
+ final File gitdir = FileKey.resolve(new File(baseDir, name), FS.DETECTED);
if (gitdir != null && canExport(gitdir))
return openRepository(gitdir);
}
@@ -377,7 +378,7 @@ public class Daemon {
private static Repository openRepository(final File gitdir) {
try {
- return RepositoryCache.open(FileKey.exact(gitdir));
+ return RepositoryCache.open(FileKey.exact(gitdir, FS.DETECTED));
} catch (IOException err) {
// null signals it "wasn't found", which is all that is suitable
// for the remote client to know.
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java
index e7a307f809..20f3174b2e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java
@@ -82,10 +82,13 @@ public class OpenSshConfig {
* requests are cached and are automatically updated if the user modifies
* the configuration file since the last time it was cached.
*
+ * @param fs
+ * the file system abstraction which will be necessary to
+ * perform certain file system operations.
* @return a caching reader of the user's configuration file.
*/
- public static OpenSshConfig get() {
- File home = FS.userHome();
+ public static OpenSshConfig get(FS fs) {
+ File home = fs.userHome();
if (home == null)
home = new File(".").getAbsoluteFile();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConfigSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConfigSessionFactory.java
index c30d32d9f9..daa6f4ca2f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConfigSessionFactory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConfigSessionFactory.java
@@ -83,15 +83,18 @@ public abstract class SshConfigSessionFactory extends SshSessionFactory {
@Override
public synchronized Session getSession(String user, String pass,
- String host, int port) throws JSchException {
- final OpenSshConfig.Host hc = getConfig().lookup(host);
+ String host, int port, FS fs) throws JSchException {
+ if (config == null)
+ config = OpenSshConfig.get(fs);
+
+ final OpenSshConfig.Host hc = config.lookup(host);
host = hc.getHostName();
if (port <= 0)
port = hc.getPort();
if (user == null)
user = hc.getUser();
- final Session session = createSession(hc, user, host, port);
+ final Session session = createSession(hc, user, host, port, fs);
if (pass != null)
session.setPassword(pass);
final String strictHostKeyCheckingPolicy = hc
@@ -117,14 +120,17 @@ public abstract class SshConfigSessionFactory extends SshSessionFactory {
* server name to connect to.
* @param port
* port number of the SSH daemon (typically 22).
+ * @param fs
+ * the file system abstraction which will be necessary to
+ * perform certain file system operations.
* @return new session instance, but otherwise unconfigured.
* @throws JSchException
* the session could not be created.
*/
protected Session createSession(final OpenSshConfig.Host hc,
- final String user, final String host, final int port)
+ final String user, final String host, final int port, FS fs)
throws JSchException {
- return getJSch(hc).getSession(user, host, port);
+ return getJSch(hc, fs).getSession(user, host, port);
}
/**
@@ -143,58 +149,54 @@ public abstract class SshConfigSessionFactory extends SshSessionFactory {
*
* @param hc
* host configuration
+ * @param fs
+ * the file system abstraction which will be necessary to
+ * perform certain file system operations.
* @return the JSch instance to use.
* @throws JSchException
* the user configuration could not be created.
*/
- protected JSch getJSch(final OpenSshConfig.Host hc) throws JSchException {
- final JSch def = getDefaultJSch();
+ protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException {
+ if (defaultJSch == null) {
+ defaultJSch = createDefaultJSch(fs);
+ for (Object name : defaultJSch.getIdentityNames()) {
+ byIdentityFile.put((String) name, defaultJSch);
+ }
+ }
+
final File identityFile = hc.getIdentityFile();
if (identityFile == null) {
- return def;
+ return defaultJSch;
}
final String identityKey = identityFile.getAbsolutePath();
JSch jsch = byIdentityFile.get(identityKey);
if (jsch == null) {
jsch = new JSch();
- jsch.setHostKeyRepository(def.getHostKeyRepository());
+ jsch.setHostKeyRepository(defaultJSch.getHostKeyRepository());
jsch.addIdentity(identityKey);
byIdentityFile.put(identityKey, jsch);
}
return jsch;
}
- private JSch getDefaultJSch() throws JSchException {
- if (defaultJSch == null) {
- defaultJSch = createDefaultJSch();
- for (Object name : defaultJSch.getIdentityNames()) {
- byIdentityFile.put((String) name, defaultJSch);
- }
- }
- return defaultJSch;
- }
-
/**
+ * @param fs
+ * the file system abstraction which will be necessary to
+ * perform certain file system operations.
* @return the new default JSch implementation.
* @throws JSchException
* known host keys cannot be loaded.
*/
- protected JSch createDefaultJSch() throws JSchException {
+ protected JSch createDefaultJSch(FS fs) throws JSchException {
final JSch jsch = new JSch();
- knownHosts(jsch);
- identities(jsch);
+ knownHosts(jsch, fs);
+ identities(jsch, fs);
return jsch;
}
- private OpenSshConfig getConfig() {
- if (config == null)
- config = OpenSshConfig.get();
- return config;
- }
-
- private static void knownHosts(final JSch sch) throws JSchException {
- final File home = FS.userHome();
+ private static void knownHosts(final JSch sch, FS fs) throws JSchException {
+ final File home = fs.userHome();
if (home == null)
return;
final File known_hosts = new File(new File(home, ".ssh"), "known_hosts");
@@ -212,8 +214,8 @@ public abstract class SshConfigSessionFactory extends SshSessionFactory {
}
}
- private static void identities(final JSch sch) {
- final File home = FS.userHome();
+ private static void identities(final JSch sch, FS fs) {
+ final File home = fs.userHome();
if (home == null)
return;
final File sshdir = new File(home, ".ssh");
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java
index 810b04ce40..d10010fcf6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java
@@ -44,6 +44,8 @@
package org.eclipse.jgit.transport;
+import org.eclipse.jgit.util.FS;
+
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
@@ -109,19 +111,22 @@ public abstract class SshSessionFactory {
* @param port
* port number the server is listening for connections on. May be <=
* 0 to indicate the IANA registered port of 22 should be used.
+ * @param fs
+ * the file system abstraction which will be necessary to
+ * perform certain file system operations.
* @return a session that can contact the remote host.
* @throws JSchException
* the session could not be created.
*/
public abstract Session getSession(String user, String pass, String host,
- int port) throws JSchException;
+ int port, FS fs) throws JSchException;
/**
* Close (or recycle) a session to a host.
*
* @param session
* a session previously obtained from this factory's
- * {@link #getSession(String,String, String, int)} method.s
+ * {@link #getSession(String,String, String, int, FS)} method.s
*/
public void releaseSession(final Session session) {
if (session.isConnected())
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshTransport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshTransport.java
index d25a7b6180..f642ac1ea8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshTransport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshTransport.java
@@ -128,7 +128,7 @@ public abstract class SshTransport extends TcpTransport {
final String host = uri.getHost();
final int port = uri.getPort();
try {
- sock = sch.getSession(user, pass, host, port);
+ sock = sch.getSession(user, pass, host, port, local.getFS());
if (!sock.isConnected())
sock.connect(tms);
} catch (JSchException je) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
index 2fe3cb9326..e1988a6c85 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
@@ -66,6 +66,7 @@ import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.TransferConfig;
+import org.eclipse.jgit.util.FS;
/**
* Connects two Git repositories together and copies objects between them.
@@ -323,9 +324,11 @@ public abstract class Transport {
*
* @param remote
* location of the remote repository.
+ * @param fs
+ * type of filesystem the local repository is stored on.
* @return true if the protocol is supported.
*/
- public static boolean canHandleProtocol(final URIish remote) {
+ public static boolean canHandleProtocol(final URIish remote, final FS fs) {
if (TransportGitSsh.canHandle(remote))
return true;
@@ -341,10 +344,10 @@ public abstract class Transport {
else if (TransportAmazonS3.canHandle(remote))
return true;
- else if (TransportBundleFile.canHandle(remote))
+ else if (TransportBundleFile.canHandle(remote, fs))
return true;
- else if (TransportLocal.canHandle(remote))
+ else if (TransportLocal.canHandle(remote, fs))
return true;
return false;
@@ -378,10 +381,10 @@ public abstract class Transport {
else if (TransportAmazonS3.canHandle(remote))
return new TransportAmazonS3(local, remote);
- else if (TransportBundleFile.canHandle(remote))
+ else if (TransportBundleFile.canHandle(remote, local.getFS()))
return new TransportBundleFile(local, remote);
- else if (TransportLocal.canHandle(remote))
+ else if (TransportLocal.canHandle(remote, local.getFS()))
return new TransportLocal(local, remote);
throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, remote));
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
index bcf6e873fe..56a5c9796d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
@@ -69,7 +69,6 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.SymbolicRef;
import org.eclipse.jgit.lib.Ref.Storage;
-import org.eclipse.jgit.util.FS;
/**
* Transport over the non-Git aware Amazon S3 protocol.
@@ -130,7 +129,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport {
Properties props = null;
File propsFile = new File(local.getDirectory(), uri.getUser());
if (!propsFile.isFile())
- propsFile = new File(FS.userHome(), uri.getUser());
+ propsFile = new File(local.getFS().userHome(), uri.getUser());
if (propsFile.isFile()) {
try {
props = AmazonS3.properties(propsFile);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java
index 0245818fe3..c47833f21c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java
@@ -58,13 +58,13 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.FS;
class TransportBundleFile extends Transport implements TransportBundle {
- static boolean canHandle(final URIish uri) {
+ static boolean canHandle(final URIish uri, FS fs) {
if (uri.getHost() != null || uri.getPort() > 0 || uri.getUser() != null
|| uri.getPass() != null || uri.getPath() == null)
return false;
if ("file".equals(uri.getScheme()) || uri.getScheme() == null) {
- final File f = FS.resolve(new File("."), uri.getPath());
+ final File f = fs.resolve(new File("."), uri.getPath());
return f.isFile() || f.getName().endsWith(".bundle");
}
@@ -75,7 +75,7 @@ class TransportBundleFile extends Transport implements TransportBundle {
TransportBundleFile(final Repository local, final URIish uri) {
super(local, uri);
- bundle = FS.resolve(new File("."), uri.getPath()).getAbsoluteFile();
+ bundle = local.getFS().resolve(new File("."), uri.getPath()).getAbsoluteFile();
}
@Override
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
index cf4dbd5392..08fd8901d8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
@@ -91,13 +91,13 @@ import org.eclipse.jgit.util.io.StreamCopyThread;
class TransportLocal extends Transport implements PackTransport {
private static final String PWD = ".";
- static boolean canHandle(final URIish uri) {
+ static boolean canHandle(final URIish uri, FS fs) {
if (uri.getHost() != null || uri.getPort() > 0 || uri.getUser() != null
|| uri.getPass() != null || uri.getPath() == null)
return false;
if ("file".equals(uri.getScheme()) || uri.getScheme() == null)
- return FS.resolve(new File(PWD), uri.getPath()).isDirectory();
+ return fs.resolve(new File(PWD), uri.getPath()).isDirectory();
return false;
}
@@ -106,7 +106,7 @@ class TransportLocal extends Transport implements PackTransport {
TransportLocal(final Repository local, final URIish uri) {
super(local, uri);
- File d = FS.resolve(new File(PWD), uri.getPath()).getAbsoluteFile();
+ File d = local.getFS().resolve(new File(PWD), uri.getPath()).getAbsoluteFile();
if (new File(d, Constants.DOT_GIT).isDirectory())
d = new File(d, Constants.DOT_GIT);
remoteGitDir = d;