Class BasePackPushConnection
- java.lang.Object
-
- org.eclipse.jgit.transport.BaseConnection
-
- org.eclipse.jgit.transport.BasePackPushConnection
-
- All Implemented Interfaces:
AutoCloseable
,Connection
,PushConnection
public abstract class BasePackPushConnection extends BaseConnection implements PushConnection
Push implementation using the native Git pack transfer service.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)
andreadAdvertisedRefs()
methods in constructor or before any use. They should also handle resources releasing inBaseConnection.close()
method if needed.
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<ObjectId>
additionalHaves
Extra objects the remote has, but which aren't offered as refs.static String
CAPABILITY_DELETE_REFS
The server supports deleting refs.static String
CAPABILITY_OFS_DELTA
The server supports packs with OFS deltas.static String
CAPABILITY_PUSH_OPTIONS
The server supports the receiving of push options.static String
CAPABILITY_REPORT_STATUS
The client expects a status report after the server processes the pack.static String
CAPABILITY_SIDE_BAND_64K
The client supports using the 64K side-band for progress messages.protected static String
CAPABILITY_SYMREF_PREFIX
protected InputStream
in
Input stream reading from the remote.protected Repository
local
The repository this transport fetches into, or pushes out of.protected OutputStream
out
Output stream sending to the remote.protected boolean
outNeedsEnd
SendPacketLineOut.end()
before closingout
?protected PacketLineIn
pckIn
Packet line decoder aroundin
.protected PacketLineOut
pckOut
Packet line encoder aroundout
.protected boolean
statelessRPC
True if this is a stateless RPC connection.protected TimeoutInputStream
timeoutIn
Low-level input stream, if a timeout was configured.protected TimeoutOutputStream
timeoutOut
Low-level output stream, if a timeout was configured.protected Transport
transport
A transport connected touri
.protected URIish
uri
Remote repository location.
-
Constructor Summary
Constructors Constructor Description BasePackPushConnection(PackTransport packTransport)
Create a new connection to push using the native git transport.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addUserAgentCapability(StringBuilder b)
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.String
getPeerUserAgent()
User agent advertised by the remote server.List<String>
getPushOptions()
Gets the list of option strings associated with this push.protected void
init(InputStream myIn, OutputStream myOut)
Configure this connection with the directional pipes.protected boolean
isCapableOf(String option)
Whether this option is supportedprotected 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
readAdvertisedRefs()
Reads the advertised references through the initialized stream.protected boolean
wantCapability(StringBuilder b, String option)
Request capability-
Methods 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 Detail
-
CAPABILITY_REPORT_STATUS
public static final String CAPABILITY_REPORT_STATUS
The client expects a status report after the server processes the pack.- Since:
- 2.0
- See Also:
- Constant Field Values
-
CAPABILITY_DELETE_REFS
public static final String CAPABILITY_DELETE_REFS
The server supports deleting refs.- Since:
- 2.0
- See Also:
- Constant Field Values
-
CAPABILITY_OFS_DELTA
public static final String CAPABILITY_OFS_DELTA
The server supports packs with OFS deltas.- Since:
- 2.0
- See Also:
- Constant Field Values
-
CAPABILITY_SIDE_BAND_64K
public static final String CAPABILITY_SIDE_BAND_64K
The client supports using the 64K side-band for progress messages.- Since:
- 2.0
- See Also:
- Constant Field Values
-
CAPABILITY_PUSH_OPTIONS
public static final String CAPABILITY_PUSH_OPTIONS
The server supports the receiving of push options.- Since:
- 4.5
- See Also:
- Constant Field Values
-
CAPABILITY_SYMREF_PREFIX
protected static final String CAPABILITY_SYMREF_PREFIX
- See Also:
- Constant Field Values
-
local
protected final Repository local
The repository this transport fetches into, or pushes out of.
-
uri
protected final URIish uri
Remote repository location.
-
timeoutIn
protected TimeoutInputStream timeoutIn
Low-level input stream, if a timeout was configured.
-
timeoutOut
protected TimeoutOutputStream timeoutOut
Low-level output stream, if a timeout was configured.
-
in
protected InputStream in
Input stream reading from the remote.
-
out
protected OutputStream out
Output stream sending to the remote.
-
pckIn
protected PacketLineIn pckIn
Packet line decoder aroundin
.
-
pckOut
protected PacketLineOut pckOut
Packet line encoder aroundout
.
-
outNeedsEnd
protected boolean outNeedsEnd
SendPacketLineOut.end()
before closingout
?
-
statelessRPC
protected boolean statelessRPC
True if this is a stateless RPC connection.
-
-
Constructor Detail
-
BasePackPushConnection
public BasePackPushConnection(PackTransport packTransport)
Create a new connection to push using the native git transport.- Parameters:
packTransport
- the transport.
-
-
Method Detail
-
push
public void push(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates) throws TransportException
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 TransportException
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
protected TransportException noRepository(Throwable cause)
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 TransportException
Push 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
public List<String> getPushOptions()
Gets the list of option strings associated with this push.- Returns:
- pushOptions
- Since:
- 4.5
-
init
protected final void init(InputStream myIn, OutputStream myOut)
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
protected boolean readAdvertisedRefs() throws TransportException
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
protected boolean isCapableOf(String option)
Whether this option is supported- Parameters:
option
- option string- Returns:
- whether this option is supported
-
wantCapability
protected boolean wantCapability(StringBuilder b, String option)
Request capability- Parameters:
b
- bufferoption
- option we want- Returns:
true
if the requested option is supported
-
getCapability
protected String getCapability(String option)
Return a capability value.- Parameters:
option
- to get- Returns:
- the value stored, if any.
-
addUserAgentCapability
protected void addUserAgentCapability(StringBuilder b)
Add user agent capability- Parameters:
b
- aStringBuilder
object.
-
getPeerUserAgent
public String getPeerUserAgent()
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()
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.
-
-