org.eclipse.jgit.transport

## Class UploadPack

- java.lang.Object
- - org.eclipse.jgit.transport.UploadPack

    public class UploadPack
    extends Object

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

### Nested Class Summary

Nested Classes
`static class` `UploadPack.AdvertisedRequestValidator` Validator corresponding to `UploadPack.RequestPolicy.ADVERTISED`.
`static class` `UploadPack.AnyRequestValidator` Validator corresponding to `UploadPack.RequestPolicy.ANY`.
`static class` `UploadPack.FirstLine` Data in the first line of a request, the line itself plus options.
`static class` `UploadPack.ReachableCommitRequestValidator` Validator corresponding to `UploadPack.RequestPolicy.REACHABLE_COMMIT`.
`static class` `UploadPack.ReachableCommitTipRequestValidator` Validator corresponding to `UploadPack.RequestPolicy.REACHABLE_COMMIT_TIP`.
`static class` `UploadPack.RequestPolicy` Policy the server uses to validate client requests
`static interface` `UploadPack.RequestValidator` Validator for client requests.
`static class` `UploadPack.TipRequestValidator` Validator corresponding to `UploadPack.RequestPolicy.TIP`.

### Constructor Summary

Constructors
Constructor and Description
`UploadPack(Repository copyFrom)` Create a new pack upload for an open repository.

### Method Summary

All Methods Instance Methods Concrete Methods
`Map<String,Ref>` `getAdvertisedRefs()` Get refs which were advertised to the client.
`AdvertiseRefsHook` `getAdvertiseRefsHook()`
`UploadPackLogger` `getLogger()`
`OutputStream` `getMessageOutputStream()`
`PackWriter.Statistics` `getPackStatistics()` Get the PackWriter's statistics if a pack was sent to the client.
`PreUploadHook` `getPreUploadHook()`
`RefFilter` `getRefFilter()`
`Repository` `getRepository()`
`UploadPack.RequestPolicy` `getRequestPolicy()`
`RevWalk` `getRevWalk()`
`int` `getTimeout()`
`boolean` `isBiDirectionalPipe()`
`boolean` `isSideBand()` Check whether the client expects a side-band stream.
`void` `sendAdvertisedRefs(RefAdvertiser adv)` Generate an advertisement of available refs and capabilities.
`void` `sendMessage(String what)` Send a message to the client, if it supports receiving them.
`void` `setAdvertisedRefs(Map<String,Ref> allRefs)` Set the refs advertised by this UploadPack.
`void` `setAdvertiseRefsHook(AdvertiseRefsHook advertiseRefsHook)` Set the hook used while advertising the refs to the client.
`void` `setBiDirectionalPipe(boolean twoWay)`
`void` `setLogger(UploadPackLogger logger)` Set the logger.
`void` `setPackConfig(PackConfig pc)` Set the configuration used by the pack generator.
`void` `setPreUploadHook(PreUploadHook hook)` Set the hook that controls how this instance will behave.
`void` `setRefFilter(RefFilter refFilter)` Set the filter used while advertising the refs to the client.
`void` `setRequestPolicy(UploadPack.RequestPolicy policy)`
`void` `setRequestValidator(UploadPack.RequestValidator validator)`
`void` `setTimeout(int seconds)` Set the timeout before willing to abort an IO call.
`void` `setTransferConfig(TransferConfig tc)`
`void` `upload(InputStream input, OutputStream output, OutputStream messages)` Execute the upload task on the socket.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### UploadPack

    public UploadPack(Repository copyFrom)

Create a new pack upload for an open repository.

Parameters:
  `copyFrom` - the source repository.

### Method Detail

#### getRepository

    public final Repository getRepository()

Returns:
  the repository this upload is reading from.

#### getRevWalk

    public final RevWalk getRevWalk()

Returns:
  the RevWalk instance used by this connection.

#### getAdvertisedRefs

    public final Map<String,Ref> getAdvertisedRefs()

Get refs which were advertised to the client.

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

#### setAdvertisedRefs

    public void setAdvertisedRefs(Map<String,Ref> allRefs)

Set the refs advertised by this UploadPack.

Intended to be called from a `PreUploadHook`.

Parameters:
  `allRefs` - 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.

#### getTimeout

    public int getTimeout()

Returns:
  timeout (in seconds) before aborting an IO operation.

#### setTimeout

    public void setTimeout(int seconds)

Set the timeout before willing to abort an IO call.

Parameters:
  `seconds` - number of seconds to wait (with no data transfer occurring) before aborting an IO read or write operation with the connected client.

#### isBiDirectionalPipe

    public boolean isBiDirectionalPipe()

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

#### setBiDirectionalPipe

    public void setBiDirectionalPipe(boolean twoWay)

Parameters:
  `twoWay` - 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.

#### getRequestPolicy

    public UploadPack.RequestPolicy getRequestPolicy()

Returns:
  policy used by the service to validate client requests, or null for a custom request validator.

#### setRequestPolicy

    public void setRequestPolicy(UploadPack.RequestPolicy policy)

Parameters:
  `policy` - the policy used to enforce validation of a client's want list. By default the policy is `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 `UploadPack.RequestPolicy.REACHABLE_COMMIT` or `UploadPack.RequestPolicy.REACHABLE_COMMIT_TIP` when callers have `setBiDirectionalPipe(boolean)` set to false. Overrides any policy specified in a `TransferConfig`.

#### setRequestValidator

    public void setRequestValidator(UploadPack.RequestValidator validator)

Parameters:
  `validator` - custom validator for client want list.
Since:
  3.1

#### getAdvertiseRefsHook

    public AdvertiseRefsHook getAdvertiseRefsHook()

Returns:
  the hook used while advertising the refs to the client

#### getRefFilter

    public RefFilter getRefFilter()

Returns:
  the filter used while advertising the refs to the client

#### setAdvertiseRefsHook

    public void setAdvertiseRefsHook(AdvertiseRefsHook advertiseRefsHook)

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

If the `AdvertiseRefsHook` chooses to call `setAdvertisedRefs(Map)`, only refs set by this hook and selected by the `RefFilter` will be shown to the client.

Parameters:
  `advertiseRefsHook` - the hook; may be null to show all refs.

#### setRefFilter

    public void setRefFilter(RefFilter refFilter)

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

Only refs allowed by this filter will be sent to the client. The filter is run against the refs specified by the `AdvertiseRefsHook` (if applicable). If null or not set, uses the filter implied by the `TransferConfig`.

Parameters:
  `refFilter` - the filter; may be null to show all refs.

#### getPreUploadHook

    public PreUploadHook getPreUploadHook()

Returns:
  the configured upload hook.

#### setPreUploadHook

    public void setPreUploadHook(PreUploadHook hook)

Set the hook that controls how this instance will behave.

Parameters:
  `hook` - the hook; if null no special actions are taken.

#### setPackConfig

    public void setPackConfig(PackConfig pc)

Set the configuration used by the pack generator.

Parameters:
  `pc` - configuration controlling packing parameters. If null the source repository's settings will be used.

#### setTransferConfig

    public void setTransferConfig(TransferConfig tc)

Parameters:
  `tc` - configuration controlling transfer options. If null the source repository's settings will be used.
Since:
  3.1

#### getLogger

    public UploadPackLogger getLogger()

Returns:
  the configured logger.

#### setLogger

    public void setLogger(UploadPackLogger logger)

Set the logger.

Parameters:
  `logger` - the logger instance. If null, no logging occurs.

#### isSideBand

    public boolean isSideBand()
                       throws RequestNotYetReadException

Check whether the client expects a side-band stream.

Returns:
  true if the client has advertised a side-band capability, false otherwise.
Throws:
  `RequestNotYetReadException` - if the client's request has not yet been read from the wire, so we do not know if they expect side-band. Note that the client may have already written the request, it just has not been read.

#### upload

    public void upload(InputStream input,
                       OutputStream output,
                       OutputStream messages)
                throws IOException

Execute the upload task on the socket.

Parameters:
  `input` - raw input to read client commands from. Caller must ensure the input is buffered, otherwise read performance may suffer.
  `output` - 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.
  `messages` - 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.
Throws:
  `IOException`

#### getPackStatistics

    public PackWriter.Statistics getPackStatistics()

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

Returns:
  statistics about pack output, if a pack was sent. Null if no pack was sent, such as during the negotation phase of a smart HTTP connection, or if the client was already up-to-date.
Since:
  3.0

#### sendAdvertisedRefs

    public void sendAdvertisedRefs(RefAdvertiser adv)
                            throws IOException,
                                   ServiceMayNotContinueException

Generate an advertisement of available refs and capabilities.

Parameters:
  `adv` - the advertisement formatter.
Throws:
  `IOException` - the formatter failed to write an advertisement.
  `ServiceMayNotContinueException` - the hook denied advertisement.

#### sendMessage

    public void sendMessage(String what)

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

If the client doesn't support receiving messages, the message will be discarded, with no other indication to the caller or to the client.

Parameters:
  `what` - string describing the problem identified by the hook. The string must not end with an LF, and must not contain an LF.
Since:
  3.1

#### getMessageOutputStream

    public OutputStream getMessageOutputStream()

Returns:
  an underlying stream for sending messages to the client, or null.
Since:
  3.1