Class TransportLocal
- java.lang.Object
-
- org.eclipse.jgit.transport.Transport
-
- org.eclipse.jgit.transport.TransportLocal
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,PackTransport
class TransportLocal extends Transport implements PackTransport
Transport to access a local directory as though it were a remote peer.This transport is suitable for use on the local system, where the caller has direct read or write access to the "remote" repository.
By default this transport works by spawning a helper thread within the same JVM, and processes the data transfer using a shared memory buffer between the calling thread and the helper thread. This is a pure-Java implementation which does not require forking an external process.
However, during
openFetch()
, if the Transport has configuredTransport.getOptionUploadPack()
to be anything other than"git-upload-pack"
or"git upload-pack"
, this implementation will fork and execute the external process, using an operating system pipe to transfer data.Similarly, during
openPush()
, if the Transport has configuredTransport.getOptionReceivePack()
to be anything other than"git-receive-pack"
or"git receive-pack"
, this implementation will fork and execute the external process, using an operating system pipe to transfer data.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
TransportLocal.ForkLocalFetchConnection
(package private) class
TransportLocal.ForkLocalPushConnection
-
Nested classes/interfaces inherited from class org.eclipse.jgit.transport.Transport
Transport.Operation
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static TransportProtocol
PROTO_LOCAL
private java.io.File
remoteGitDir
-
Fields inherited from class org.eclipse.jgit.transport.Transport
DEFAULT_FETCH_THIN, DEFAULT_PUSH_THIN, local, protocol, REFSPEC_PUSH_ALL, REFSPEC_TAGS, uri
-
-
Constructor Summary
Constructors Constructor Description TransportLocal(Repository local, URIish uri, java.io.File gitDir)
TransportLocal(URIish uri, java.io.File gitDir)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
(package private) ReceivePack
createReceivePack(Repository dst)
(package private) UploadPack
createUploadPack(Repository dst)
FetchConnection
openFetch()
Begins a new connection for fetching from the remote repository.FetchConnection
openFetch(java.util.Collection<RefSpec> refSpecs, java.lang.String... additionalPatterns)
Begins a new connection for fetching from the remote repository.PushConnection
openPush()
Begins a new connection for pushing into the remote repository.private Repository
openRepo()
protected java.lang.Process
spawn(java.lang.String cmd)
Spawn processprivate java.lang.Process
spawn(java.lang.String cmd, TransferConfig.ProtocolVersion protocolVersion)
Spawn process-
Methods inherited from class org.eclipse.jgit.transport.Transport
applyConfig, fetch, fetch, findRemoteRefUpdatesFor, findRemoteRefUpdatesFor, findRemoteRefUpdatesFor, findRemoteRefUpdatesFor, findTrackingRefName, getCredentialsProvider, getFilterBlobLimit, getFilterSpec, getObjectChecker, getOptionReceivePack, getOptionUploadPack, getPackConfig, getPushOptions, getTagOpt, getTimeout, getTransportProtocols, getURI, isCheckFetchedObjects, isDryRun, isFetchThin, isPushAtomic, isPushThin, isRemoveDeletedRefs, open, open, open, open, open, open, open, openAll, openAll, openAll, openAll, push, push, register, setCheckFetchedObjects, setCredentialsProvider, setDryRun, setFetchThin, setFilterBlobLimit, setFilterSpec, setObjectChecker, setOptionReceivePack, setOptionUploadPack, setPackConfig, setPushAtomic, setPushOptions, setPushThin, setRemoveDeletedRefs, setTagOpt, setTimeout, unregister
-
-
-
-
Field Detail
-
PROTO_LOCAL
static final TransportProtocol PROTO_LOCAL
-
remoteGitDir
private final java.io.File remoteGitDir
-
-
Constructor Detail
-
TransportLocal
TransportLocal(Repository local, URIish uri, java.io.File gitDir)
-
TransportLocal
TransportLocal(URIish uri, java.io.File gitDir)
-
-
Method Detail
-
createUploadPack
UploadPack createUploadPack(Repository dst)
-
createReceivePack
ReceivePack createReceivePack(Repository dst)
-
openRepo
private Repository openRepo() throws TransportException
- Throws:
TransportException
-
openFetch
public FetchConnection openFetch() throws TransportException
Begins a new connection for fetching from the remote repository.If the transport has no local repository, the fetch connection can only be used for reading remote refs.
- Specified by:
openFetch
in classTransport
- Returns:
- a fresh connection to fetch from the remote repository.
- Throws:
TransportException
- the remote connection could not be established.
-
openFetch
public FetchConnection openFetch(java.util.Collection<RefSpec> refSpecs, java.lang.String... additionalPatterns) throws TransportException
Description copied from class:Transport
Begins a new connection for fetching from the remote repository.If the transport has no local repository, the fetch connection can only be used for reading remote refs.
If the server supports git protocol V2, the
RefSpec
s and the additional patterns, if any, are used to restrict the server's ref advertisement to matching refs only.Transports that want to support git protocol V2 must override this; the default implementation ignores its arguments and calls
Transport.openFetch()
.- Overrides:
openFetch
in classTransport
- Parameters:
refSpecs
- that will be fetched viaFetchConnection.fetch(ProgressMonitor, Collection, java.util.Set, OutputStream)
lateradditionalPatterns
- that will be set as ref prefixes if the server supports git protocol V2;null
values are ignored- Returns:
- a fresh connection to fetch from the remote repository.
- Throws:
TransportException
- the remote connection could not be established.
-
openPush
public PushConnection openPush() throws TransportException
Begins a new connection for pushing into the remote repository.- Specified by:
openPush
in classTransport
- Returns:
- a fresh connection to push into the remote repository.
- Throws:
TransportException
- the remote connection could not be established
-
close
public void close()
Close any resources used by this transport.
If the remote repository is contacted by a network socket this method must close that network socket, disconnecting the two peers. If the remote repository is actually local (same system) this method must close any open file handles used to read the "remote" repository.
AutoClosable.close()
declares that it throwsException
. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.
-
spawn
protected java.lang.Process spawn(java.lang.String cmd) throws TransportException
Spawn process- Parameters:
cmd
- command- Returns:
- a
Process
object. - Throws:
TransportException
- if any.
-
spawn
private java.lang.Process spawn(java.lang.String cmd, TransferConfig.ProtocolVersion protocolVersion) throws TransportException
Spawn process- Parameters:
cmd
- commandprotocolVersion
- to use- Returns:
- a
Process
object. - Throws:
TransportException
- if any.
-
-