- All Implemented Interfaces:
AutoCloseable
,Connection
,PushConnection
This is the canonical implementation for transferring objects to the remote repository from the local repository by talking to the 'git-receive-pack' service. Objects are packed on the local side into a pack file and then sent to the remote repository.
This connection requires only a bi-directional pipe or socket, and thus is easily wrapped up into a local process pipe, anonymous TCP socket, or a command executed through an SSH tunnel.
This implementation honors
Transport.isPushThin()
option.
Concrete implementations should just call
init(java.io.InputStream, java.io.OutputStream)
and
readAdvertisedRefs()
methods in constructor or before any use. They
should also handle resources releasing in BaseConnection.close()
method if needed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionExtra objects the remote has, but which aren't offered as refs.static final String
The server supports deleting refs.static final String
The server supports packs with OFS deltas.static final String
The server supports the receiving of push options.static final String
The client expects a status report after the server processes the pack.static final String
The client supports using the 64K side-band for progress messages.protected static final String
The capability prefix for a symlinkprotected InputStream
Input stream reading from the remote.protected final Repository
The repository this transport fetches into, or pushes out of.protected OutputStream
Output stream sending to the remote.protected boolean
SendPacketLineOut.end()
before closingBasePackConnection.out
?protected PacketLineIn
Packet line decoder aroundBasePackConnection.in
.protected PacketLineOut
Packet line encoder aroundBasePackConnection.out
.protected boolean
True if this is a stateless RPC connection.protected TimeoutInputStream
Low-level input stream, if a timeout was configured.protected TimeoutOutputStream
Low-level output stream, if a timeout was configured.protected final Transport
A transport connected toBasePackConnection.uri
.protected final URIish
Remote repository location. -
Constructor Summary
ConstructorsConstructorDescriptionBasePackPushConnection
(PackTransport packTransport) Create a new connection to push using the native git transport. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Add user agent capabilityvoid
close()
protected void
doPush
(ProgressMonitor monitor, Map<String, RemoteRefUpdate> refUpdates, OutputStream outputStream) Push one or more objects and update the remote repository.protected void
endOut()
Tell the peer we are disconnecting, if it cares to know.protected String
getCapability
(String option) Return a capability value.User agent advertised by the remote server.Gets the list of option strings associated with this push.protected final void
init
(InputStream myIn, OutputStream myOut) Configure this connection with the directional pipes.protected boolean
isCapableOf
(String option) Whether this option is supportedboolean
Whether to use bitmaps for push.protected void
lsRefs
(Collection<RefSpec> refSpecs, String... additionalPatterns) Issue a protocol V2 ls-refs command and read its response.protected TransportException
noRepository
(Throwable cause) Create an exception to indicate problems finding a remote repository.void
push
(ProgressMonitor monitor, Map<String, RemoteRefUpdate> refUpdates) Pushes to the remote repository basing on provided specification.void
push
(ProgressMonitor monitor, Map<String, RemoteRefUpdate> refUpdates, OutputStream outputStream) Pushes to the remote repository basing on provided specification.protected boolean
Reads the advertised references through the initialized stream.protected boolean
wantCapability
(StringBuilder b, String option) Request capabilityMethods inherited from class org.eclipse.jgit.transport.BaseConnection
available, getMessages, getMessageWriter, getRef, getRefs, getRefsMap, markStartedOperation, setMessageWriter, setPeerUserAgent
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.jgit.transport.Connection
close, getMessages, getPeerUserAgent, getRef, getRefs, getRefsMap
-
Field Details
-
CAPABILITY_REPORT_STATUS
The client expects a status report after the server processes the pack.- Since:
- 2.0
- See Also:
-
CAPABILITY_DELETE_REFS
The server supports deleting refs.- Since:
- 2.0
- See Also:
-
CAPABILITY_OFS_DELTA
The server supports packs with OFS deltas.- Since:
- 2.0
- See Also:
-
CAPABILITY_SIDE_BAND_64K
The client supports using the 64K side-band for progress messages.- Since:
- 2.0
- See Also:
-
CAPABILITY_PUSH_OPTIONS
The server supports the receiving of push options.- Since:
- 4.5
- See Also:
-
CAPABILITY_SYMREF_PREFIX
The capability prefix for a symlink- See Also:
-
local
The repository this transport fetches into, or pushes out of. -
uri
Remote repository location. -
transport
A transport connected toBasePackConnection.uri
. -
timeoutIn
Low-level input stream, if a timeout was configured. -
timeoutOut
Low-level output stream, if a timeout was configured. -
in
Input stream reading from the remote. -
out
Output stream sending to the remote. -
pckIn
Packet line decoder aroundBasePackConnection.in
. -
pckOut
Packet line encoder aroundBasePackConnection.out
. -
outNeedsEnd
protected boolean outNeedsEndSendPacketLineOut.end()
before closingBasePackConnection.out
? -
statelessRPC
protected boolean statelessRPCTrue if this is a stateless RPC connection. -
additionalHaves
Extra objects the remote has, but which aren't offered as refs.
-
-
Constructor Details
-
BasePackPushConnection
Create a new connection to push using the native git transport.- Parameters:
packTransport
- the transport.
-
-
Method Details
-
push
public void push(ProgressMonitor monitor, Map<String, RemoteRefUpdate> refUpdates) throws TransportExceptionDescription copied from interface:PushConnection
Pushes to the remote repository basing on provided specification. This possibly result in update/creation/deletion of refs on remote repository and sending objects that remote repository need to have a consistent objects graph from new refs.Only one call per connection is allowed. Subsequent calls will result in
TransportException
.Implementation may use local repository to send a minimum set of objects needed by remote repository in efficient way.
Transport.isPushThin()
should be honored if applicable. refUpdates should be filled with information about status of each update.- Specified by:
push
in interfacePushConnection
- Parameters:
monitor
- progress monitor to update the end-user about the amount of work completed, or to indicate cancellation. Implementors should poll the monitor at regular intervals to look for cancellation requests from the user.refUpdates
- map of remote refnames to remote refs update specifications/statuses. Can't be empty. This indicate what refs caller want to update on remote side. Only refs updates withRemoteRefUpdate.Status.NOT_ATTEMPTED
should passed. Implementation must ensure that and appropriate status with optional message should be set during call. No refUpdate withRemoteRefUpdate.Status.AWAITING_REPORT
orRemoteRefUpdate.Status.NOT_ATTEMPTED
can be leaved by implementation after return from this call.- Throws:
TransportException
- objects could not be copied due to a network failure, critical protocol error, or error on remote side, or connection was already used for push - new connection must be created. Non-critical errors concerning only isolated refs should be placed in refUpdates.
-
push
public void push(ProgressMonitor monitor, Map<String, RemoteRefUpdate> refUpdates, OutputStream outputStream) throws TransportExceptionDescription copied from interface:PushConnection
Pushes to the remote repository basing on provided specification. This possibly result in update/creation/deletion of refs on remote repository and sending objects that remote repository need to have a consistent objects graph from new refs.Only one call per connection is allowed. Subsequent calls will result in
TransportException
.Implementation may use local repository to send a minimum set of objects needed by remote repository in efficient way.
Transport.isPushThin()
should be honored if applicable. refUpdates should be filled with information about status of each update.- Specified by:
push
in interfacePushConnection
- Parameters:
monitor
- progress monitor to update the end-user about the amount of work completed, or to indicate cancellation. Implementors should poll the monitor at regular intervals to look for cancellation requests from the user.refUpdates
- map of remote refnames to remote refs update specifications/statuses. Can't be empty. This indicate what refs caller want to update on remote side. Only refs updates withRemoteRefUpdate.Status.NOT_ATTEMPTED
should passed. Implementation must ensure that and appropriate status with optional message should be set during call. No refUpdate withRemoteRefUpdate.Status.AWAITING_REPORT
orRemoteRefUpdate.Status.NOT_ATTEMPTED
can be leaved by implementation after return from this call.outputStream
- output stream to write sideband messages to- Throws:
TransportException
- objects could not be copied due to a network failure, critical protocol error, or error on remote side, or connection was already used for push - new connection must be created. Non-critical errors concerning only isolated refs should be placed in refUpdates.
-
noRepository
Create an exception to indicate problems finding a remote repository. The caller is expected to throw the returned exception. Subclasses may override this method to provide better diagnostics.- Parameters:
cause
- root cause exception- Returns:
- a TransportException saying a repository cannot be found and possibly why.
-
doPush
protected void doPush(ProgressMonitor monitor, Map<String, RemoteRefUpdate> refUpdates, OutputStream outputStream) throws TransportExceptionPush one or more objects and update the remote repository.- Parameters:
monitor
- progress monitor to receive status updates.refUpdates
- update commands to be applied to the remote repository.outputStream
- output stream to write sideband messages to- Throws:
TransportException
- if any exception occurs.- Since:
- 3.0
-
getPushOptions
Gets the list of option strings associated with this push.- Returns:
- pushOptions
- Since:
- 4.5
-
isUseBitmaps
public boolean isUseBitmaps()Whether to use bitmaps for push.- Returns:
- true if push use bitmaps.
- Since:
- 6.4
-
init
Configure this connection with the directional pipes.- Parameters:
myIn
- input stream to receive data from the peer. Caller must ensure the input is buffered, otherwise read performance may suffer.myOut
- output stream to transmit data to the peer. Caller must ensure the output is buffered, otherwise write performance may suffer.
-
readAdvertisedRefs
Reads the advertised references through the initialized stream.Subclass implementations may call this method only after setting up the input and output streams with
init(InputStream, OutputStream)
.If any errors occur, this connection is automatically closed by invoking
BaseConnection.close()
and the exception is wrapped (if necessary) and thrown as aTransportException
.- Returns:
true
if the refs were read;false
otherwise indicating thatlsRefs(java.util.Collection<org.eclipse.jgit.transport.RefSpec>, java.lang.String...)
must be called- Throws:
TransportException
- the reference list could not be scanned.
-
lsRefs
protected void lsRefs(Collection<RefSpec> refSpecs, String... additionalPatterns) throws TransportException Issue a protocol V2 ls-refs command and read its response.- Parameters:
refSpecs
- to produce ref prefixes from if the server supports git protocol V2additionalPatterns
- to use for ref prefixes if the server supports git protocol V2- Throws:
TransportException
- if the command could not be run or its output not be read
-
isCapableOf
Whether this option is supported- Parameters:
option
- option string- Returns:
- whether this option is supported
-
wantCapability
Request capability- Parameters:
b
- bufferoption
- option we want- Returns:
true
if the requested option is supported
-
getCapability
Return a capability value.- Parameters:
option
- to get- Returns:
- the value stored, if any.
-
addUserAgentCapability
Add user agent capability- Parameters:
b
- aStringBuilder
object.
-
getPeerUserAgent
Description copied from class:BaseConnection
User agent advertised by the remote server. User agent advertised by the remote server.- Specified by:
getPeerUserAgent
in interfaceConnection
- Overrides:
getPeerUserAgent
in classBaseConnection
- Returns:
- agent (version of Git) running on the remote server. Null if the server does not advertise this version.
-
close
public void close()Description copied from interface:Connection
Close any resources used by this connection.
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.
If additional messages were produced by the remote peer, these should still be retained in the connection instance for
Connection.getMessages()
.AutoClosable.close()
declares that it throwsException
. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Specified by:
close
in classBaseConnection
-
endOut
protected void endOut()Tell the peer we are disconnecting, if it cares to know.
-