lfs

package
v0.0.0-...-4d27c9e Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2016 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "0.5.1"

Variables

View Source
var (
	LargeSizeThreshold = 5 * 1024 * 1024
	TempDir            = filepath.Join(os.TempDir(), "git-lfs")
	UserAgent          string
	LocalWorkingDir    string
	LocalGitDir        string
	LocalMediaDir      string
	LocalLogDir        string
)
View Source
var (
	Config = NewConfig()
)
View Source
var (
	NotInARepositoryError = errors.New("Not in a repository")
)

Functions

func Batch

func Batch(objects []*ObjectResource) ([]*ObjectResource, *WrappedError)

func CopyWithCallback

func CopyWithCallback(writer io.Writer, reader io.Reader, totalSize int64, cb CopyCallback) (int64, error)

func DoHTTP

func DoHTTP(c *Configuration, req *http.Request) (*http.Response, error)

func DownloadCheck

func DownloadCheck(oid string) (*ObjectResource, *WrappedError)

func EmbedStructInJsonRawMessage

func EmbedStructInJsonRawMessage(in interface{}) (*json.RawMessage, error)

func EncodePointer

func EncodePointer(writer io.Writer, pointer *Pointer) (int, error)

func Environ

func Environ() []string

func ExtractStructFromJsonRawMessage

func ExtractStructFromJsonRawMessage(raw *json.RawMessage, out interface{}) error

Late-bind a method-specific structure from the raw message

func InRepo

func InRepo() bool

func InstallFilters

func InstallFilters() error

func InstallHooks

func InstallHooks(force bool) error

func LimitReadCloser

func LimitReadCloser(r io.Reader, sz int64) io.ReadCloser

Return an initialised LimitedReadCloser

func LocalMediaPath

func LocalMediaPath(sha string) (string, error)

func NewUploadable

func NewUploadable(oid, filename string, index, totalFiles int) (*Uploadable, *WrappedError)

NewUploadable builds the Uploadable from the given information.

func ObjectUrl

func ObjectUrl(endpoint Endpoint, oid string) (*url.URL, error)

func PointerClean

func PointerClean(reader io.Reader, size int64, cb CopyCallback) (*cleanedAsset, error)

func PointerSmudge

func PointerSmudge(writer io.Writer, ptr *Pointer, workingfile string, cb CopyCallback) error

func PointerSmudgeObject

func PointerSmudgeObject(ptr *Pointer, obj *ObjectResource, cb CopyCallback) error

PointerSmudgeObject uses a Pointer and ObjectResource to download the object to the media directory. It does not write the file to the working directory.

func ReleaseApiContext

func ReleaseApiContext(ctx ApiContext)

Release an API context for use by other callers later. You should call this sometime after GetApiContext once you are done with the context. It allows stateful contexts to re-use resources such as connections between subsequent operations.

func ResetTempDir

func ResetTempDir() error

func Shutdown

func Shutdown()

Shut down any cached or otherwise persistent structures

func ShutdownApiContexts

func ShutdownApiContexts()

Shut down any open API contexts

func Stack

func Stack() []byte

func TempFile

func TempFile(prefix string) (*os.File, error)

func UploadCheck

func UploadCheck(oidPath string) (*ObjectResource, *WrappedError)

Types

type AltConfig

type AltConfig struct {
	Remote map[string]*struct {
		Media string
	}

	Media struct {
		Url string
	}
}

type ApiContext

type ApiContext interface {
	// Get the endpoint this context was constructed from
	Endpoint() Endpoint
	// Close the context & any resources it's using
	Close() error

	// Download a single object, return reader for data, size and any error
	// Essentially the same as calling DownloadCheck() then DownloadObject()
	Download(oid string) (io.ReadCloser, int64, *WrappedError)
	// Check whether an object is available for download and return an object resource if so
	DownloadCheck(oid string) (*ObjectResource, *WrappedError)
	// Download a single object from an already identified resource from DownloadCheck(), return reader for data, size and any error
	DownloadObject(obj *ObjectResource) (io.ReadCloser, int64, *WrappedError)
	// Check whether an upload would be accepted for an object and return the resource to use if so
	UploadCheck(oid string, sz int64) (*ObjectResource, *WrappedError)
	// Perform the actual upload of an object having identified it will be accepted and the resource to use
	UploadObject(o *ObjectResource, reader io.Reader) *WrappedError
	// Perform a batch request for a number of objects to determine what can be uploaded/downloaded
	Batch(objects []*ObjectResource) ([]*ObjectResource, *WrappedError)
}

