diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index 93392e202..be6080228 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -450,6 +450,7 @@ transportExceptionEmptyRef=Empty ref: {0} transportExceptionInvalid=Invalid {0} {1}:{2} transportExceptionMissingAssumed=Missing assumed {0} transportExceptionReadRef=read {0} +transportNeedsRepository=Transport needs repository transportProtoAmazonS3=Amazon S3 transportProtoBundleFile=Git Bundle File transportProtoFTP=FTP diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index bcc9589da..aca9574a5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -510,6 +510,7 @@ public class JGitText extends TranslationBundle { /***/ public String transportExceptionInvalid; /***/ public String transportExceptionMissingAssumed; /***/ public String transportExceptionReadRef; + /***/ public String transportNeedsRepository; /***/ public String transportProtoAmazonS3; /***/ public String transportProtoBundleFile; /***/ public String transportProtoFTP; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java index 3793a0abf..4f8f89df9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java @@ -66,4 +66,13 @@ public abstract class HttpTransport extends Transport { protected HttpTransport(Repository local, URIish uri) { super(local, uri); } + + /** + * Create a minimal HTTP transport instance not tied to a single repository. + * + * @param uri + */ + protected HttpTransport(URIish uri) { + super(uri); + } } 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 90fdf4d9d..affccf947 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -556,6 +556,29 @@ public abstract class Transport { throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri)); } + /** + * Open a new transport with no local repository. + * + * @param uri + * @return new Transport instance + * @throws NotSupportedException + * @throws TransportException + */ + public static Transport open(URIish uri) throws NotSupportedException, TransportException { + for (WeakReference ref : protocols) { + TransportProtocol proto = ref.get(); + if (proto == null) { + protocols.remove(ref); + continue; + } + + if (proto.canHandle(uri, null, null)) + return proto.open(uri); + } + + throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri)); + } + /** * Convert push remote refs update specification from {@link RefSpec} form * to {@link RemoteRefUpdate}. Conversion expands wildcards by matching @@ -745,6 +768,18 @@ public abstract class Transport { this.credentialsProvider = CredentialsProvider.getDefault(); } + /** + * Create a minimal transport instance not tied to a single repository. + * + * @param uri + */ + protected Transport(final URIish uri) { + this.uri = uri; + this.local = null; + this.checkFetchedObjects = true; + this.credentialsProvider = CredentialsProvider.getDefault(); + } + /** * Get the URI this transport connects to. *

diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java index 71f5bcb51..7adeeca50 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -167,6 +167,10 @@ public class TransportHttp extends HttpTransport implements WalkTransport, throws NotSupportedException { return new TransportHttp(local, uri); } + + public Transport open(URIish uri) throws NotSupportedException { + return new TransportHttp(uri); + } }; static final TransportProtocol PROTO_FTP = new TransportProtocol() { @@ -224,6 +228,10 @@ public class TransportHttp extends HttpTransport implements WalkTransport, postBuffer = rc.getInt("http", "postbuffer", 1 * 1024 * 1024); //$NON-NLS-1$ //$NON-NLS-2$ sslVerify = rc.getBoolean("http", "sslVerify", true); } + + private HttpConfig() { + this(new Config()); + } } private final URL baseUrl; @@ -254,6 +262,27 @@ public class TransportHttp extends HttpTransport implements WalkTransport, proxySelector = ProxySelector.getDefault(); } + /** + * Create a minimal HTTP transport with default configuration values. + * + * @param uri + * @throws NotSupportedException + */ + TransportHttp(final URIish uri) throws NotSupportedException { + super(uri); + try { + String uriString = uri.toString(); + if (!uriString.endsWith("/")) //$NON-NLS-1$ + uriString += "/"; //$NON-NLS-1$ + baseUrl = new URL(uriString); + objectsUrl = new URL(baseUrl, "objects/"); //$NON-NLS-1$ + } catch (MalformedURLException e) { + throw new NotSupportedException(MessageFormat.format(JGitText.get().invalidURL, uri), e); + } + http = new HttpConfig(); + proxySelector = ProxySelector.getDefault(); + } + /** * Toggle whether or not smart HTTP transport should be used. *

diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java index 32fa58046..e08efc4ea 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java @@ -49,6 +49,7 @@ import java.util.Set; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; +import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.Repository; /** @@ -253,4 +254,19 @@ public abstract class TransportProtocol { public abstract Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException, TransportException; + + /** + * Open a new transport instance to the remote repository. Use default + * configuration instead of reading from configuration files. + * + * @param uri + * @return new Transport + * @throws NotSupportedException + * @throws TransportException + */ + public Transport open(URIish uri) + throws NotSupportedException, TransportException { + throw new NotSupportedException(JGitText + .get().transportNeedsRepository); + } }