lfs

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MediaType contains the media type for LFS server requests.
	MediaType = "application/vnd.git-lfs+json"

	// OperationDownload is the operation name for a download request.
	OperationDownload = "download"

	// OperationUpload is the operation name for an upload request.
	OperationUpload = "upload"

	// ActionDownload is the action name for a download request.
	ActionDownload = OperationDownload

	// ActionUpload is the action name for an upload request.
	ActionUpload = OperationUpload

	// ActionVerify is the action name for a verify request.
	ActionVerify = "verify"

	// DefaultLocksLimit is the default number of locks to return in a single
	// request.
	DefaultLocksLimit = 20
)
View Source
const (

	// HashAlgorithmSHA256 is the hash algorithm used for Git LFS.
	HashAlgorithmSHA256 = "sha256"

	// MetaFileIdentifier is the string appearing at the first line of LFS pointer files.
	// https://github.com/git-lfs/git-lfs/blob/master/docs/spec.md
	MetaFileIdentifier = "version https://git-lfs.github.com/spec/v1"

	// MetaFileOidPrefix appears in LFS pointer files on a line before the sha256 hash.
	MetaFileOidPrefix = "oid " + HashAlgorithmSHA256 + ":"
)
View Source
const TransferBasic = "basic"

TransferBasic is the name of the Git LFS basic transfer protocol.

Variables

View Source
var (
	// ErrMissingPrefix occurs if the content lacks the LFS prefix
	ErrMissingPrefix = errors.New("Content lacks the LFS prefix")

	// ErrInvalidStructure occurs if the content has an invalid structure
	ErrInvalidStructure = errors.New("Content has an invalid structure")

	// ErrInvalidOIDFormat occurs if the oid has an invalid format
	ErrInvalidOIDFormat = errors.New("OID has an invalid format")
)

Functions

func SearchPointerBlobs

func SearchPointerBlobs(ctx context.Context, repo *git.Repository, pointerChan chan<- PointerBlob, errChan chan<- error)

SearchPointerBlobs scans the whole repository for LFS pointer files

Types

type AuthenticateResponse

type AuthenticateResponse struct {
	Header    map[string]string `json:"header"`
	Href      string            `json:"href"`
	ExpiresIn time.Duration     `json:"expires_in"`
	ExpiresAt time.Time         `json:"expires_at"`
}

AuthenticateResponse is the git-lfs-authenticate JSON response object.

type BasicTransferAdapter

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

BasicTransferAdapter implements the "basic" adapter

func (*BasicTransferAdapter) Download

func (a *BasicTransferAdapter) Download(ctx context.Context, _ Pointer, l *Link) (io.ReadCloser, error)

Download reads the download location and downloads the data

func (*BasicTransferAdapter) Name

func (a *BasicTransferAdapter) Name() string

Name returns the name of the adapter

func (*BasicTransferAdapter) Upload

func (a *BasicTransferAdapter) Upload(ctx context.Context, p Pointer, r io.Reader, l *Link) error

Upload sends the content to the LFS server

func (*BasicTransferAdapter) Verify

func (a *BasicTransferAdapter) Verify(ctx context.Context, p Pointer, l *Link) error

Verify calls the verify handler on the LFS server

type BatchRequest

type BatchRequest struct {
	Operation string     `json:"operation"`
	Transfers []string   `json:"transfers,omitempty"`
	Ref       *Reference `json:"ref,omitempty"`
	Objects   []Pointer  `json:"objects"`
	HashAlgo  string     `json:"hash_algo,omitempty"`
}

BatchRequest contains multiple requests processed in one batch operation. https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#requests

type BatchResponse

type BatchResponse struct {
	Transfer string            `json:"transfer,omitempty"`
	Objects  []*ObjectResponse `json:"objects"`
	HashAlgo string            `json:"hash_algo,omitempty"`
}

BatchResponse contains multiple object metadata Representation structures for use with the batch API. https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#successful-responses

type Client

type Client interface {
	Download(ctx context.Context, objects []Pointer, callback DownloadCallback) error
	Upload(ctx context.Context, objects []Pointer, callback UploadCallback) error
}

Client is a Git LFS client to communicate with a LFS source API.

func NewClient

func NewClient(e Endpoint) Client

NewClient returns a new Git LFS client.

type DownloadCallback

type DownloadCallback func(p Pointer, content io.ReadCloser, objectError error) error

DownloadCallback gets called for every requested LFS object to process its content

type Endpoint

type Endpoint = *url.URL

Endpoint is a Git LFS endpoint.

func NewEndpoint

func NewEndpoint(rawurl string) (Endpoint, error)

NewEndpoint returns a new Git LFS endpoint.

type ErrorResponse

