Merge "Add Transport URI constructor without a repository"
This commit is contained in:
commit
9af5f1888e
|
@ -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
|
||||
|
|
|
@ -510,6 +510,7 @@ public static JGitText get() {
|
|||
/***/ public String transportExceptionInvalid;
|
||||
/***/ public String transportExceptionMissingAssumed;
|
||||
/***/ public String transportExceptionReadRef;
|
||||
/***/ public String transportNeedsRepository;
|
||||
/***/ public String transportProtoAmazonS3;
|
||||
/***/ public String transportProtoBundleFile;
|
||||
/***/ public String transportProtoFTP;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -556,6 +556,29 @@ public static Transport open(Repository local, URIish uri, String remoteName)
|
|||
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<TransportProtocol> 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 @@ protected Transport(final Repository local, final URIish uri) {
|
|||
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.
|
||||
* <p>
|
||||
|
|
|
@ -167,6 +167,10 @@ public Transport open(URIish uri, Repository local, String remoteName)
|
|||
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 @@ private static class HttpConfig {
|
|||
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 @@ private static class HttpConfig {
|
|||
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.
|
||||
* <p>
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
|
||||
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 boolean canHandle(URIish uri, Repository local, String remoteName) {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue