Top Description Inners Fields Constructors Methods
org.eclipse.jgit.transport

public Class ReceivePack

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8, org.eclipse.jgit.lib.Constants.HEAD, org.eclipse.jgit.transport.GitProtocolConstants.CAPABILITY_ATOMIC, .GitProtocolConstants.CAPABILITY_DELETE_REFS, .GitProtocolConstants.CAPABILITY_OFS_DELTA, .GitProtocolConstants.CAPABILITY_PUSH_OPTIONS, .GitProtocolConstants.CAPABILITY_QUIET, .GitProtocolConstants.CAPABILITY_REPORT_STATUS, .GitProtocolConstants.CAPABILITY_SIDE_BAND_64K, .GitProtocolConstants.OPTION_AGENT, .GitProtocolConstants.PACKET_ERR, .GitProtocolConstants.PACKET_SHALLOW, .GitProtocolConstants.OPTION_SESSION_ID, .SideBandOutputStream.CH_DATA, .SideBandOutputStream.CH_ERROR, .SideBandOutputStream.CH_PROGRESS, .SideBandOutputStream.MAX_BUF

Implements the server side of a push connection, receiving objects.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
pack-priv class
ReceivePack.MessageOutputWrapper

Output stream that wraps the current msgOut.

private class
private static class
ReceivePack.ReceiveConfig

Configuration for receive operations.

pack-priv abstract static class
ReceivePack.Reporter

Interface for reporting status messages.

Field Summary

Modifier and TypeField and Description
private Set<ObjectId>
advertisedHaves

All SHA-1s shown to the client, which can be possible edges.

private StringBuilder
private AdvertiseRefsHook
advertiseRefsHook

Hook used while advertising the refs to the client.

private boolean
allowAnyDeletes

Should an incoming transfer permit delete requests?

private boolean
private boolean
allowCreates

Should an incoming transfer permit create requests?

private boolean
allowNonFastForwards

Should an incoming transfer permit non-fast-forward requests?

private boolean
private boolean
allowPushOptions

Should an incoming transfer permit push options?

private boolean
private boolean
allowReceiveClientSID

Should the server advertise and accept the session-id capability.

private boolean
atomic

Should the requested ref updates be performed as a single atomic transaction?

private boolean
biDirectionalPipe

Is the client connection a bi-directional socket or pipe?

private boolean
private Set<ObjectId>
private String
clientSID

Session ID sent from the client.

private List<ReceiveCommand>
protected ConnectivityChecker
connectivityChecker

Connectivity checker to use.

private final Repository
db

Database we write the stored objects into.

private Map<String, String>
enabledCapabilities

Capabilities requested by the client.

private SideBandOutputStream
private boolean
expectDataAfterPackFooter

Expecting data after the pack footer

private long
private long
private long
maxObjectSizeLimit

Git object size limit

private long
maxPackSizeLimit

Total pack size limit

private OutputStream
msgOut

Optional message output stream.

private final ReceivePack.MessageOutputWrapper
private ObjectChecker
objectChecker

Should an incoming transfer validate objects?

private OutputStream
private PackLock
packLock

Lock around the received pack file, while updating refs.

private Long
packSize

The size of the received pack, including index size

private PackParser
private PacketLineIn
pckIn

Packet line input stream around rawIn.

private PacketLineOut
pckOut

Packet line output stream around rawOut.

private PostReceiveHook
postReceive

Hook to report on the commands after execution.

private PreReceiveHook
preReceive

Hook to validate the update commands before execution.

private PushCertificate
private PushCertificateParser
private List<String>
private boolean
private InputStream
rawIn

Raw input stream.

private OutputStream
rawOut

Raw output stream.

private ReceiveCommandErrorHandler
private RefFilter
refFilter

Filter used while advertising the refs to the client.

private PersonIdent
refLogIdent

Identity to record action as within the reflog.

private Map<String, Ref>
refs

The refs we advertised as existing at the start of the connection.

private boolean
private boolean
private SignedPushConfig
private ReceivedPackStatistics
private int
timeout

Timeout in seconds to wait for client interaction.

private TimeoutInputStream
private InterruptTimer
timer

Timer to manage timeout.

private UnpackErrorHandler
private boolean
usePushOptions

Whether the client intends to use push options.

pack-priv String
private final RevWalk
walk

Revision traversal support over db.

Constructor Summary

AccessConstructor and Description
public
ReceivePack(Repository
the destination repository.
into
)

Create a new pack receive for an open repository.

Method Summary

Modifier and TypeMethod and Description
private boolean

Returns:

if any commands have been rejected so far.
anyRejects
()

Whether any commands have been rejected so far.

private void
private void
private void
private void
private void
close()

Close and flush (if necessary) the underlying streams.

private ConnectivityChecker.ConnectivityCheckInfo
private void
private void
enableCapabilities()

Enable capabilities based on a previously read capabilities line.

protected void
executeCommands()

Execute commands to update references.

private void
failPendingCommands()

Set the result to fail for any command that was not processed yet.

private void
protected List<ReceiveCommand>

Returns:

a copy of the command list containing only those commands with the desired status.
filterCommands
(ReceiveCommand.Result
desired status to filter by.
want
)

Filter the list of commands according to result.

public final Set<ObjectId>

Returns:

the set of objects advertised to the as present in this repository, or null if setAdvertisedRefs(Map, Set) has not been called yet.
getAdvertisedObjects
()

Get objects advertised to the client.

private Map<String, Ref>

Returns:

advertised refs, or the default if not explicitly advertised.
getAdvertisedOrDefaultRefs
()

Get advertised refs, or the default if not explicitly advertised.

public Map<String, Ref>

Returns:

all refs which were advertised to the client, or null if setAdvertisedRefs(Map, Set) has not been called yet.
getAdvertisedRefs
()

Get refs which were advertised to the client.

public AdvertiseRefsHook

Returns:

the hook used while advertising the refs to the client
getAdvertiseRefsHook
()

Get the hook used while advertising the refs to the client

public List<ReceiveCommand>

Returns:

all of the command received by the current request.
getAllCommands
()

Get all of the command received by the current request.

private Map<String, Ref>

Returns:

Map of all refname/ref
getAllRefs
()

Extract the full list of refs from the ref-db.

private Set<ObjectId>

Returns:

if the client is a shallow repository, the list of edge commits that define the client's shallow boundary. Empty set if the client is earlier than Git 1.9, or is a full clone.
getClientShallowCommits
()

Get the commits from the client's shallow file.

public String

Returns:

The client session-id.
getClientSID
()

Get the client session-id

public OutputStream

Returns:

an underlying stream for sending messages to the client.
getMessageOutputStream
()

Get an underlying stream for sending messages to the client.

public long

Returns:

the size of the received pack including index size
getPackSize
()

Get the size of the received pack file including the index size.

public String

Returns:

user agent supplied by the client. Available only if the client is new enough to advertise its user agent.
getPeerUserAgent
()

Get the user agent of the client.

public PostReceiveHook

Returns:

the hook invoked after updates occur.
getPostReceiveHook
()

Get the hook invoked after updates occur.

public PreReceiveHook

Returns:

the hook invoked before updates occur.
getPreReceiveHook
()

Get the hook invoked before updates occur.

public PushCertificate

Returns:

the parsed certificate, or null if push certificates are disabled or no cert was presented by the client.
getPushCertificate
()

Get the push certificate used to verify the pusher's identity.

private PushCertificateParser
public List<String>

Returns:

an unmodifiable view of pushOptions, or null (if pushOptions is).
getPushOptions
()

Gets an unmodifiable view of the option strings associated with the push.

public ReceivedPackStatistics

Returns:

ReceivedPackStatistics
getReceivedPackStatistics
()

Returns the statistics on the received pack if available.

public RefFilter

Returns:

the filter used while advertising the refs to the client
getRefFilter
()

Get the filter used while advertising the refs to the client

public PersonIdent

Returns:

identity of the user making the changes in the reflog.
getRefLogIdent
()

Get identity of the user making the changes in the reflog.

public Repository

Returns:

the repository this receive completes into.
getRepository
()

Get the repository this receive completes into.

public RevWalk

Returns:

the RevWalk instance used by this connection.
getRevWalk
()

Get the RevWalk instance used by this connection.

public int

Returns:

timeout (in seconds) before aborting an IO operation.
getTimeout
()

Get timeout (in seconds) before aborting an IO operation.

public UnpackErrorHandler

Returns:

the current unpack error handler.
getUnpackErrorHandler
()

Get the current unpack error handler.

private boolean

Returns:

true if any commands to be executed have been read.
hasCommands
()

Whether any commands to be executed have been read.

private boolean

Returns:

true if an error occurred that should be advertised.
hasError
()

Whether an error occurred that should be advertised.

public boolean

Returns:

true if a pack has been received.
hasReceivedPack
()

Get whether or not a pack has been received.

protected void
init(final InputStream
raw input to read client commands and pack data from. Caller must ensure the input is buffered, otherwise read performance may suffer.
input
,
final OutputStream
response back to the Git network client. Caller must ensure the output is buffered, otherwise write performance may suffer.
output
,
final OutputStream
secondary "notice" channel to send additional messages out through. When run over SSH this should be tied back to the standard error channel of the command execution. For most other network connections this should be null.
messages
)

Initialize the instance with the given streams.

public boolean

Returns:

true if the client can delete from refs/heads/.
isAllowBranchDeletes
()

Whether the client can delete from refs/heads/.

