Movatterモバイル変換


[0]ホーム

URL:


Notice  The highest tagged major version isv5.

packp

package
v4.7.0+incompatibleLatest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2018 License:Apache-2.0Imports:18Imported by:0

Details

Repository

github.com/go-git/go-git

Links

Documentation

Index

Examples

Constants

View Source
const (CreateAction = "create"Update         = "update"Delete         = "delete"Invalid        = "invalid")

Variables

View Source
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"))
View Source
var (ErrEmptyCommands    =errors.New("commands cannot be empty")ErrMalformedCommand =errors.New("malformed command"))
View Source
var (ErrEmpty =errors.New("empty update-request message"))
View Source
var ErrUploadPackResponseNotDecoded =errors.New("upload-pack-response should be decoded")

ErrUploadPackResponseNotDecoded is returned if Read is called withoutdecoding first

Functions

funcNewErrUnexpectedData

func NewErrUnexpectedData(msgstring, data []byte)error

NewErrUnexpectedData returns a new ErrUnexpectedData containing the data andthe message given

Types

typeAction

type Actionstring

typeAdvRefs

type AdvRefs struct {// Prefix stores prefix payloads.//// When using this message over (smart) HTTP, you have to add a pktline// before the whole thing with the following payload://// '# service=$servicename" LF//// Moreover, some (all) git HTTP smart servers will send a flush-pkt// just after the first pkt-line.//// To accommodate both situations, the Prefix field allow you to store// any data you want to send before the actual pktlines.  It will also// be filled up with whatever is found on the line.Prefix [][]byte// Head stores the resolved HEAD reference if present.// This can be present with git-upload-pack, not with git-receive-pack.Head *plumbing.Hash// Capabilities are the capabilities.Capabilities *capability.List// References are the hash references.References map[string]plumbing.Hash// Peeled are the peeled hash references.Peeled map[string]plumbing.Hash// Shallows are the shallow object ids.Shallows []plumbing.Hash}

AdvRefs values represent the information transmitted on anadvertised-refs message. Values from this type are not zero-valuesafe, use the New function instead.

funcNewAdvRefs

func NewAdvRefs() *AdvRefs

NewAdvRefs returns a pointer to a new AdvRefs value, ready to be used.

func (*AdvRefs)AddReference

func (a *AdvRefs) AddReference(r *plumbing.Reference)error

func (*AdvRefs)AllReferences

func (a *AdvRefs) AllReferences() (memory.ReferenceStorage,error)

func (*AdvRefs)Decode

func (a *AdvRefs) Decode(rio.Reader)error

Decode reads the next advertised-refs message form its input andstores it in the AdvRefs.

Example
// Here is a raw advertised-ref message.raw := "" +"0065a6930aaee06755d1bdcfd943fbf614e4d92bb0c7 HEAD\x00multi_ack ofs-delta symref=HEAD:/refs/heads/master\n" +"003fa6930aaee06755d1bdcfd943fbf614e4d92bb0c7 refs/heads/master\n" +"00441111111111111111111111111111111111111111 refs/tags/v2.6.11-tree\n" +"00475555555555555555555555555555555555555555 refs/tags/v2.6.11-tree^{}\n" +"0035shallow 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c\n" +"0000"// Use the raw message as our input.input := strings.NewReader(raw)// Decode the input into a newly allocated AdvRefs value.ar := NewAdvRefs()_ = ar.Decode(input) // error check ignored for brevity// Do something interesting with the AdvRefs, e.g. print its contents.fmt.Println("head =", ar.Head)fmt.Println("capabilities =", ar.Capabilities.String())fmt.Println("...")fmt.Println("shallows =", ar.Shallows)
Output:head = a6930aaee06755d1bdcfd943fbf614e4d92bb0c7capabilities = multi_ack ofs-delta symref=HEAD:/refs/heads/master...shallows = [5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c]

func (*AdvRefs)Encode

func (a *AdvRefs) Encode(wio.Writer)error

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 forpeeled references that always follow their corresponding references.

Example
// Create an AdvRefs with the contents you want...ar := NewAdvRefs()// ...add a hash for the HEAD...head := plumbing.NewHash("1111111111111111111111111111111111111111")ar.Head = &head// ...add some server capabilities...ar.Capabilities.Add(capability.MultiACK)ar.Capabilities.Add(capability.OFSDelta)ar.Capabilities.Add(capability.SymRef, "HEAD:/refs/heads/master")// ...add a couple of references...ar.References["refs/heads/master"] = plumbing.NewHash("2222222222222222222222222222222222222222")ar.References["refs/tags/v1"] = plumbing.NewHash("3333333333333333333333333333333333333333")// ...including a peeled ref...ar.Peeled["refs/tags/v1"] = plumbing.NewHash("4444444444444444444444444444444444444444")// ...and finally add a shallowar.Shallows = append(ar.Shallows, plumbing.NewHash("5555555555555555555555555555555555555555"))// Encode the packpContents to a bytes.Buffer.// You can encode into stdout too, but you will not be able// see the '\x00' after "HEAD".var buf bytes.Buffer_ = ar.Encode(&buf) // error checks ignored for brevity// Print the contents of the buffer as a quoted string.// Printing is as a non-quoted string will be prettier but you// will miss the '\x00' after "HEAD".fmt.Printf("%q", buf.String())
Output:"00651111111111111111111111111111111111111111 HEAD\x00multi_ack ofs-delta symref=HEAD:/refs/heads/master\n003f2222222222222222222222222222222222222222 refs/heads/master\n003a3333333333333333333333333333333333333333 refs/tags/v1\n003d4444444444444444444444444444444444444444 refs/tags/v1^{}\n0035shallow 5555555555555555555555555555555555555555\n0000"

typeCommand

type Command struct {Nameplumbing.ReferenceNameOldplumbing.HashNewplumbing.Hash}

func (*Command)Action

func (c *Command) Action()Action

typeCommandStatus

type CommandStatus struct {ReferenceNameplumbing.ReferenceNameStatusstring}

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.

typeDepth

type Depth interface {IsZero()bool// contains filtered or unexported methods}

Depth values stores the desired depth of the requested packfile: seeDepthCommit, DepthSince and DepthReference.

typeDepthCommits

type DepthCommitsint

DepthCommits values stores the maximum number of requested commits inthe packfile. Zero means infinite. A negative value will haveundefined consequences.

func (DepthCommits)IsZero

func (dDepthCommits) IsZero()bool

typeDepthReference

type DepthReferencestring

DepthReference requests only commits not to found in the specified reference.

func (DepthReference)IsZero

func (dDepthReference) IsZero()bool

typeDepthSince

type DepthSincetime.Time

DepthSince values requests only commits newer than the specified time.

func (DepthSince)IsZero

func (dDepthSince) IsZero()bool

typeErrUnexpectedData

type ErrUnexpectedData struct {MsgstringData []byte}

ErrUnexpectedData represents an unexpected data decoding a message

func (*ErrUnexpectedData)Error

func (err *ErrUnexpectedData) Error()string

typeReferenceUpdateRequest

type ReferenceUpdateRequest struct {Capabilities *capability.ListCommands     []*CommandShallow      *plumbing.Hash// Packfile contains an optional packfile reader.Packfileio.ReadCloser// Progress receives sideband progress messages from the serverProgresssideband.Progress}

ReferenceUpdateRequest values represent reference upload requests.Values from this type are not zero-value safe, use the New function instead.

funcNewReferenceUpdateRequest

func NewReferenceUpdateRequest() *ReferenceUpdateRequest

New returns a pointer to a new ReferenceUpdateRequest value.

funcNewReferenceUpdateRequestFromCapabilities

func NewReferenceUpdateRequestFromCapabilities(adv *capability.List) *ReferenceUpdateRequest

NewReferenceUpdateRequestFromCapabilities returns a pointer to a newReferenceUpdateRequest value, the request capabilities are filled with themost optimal ones, based on the adv value (advertised capabilities), theReferenceUpdateRequest contains no commands

It does set the following capabilities:

  • agent
  • report-status
  • ofs-delta
  • ref-delta
  • delete-refs

It leaves up to the user to add the following capabilities later:

  • atomic
  • ofs-delta
  • side-band
  • side-band-64k
  • quiet
  • push-cert

func (*ReferenceUpdateRequest)Decode

Decode reads the next update-request message form the reader and wr

func (*ReferenceUpdateRequest)Encode

Encode writes the ReferenceUpdateRequest encoding to the stream.

typeReportStatus

type ReportStatus struct {UnpackStatusstringCommandStatuses []*CommandStatus}

ReportStatus is a report status message, as used in the git-receive-packprocess whenever the 'report-status' capability is negotiated.

funcNewReportStatus

func NewReportStatus() *ReportStatus

NewReportStatus creates a new ReportStatus message.

func (*ReportStatus)Decode

func (s *ReportStatus) Decode(rio.Reader)error

Decode reads from the given reader and decodes a report-status message. Itdoes not read more input than what is needed to fill the report status.

func (*ReportStatus)Encode

func (s *ReportStatus) Encode(wio.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.

typeServerResponse

type ServerResponse struct {ACKs []plumbing.Hash}

ServerResponse object acknowledgement from upload-pack service

func (*ServerResponse)Decode

func (r *ServerResponse) Decode(reader *bufio.Reader, isMultiACKbool)error

Decode decodes the response into the struct, isMultiACK should be true, ifthe request was done with multi_ack or multi_ack_detailed capabilities.

func (*ServerResponse)Encode

func (r *ServerResponse) Encode(wio.Writer)error

Encode encodes the ServerResponse into a writer.

typeShallowUpdate

type ShallowUpdate struct {Shallows   []plumbing.HashUnshallows []plumbing.Hash}

func (*ShallowUpdate)Decode

func (r *ShallowUpdate) Decode(readerio.Reader)error

func (*ShallowUpdate)Encode

func (r *ShallowUpdate) Encode(wio.Writer)error

typeUploadHaves

type UploadHaves struct {Haves []plumbing.Hash}

UploadHaves is a message to signal the references that a client has in aupload-pack. Do not use this directly. Use UploadPackRequest request instead.

func (*UploadHaves)Encode

func (u *UploadHaves) Encode(wio.Writer, flushbool)error

Encode encodes the UploadHaves into the Writer. If flush is true, a flushcommand will be encoded at the end of the writer content.

typeUploadPackRequest

type UploadPackRequest struct {UploadRequestUploadHaves}

UploadPackRequest represents a upload-pack request.Zero-value is not safe, use NewUploadPackRequest instead.

funcNewUploadPackRequest

func NewUploadPackRequest() *UploadPackRequest

NewUploadPackRequest creates a new UploadPackRequest and returns a pointer.

funcNewUploadPackRequestFromCapabilities

func NewUploadPackRequestFromCapabilities(adv *capability.List) *UploadPackRequest

NewUploadPackRequestFromCapabilities creates a new UploadPackRequest andreturns a pointer. The request capabilities are filled with the most optiomalones, based on the adv value (advertaised capabilities), the UploadPackRequestit has no wants, haves or shallows and an infinite depth

func (*UploadPackRequest)IsEmpty

func (r *UploadPackRequest) IsEmpty()bool

IsEmpty a request if empty if Haves are contained in the Wants, or if Wantslength is zero

typeUploadPackResponse

type UploadPackResponse struct {ShallowUpdateServerResponse// contains filtered or unexported fields}

UploadPackResponse contains all the information responded by the upload-packservice, the response implements io.ReadCloser that allows to read thepackfile directly from it.

funcNewUploadPackResponse

func NewUploadPackResponse(req *UploadPackRequest) *UploadPackResponse

NewUploadPackResponse create a new UploadPackResponse instance, the requestbeing responded by the response is required.

funcNewUploadPackResponseWithPackfile

func NewUploadPackResponseWithPackfile(req *UploadPackRequest,pfio.ReadCloser) *UploadPackResponse

NewUploadPackResponseWithPackfile creates a new UploadPackResponse instance,and sets its packfile reader.

func (*UploadPackResponse)Close

func (r *UploadPackResponse) Close()error

Close the underlying reader, if any

func (*UploadPackResponse)Decode

func (r *UploadPackResponse) Decode(readerio.ReadCloser)error

Decode decodes all the responses sent by upload-pack service into the structand prepares it to read the packfile using the Read method

func (*UploadPackResponse)Encode

func (r *UploadPackResponse) Encode(wio.Writer) (errerror)

Encode encodes an UploadPackResponse.

func (*UploadPackResponse)Read

func (r *UploadPackResponse) Read(p []byte) (int,error)

Read reads the packfile data, if the request was done with any Sidebandcapability the content read should be demultiplexed. If the methods wasn'tcalled before the ErrUploadPackResponseNotDecoded will be return

typeUploadRequest

type UploadRequest struct {Capabilities *capability.ListWants        []plumbing.HashShallows     []plumbing.HashDepthDepth}

UploadRequest values represent the information transmitted on aupload-request message. Values from this type are not zero-valuesafe, use the New function instead.This is a low level type, use UploadPackRequest instead.

funcNewUploadRequest

func NewUploadRequest() *UploadRequest

NewUploadRequest returns a pointer to a new UploadRequest value, ready to beused. It has no capabilities, wants or shallows and an infinite depth. Pleasenote that to encode an upload-request it has to have at least one wanted hash.

funcNewUploadRequestFromCapabilities

func NewUploadRequestFromCapabilities(adv *capability.List) *UploadRequest

NewUploadRequestFromCapabilities returns a pointer to a new UploadRequestvalue, the request capabilities are filled with the most optiomal ones, basedon the adv value (advertaised capabilities), the UploadRequest generated ithas no wants or shallows and an infinite depth.

func (*UploadRequest)Decode

func (u *UploadRequest) Decode(rio.Reader)error

Decode reads the next upload-request form its input andstores it in the UploadRequest.

Example
// Here is a raw advertised-ref message.raw := "" +"005bwant 1111111111111111111111111111111111111111 ofs-delta symref=HEAD:/refs/heads/master\n" +"0032want 2222222222222222222222222222222222222222\n" +"0032want 3333333333333333333333333333333333333333\n" +"0035shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" +"0035shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" +"001cdeepen-since 1420167845\n" + // 2015-01-02 03:04:05 +0000 UTCpktline.FlushString// Use the raw message as our input.input := strings.NewReader(raw)// Create the Decoder reading from our input.d := newUlReqDecoder(input)// Decode the input into a newly allocated UlReq value.ur := NewUploadRequest()_ = d.Decode(ur) // error check ignored for brevity// Do something interesting with the UlReq, e.g. print its contents.fmt.Println("capabilities =", ur.Capabilities.String())fmt.Println("wants =", ur.Wants)fmt.Println("shallows =", ur.Shallows)switch depth := ur.Depth.(type) {case DepthCommits:fmt.Println("depth =", int(depth))case DepthSince:fmt.Println("depth =", time.Time(depth))case DepthReference:fmt.Println("depth =", string(depth))}
Output:capabilities = ofs-delta symref=HEAD:/refs/heads/masterwants = [1111111111111111111111111111111111111111 2222222222222222222222222222222222222222 3333333333333333333333333333333333333333]shallows = [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb]depth = 2015-01-02 03:04:05 +0000 UTC

func (*UploadRequest)Encode

func (u *UploadRequest) Encode(wio.Writer)error

Encode writes the UlReq encoding of u to the stream.

All the payloads will end with a newline character. Wants andshallows are sorted alphabetically. A depth of 0 means no depthrequest is sent.

Example
// Create an empty UlReq with the contents you want...ur := NewUploadRequest()// Add a couple of wantsur.Wants = append(ur.Wants, plumbing.NewHash("3333333333333333333333333333333333333333"))ur.Wants = append(ur.Wants, plumbing.NewHash("1111111111111111111111111111111111111111"))ur.Wants = append(ur.Wants, plumbing.NewHash("2222222222222222222222222222222222222222"))// And some capabilities you will like the server to useur.Capabilities.Add(capability.OFSDelta)ur.Capabilities.Add(capability.SymRef, "HEAD:/refs/heads/master")// Add a couple of shallowsur.Shallows = append(ur.Shallows, plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))ur.Shallows = append(ur.Shallows, plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))// And retrict the answer of the server to commits newer than "2015-01-02 03:04:05 UTC"since := time.Date(2015, time.January, 2, 3, 4, 5, 0, time.UTC)ur.Depth = DepthSince(since)// Create a new Encode for the stdout...e := newUlReqEncoder(os.Stdout)// ...and encode the upload-request to it._ = e.Encode(ur) // ignoring errors for brevity
Output:005bwant 1111111111111111111111111111111111111111 ofs-delta symref=HEAD:/refs/heads/master0032want 22222222222222222222222222222222222222220032want 33333333333333333333333333333333333333330035shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0035shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb001cdeepen-since 14201678450000

func (*UploadRequest)Validate

func (r *UploadRequest) Validate()error

Validate validates the content of UploadRequest, following the next rules:

  • Wants MUST have at least one reference
  • capability.Shallow MUST be present if Shallows is not empty
  • is a non-zero DepthCommits is given capability.Shallow MUST be present
  • is a DepthSince is given capability.Shallow MUST be present
  • is a DepthReference is given capability.DeepenNot MUST be present
  • MUST contain only maximum of one of capability.Sideband and capability.Sideband64k
  • MUST contain only maximum of one of capability.MultiACK and capability.MultiACKDetailed

Source Files

View all Source files

Directories

PathSynopsis
Package capability defines the server and client capabilities.
Package capability defines the server and client capabilities.
Package sideband implements a sideband mutiplex/demultiplexer
Package sideband implements a sideband mutiplex/demultiplexer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp