Help us shape the future of Go! Take the 2026 Go Developer Survey

git_lfs

package
v0.57.11 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package git_lfs implements a git-lfs standalone custom transfer agent that stores Git LFS objects in a Store.

git-lfs starts the agent once per transfer batch when the repository sets lfs.standalonetransferagent, and exchanges one JSON object per line on the agent's stdin and stdout. See https://github.com/git-lfs/git-lfs/blob/main/docs/custom-transfers.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOid is returned when an oid is not a SHA-256 hex digest.
	ErrInvalidOid = errors.New("git-lfs: oid must be 64 lowercase hex characters")
	// ErrOidMismatch is returned when downloaded bytes hash to another oid.
	ErrOidMismatch = errors.New("git-lfs: downloaded object does not match its oid")
	// ErrSizeMismatch is returned when a download has the wrong length.
	ErrSizeMismatch = errors.New("git-lfs: downloaded object has the wrong size")
)

Functions

func ObjectPath

func ObjectPath(oid string) string

ObjectPath returns the slash path of oid within the UnixFS object: objects/<oid[0:2]>/<oid[2:4]>/<oid>, the layout git-lfs uses locally. The two-level shard keeps each directory small.

func ValidateOid

func ValidateOid(oid string) error

ValidateOid checks that oid is a SHA-256 digest in lowercase hex, the form git-lfs uses, so it is safe to use as a path component.

Types

type Agent

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

Agent serves the git-lfs standalone custom transfer protocol over a Store.

func NewAgent

func NewAgent(store Store, tmpDir string) *Agent

NewAgent constructs an Agent that stores objects in store and writes downloads into tmpDir.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, r io.Reader, w io.Writer) error

Run reads protocol events from r and writes responses to w until git-lfs sends terminate or closes r. A failed transfer is reported to git-lfs and does not end Run; a malformed event or a write failure does.

type Store

type Store interface {
	// Has reports whether the Store holds oid with exactly size bytes.
	Has(ctx context.Context, oid string, size int64) (bool, error)
	// Put stores size bytes read from rdr as oid, replacing an entry of
	// another size. The object becomes visible only when Put succeeds.
	Put(ctx context.Context, oid string, size int64, rdr io.Reader) error
	// Get writes the size bytes of oid to w in order.
	Get(ctx context.Context, oid string, size int64, w io.Writer) error
}

Store holds Git LFS objects addressed by their SHA-256 oid.

The Agent validates every oid before calling a Store, so an oid is always 64 lowercase hexadecimal characters.

type UnixFSStore

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

UnixFSStore stores Git LFS objects as files in a UnixFS object at ObjectPath, through the object's root handle resource.

Each Put is one UploadTree call, so the blob is ingested outside the object's write lock and the file and its shard directories land in one commit. Concurrent Puts from several agents overlap their ingest.

func NewUnixFSStore

NewUnixFSStore constructs a UnixFSStore over the root handle of a UnixFS object and the resource client that owns it.

func (*UnixFSStore) Get

func (s *UnixFSStore) Get(ctx context.Context, oid string, size int64, w io.Writer) error

Get writes the file for oid to w through one ReadStream call.

func (*UnixFSStore) Has

func (s *UnixFSStore) Has(ctx context.Context, oid string, size int64) (bool, error)

Has reports whether a file of exactly size bytes is stored for oid.

Errors cross the resource RPC as strings, so a missing path cannot be told apart from another lookup failure. Every failure reports the object as missing; the Put that follows surfaces a real failure.

func (*UnixFSStore) Put

func (s *UnixFSStore) Put(ctx context.Context, oid string, size int64, rdr io.Reader) error

Put streams size bytes from rdr into the file for oid in one UploadTree call, replacing an existing file.

Jump to

Keyboard shortcuts

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