public boolean

Returns:

true if the client can request refs to be created.
isAllowCreates
()

Whether the client can request refs to be created.

public boolean

Returns:

true if the client can request refs to be deleted.
isAllowDeletes
()

Whether the client can request refs to be deleted.

public boolean

Returns:

true if the client can request non-fast-forward updates of a ref, possibly making objects unreachable.
isAllowNonFastForwards
()

Whether the client can request non-fast-forward updates of a ref, possibly making objects unreachable.

public boolean

Returns:

true if the server supports receiving push options.
isAllowPushOptions
()

Whether the server supports receiving push options.

public boolean

Returns:

true if clients may request avoiding noisy progress messages.
isAllowQuiet
()

Whether clients may request avoiding noisy progress messages.

public boolean

Returns:

true if the client's commands should be performed as a single atomic transaction.
isAtomic
()

Whether the client's commands should be performed as a single atomic transaction.

public boolean

Returns:

true if this class expects a bi-directional pipe opened between the client and itself. The default is true.
isBiDirectionalPipe
()

Whether this class expects a bi-directional pipe opened between the client and itself.

private boolean

Returns:

true if the peer requested the capability to be enabled.
isCapabilityEnabled
(String
protocol name identifying the capability.
name
)

Check if the peer requested a capability.

public boolean

Returns:

true if this instance will verify received objects are formatted correctly. Validating objects requires more CPU time on this side of the connection.
isCheckReceivedObjects
()

Whether this instance will verify received objects are formatted correctly.

public boolean

Returns:

true if this instance will validate all referenced, but not supplied by the client, objects are reachable from another reference.
isCheckReferencedObjectsAreReachable
()

Whether this instance will validate all referenced, but not supplied by the client, objects are reachable from another reference.

public boolean

Returns:

true if there is data expected after the pack footer.
isExpectDataAfterPackFooter
()

Whether there is data expected after the pack footer.

public boolean

Returns:

true if the client has requested the server to be less verbose.
isQuiet
()

True if the client wants less verbose output.

public boolean

Returns:

true if the client has advertised a side-band capability, false otherwise.
isSideBand
()

Check whether the client expects a side-band stream.

private boolean
private boolean

Returns:

true if a pack is expected based on the list of commands.
needPack
()

Whether a pack is expected based on the list of commands.

private InputStream
pack-priv static ReceiveCommand
private void
pack-priv void
readPostCommands(PacketLineIn
request stream.
in
)

public void
receive(final InputStream
raw input to read client commands and pack data from. Caller must ensure the input is buffered, otherwise read performance may suffer.
input
,
final OutputStream
response back to the Git network client. Caller must ensure the output is buffered, otherwise write performance may suffer.
output
,
final OutputStream
secondary "notice" channel to send additional messages out through. When run over SSH this should be tied back to the standard error channel of the command execution. For most other network connections this should be null.
messages
)

Execute the receive task on the socket.

private void
receivePack()

Receive a pack from the input and store it in the repository.

protected void
receivePackAndCheckConnectivity()

Receive a pack from the stream and check connectivity if necessary.

public void
receiveWithExceptionPropagation(InputStream
raw input to read client commands and pack data from. Caller must ensure the input is buffered, otherwise read performance may suffer.
input
,
OutputStream
response back to the Git network client. Caller must ensure the output is buffered, otherwise write performance may suffer.
output
,
OutputStream
secondary "notice" channel to send additional messages out through. When run over SSH this should be tied back to the standard error channel of the command execution. For most other network connections this should be null.
messages
)

Execute the receive task on the socket.

private void
recvCommands()

Receive a list of commands from the input.

private void
release()

Release any resources used by this object.

public void
sendAdvertisedRefs(RefAdvertiser
the advertisement formatter.
adv
)

Generate an advertisement of available refs and capabilities.

public void
sendError(String
string describing the problem identified by the hook. The string must not end with an LF, and must not contain an LF.
what
)

Send an error message to the client.

public void
sendMessage(String
string describing the problem identified by the hook. The string must not end with an LF, and must not contain an LF.
what
)

Send a message to the client, if it supports receiving them.

private void
sendStatusReport(Throwable
an error that occurred during unpacking, or null
unpackError
)

Send a status report.

private void
public void
setAdvertisedRefs(Map<String, Ref>
explicit set of references to claim as advertised by this ReceivePack instance. This overrides any references that may exist in the source repository. The map is passed to the configured getRefFilter(). If null, assumes all refs were advertised.
allRefs
,
Set<ObjectId>
explicit set of additional haves to claim as advertised. If null, assumes the default set of additional haves from the repository.
additionalHaves
)

Set the refs advertised by this ReceivePack.

public void
setAdvertiseRefsHook(AdvertiseRefsHook
the hook; may be null to show all refs.
advertiseRefsHook
)

