ulreq

package
v4.0.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ulreq implements encoding and decoding upload-request messages from a git-upload-pack command.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder reads and decodes AdvRef values from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

Will not read more data from r than necessary.

func (*Decoder) Decode

func (d *Decoder) Decode(v *UlReq) error

Decode reads the next upload-request form its input and stores it in the value pointed to by v.

Example
// Here is a raw advertised-ref message.
raw := "" +
	"005bwant 1111111111111111111111111111111111111111 ofs-delta sysref=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 UTC
	pktline.FlushString

// Use the raw message as our input.
input := strings.NewReader(raw)

// Create the Decoder reading from our input.
d := NewDecoder(input)

// Decode the input into a newly allocated UlReq value.
ur := New()
_ = 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 sysref=HEAD:/refs/heads/master
wants = [1111111111111111111111111111111111111111 2222222222222222222222222222222222222222 3333333333333333333333333333333333333333]
shallows = [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb]
depth = 2015-01-02 03:04:05 +0000 UTC

type Depth

type Depth interface {
	// contains filtered or unexported methods
}

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

type DepthCommits

type DepthCommits int

DepthCommits values stores the maximum number of requested commits in the packfile. Zero means infinite. A negative value will have undefined consecuences.

type DepthReference

type DepthReference string

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

type DepthSince

type DepthSince time.Time

DepthSince values requests only commits newer than the specified time.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

An Encoder writes UlReq values to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(v *UlReq) error

Encode writes the UlReq encoding of v to the stream.

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

Example
// Create an empty UlReq with the contents you want...
ur := New()

// Add a couple of wants
ur.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 use
ur.Capabilities.Add("sysref", "HEAD:/refs/heads/master")
ur.Capabilities.Add("ofs-delta")

// Add a couple of shallows
ur.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 := NewEncoder(os.Stdout)
// ...and encode the upload-request to it.
_ = e.Encode(ur) // ignoring errors for brevity
Output:

005bwant 1111111111111111111111111111111111111111 ofs-delta sysref=HEAD:/refs/heads/master
0032want 2222222222222222222222222222222222222222
0032want 3333333333333333333333333333333333333333
0035shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
0035shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
001cdeepen-since 1420167845
0000

type UlReq

type UlReq struct {
	Capabilities *packp.Capabilities
	Wants        []plumbing.Hash
	Shallows     []plumbing.Hash
	Depth        Depth
}

UlReq values represent the information transmitted on a upload-request message. Values from this type are not zero-value safe, use the New function instead.

func New

func New() *UlReq

New returns a pointer to a new UlReq value, ready to be used. It has no capabilities, wants or shallows and an infinite depth. Please note that to encode an upload-request it has to have at least one wanted hash.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL