This is the canonical implementation for transferring objects from the remote repository to the local repository by talking to the 'git-upload-pack' service. Objects are packed on the remote side into a pack file and then sent down the pipe to us.
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.
If org. is
true, this connection can be tunneled over a request-response style
RPC system like HTTP. The RPC call boundary is determined by this class
switching from writing to the OutputStream to reading from the InputStream.
Concrete implementations should just call
init(java. and
readAdvertisedRefs() methods in constructor or before any use. They
should also handle resources releasing in close() method if needed.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| pack-priv static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final RevFlag | ADVERTISED
Marks a commit listed in the advertised refs. |
| private boolean | |
| pack-priv final RevFlag | COMMON
Marks a commit known to both sides of the connection. |
| private List | |
| private Instant | |
| private Integer | |
| private final FilterSpec | filterSpec
Either FilterSpec.NO_FILTER for a filter that doesn't filter anything, or a filter that indicates what and what not to send to the server. |
| private boolean | |
| private String | |
| private static final int | MAX_HAVES
Maximum number of 'have' lines to send before giving up. |
| private int | |
| protected static final int | MIN_CLIENT_BUFFER
Amount of data the client sends before starting to read. |
| private GitProtocolConstants. | |
| private boolean | |
| private boolean | |
| public static final String | OPTION_ALLOW_REACHABLE_SHA1_IN_WANT
The client supports fetching objects that are reachable from a tip of a ref that is allowed to fetch. |
| public static final String | OPTION_ALLOW_TIP_SHA1_IN_WANT
The client supports fetching objects at the tip of any ref, even if not advertised. |
| public static final String | OPTION_FILTER
The client specified a filter expression. |
| public static final String | OPTION_INCLUDE_TAG
Include tags if we are also including the referenced objects. |
| public static final String | OPTION_MULTI_ACK
Multi-ACK support for improved negotiation. |
| public static final String | OPTION_MULTI_ACK_DETAILED
Multi-ACK detailed support for improved negotiation. |
| public static final String | OPTION_NO_DONE
The client supports receiving a pack before it has sent "done". |
| public static final String | OPTION_NO_PROGRESS
The client does not want progress messages and will ignore them. |
| public static final String | OPTION_OFS_DELTA
The client supports packs with OFS deltas. |
| public static final String | OPTION_SHALLOW
The client supports shallow fetches. |
| public static final String | OPTION_SIDE_BAND
The client supports using the side-band for progress messages. |
| public static final String | OPTION_SIDE_BAND_64K
The client supports using the 64K side-band for progress messages. |
| public static final String | OPTION_THIN_PACK
The client supports packs with deltas but not their bases. |
| private PackLock | |
| private PacketLineOut | |
| pack-priv final RevFlag | REACHABLE
Marks an object as having all its dependencies. |
| private RevCommitList | reachableCommits
All commits that are immediately reachable by a local ref. |
| private boolean | |
| private final RevFlag | |
| private TemporaryBuffer. | state
RPC state, if |
| private boolean | |
| private boolean | |
| private final RevWalk |
| Access | Constructor and Description |
|---|---|
| public | BasePackFetchConnection(PackTransport
the transport. packTransport)Create a new connection to fetch using the native git transport. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | close()
Overrides org. Implements org. Closes this resource, relinquishing any underlying resources. |
| public boolean | didFetchIncludeTags()
Implements org. Did the last |
| public boolean | didFetchTestConnectivity()
Implements org. Did the last |
| protected void | doFetch(final ProgressMonitor
progress monitor to receive status updates. If the monitor is
the monitor, final Collection<Ref> org., then the no-progress
option enabled.the advertised remote references the caller wants to fetch. want, final Set<ObjectId> additional objects to assume that already exist locally. This
will be added to the set of objects reachable from the
destination repository's references. have, OutputStream ouputStream to write sideband messages to outputStream)Execute common ancestor negotiation and fetch the objects. |
| private void | doFetchV2(ProgressMonitor monitor, Collection<Ref> want, OutputStream outputStream, boolean hasObjects)
|
| private String | |
| public final void | fetch(final ProgressMonitor
progress monitor to inform the end-user about the amount of
work completed, or to indicate cancellation. Implementations
should poll the monitor at regular intervals to look for
cancellation requests from the user. monitor, final Collection<Ref> one or more refs advertised by this connection that the caller
wants to store locally. want, final Set<ObjectId> additional objects known to exist in the destination
repository, especially if they aren't yet reachable by the ref
database. Connections should take this set as an addition to
what is reachable through all Refs, not in replace of it. have)Implements org. Fetch objects we don't have but that are reachable from advertised refs. |
| public final void | fetch(final ProgressMonitor
progress monitor to inform the end-user about the amount of
work completed, or to indicate cancellation. Implementations
should poll the monitor at regular intervals to look for
cancellation requests from the user. monitor, final Collection<Ref> one or more refs advertised by this connection that the caller
wants to store locally. want, final Set<ObjectId> additional objects known to exist in the destination
repository, especially if they aren't yet reachable by the ref
database. Connections should take this set as an addition to
what is reachable through all Refs, not in replace of it. have, OutputStream OutputStream to write sideband messages to outputStream)Implements org. Fetch objects we don't have but that are reachable from advertised refs. |
| private Set | |
| pack-priv BasePackFetchConnection. | |
| public Collection | getPackLocks()
Implements org. All locks created by the last
|
| private static ObjectId | |
| private String | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | markReachableRefTips(Collection<Ref>
references that client is requesting to be marked. refsToMark)Marks commits reachable. |
| private void | |
| private int | |
| private void | |
| private void | |
| protected void | |
| private boolean | Returns: true if a "ready" was received and a packfile is expected
nextto update fetchState,to read from input, ProgressMonitor for progress reporting and cancellation monitor)Reads and processes acknowledgments, adding ACKed objects as "have"s to
the global state |
| private void | |
| private boolean | Returns: true if a "done" was written and we should thus expect a
packfile nextis updated with information about the number of items written,
and whether to expect a packfile next fetchState,to write to output, ProgressMonitor for progress reporting and cancellation monitor)Sends the next batch of "have"s and terminates the |
| private void | |
| private boolean | |
| public void | setPackLockMessage(String
message to use when holding a pack in place. message)Implements org. Set the lock message used when holding a pack out of garbage collection. |
| private Collection |
| ADVERTISED | back to summary |
|---|---|
| pack-priv final RevFlag ADVERTISED Marks a commit listed in the advertised refs. | |
| allowOfsDelta | back to summary |
|---|---|
| private boolean allowOfsDelta | |
| COMMON | back to summary |
|---|---|
| pack-priv final RevFlag COMMON Marks a commit known to both sides of the connection. | |
| deepenNots | back to summary |
|---|---|
| private List<String> deepenNots | |
| deepenSince | back to summary |
|---|---|
| private Instant deepenSince | |
| depth | back to summary |
|---|---|
| private Integer depth | |
| filterSpec | back to summary |
|---|---|
| private final FilterSpec filterSpec Either FilterSpec.NO_FILTER for a filter that doesn't filter anything, or a filter that indicates what and what not to send to the server. | |
| includeTags | back to summary |
|---|---|
| private boolean includeTags | |
| lockMessage | back to summary |
|---|---|
| private String lockMessage | |
| MAX_HAVES | back to summary |
|---|---|
| private static final int MAX_HAVES Maximum number of 'have' lines to send before giving up.
During | |
| maxHaves | back to summary |
|---|---|
| private int maxHaves | |
| MIN_CLIENT_BUFFER | back to summary |
|---|---|
| protected static final int MIN_CLIENT_BUFFER Amount of data the client sends before starting to read. Any output stream given to the client must be able to buffer this many bytes before the client will stop writing and start reading from the input stream. If the output stream blocks before this many bytes are in the send queue, the system will deadlock. | |
| multiAck | back to summary |
|---|---|
| private GitProtocolConstants. | |
| noDone | back to summary |
|---|---|
| private boolean noDone | |
| noProgress | back to summary |
|---|---|
| private boolean noProgress | |
| OPTION_ALLOW_REACHABLE_SHA1_IN_WANT | back to summary |
|---|---|
| public static final String OPTION_ALLOW_REACHABLE_SHA1_IN_WANT The client supports fetching objects that are reachable from a tip of a ref that is allowed to fetch.
| |
| OPTION_ALLOW_TIP_SHA1_IN_WANT | back to summary |
|---|---|
| public static final String OPTION_ALLOW_TIP_SHA1_IN_WANT The client supports fetching objects at the tip of any ref, even if not advertised.
| |
| OPTION_FILTER | back to summary |
|---|---|
| public static final String OPTION_FILTER The client specified a filter expression.
| |
| OPTION_INCLUDE_TAG | back to summary |
|---|---|
| public static final String OPTION_INCLUDE_TAG Include tags if we are also including the referenced objects.
| |
| OPTION_MULTI_ACK | back to summary |
|---|---|
| public static final String OPTION_MULTI_ACK Multi-ACK support for improved negotiation.
| |
| OPTION_MULTI_ACK_DETAILED | back to summary |
|---|---|
| public static final String OPTION_MULTI_ACK_DETAILED Multi-ACK detailed support for improved negotiation.
| |
| OPTION_NO_DONE | back to summary |
|---|---|
| public static final String OPTION_NO_DONE The client supports receiving a pack before it has sent "done".
| |
| OPTION_NO_PROGRESS | back to summary |
|---|---|
| public static final String OPTION_NO_PROGRESS The client does not want progress messages and will ignore them.
| |
| OPTION_OFS_DELTA | back to summary |
|---|---|
| public static final String OPTION_OFS_DELTA The client supports packs with OFS deltas.
| |
| OPTION_SHALLOW | back to summary |
|---|---|
| public static final String OPTION_SHALLOW The client supports shallow fetches.
| |
| OPTION_SIDE_BAND | back to summary |
|---|---|
| public static final String OPTION_SIDE_BAND The client supports using the side-band for progress messages.
| |
| OPTION_SIDE_BAND_64K | back to summary |
|---|---|
| public static final String OPTION_SIDE_BAND_64K The client supports using the 64K side-band for progress messages.
| |
| OPTION_THIN_PACK | back to summary |
|---|---|
| public static final String OPTION_THIN_PACK The client supports packs with deltas but not their bases.
| |
| packLock | back to summary |
|---|---|
| private PackLock packLock | |
| pckState | back to summary |
|---|---|
| private PacketLineOut pckState | |
| REACHABLE | back to summary |
|---|---|
| pack-priv final RevFlag REACHABLE Marks an object as having all its dependencies. | |
| reachableCommits | back to summary |
|---|---|
| private RevCommitList<RevCommit> reachableCommits All commits that are immediately reachable by a local ref. | |
| sideband | back to summary |
|---|---|
| private boolean sideband | |
| STATE | back to summary |
|---|---|
| private final RevFlag STATE | |
| state | back to summary |
|---|---|
| private TemporaryBuffer. RPC state, if | |
| thinPack | back to summary |
|---|---|
| private boolean thinPack | |
| useNegotiationTip | back to summary |
|---|---|
| private boolean useNegotiationTip | |
| walk | back to summary |
|---|---|
| private final RevWalk walk | |
| BasePackFetchConnection | back to summary |
|---|---|
| public BasePackFetchConnection(PackTransport packTransport) Create a new connection to fetch using the native git transport.
| |
| clearState | back to summary |
|---|---|
| private void clearState() | |
| close | back to summary |
|---|---|
| public void close() Overrides org. Implements org. Doc from org. Closes this resource, relinquishing any underlying resources.
This method is invoked automatically on objects managed by the
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
| |
| didFetchIncludeTags | back to summary |
|---|---|
| public boolean didFetchIncludeTags() Implements org. Doc from org. Did the last
Some Git aware transports are able to implicitly grab an annotated tag if
By returning only true/false (and not the actual list of tags obtained) the transport itself does not need to be aware of whether or not tags were included in the transfer.
| |
| didFetchTestConnectivity | back to summary |
|---|---|
| public boolean didFetchTestConnectivity() Implements org. Doc from org. Did the last Some transports walk the object graph on the client side, with the client looking for what objects it is missing and requesting them individually from the remote peer. By virtue of completing the fetch call the client implicitly tested the object connectivity, as every object in the graph was either already local or was requested successfully from the peer. In such transports this method returns true. Some transports assume the remote peer knows the Git object graph and is able to supply a fully connected graph to the client (although it may only be transferring the parts the client does not yet have). Its faster to assume such remote peers are well behaved and send the correct response to the client. In such transports this method returns false.
| |
| doFetch | back to summary |
|---|---|
| protected void doFetch(final ProgressMonitor monitor, final Collection<Ref> want, final Set<ObjectId> have, OutputStream outputStream) throws TransportException Execute common ancestor negotiation and fetch the objects.
| |
| doFetchV2 | back to summary |
|---|---|
| private void doFetchV2(ProgressMonitor monitor, Collection<Ref> want, OutputStream outputStream, boolean hasObjects) throws IOException, CancelledException | |
| enableCapabilities | back to summary |
|---|---|
| private String enableCapabilities() throws TransportException | |
| fetch | back to summary |
|---|---|
| public final void fetch(final ProgressMonitor monitor, final Collection<Ref> want, final Set<ObjectId> have) throws TransportException Implements org. Doc from org. Fetch objects we don't have but that are reachable from advertised refs.
Only one call per connection is allowed. Subsequent calls will result in
Implementations are free to use network connections as necessary to
efficiently (for both client and server) transfer objects from the remote
repository into this repository. When possible implementations should
avoid replacing/overwriting/duplicating an object already available in
the local destination repository. Locally available objects and packs
should always be preferred over remotely available objects and packs.
| |
| fetch | back to summary |
|---|---|
| public final void fetch(final ProgressMonitor monitor, final Collection<Ref> want, final Set<ObjectId> have, OutputStream outputStream) throws TransportException Implements org. Doc from org. Fetch objects we don't have but that are reachable from advertised refs.
Only one call per connection is allowed. Subsequent calls will result in
Implementations are free to use network connections as necessary to
efficiently (for both client and server) transfer objects from the remote
repository into this repository. When possible implementations should
avoid replacing/overwriting/duplicating an object already available in
the local destination repository. Locally available objects and packs
should always be preferred over remotely available objects and packs.
| |
| getCapabilitiesV2 | back to summary |
|---|---|
| private Set | |
| getFetchConfig | back to summary |
|---|---|
| pack-priv BasePackFetchConnection. | |
| getPackLocks | back to summary |
|---|---|
| public Collection Implements org. Doc from org. All locks created by the last
| |
| getRefObjectId | back to summary |
|---|---|
| private static ObjectId getRefObjectId(Ref ref) | |
| handleShallowUnshallow | back to summary |
|---|---|
| private String handleShallowUnshallow(Set<ObjectId> advertisedShallowCommits, PacketLineIn input) throws IOException | |
| markAdvertised | back to summary |
|---|---|
| private void markAdvertised(AnyObjectId id) | |
| markCommon | back to summary |
|---|---|
| private void markCommon(RevObject obj, PacketLineIn. | |
| markReachable | back to summary |
|---|---|
| private void markReachable(Collection<Ref> want, Set<ObjectId> have, int maxTime) throws IOException | |
| markReachable | back to summary |
|---|---|
| private void markReachable(ObjectId id) | |
| markReachableRefTips | back to summary |
|---|---|
| private void markReachableRefTips(Collection<Ref> refsToMark) Marks commits reachable.
| |
| markRefsAdvertised | back to summary |
|---|---|
| private void markRefsAdvertised() | |
| maxTimeWanted | back to summary |
|---|---|
| private int maxTimeWanted(Collection<Ref> wants, boolean hasObjects) | |
| negotiate | back to summary |
|---|---|
| private void negotiate(ProgressMonitor monitor, boolean mayHaveShallow, Set<ObjectId> shallowCommits) throws IOException, CancelledException | |
| negotiateBegin | back to summary |
|---|---|
| private void negotiateBegin() throws IOException | |
| onReceivePack | back to summary |
|---|---|
| protected void onReceivePack() Notification event delivered just before the pack is received from the
network. This event can be used by RPC such as
| |
| readAcknowledgments | back to summary |
|---|---|
| private boolean readAcknowledgments(BasePackFetchConnection. Reads and processes acknowledgments, adding ACKed objects as "have"s to
the global state
| |
| receivePack | back to summary |
|---|---|
| private void receivePack(final ProgressMonitor monitor, OutputStream outputStream) throws IOException | |
| sendNextHaveBatch | back to summary |
|---|---|
| private boolean sendNextHaveBatch(BasePackFetchConnection. Sends the next batch of "have"s and terminates the
| |
| sendShallow | back to summary |
|---|---|
| private void sendShallow(Set<ObjectId> shallowCommits, PacketLineOut output) throws IOException | |
| sendWants | back to summary |
|---|---|
| private boolean sendWants(Collection<Ref> want, PacketLineOut p, boolean hasObjects) throws IOException | |
| setPackLockMessage | back to summary |
|---|---|
| public void setPackLockMessage(String message) Implements org. Doc from org. Set the lock message used when holding a pack out of garbage collection.
Callers that set a lock message must ensure they call
| |
| translateToLocalTips | back to summary |
|---|---|
| private Collection | |
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| private |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| CancelledException | back to summary |
|---|---|
| private CancelledException() | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final boolean | |
| pack-priv final int | |
| pack-priv final boolean |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | |
| pack-priv | FetchConfig(boolean
when true optimizes the pack size by deltafying base
object allowOfsDelta, int max haves to be sent per negotiation maxHaves, boolean if true uses the wanted refs instead of all refs as source
of the "have" list to send. useNegotiationTip)
|
| allowOfsDelta | back to summary |
|---|---|
| pack-priv final boolean allowOfsDelta | |
| maxHaves | back to summary |
|---|---|
| pack-priv final int maxHaves | |
| useNegotiationTip | back to summary |
|---|---|
| pack-priv final boolean useNegotiationTip | |
| FetchConfig | back to summary |
|---|---|
| pack-priv FetchConfig(Config c) | |
| FetchConfig | back to summary |
|---|---|
| pack-priv FetchConfig(boolean allowOfsDelta, int maxHaves) | |
| FetchConfig | back to summary |
|---|---|
pack-priv FetchConfig(boolean allowOfsDelta, int maxHaves, boolean useNegotiationTip)
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv boolean | |
| pack-priv long | |
| pack-priv long | |
| pack-priv long |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void |
| hadAcks | back to summary |
|---|---|
| pack-priv boolean hadAcks | |
| havesToSend | back to summary |
|---|---|
| pack-priv long havesToSend | |
| havesTotal | back to summary |
|---|---|
| pack-priv long havesTotal | |
| havesWithoutAck | back to summary |
|---|---|
| pack-priv long havesWithoutAck | |
| FetchStateV2 | back to summary |
|---|---|
| private FetchStateV2() | |
| incHavesToSend | back to summary |
|---|---|
| pack-priv void incHavesToSend(boolean statelessRPC) | |