An abstract interface providing state & resource management for a specific Endpoint across potentially multiple requests

func GetApiContext

func GetApiContext(endpoint Endpoint) ApiContext

Return an API context appropriate for a given Endpoint Once this context is returned it may be made *unavailable* to subsequent callers, until ReleaseApiContext is called. This is to ensure that contexts which maintain state are only available to be used by one goroutine at a time.

func NewHttpApiContext

func NewHttpApiContext(endpoint Endpoint) ApiContext

func NewSshApiContext

func NewSshApiContext(endpoint Endpoint) ApiContext

Below here is the pure-SSH API interface The API is basically the same except there's no need for hypermedia links

type ApiContextReadCloser

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

ReadCloser which will release an ApiContext when reading is finished

func (*ApiContextReadCloser) Close

func (self *ApiContextReadCloser) Close() error

func (*ApiContextReadCloser) Read

func (self *ApiContextReadCloser) Read(p []byte) (int, error)

type BatchRequest

type BatchRequest struct {
	Objects []BatchRequestObject `json:"objects"`
}

type BatchRequestObject

type BatchRequestObject struct {
	Oid  string `json:"oid"`
	Size int64  `json:"size"`
}

type BatchResponse

type BatchResponse struct {
	Results []BatchResponseObject `json:"results"`
}

type BatchResponseObject

type BatchResponseObject struct {
	Oid    string `json:"oid"`
	Action string `json:"action"`
	Size   int64  `json:"size"`
}

type CallbackReader

type CallbackReader struct {
	C         CopyCallback
	TotalSize int64
	ReadSize  int64
	io.Reader
}

func (*CallbackReader) Read

func (w *CallbackReader) Read(p []byte) (int, error)

type CleanedPointerError

type CleanedPointerError struct {
	Bytes []byte
}

func (*CleanedPointerError) Error

func (e *CleanedPointerError) Error() string

type ClientError

type ClientError struct {
	Message          string `json:"message"`
	DocumentationUrl string `json:"documentation_url,omitempty"`
	RequestId        string `json:"request_id,omitempty"`
}

func (*ClientError) Error

func (e *ClientError) Error() string

type Configuration

