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

public Class UploadPack

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Static Imports
java.util.Collections.emptyList, .Collections.unmodifiableMap, .Objects.requireNonNull, org.eclipse.jgit.lib.Constants.R_TAGS, org.eclipse.jgit.transport.GitProtocolConstants.CAPABILITY_REF_IN_WANT, .GitProtocolConstants.CAPABILITY_SERVER_OPTION, .GitProtocolConstants.COMMAND_FETCH, .GitProtocolConstants.COMMAND_LS_REFS, .GitProtocolConstants.COMMAND_OBJECT_INFO, .GitProtocolConstants.OPTION_AGENT, .GitProtocolConstants.OPTION_ALLOW_REACHABLE_SHA1_IN_WANT, .GitProtocolConstants.OPTION_ALLOW_TIP_SHA1_IN_WANT, .GitProtocolConstants.OPTION_DEEPEN_RELATIVE, .GitProtocolConstants.OPTION_FILTER, .GitProtocolConstants.OPTION_INCLUDE_TAG, .GitProtocolConstants.OPTION_MULTI_ACK, .GitProtocolConstants.OPTION_MULTI_ACK_DETAILED, .GitProtocolConstants.OPTION_NO_DONE, .GitProtocolConstants.OPTION_NO_PROGRESS, .GitProtocolConstants.OPTION_OFS_DELTA, .GitProtocolConstants.OPTION_SESSION_ID, .GitProtocolConstants.OPTION_SHALLOW, .GitProtocolConstants.OPTION_SIDEBAND_ALL, .GitProtocolConstants.OPTION_SIDE_BAND, .GitProtocolConstants.OPTION_SIDE_BAND_64K, .GitProtocolConstants.OPTION_THIN_PACK, .GitProtocolConstants.OPTION_WAIT_FOR_DONE, .GitProtocolConstants.PACKET_ACK, .GitProtocolConstants.PACKET_DONE, .GitProtocolConstants.PACKET_ERR, .GitProtocolConstants.PACKET_HAVE, .GitProtocolConstants.PACKET_SHALLOW, .GitProtocolConstants.PACKET_UNSHALLOW, .GitProtocolConstants.VERSION_2_REQUEST, org.eclipse.jgit.util.RefMap.toRefMap

Implements the server side of a fetch connection, transmitting objects.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
private static interface
private static interface
private static enum
private class
public static class
public static class
public static enum
UploadPack.RequestPolicy

Policy the server uses to validate client requests

public static interface
UploadPack.RequestValidator

Validator for client requests.

private static class
private class
public static class

Field Summary

Modifier and TypeField and Description
private Set<ObjectId>
advertised

Objects we sent in our advertisement list.

private AdvertiseRefsHook
advertiseRefsHook

Hook used while advertising the refs to the client.

private boolean
advertiseRefsHookCalled

Whether the advertiseRefsHook has been invoked.

private boolean
biDirectionalPipe

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

private CachedPackUriProvider
private boolean
clientRequestedV2

Whether the client requested to use protocol V2 through a side channel (such as the Git-Protocol HTTP header).

private final RevFlag
COMMON

Marked on objects in commonBase.

private final Set<RevObject>
commonBase

Objects on both sides, these don't have to be sent.

private FetchRequest
currentRequest

Request this instance is handling.

private final Repository
db

Database we read the objects from.

private UploadPack.ErrorWriter
private OutputStream
private GitProtocolConstants.MultiAck
private boolean
private Boolean
okToGiveUp

null if commonBase should be examined again.

private int
oldestTime

Commit time of the oldest common commit, in seconds.

private PackConfig
packConfig

Configuration to pass into the PackWriter.

private PacketLineIn
private final RevFlag
PEER_HAS

Marked on objects both we and the client have.

private PostUploadHook
postUploadHook

Hook for taking post upload actions.

private PreUploadHook
preUploadHook

Hook handling the various upload phases.

private ProtocolV2Hook
protocolV2Hook

Hook used while processing Git protocol v2 requests.

private InputStream
private UploadPack.ResponseBufferedOutputStream
private RefFilter
refFilter

Filter used while advertising the refs to the client.

private Map<String, Ref>
refs

Refs eligible for advertising to the client, set using setAdvertisedRefs.

private UploadPack.RequestValidator
private final RevFlag
SATISFIED

Objects where we found a path from the want list to a common base.

private final RevFlagSet
private boolean
private PackStatistics
private int
timeout

Timeout in seconds to wait for client interaction.