Set the hook used while advertising the refs to the client.

public void
setAllowBranchDeletes(boolean
true to permit deletion of branches from the refs/heads/ namespace.
canDelete
)

Configure whether to permit deletion of branches from the refs/heads/ namespace.

public void
setAllowCreates(boolean
true to permit create ref commands to be processed.
canCreate
)

Whether to permit create ref commands to be processed.

public void
setAllowDeletes(boolean
true to permit delete ref commands to be processed.
canDelete
)

Whether to permit delete ref commands to be processed.

public void
setAllowNonFastForwards(boolean
true to permit the client to ask for non-fast-forward updates of an existing ref.
canRewind
)

Configure whether to permit the client to ask for non-fast-forward updates of an existing ref.

public void
setAllowPushOptions(boolean
true to optionally accept option strings from the client.
allow
)

Configure if the server supports receiving push options.

public void
setAllowQuiet(boolean
true to allow clients to request quiet behavior; false to refuse quiet behavior and send messages anyway. This may be necessary if processing is slow and the client-server network connection can timeout.
allow
)

Configure if clients may request the server skip noisy messages.

public void
setAtomic(boolean
true to perform the client's commands as a single atomic transaction.
atomic
)

Configure whether to perform the client's commands as a single atomic transaction.

public void
setBiDirectionalPipe(boolean
if true, this class will assume the socket is a fully bidirectional pipe between the two peers and takes advantage of that by first transmitting the known refs, then waiting to read commands. If false, this class assumes it must read the commands before writing output and does not perform the initial advertising.
twoWay
)

Whether this class will assume the socket is a fully bidirectional pipe between the two peers and takes advantage of that by first transmitting the known refs, then waiting to read commands.

public void
setCheckReceivedObjects(boolean
true to enable checking received objects; false to assume all received objects are valid.
check
)

Whether to enable checking received objects

public void
setCheckReferencedObjectsAreReachable(boolean
true to enable the additional check.
b
)

Validate all referenced but not supplied objects are reachable.

public void
setExpectDataAfterPackFooter(boolean
true if there is additional data in InputStream after pack.
e
)

Whether there is additional data in InputStream after pack.

public void
setMaxCommandBytes(long
command limit in bytes; if 0 there is no limit.
limit
)

Set the maximum number of command bytes to read from the client.

public void
setMaxCommandDiscardBytes(long
discard limit in bytes; if 0 there is no limit; if -1 the implementation tries to set a reasonable default.
limit
)

Set the maximum number of command bytes to discard from the client.

public void
setMaxObjectSizeLimit(long
the Git object size limit. If zero then there is not limit.
limit
)

Set the maximum allowed Git object size.

public void
setMaxPackSizeLimit(long
the pack size limit, in bytes
limit
)

Set the maximum allowed pack size.

public void
setObjectChecker(ObjectChecker
if non-null the object checking instance to verify each received object with; null to disable object checking.
impl
)

Set the object checking instance to verify each received object with

public void
setPostReceiveHook(PostReceiveHook
the hook instance; may be null to disable the hook.
h
)

Set the hook which is invoked after commands are executed.

public void
setPreReceiveHook(PreReceiveHook
the hook instance; may be null to disable the hook.
h
)

Set the hook which is invoked prior to commands being executed.

public void
setPushCertificate(PushCertificate
the push certificate to set.
cert
)

Set the push certificate used to verify the pusher's identity.

public void
setPushOptions(List<String>
the list of options supplied by the client. The ReceivePack instance takes ownership of this list. Callers are encouraged to first create a copy if the list may be modified later.
options
)

Set the push options supplied by the client.

public void
setReceiveCommandErrorHandler(ReceiveCommandErrorHandler
the error handler
receiveCommandErrorHandler
)

Set an error handler for ReceiveCommand.

public void
setRefFilter(RefFilter
the filter; may be null to show all refs.
refFilter
)

Set the filter used while advertising the refs to the client.

public void
setRefLogIdent(PersonIdent
identity of the user. If null the identity will be automatically determined based on the repository configuration.
pi
)

Set the identity of the user appearing in the affected reflogs.

public void
setSignedPushConfig(SignedPushConfig
new configuration; if this object is null or its SignedPushConfig#getCertNonceSeed() is null, push certificate verification will be disabled.
cfg
)

Set the configuration for push certificate verification.

public void
setTimeout(int
number of seconds to wait (with no data transfer occurring) before aborting an IO read or write operation with the connected client.
seconds
)

Set the timeout before willing to abort an IO call.

public void
setUnpackErrorHandler(UnpackErrorHandler
the unpackErrorHandler
unpackErrorHandler
)

Set the unpackErrorHandler

private void
unlockPack()

Unlock the pack written by this object.

private void
validateCommands()

Validate the command list.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait