public abstract class BasePackPushConnection extends BaseConnection implements 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 close()
method if needed.
Modifier and Type | Field and 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 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
Send
PacketLineOut.end() before closing out ? |
protected PacketLineIn |
pckIn
Packet line decoder around
in . |
protected PacketLineOut |
pckOut
Packet line encoder around
out . |
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 to
uri . |
protected URIish |
uri
Remote repository location.
|
Constructor and Description |
---|
BasePackPushConnection(PackTransport packTransport)
Create a new connection to push using the native git transport.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addUserAgentCapability(StringBuilder b)
Add user agent capability
|
void |
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.
|
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 supported
|
protected TransportException |
noRepository()
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 void |
readAdvertisedRefs()
Reads the advertised references through the initialized stream.
|
protected boolean |
wantCapability(StringBuilder b,
String option)
Request capability
|
available, getMessages, getMessageWriter, getRef, getRefs, getRefsMap, markStartedOperation, setMessageWriter, setPeerUserAgent
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, getMessages, getPeerUserAgent, getRef, getRefs, getRefsMap
public static final String CAPABILITY_REPORT_STATUS
public static final String CAPABILITY_DELETE_REFS
public static final String CAPABILITY_OFS_DELTA
public static final String CAPABILITY_SIDE_BAND_64K
public static final String CAPABILITY_PUSH_OPTIONS
protected final Repository local
protected final URIish uri
protected TimeoutInputStream timeoutIn
protected TimeoutOutputStream timeoutOut
protected InputStream in
protected OutputStream out
protected PacketLineIn pckIn
in
.protected PacketLineOut pckOut
out
.protected boolean outNeedsEnd
PacketLineOut.end()
before closing out
?protected boolean statelessRPC
public BasePackPushConnection(PackTransport packTransport)
packTransport
- the transport.public void push(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates) throws TransportException
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.
push
in interface PushConnection
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
with
RemoteRefUpdate.Status.NOT_ATTEMPTED
should passed. Implementation must ensure that and appropriate
status with optional message should be set during call. No
refUpdate with
RemoteRefUpdate.Status.AWAITING_REPORT
or
RemoteRefUpdate.Status.NOT_ATTEMPTED
can be leaved by implementation after return from this call.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.public void push(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates, OutputStream outputStream) throws TransportException
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.
push
in interface PushConnection
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
with
RemoteRefUpdate.Status.NOT_ATTEMPTED
should passed. Implementation must ensure that and appropriate
status with optional message should be set during call. No
refUpdate with
RemoteRefUpdate.Status.AWAITING_REPORT
or
RemoteRefUpdate.Status.NOT_ATTEMPTED
can be leaved by implementation after return from this call.outputStream
- output stream to write sideband messages toTransportException
- 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.protected TransportException noRepository()
protected void doPush(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates, OutputStream outputStream) throws TransportException
monitor
- progress monitor to receive status updates.refUpdates
- update commands to be applied to the remote repository.outputStream
- output stream to write sideband messages toTransportException
- if any exception occurs.public List<String> getPushOptions()
protected final void init(InputStream myIn, OutputStream myOut)
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.protected void readAdvertisedRefs() throws TransportException
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
close()
and the exception is wrapped (if necessary) and thrown
as a TransportException
.
TransportException
- the reference list could not be scanned.protected boolean isCapableOf(String option)
option
- option stringprotected boolean wantCapability(StringBuilder b, String option)
b
- bufferoption
- option we wanttrue
if the requested option is supportedprotected void addUserAgentCapability(StringBuilder b)
b
- a StringBuilder
object.public String getPeerUserAgent()
getPeerUserAgent
in interface Connection
getPeerUserAgent
in class BaseConnection
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 throws Exception
.
Implementers shouldn't throw checked exceptions. This override narrows
the signature to prevent them from doing so.
close
in interface AutoCloseable
close
in interface Connection
close
in class BaseConnection
protected void endOut()
Copyright © 2020 Eclipse JGit Project. All rights reserved.