private InterruptTimer
timer

Timer to manage timeout.

private TransferConfig
transferConfig

Configuration for various transfer options.

pack-priv String
userAgent

Caller user agent

private final RevWalk
walk

Revision traversal support over db.

private final RevFlag
WANT

Marked on objects the client has asked us to give them.

private final Set<RevObject>
wantAll

Objects the client wants to obtain.

private Set<ObjectId>
wantIds

Raw ObjectIds the client has asked for, before validating them.

Constructor Summary

AccessConstructor and Description
public
UploadPack(Repository
the source repository.
copyFrom
)

Create a new pack upload for an open repository.

Method Summary

Modifier and TypeMethod and Description
private void
private void
private static void
checkNotAdvertisedWants(UploadPack up, List<ObjectId> notAdvertisedWants, Collection<Ref> visibleRefs)

public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

private void
private Map<String, Ref>

Returns:

the requested Refs, omitting any that are not visible or do not exist.
exactRefs
(List<String>
unabbreviated names of references.
names
)

Read refs on behalf of the client.

private void
private Ref

Returns:

the requested Ref, or null if it is not visible or does not exist.
findRef
(String
short name of the ref to find, e.g. "master" to find "refs/heads/master".
name
)

Find a ref in the usual search path on behalf of the client.

private static void
findSymrefs(final RefAdvertiser adv, final Map<String, Ref> refs)

private Map<String, Ref>
public final Map<String, Ref>

Returns:

all refs which were advertised to the client. Only valid during the negotiation phase. Will return null if setAdvertisedRefs(Map) has not been called yet or if #sendPack() has been called.
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.

private Map<String, Ref>

Returns:

Map of all refname/ref
getAllRefs
()

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

public String

Returns:

The session ID if it has been received from the client.
getClientSID
()

Get the session ID if received from the client.

public int

Returns:

the depth requested by the client, or 0 if unbounded.
getDepth
()

Returns the clone/fetch depth.

private Map<String, Ref>
public final FilterSpec

Returns:

filter requested by the client
getFilterSpec
()

Returns the filter spec for the current request.

public OutputStream

Returns:

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

Get an underlying stream for sending messages to the client

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 PostUploadHook

Returns:

the configured post upload hook.
getPostUploadHook
()

Get the configured post upload hook.

public PreUploadHook

Returns:

the configured pre upload hook.
getPreUploadHook
()

Get the configured pre upload hook.

public ProtocolV2Hook

Returns:

the hook or a default implementation if none installed.
getProtocolV2Hook
()

Get the currently installed protocol v2 hook.

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 final Repository

Returns:

the repository this upload is reading from.
getRepository
()

Get the repository this upload is reading from.

public UploadPack.RequestPolicy

Returns:

policy used by the service to validate client requests, or null for a custom request validator.
getRequestPolicy
()

Get policy used by the service to validate client requests

public final RevWalk

Returns:

the RevWalk instance used by this connection.
getRevWalk
()

Get the RevWalk instance used by this connection.

public PackStatistics

Returns:

statistics about pack output, if a pack was sent. Null if no pack was sent, such as during the negotiation phase of a smart HTTP connection, or if the client was already up-to-date.
getStatistics
()

Get the PackWriter's statistics if a pack was sent to the client.

public int

Returns:

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

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

private List<String>
pack-priv static Stream<Ref>
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.

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 void
private static Map<String, Ref>

Returns:

the requested Refs, omitting any that are null or missing.
mapRefs
(Map<String, Ref>
Map to search for refs to return.
refs
,
List<String>
which refs to search for in refs.
names
)

Returns the specified references.

private boolean
private static <T> Predicate<T>
not(Predicate<T> t)

private static List<RevObject>
private static RevCommit

Returns:

RevCommit instance or null if the object is missing
objectIdToRevCommit
(RevWalk
walk on the relevant object storae
walk
,
ObjectId
Object Id
objectId
)

Translate an object id to a RevCommit.

private static RevObject

Returns:

RevObject instance or null if the object is missing
objectIdToRevObject
(RevWalk
walk on the relevant object storage
walk
,
ObjectId
Object Id
objectId
)

Translate an object id to a RevObject.

private void
private boolean
private boolean
private List<ObjectId>
private void
private ObjectId
private static Set<ObjectId>
private static ObjectId
public void
sendAdvertisedRefs(RefAdvertiser
the advertisement formatter.
adv
)

Generate an advertisement of available refs and capabilities.