type Configuration struct {
	CurrentRemote string
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig() *Configuration

func (*Configuration) BatchTransfer

func (c *Configuration) BatchTransfer() bool

func (*Configuration) ConcurrentTransfers

func (c *Configuration) ConcurrentTransfers() int

func (*Configuration) Endpoint

func (c *Configuration) Endpoint() Endpoint

func (*Configuration) GitConfig

func (c *Configuration) GitConfig(key string) (string, bool)

func (*Configuration) HttpClient

func (c *Configuration) HttpClient() *http.Client

func (*Configuration) ObjectUrl

func (c *Configuration) ObjectUrl(oid string) (*url.URL, error)

func (*Configuration) RemoteEndpoint

func (c *Configuration) RemoteEndpoint(remote string) Endpoint

func (*Configuration) Remotes

func (c *Configuration) Remotes() []string

func (*Configuration) SetConfig

func (c *Configuration) SetConfig(key, value string)

type CopyCallback

type CopyCallback func(totalSize int64, readSoFar int64, readSinceLast int) error

func CopyCallbackFile

func CopyCallbackFile(event, filename string, index, totalFiles int) (CopyCallback, *os.File, error)

type CredentialCmd

type CredentialCmd struct {
	SubCommand string
	*exec.Cmd
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(input Creds, subCommand string) *CredentialCmd

func (*CredentialCmd) Credentials

func (c *CredentialCmd) Credentials() Creds

func (*CredentialCmd) StdoutString

func (c *CredentialCmd) StdoutString() string

type Creds

type Creds map[string]string

func (Creds) Buffer

func (c Creds) Buffer() *bytes.Buffer

type DownloadCheckRequest

type DownloadCheckRequest struct {
	Oid string `json:"oid"`
}

type DownloadCheckResponse

type DownloadCheckResponse struct {
	Size int64 `json:"size"`
}

type DownloadRequest

type DownloadRequest struct {
	Oid  string `json:"oid"`
	Size int64  `json:"size"`
}

type Downloadable

type Downloadable struct {
	Pointer *WrappedPointer
	// contains filtered or unexported fields
}

func NewDownloadable

func NewDownloadable(p *WrappedPointer) *Downloadable

func (*Downloadable) Check

func (d *Downloadable) Check() (*ObjectResource, *WrappedError)

func (*Downloadable) Object

func (d *Downloadable) Object() *ObjectResource

func (*Downloadable) Oid

func (d *Downloadable) Oid() string

func (*Downloadable) SetObject

func (d *Downloadable) SetObject(o *ObjectResource)

func (*Downloadable) Size

func (d *Downloadable) Size() int64

func (*Downloadable) Transfer

func (d *Downloadable) Transfer(cb CopyCallback) *WrappedError

type Endpoint

type Endpoint struct {
	Url            string
	SshUserAndHost string
	SshPath        string
	SshPort        string
}

func NewEndpoint

func NewEndpoint(urlstr string) Endpoint

type ExitRequest

type ExitRequest struct {
}

type ExitResponse

type ExitResponse struct {
}

type HookExists

type HookExists struct {
	Name     string
	Path     string
	Contents string
}

func (*HookExists) Error

func (e *HookExists) Error() string

type HttpApiContext

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

HTTP specific API contect implementation HTTP implementation of ApiContext

func (*HttpApiContext) Batch

func (self *HttpApiContext) Batch(objects []*ObjectResource) ([]*ObjectResource, *WrappedError)

func (*HttpApiContext) Close

func (*HttpApiContext) Close() error

func (*HttpApiContext) Download

func (self *HttpApiContext) Download(oid string) (io.ReadCloser, int64, *WrappedError)

func (*HttpApiContext) DownloadCheck

func (self *HttpApiContext) DownloadCheck(oid string) (*ObjectResource, *WrappedError)

func (*HttpApiContext) DownloadObject

func (self *HttpApiContext) DownloadObject(obj *ObjectResource) (io.ReadCloser, int64, *WrappedError)

func (*HttpApiContext) Endpoint

func (self *HttpApiContext) Endpoint() Endpoint

func (*HttpApiContext) UploadCheck

func (self *HttpApiContext) UploadCheck(oid string, sz int64) (*ObjectResource, *WrappedError)

func (*HttpApiContext) UploadObject

func (self *HttpApiContext) UploadObject(o *ObjectResource, reader io.Reader) *WrappedError

type JsonRequest

type JsonRequest struct {
	Id     int    `json:"id"`
	Method string `json:"method"`
	// RawMessage allows us to store late-resolved, message-specific nested types
	// requires an extra couple of steps though; even though RawMessage is a []byte, it's not
	// JSON itself. You need to convert JSON to/from RawMessage as well as JSON to/from the structure
	// - see RawMessage's own UnmarshalJSON/MarshalJSON for this extra step
	Params *json.RawMessage `json:"params"`
}

Utility methods for JSON-RPC style request/response over SSH This works for any persistent connection and could be used elsewhere too but for now, localised Note *not* using net/rpc and net/rpc/jsonrpc because we want more control golang's rpc requires a certain method format (Object.Method) and also doesn't easily support interleaving with raw byte streams like we need to. as per http://www.jsonrpc.org/specification

func NewJsonRequest

func NewJsonRequest(method string, params interface{}) (*JsonRequest, error)

type JsonResponse

type JsonResponse struct {
	Id    int         `json:"id"`
	Error interface{} `json:"error"`
	// RawMessage allows us to store late-resolved, message-specific nested types
	// requires an extra couple of steps though; even though RawMessage is a []byte, it's not
	// JSON itself. You need to convert JSON to/from RawMessage as well as JSON to/from the structure
	// - see RawMessage's own UnmarshalJSON/MarshalJSON for this extra step
	Result *json.RawMessage `json:"result"`
}

func NewJsonErrorResponse

func NewJsonErrorResponse(id int, err interface{}) *JsonResponse

func NewJsonResponse

func NewJsonResponse(id int, result interface{}) (*JsonResponse, error)

type LimitedReadCloser

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

A wrapper around a reader for a multi-purpose stream which reads exactly a number of bytes before returning EOF, so that 'read to end' and 'close' just read the fixed number of bytes and leaves the stream available for subsequent use by others This is just like io.LimitedReader but responds to Close() too

func (*LimitedReadCloser) Close

func (self *LimitedReadCloser) Close() error

func (*LimitedReadCloser) Read

func (self *LimitedReadCloser) Read(p []byte) (n int, err error)

type ObjectResource

type ObjectResource struct {
	Oid   string                   `json:"oid,omitempty"`
	Size  int64                    `json:"size"`
	Links map[string]*linkRelation `json:"_links,omitempty"`
}

func (*ObjectResource) CanDownload

func (o *ObjectResource) CanDownload() bool

func (*ObjectResource) CanUpload

func (o *ObjectResource) CanUpload() bool

func (*ObjectResource) NewRequest

func (o *ObjectResource) NewRequest(ctx *HttpApiContext, relation, method string) (*http.Request, Creds, error)

func (*ObjectResource) Rel

func (o *ObjectResource) Rel(name string) (*linkRelation, bool)

type Pointer

type Pointer struct {
	Version string
	Oid     string
	Size    int64
	OidType string
}

func DecodeFrom

func DecodeFrom(reader io.Reader) ([]byte, *Pointer, error)

func DecodePointer

func DecodePointer(reader io.Reader) (*Pointer, error)

func NewPointer

func NewPointer(oid string, size int64) *Pointer

func (*Pointer) Encode

func (p *Pointer) Encode(writer io.Writer) (int, error)

func (*Pointer) Encoded

func (p *Pointer) Encoded() string

func (*Pointer) Smudge

func (p *Pointer) Smudge(writer io.Writer, workingfile string, cb CopyCallback) error

type ServerVersionRequest

type ServerVersionRequest struct {
}

type ServerVersionResponse

type ServerVersionResponse struct {
	Major int `json:"major"`
	Minor int `json:"minor"`
	Patch int `json:"patch"`
}

type SmudgeError

type SmudgeError struct {
	Oid      string
	Filename string
	*WrappedError
}

type SshApiContext

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

func NewManualSSHApiContext

func NewManualSSHApiContext(in io.WriteCloser, out io.ReadCloser) *SshApiContext

Create a manually initialised API context where I/O is already running

func (*SshApiContext) Batch

func (self *SshApiContext) Batch(objects []*ObjectResource) ([]*ObjectResource, *WrappedError)

func (*SshApiContext) Close

func (self *SshApiContext) Close() error

func (*SshApiContext) Download

func (self *SshApiContext) Download(oid string) (io.ReadCloser, int64, *WrappedError)

func (*SshApiContext) DownloadCheck

func (self *SshApiContext) DownloadCheck(oid string) (*ObjectResource, *WrappedError)

func (*SshApiContext) DownloadObject

func (self *SshApiContext) DownloadObject(obj *ObjectResource) (io.ReadCloser, int64, *WrappedError)

func (*SshApiContext) Endpoint

func (self *SshApiContext) Endpoint() Endpoint

func (*SshApiContext) ServerVersion

func (self *SshApiContext) ServerVersion() (major, minor, patch int, e error)

Get the version of the SSH server

func (*SshApiContext) UploadCheck

func (self *SshApiContext) UploadCheck(oid string, sz int64) (*ObjectResource, *WrappedError)

func (*SshApiContext) UploadObject

func (self *SshApiContext) UploadObject(o *ObjectResource, content io.Reader) *WrappedError

type StatefulApiContextHolder

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

Holds limited number of stateful ApiContext instances & parcels them out via queues

type TransferQueue

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

TransferQueue provides a queue that will allow concurrent transfers.

func NewDownloadQueue

func NewDownloadQueue(workers, files int) *TransferQueue

NewDownloadQueue builds a DownloadQueue, allowing `workers` concurrent downloads.

func NewUploadQueue

func NewUploadQueue(workers, files int) *TransferQueue

NewUploadQueue builds an UploadQueue, allowing `workers` concurrent uploads.

func (*TransferQueue) Add

func (q *TransferQueue) Add(t Transferable)

Add adds a Transferable to the transfer queue.

func (*TransferQueue) Errors

func (q *TransferQueue) Errors() []*WrappedError

Errors returns any errors encountered during transfer.

func (*TransferQueue) Process

func (q *TransferQueue) Process()

Process starts the transfer queue and displays a progress bar. Process will do individual or batch transfers depending on the Config.BatchTransfer() value. Process will transfer files sequentially or concurrently depending on the Concig.ConcurrentTransfers() value.

func (*TransferQueue) Watch

func (q *TransferQueue) Watch() chan string

Watch returns a channel where the queue will write the OID of each transfer as it completes. The channel will be closed when the queue finishes processing.

type Transferable

type Transferable interface {
	Check() (*ObjectResource, *WrappedError)
	Transfer(CopyCallback) *WrappedError
	Object() *ObjectResource
	Oid() string
	Size() int64
	SetObject(*ObjectResource)
}

type UploadCompleteResponse

type UploadCompleteResponse struct {
	ReceivedOk bool `json:"receivedOk"`
}

type UploadRequest

type UploadRequest struct {
	Oid  string `json:"oid"`
	Size int64  `json:"size"`
}

type UploadResponse

type UploadResponse struct {
	OkToSend bool `json:"okToSend"`
}

type Uploadable

type Uploadable struct {
	OidPath  string
	Filename string
	CB       CopyCallback
	// contains filtered or unexported fields
}

Uploadable describes a file that can be uploaded.

func (*Uploadable) Check

func (u *Uploadable) Check() (*ObjectResource, *WrappedError)

func (*Uploadable) Object

func (u *Uploadable) Object() *ObjectResource

func (*Uploadable) Oid

func (u *Uploadable) Oid() string

func (*Uploadable) SetObject

func (u *Uploadable) SetObject(o *ObjectResource)

func (*Uploadable) Size

func (u *Uploadable) Size() int64

func (*Uploadable) Transfer

func (u *Uploadable) Transfer(cb CopyCallback) *WrappedError

type WrappedError

type WrappedError struct {
	Err     error
	Message string
	Panic   bool
	// contains filtered or unexported fields
}

func Download

func Download(oid string) (io.ReadCloser, int64, *WrappedError)

func DownloadObject

func DownloadObject(obj *ObjectResource) (io.ReadCloser, int64, *WrappedError)

func Error

func Error(err error) *WrappedError

func Errorf

func Errorf(err error, format string, args ...interface{}) *WrappedError

func UploadObject

func UploadObject(o *ObjectResource, cb CopyCallback) *WrappedError

func (*WrappedError) Context

func (e *WrappedError) Context() map[string]string

func (*WrappedError) Del

func (e *WrappedError) Del(key string)

func (*WrappedError) Error

func (e *WrappedError) Error() string

func (*WrappedError) Errorf

func (e *WrappedError) Errorf(format string, args ...interface{})

func (*WrappedError) Get

func (e *WrappedError) Get(key string) string

func (*WrappedError) InnerError

func (e *WrappedError) InnerError() string

func (*WrappedError) Set

func (e *WrappedError) Set(key, value string)

func (*WrappedError) Stack

func (e *WrappedError) Stack() []byte

type WrappedPointer

type WrappedPointer struct {
	Sha1    string
	Name    string
	SrcName string
	Size    int64
	Status  string
	*Pointer
}

WrappedPointer wraps a pointer.Pointer and provides the git sha1 and the file name associated with the object, taken from the rev-list output.

func ScanIndex

func ScanIndex() ([]*WrappedPointer, error)

ScanIndex returns a slice of WrappedPointer objects for all Git LFS pointers it finds in the index.

func ScanRefs

func ScanRefs(refLeft, refRight string) ([]*WrappedPointer, error)

ScanRefs takes a ref and returns a slice of WrappedPointer objects for all Git LFS pointers it finds for that ref.

Jump to

Keyboard shortcuts

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