Documentation
¶
Overview ¶
Package packp implements encoding and decoding of the Git packfile protocol messages.
Index ¶
- Variables
- func DecodeListV2(r io.Reader, l *capability.List) (int, error)
- func EncodeListV2(w io.Writer, l *capability.List) error
- func NewErrUnexpectedData(msg string, data []byte) error
- func ResolveHeadFromHashHeuristic(head *plumbing.Reference, refs []*plumbing.Reference) *plumbing.Reference
- type ACK
- type ACKStatus
- type Acknowledgments
- type Action
- type AdvRefs
- func (a *AdvRefs) Decode(r io.Reader) error
- func (a *AdvRefs) Encode(w io.Writer) error
- func (a *AdvRefs) Head() (*plumbing.Reference, error)
- func (a *AdvRefs) IsEmpty() bool
- func (a *AdvRefs) ResolvedHead() (*plumbing.Reference, error)
- func (a *AdvRefs) ResolvedReferences() ([]*plumbing.Reference, error)
- type BlobLimitPrefix
- type CapabilityAdv
- type Command
- type CommandArgs
- type CommandRequest
- type CommandStatus
- type CommandStatusErr
- type Decoder
- type DepthRequest
- type Encoder
- type ErrUnexpectedData
- type FetchArgs
- type FetchOutput
- type Filter
- type GitProtoRequest
- type InfoRefs
- type LsRefsArgs
- type LsRefsOutput
- type MalformedResponseError
- type PackfileURIs
- type PushOptions
- type ReportStatus
- type ServerResponse
- type ShallowInfo
- type ShallowUpdate
- type SmartReply
- type UnpackStatusErr
- type UpdateRequests
- type UploadHaves
- type UploadRequest
- type WantedRefs
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyAdvRefs is returned by Decode if it gets an empty advertised // references message. ErrEmptyAdvRefs = errors.New("empty advertised-ref message") // ErrEmptyInput is returned by Decode if the input is empty. ErrEmptyInput = errors.New("empty input") )
var ( ErrEmptyCommands = errors.New("commands cannot be empty") ErrMalformedCommand = errors.New("malformed command") )
Errors returned by the updreq package.
var ErrDeepenMutuallyExclusive = errors.New("deepen and deepen-since (or deepen-not) cannot be used together")
ErrDeepenMutuallyExclusive is returned when a request contains both deepen and deepen-since/deepen-not specifications.
var (
ErrEmpty = errors.New("empty update-request message")
)
Decode errors.
var ErrInvalidGitProtoRequest = fmt.Errorf("invalid git protocol request")
ErrInvalidGitProtoRequest is returned by Decode if the input is not a valid git protocol request.
var ErrInvalidPushOption = errors.New("invalid push option")
ErrInvalidPushOption is returned when a push option contains invalid characters.
var ErrInvalidSmartReply = errors.New("invalid smart reply")
ErrInvalidSmartReply is returned when a SmartReply is invalid.
var ErrNilWriter = fmt.Errorf("nil writer")
ErrNilWriter is returned when a nil writer is passed to the encoder.
var ErrUnsupportedObjectFilterType = errors.New("unsupported object filter type")
ErrUnsupportedObjectFilterType is returned when the filter type is not supported.
Functions ¶
func DecodeListV2 ¶
DecodeListV2 reads capabilities in v2 format from a pkt-line stream. It reads pkt-lines until flush-pkt, delim-pkt, or EOF, appending each parsed capability to the list. It returns the terminating packet length (pktline.Flush, pktline.Delim, or pktline.ResponseEnd) so the caller knows what terminated the capability list.
func EncodeListV2 ¶
func EncodeListV2(w io.Writer, l *capability.List) error
EncodeListV2 writes capabilities in v2 format: one capability per pkt-line. Each capability is written as "key\n" or "key=value\n" or "key=v1 v2\n". The caller is responsible for writing the terminating packet (flush-pkt or delim-pkt) after the last capability.
func NewErrUnexpectedData ¶
NewErrUnexpectedData returns a new ErrUnexpectedData containing the data and the message given
func ResolveHeadFromHashHeuristic ¶
func ResolveHeadFromHashHeuristic(head *plumbing.Reference, refs []*plumbing.Reference) *plumbing.Reference
ResolveHeadFromHashHeuristic converts a detached HEAD (a HashReference) into a SymbolicReference pointing to the branch that shares its hash, scanning refs. It is shared by the v0/v1 advertisement resolution and the Protocol v2 ls-refs path, so a detached remote HEAD still yields a symbolic local HEAD on clone, matching reference git's pre-symref heuristic:
- Prefer refs/heads/master when it has the same hash as HEAD.
- Otherwise pick the alphabetically-first non-peeled ref with that hash.
- If nothing matches, HEAD is returned unchanged.
Types ¶
type ACK ¶
ACK represents an object acknowledgement. A status can be zero when the response doesn't support multi_ack and multi_ack_detailed capabilities.
type Acknowledgments ¶
type Acknowledgments struct {
// ACKs is the list of common object IDs acknowledged by the server.
// Empty list means the server found no common objects (NAK).
ACKs []plumbing.Hash
// Ready indicates the server is ready to send a packfile after the
// acknowledgments section. For stream transports, ready is implied and
// this field is always true.
Ready bool
}
Acknowledgments represents the server response to a v2 fetch command's acknowledgments section. It is used by the transport layer to determine which objects the server has in common with the client.
type AdvRefs ¶
type AdvRefs struct {
// Version is the protocol version of the advertisement. The only acceptable
// values are V0 and V1; any other value is invalid. Decode parses it from
// the leading "version" pkt-line (absent for V0) and Encode emits that line
// from it. Within the transport it is set from the version the handshake
// negotiated (DiscoverVersion), which is the single source of truth.
Version protocol.Version
// Capabilities are the capabilities.
Capabilities capability.List
// References are the hash references, including HEAD and peeled refs
// (whose names end in ^{}). They are stored in wire order.
References []*plumbing.Reference
// Shallows are the shallow object ids.
Shallows []plumbing.Hash
}
AdvRefs values represent the information transmitted on an advertised-refs message. The zero value is safe to use; References and Shallows can be populated via append.
func (*AdvRefs) Decode ¶
Decode reads the next advertised-refs message form its input and stores it in the AdvRefs.
func (*AdvRefs) Encode ¶
Encode writes the AdvRefs encoding to a writer.
All the payloads will end with a newline character. Capabilities, references and shallows are written in alphabetical order, except for peeled references that always follow their corresponding references.
func (*AdvRefs) Head ¶
Head returns the HEAD reference. It checks the first reference in References (HEAD is always first on the wire) before scanning the rest.
func (*AdvRefs) ResolvedHead ¶
ResolvedHead returns HEAD as a SymbolicReference when possible. If the symref capability is present it is used; otherwise the heuristic described in resolvedHeadFromHeuristic is applied. If HEAD cannot be resolved it is returned as-is (a HashReference). Returns ErrReferenceNotFound if HEAD is not present in References.
type BlobLimitPrefix ¶
type BlobLimitPrefix string
BlobLimitPrefix specifies the unit prefix for blob size limits.
const ( BlobLimitPrefixNone BlobLimitPrefix = "" BlobLimitPrefixKibi BlobLimitPrefix = "k" BlobLimitPrefixMebi BlobLimitPrefix = "m" BlobLimitPrefixGibi BlobLimitPrefix = "g" )
Blob limit prefix values.
type CapabilityAdv ¶
type CapabilityAdv struct {
// Version is the protocol version. Decode sets this to V2.
// Encode writes the version line when Version is V2.
Version protocol.Version
// Capabilities is the parsed list of server capabilities.
Capabilities capability.List
}
CapabilityAdv represents a protocol v2 server capability advertisement. It includes the version line and the capability lines that follow it.
In protocol v2, the server sends:
version 2\n agent=git/2.45.0\n ls-refs=unborn\n fetch=shallow wait-for-done filter\n 0000
Capabilities are one per line in "key" or "key=value" format, terminated by a flush packet. This differs from v0/v1 where capabilities are space-separated after a NUL byte on the first ref line.
func (*CapabilityAdv) Decode ¶
func (ca *CapabilityAdv) Decode(r io.Reader) error
Decode reads a v2 capability advertisement from a pkt-line stream. It expects the stream to start with the "version 2\n" line, followed by capability lines (one per line), terminated by a flush packet.
func (*CapabilityAdv) Encode ¶
func (ca *CapabilityAdv) Encode(w io.Writer) error
Encode writes a v2 capability advertisement to a pkt-line stream. It writes the "version N\n" line (where N is ca.Version), then each capability on its own line, and terminates with a flush packet. Encode returns an error if ca.Version is not V2.
type CommandArgs ¶
CommandArgs is the interface for v2 command-specific arguments.
type CommandRequest ¶
type CommandRequest struct {
Command string
Capabilities capability.List
Args CommandArgs
}
CommandRequest represents a v2 command request.
Wire format:
request = empty-request | command-request
empty-request = flush-pkt
command-request = command
capability-list
delim-pkt
command-args
flush-pkt
command = PKT-LINE("command=" key LF)
command-args = *command-specific-arg
An empty Command encodes as an empty request (a single flush-pkt). On decode, a flush-pkt as the first packet leaves Command empty.
type CommandStatus ¶
type CommandStatus struct {
ReferenceName plumbing.ReferenceName
Status string
}
CommandStatus is the status of a reference in a report status. See ReportStatus struct.
func (*CommandStatus) Error ¶
func (s *CommandStatus) Error() error
Error returns the error, if any.
type CommandStatusErr ¶
type CommandStatusErr struct {
ReferenceName plumbing.ReferenceName
Status string
}
CommandStatusErr is the error returned when the command status is not ok.
func (CommandStatusErr) Error ¶
func (e CommandStatusErr) Error() string
Error implements the error interface.
type Decoder ¶
Decoder is the interface implemented by an object that can decode itself from a io.Reader.
type DepthRequest ¶
type DepthRequest struct {
// Deepen limits the fetch to the given number of commits from the tip.
// Zero means no commit-based depth limit.
// Corresponds to "deepen <n>" in the protocol.
Deepen int
// DeepenSince limits the fetch to commits newer than the given time.
// Zero value means no time-based limit.
// Corresponds to "deepen-since <timestamp>" in the protocol.
DeepenSince time.Time
// DeepenNot excludes commits reachable from the named references.
// Multiple refs may be specified. Each emits a "deepen-not <ref>" line.
DeepenNot []string
}
DepthRequest specifies the depth constraints for a fetch request. The zero value means no depth constraint (infinite depth).
Commits cannot be combined with Since or NotRefs (git rejects it). Since and NotRefs may be combined to further refine the shallow boundary.
func (DepthRequest) IsZero ¶
func (d DepthRequest) IsZero() bool
IsZero returns true when no depth constraints are set.
type Encoder ¶
Encoder is the interface implemented by an object that can encode itself into a io.Writer.
type ErrUnexpectedData ¶
ErrUnexpectedData represents an unexpected data decoding a message
func (*ErrUnexpectedData) Error ¶
func (err *ErrUnexpectedData) Error() string
type FetchArgs ¶
type FetchArgs struct {
// Wants is the list of object IDs the client wants.
Wants []plumbing.Hash
// Haves is the list of object IDs the client already has.
Haves []plumbing.Hash
// Done indicates the client is done sending wants and haves.
// If false, the client may send additional want/have lines
// in subsequent request rounds (stateful transport only).
Done bool
// ThinPack requests a thin pack if the server supports it.
ThinPack bool
// NoProgress requests that the server suppress progress messages.
NoProgress bool
// IncludeTag requests that the server include tag objects.
IncludeTag bool
// OFSDelta requests that the server use OFS_DELTA objects.
OFSDelta bool
// Shallows is the list of shallow object IDs the client has.
Shallows []plumbing.Hash
// Deepen specifies the number of depth commits to fetch.
Deepen int
// DeepenRelative indicates that deepen is relative to the shallow boundary.
DeepenRelative bool
// DeepenSince specifies a time-based depth constraint.
DeepenSince time.Time
// DeepenNot specifies references to exclude from the shallow boundary.
DeepenNot []string
// Filter specifies a partial clone filter.
Filter Filter
// WaitForDone indicates that the client will wait for the server to send a
// done acknowledgment before sending additional want/have lines.
WaitForDone bool
}
FetchArgs represents the arguments for the v2 fetch command.
type FetchOutput ¶
type FetchOutput struct {
// Acknowledgments indicates the server sent an acknowledgments section.
Acknowledgments *Acknowledgments
// ShallowInfo indicates the server sent a shallow-info section.
ShallowInfo *ShallowInfo
// WantedRefs indicates the server sent a wanted-refs section.
WantedRefs *WantedRefs
// PackfileURIs indicates the server sent a packfile-uris section.
PackfileURIs *PackfileURIs
// Packfile reports whether a packfile section follows the metadata
// sections. When true, Decode leaves the reader positioned at the first
// packfile pkt-line so the caller can stream it, and Encode writes the
// "packfile" section header so the caller can write the packfile data.
// When false, the response is a negotiation round
// (acknowledgments flush-pkt) that carries no packfile.
Packfile bool
}
FetchOutput represents the server response to a v2 fetch command.
The response has explicit sections separated by delim-pkt:
acknowledgments\n ACK <oid>\n ready\n 0001 shallow-info\n shallow <oid>\n 0001 packfile\n <sideband packfile data> 0000
For HTTP, the transport layer consumes response-end (0002) after Decode returns.
func (*FetchOutput) Decode ¶
func (r *FetchOutput) Decode(rd io.Reader) error
Decode reads the v2 fetch response from a reader. The response has explicit sections separated by delim-pkt:
acknowledgments\n ACK <oid>\n ready\n 0001 shallow-info\n shallow <oid>\n 0001 packfile\n <sideband packfile data> 0000
A response is one of two shapes (gitprotocol-v2):
output = acknowledgments flush-pkt |
[acknowledgments delim-pkt] [shallow-info delim-pkt]
[wanted-refs delim-pkt] [packfile-uris delim-pkt]
packfile flush-pkt
When a metadata section ends with a flush-pkt (the first shape) the response is a negotiation round that carries no packfile, and Decode returns with Packfile set to false. When Decode reaches the "packfile" section header it sets Packfile to true and returns with the reader positioned at the first packfile pkt-line; Decode does not read the packfile data, leaving the caller to stream it (demultiplexing the sideband as needed).
For HTTP, the transport layer consumes response-end (0002) after Decode returns.
func (*FetchOutput) Encode ¶
func (r *FetchOutput) Encode(w io.Writer) error
Encode writes the v2 fetch response to a writer.
When Packfile is true, Encode writes the present metadata sections (acknowledgments, shallow-info, wanted-refs, packfile-uris), each terminated by a delim-pkt, followed by the "packfile" section header. The caller then streams the packfile data and writes the final flush-pkt.
When Packfile is false, the response is a negotiation round: Encode writes the acknowledgments section terminated by a flush-pkt and writes nothing else. In that case the acknowledgments section must be present and must not be ready, and no other metadata sections may be set.
type Filter ¶
type Filter string
Filter values enable the partial clone capability which causes the server to omit objects that match the filter.
See Git's documentation for more details.
func FilterBlobLimit ¶
func FilterBlobLimit(n uint64, prefix BlobLimitPrefix) Filter
FilterBlobLimit omits blobs of size at least n bytes (when prefix is BlobLimitPrefixNone), n kibibytes (when prefix is BlobLimitPrefixKibi), n mebibytes (when prefix is BlobLimitPrefixMebi) or n gibibytes (when prefix is BlobLimitPrefixGibi). n can be zero, in which case all blobs will be omitted.
func FilterCombine ¶
FilterCombine combines multiple Filter values together.
func FilterObjectType ¶
func FilterObjectType(t plumbing.ObjectType) (Filter, error)
FilterObjectType omits all objects which are not of the requested type t. Supported types are TagObject, CommitObject, TreeObject and BlobObject.
func FilterTreeDepth ¶
FilterTreeDepth omits all blobs and trees whose depth from the root tree is larger or equal to depth.
type GitProtoRequest ¶
type GitProtoRequest struct {
RequestCommand string
Pathname string
// Optional
Host string
// Optional
ExtraParams []string
}
GitProtoRequest is a command request for the git protocol. It is used to send the command, endpoint, and extra parameters to the remote. See https://git-scm.com/docs/pack-protocol#_git_transport
type InfoRefs ¶
type InfoRefs struct {
// References are the hash references, including peeled refs (whose
// names end in ^{}). They are stored in the order received from the
// server.
References []*plumbing.Reference
}
InfoRefs represents the information of the references advertised by an HTTP dumb server.
type LsRefsArgs ¶
LsRefsArgs represents the arguments for the v2 ls-refs command. It is encoded as the command-specific arguments and a flush-pkt in a v2 command request.
type LsRefsOutput ¶
LsRefsOutput represents the server response to an ls-refs command.
Each ref line has the format:
<oid> SP <refname> [SP symref-target:<target>] [SP peeled:<oid>]
or for unborn refs:
unborn SP <refname> SP symref-target:<target>
The response ends with a flush-pkt. For HTTP, response-end (0002) is consumed by the transport layer and not seen by Decode.
func (*LsRefsOutput) Decode ¶
func (r *LsRefsOutput) Decode(rd io.Reader) error
Decode reads ref lines until a flush-pkt.
func (*LsRefsOutput) Encode ¶
func (r *LsRefsOutput) Encode(w io.Writer) error
Encode writes the ls-refs response lines as pkt-lines following the v2 grammar: "<oid> SP <refname> [SP symref-target:<target>] [SP peeled:<oid>]", or "unborn SP <refname> SP symref-target:<target>" for an unborn HEAD. Peeled "^{}" entries are folded into their base ref's line as a peeled attribute, and a symbolic ref carries the resolved oid of its target when present. The caller is responsible for writing the flush-pkt after these lines.
type MalformedResponseError ¶
type MalformedResponseError struct {
Reason string
}
MalformedResponseError reports a server response that violates the gitprotocol-v2 grammar: a malformed pkt-line, an unrecognized line within a section, an unexpected/repeated/out-of-order section, or a section terminator that contradicts the response shape. It mirrors the situations where upstream fetch-pack.c calls die() on the response.
func (*MalformedResponseError) Error ¶
func (e *MalformedResponseError) Error() string
type PackfileURIs ¶
type PackfileURIs struct {
// URIs is the list of alternate URIs the server suggests for fetching the
// packfile.
URIs []string
}
PackfileURIs represents the server response to a v2 fetch command's packfile-uris section. It is used by the transport layer to determine which alternate URIs the server suggests for fetching the packfile.
type PushOptions ¶
type PushOptions struct {
Options []string
}
PushOptions represents a list of update request push-options.
See https://git-scm.com/docs/gitprotocol-pack#_reference_update_request_and_packfile_transfer
type ReportStatus ¶
type ReportStatus struct {
UnpackStatus string
CommandStatuses []*CommandStatus
}
ReportStatus is a report status message, as used in the git-receive-pack process whenever the 'report-status' capability is negotiated. The zero value is safe to use.
func (*ReportStatus) Decode ¶
func (s *ReportStatus) Decode(r io.Reader) error
Decode reads from the given reader and decodes a report-status message. It does not read more input than what is needed to fill the report status.
func (*ReportStatus) Encode ¶
func (s *ReportStatus) Encode(w io.Writer) error
Encode writes the report status to a writer.
func (*ReportStatus) Error ¶
func (s *ReportStatus) Error() error
Error returns the first error if any.
type ServerResponse ¶
type ServerResponse struct {
ACKs []ACK
}
ServerResponse object acknowledgement from upload-pack service
type ShallowInfo ¶
type ShallowInfo struct {
// Shallows is the list of shallow object IDs sent by the server.
Shallows []plumbing.Hash
// Unshallows is the list of object IDs that are no longer shallow.
Unshallows []plumbing.Hash
}
ShallowInfo represents the server response to a v2 fetch command's shallow-info section. It is used by the transport layer to update the client's shallow boundary after a fetch.
type ShallowUpdate ¶
ShallowUpdate represents shallow/unshallow updates during fetch.
type SmartReply ¶
type SmartReply struct {
Service string
}
SmartReply represents Git HTTP smart protocol service payload.
When sending a message over (smart) HTTP, you have to add a pktline before the whole thing with the following payload:
'# service=$servicename" LF
Moreover, some if not all, git HTTP smart servers will send a flush-pkt just after the first pkt-line.
type UnpackStatusErr ¶
type UnpackStatusErr struct {
Status string
}
UnpackStatusErr is the error returned when the report status is not ok.
func (UnpackStatusErr) Error ¶
func (e UnpackStatusErr) Error() string
Error implements the error interface.
type UpdateRequests ¶
type UpdateRequests struct {
Capabilities capability.List
Commands []*Command
Shallows []plumbing.Hash
}
UpdateRequests values represent reference upload requests. The zero value is safe to use; Commands and Shallows can be populated via append.
type UploadHaves ¶
UploadHaves is a message to signal the references that a client has in a upload-pack. Done is true when the client has sent a "done" message. Otherwise, it means that the client has more haves to send and this request was completed with a flush.
type UploadRequest ¶
type UploadRequest struct {
Capabilities capability.List
Wants []plumbing.Hash
Shallows []plumbing.Hash
Depth DepthRequest
Filter Filter
}
UploadRequest values represent the information transmitted on a upload-request message. The zero value is safe to use; Wants, Shallows and Capabilities can be populated via append.
type WantedRefs ¶
type WantedRefs struct {
// Refs is the list of references sent by the server.
Refs []*plumbing.Reference
}
WantedRefs represents the server response to a v2 fetch command's wanted-refs section. It is used by the transport layer to determine which references the server wants the client to have.