type ErrorResponse struct {
	Message          string `json:"message,omitempty"`
	DocumentationURL string `json:"documentation_url,omitempty"`
	RequestID        string `json:"request_id,omitempty"`
}

ErrorResponse describes the error to the client.

type Link struct {
	Href      string            `json:"href"`
	Header    map[string]string `json:"header,omitempty"`
	ExpiresAt *time.Time        `json:"expires_at,omitempty"`
	ExpiresIn *time.Duration    `json:"expires_in,omitempty"`
}

Link provides a structure with information about how to access a object.

type Lock

type Lock struct {
	ID       string    `json:"id"`
	Path     string    `json:"path"`
	LockedAt time.Time `json:"locked_at"`
	Owner    Owner     `json:"owner,omitempty"`
}

Lock contains the response data for creating a lock. https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-create-response-schema.json

type LockCreateRequest

type LockCreateRequest struct {
	Path string    `json:"path"`
	Ref  Reference `json:"ref,omitempty"`
}

LockCreateRequest contains the request data for creating a lock. https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-create-request-schema.json

type LockDeleteRequest

type LockDeleteRequest struct {
	Force bool      `json:"force,omitempty"`
	Ref   Reference `json:"ref,omitempty"`
}

LockDeleteRequest contains the request data for deleting a lock. https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-delete-request-schema.json

type LockListResponse

type LockListResponse struct {
	Locks      []Lock `json:"locks"`
	NextCursor string `json:"next_cursor,omitempty"`
}

LockListResponse contains the response data for listing locks. https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-list-response-schema.json

type LockResponse

type LockResponse struct {
	Lock Lock `json:"lock"`
	ErrorResponse
}

LockResponse contains the response data for a lock.

type LockVerifyRequest

type LockVerifyRequest struct {
	Ref    Reference `json:"ref,omitempty"`
	Cursor string    `json:"cursor,omitempty"`
	Limit  int       `json:"limit,omitempty"`
}

LockVerifyRequest contains the request data for verifying a lock.

type LockVerifyResponse

type LockVerifyResponse struct {
	Ours       []Lock `json:"ours"`
	Theirs     []Lock `json:"theirs"`
	NextCursor string `json:"next_cursor,omitempty"`
}

LockVerifyResponse contains the response data for verifying a lock. https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-verify-response-schema.json

type ObjectError

type ObjectError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ObjectError defines the JSON structure returned to the client in case of an error.

type ObjectResponse

type ObjectResponse struct {
	Pointer
	Actions map[string]*Link `json:"actions,omitempty"`
	Error   *ObjectError     `json:"error,omitempty"`
}

ObjectResponse is object metadata as seen by clients of the LFS server.

type Owner

type Owner struct {
	Name string `json:"name"`
}

Owner contains the owner data for a lock.

type Pointer

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

Pointer contains LFS pointer data

func GeneratePointer

func GeneratePointer(content io.Reader) (Pointer, error)

GeneratePointer generates a pointer for arbitrary content

func ReadPointer

func ReadPointer(reader io.Reader) (Pointer, error)

ReadPointer tries to read LFS pointer data from the reader

func ReadPointerFromBuffer

func ReadPointerFromBuffer(buf []byte) (Pointer, error)

ReadPointerFromBuffer will return a pointer if the provided byte slice is a pointer file or an error otherwise.

func (Pointer) IsValid

func (p Pointer) IsValid() bool

IsValid checks if the pointer has a valid structure. It doesn't check if the pointed-to-content exists.

func (Pointer) RelativePath

func (p Pointer) RelativePath() string

RelativePath returns the relative storage path of the pointer https://github.com/git-lfs/git-lfs/blob/main/docs/spec.md#intercepting-git

func (Pointer) String

func (p Pointer) String() string

String returns the string representation of the pointer https://github.com/git-lfs/git-lfs/blob/main/docs/spec.md#the-pointer

type PointerBlob

type PointerBlob struct {
	Hash string
	Pointer
}

PointerBlob associates a Git blob with a Pointer.

type Reference

type Reference struct {
	Name string `json:"name"`
}

Reference contains a git reference. https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#ref-property

type TransferAdapter

type TransferAdapter interface {
	Name() string
	Download(ctx context.Context, p Pointer, l *Link) (io.ReadCloser, error)
	Upload(ctx context.Context, p Pointer, r io.Reader, l *Link) error
	Verify(ctx context.Context, p Pointer, l *Link) error
}

TransferAdapter represents an adapter for downloading/uploading LFS objects

type UploadCallback

type UploadCallback func(p Pointer, objectError error) (io.ReadCloser, error)

UploadCallback gets called for every requested LFS object to provide its content

Jump to

Keyboard shortcuts

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