gitlfs

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitlfs is the grammar of the Git LFS server protocol (https://github.com/git-lfs/git-lfs/blob/main/docs/api): object ids, the batch request and response documents and the error bodies. It holds no policy; the handler (internal/format/gitlfs) and the RBAC middleware, which must agree on what a batch request asks for, both read requests through it.

Index

Constants

View Source
const (
	OperationDownload = "download"
	OperationUpload   = "upload"
)

Operations of a batch request.

View Source
const (
	ActionDownload = "download"
	ActionUpload   = "upload"
	ActionVerify   = "verify"
)

Actions of a batch response object.

View Source
const HashSHA256 = "sha256"

HashSHA256 is the only hash algorithm of an object id.

View Source
const MaxBatchBytes = 1 << 20

MaxBatchBytes bounds a batch request body. Clients send 100 objects per batch by default (about 11 KB); the cap leaves room for ten thousand.

View Source
const MediaType = "application/vnd.git-lfs+json"

MediaType is the Content-Type and Accept value of every JSON document of the protocol.

View Source
const TransferBasic = "basic"

TransferBasic is the only transfer adapter the server speaks: one HTTP PUT or GET of the whole object.

Variables

View Source
var ErrInvalidBatch = errors.New("invalid batch request")

ErrInvalidBatch is returned for a batch request that is not a batch document.

Functions

func ObjectPath

func ObjectPath(oid string) string

ObjectPath is the repository-wide path an object is stored under: objects/ab/cd/<oid>, the layout of every LFS server's store.

func PeekOperation

func PeekOperation(body []byte) string

PeekOperation returns the operation of a batch request body, or "" when the body is not a batch document. It decodes the one key ParseBatch decodes into BatchRequest.Operation with the same rules (case-insensitive key match, the last duplicate wins), so authorization and the handler never disagree on what a request asks for.

func ValidOID

func ValidOID(s string) bool

ValidOID reports whether s is an object id: a lower-case hex SHA-256.

Types

type Action

type Action struct {
	Href      string            `json:"href"`
	Header    map[string]string `json:"header,omitempty"`
	ExpiresIn int               `json:"expires_in,omitempty"`
}

Action is one thing the client may do with an object.

type BatchRequest

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

BatchRequest is the body of POST objects/batch.

func ParseBatch

func ParseBatch(body []byte) (*BatchRequest, error)

ParseBatch decodes a batch request. It checks the document, not its meaning: object ids and sizes are validated per object by the handler, so one bad pointer does not fail the others.

type BatchResponse

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

BatchResponse is the body of a successful batch.

type Error

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

Error is the body of a failed request.

type ObjectError

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

ObjectError is a per-object failure inside a batch response.

type ObjectResult

type ObjectResult struct {
	OID           string            `json:"oid"`
	Size          int64             `json:"size"`
	Authenticated bool              `json:"authenticated,omitempty"`
	Actions       map[string]Action `json:"actions,omitempty"`
	Error         *ObjectError      `json:"error,omitempty"`
}

ObjectResult is one object of a batch response: the actions the client takes (none when there is nothing to do) or the error that applies to it.

type Pointer

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

Pointer names one object of a batch.

type Ref

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

Ref is the Git ref the batch is for; the server does not use it.

Jump to

Keyboard shortcuts

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