public void
sendAdvertisedRefs(RefAdvertiser
the advertisement formatter.
adv
,
String
if not null, also output "# service=serviceName" followed by a flush packet before the advertisement. This is required in v0 of the HTTP protocol, described in Git's Documentation/technical/http-protocol.txt.
serviceName
)

Generate an advertisement of available refs and capabilities.

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
sendPack(PackStatistics.Accumulator
where to write statistics about the content of the pack.
accumulator
,
FetchRequest
request in process
req
,
Collection<Ref>
refs to search for annotated tags to include in the pack if the GitProtocolConstants#OPTION_INCLUDE_TAG capability was requested.
allTags
,
List<ObjectId>
shallow commits on the client that are now becoming unshallow
unshallowCommits
,
List<ObjectId>
objects that the client specified using --shallow-exclude
deepenNots
,
PacketLineOut
output writer
pckOut
)

Send the requested objects to the client.

private void
sendPack(ProgressMonitor
progress monitor
pm
,
PacketLineOut
PacketLineOut that shares the output with packOut
pckOut
,
OutputStream
packfile output
packOut
,
FetchRequest
request being processed
req
,
PackStatistics.Accumulator
where to write statistics about the content of the pack.
accumulator
,
Collection<Ref>
refs to search for annotated tags to include in the pack if the GitProtocolConstants#OPTION_INCLUDE_TAG capability was requested.
allTags
,
List<ObjectId>
shallow commits on the client that are now becoming unshallow
unshallowCommits
,
List<ObjectId>
objects that the client specified using --shallow-exclude
deepenNots
)

Send the requested objects to the client.

private boolean
private void
private void
public void
setAdvertisedRefs(Map<String, Ref>
explicit set of references to claim as advertised by this UploadPack 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 the refs advertised by this UploadPack.

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
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
)

Set whether this class will assume the socket is a fully bidirectional pipe between the two peers

public void
setCachedPackUriProvider(CachedPackUriProvider
provider of URIs corresponding to cached packs (to support the packfile URIs feature)
p
)

Set provider of cached pack URIs

public void
setExtraParameters(Collection<String>
parameters supplied by the client, split at colons or NUL bytes.
params
)

Set the Extra Parameters provided by the client.

public void
setPackConfig(PackConfig
configuration controlling packing parameters. If null the source repository's settings will be used.
pc
)

Set the configuration used by the pack generator.

public void
setPostUploadHook(PostUploadHook
the hook; if null no special actions are taken.
hook
)

Set the hook for post upload actions (logging, repacking).

public void
setPreUploadHook(PreUploadHook
the hook; if null no special actions are taken.
hook
)

Set the hook that controls how this instance will behave.

public void
setProtocolV2Hook(ProtocolV2Hook
the hook; if null no special actions are taken.
hook
)

Set the protocol V2 hook.

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
setRequestPolicy(UploadPack.RequestPolicy
the policy used to enforce validation of a client's want list. By default the policy is org.eclipse.jgit.transport.UploadPack.RequestPolicy#ADVERTISED, which is the Git default requiring clients to only ask for an object that a reference directly points to. This may be relaxed to org.eclipse.jgit.transport.UploadPack.RequestPolicy#REACHABLE_COMMIT or org.eclipse.jgit.transport.UploadPack.RequestPolicy#REACHABLE_COMMIT_TIP when callers have setBiDirectionalPipe(boolean) set to false. Overrides any policy specified in a org.eclipse.jgit.transport.TransferConfig.
policy
)

Set the policy used to enforce validation of a client's want list.

public void
setRequestValidator(UploadPack.RequestValidator
custom validator for client want list.
validator
)

Set custom validator for client want list.

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
setTransferConfig(TransferConfig
configuration controlling transfer options. If null the source repository's settings will be used.
tc
)

Set configuration controlling transfer options.

private boolean
shouldGiveUp(List<ObjectId> peerHas, PacketLineOut out, int missCnt)

public void
upload(InputStream
input stream
input
,
OutputStream
output stream
output
,
OutputStream
stream for messages
messages
)

Execute the upload task on the socket.

public void
uploadWithExceptionPropagation(InputStream
raw input to read client commands from. Caller must ensure the input is buffered, otherwise read performance may suffer.
input
,
OutputStream
response back to the Git network client, to write the pack data onto. 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 upload task on the socket.

private boolean
private void
verifyClientShallow(Set<ObjectId> shallowCommits)

private void
private Map<String, ObjectId>
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait