catfile

package
v3.1.23 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinToHex

func BinToHex(objectFormat ObjectFormat, sha, out []byte) []byte

BinToHex converts a binary hash into a hex encoded one. Input and output can be the same byte slice to support in-place conversion without allocations.

func DiscardFull

func DiscardFull(rd *bufio.Reader, discard int64) error

DiscardFull discards the requested amount of bytes from the buffered reader regardless of its internal limit.

func EnsureValidGitRepository

func EnsureValidGitRepository(ctx context.Context, repoPath string) error

EnsureValidGitRepository runs `git rev-parse` in the repository path to make sure the directory is a valid git repository. This avoids git cat-file hanging indefinitely when invoked in invalid paths.

func IsErrObjectNotFound

func IsErrObjectNotFound(err error) bool

IsErrObjectNotFound reports whether err is an ErrObjectNotFound

func ParseCatFileTreeLine

func ParseCatFileTreeLine(objectFormat ObjectFormat, rd *bufio.Reader, modeBuf, fnameBuf, shaBuf []byte) (mode, fname, sha []byte, n int, err error)

ParseCatFileTreeLine reads an entry from a tree in a cat-file --batch stream and avoids allocations where possible. Each line is composed of: <mode-in-ascii> SP <fname> NUL <binary HASH>

func ReadBatchLine

func ReadBatchLine(rd *bufio.Reader) (sha []byte, typ string, size int64, err error)

ReadBatchLine reads the header line from cat-file --batch. It expects the format "<oid> SP <type> SP <size> LF" and leaves the reader positioned at the start of the object contents (which must be fully consumed by the caller).

func ReadTagObjectID

func ReadTagObjectID(rd *bufio.Reader, size int64) (string, error)

ReadTagObjectID reads a tag object ID hash from a cat-file --batch stream, throwing away the rest.

func ReadTreeID

func ReadTreeID(rd *bufio.Reader, size int64) (string, error)

ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the commit content.

Types

type Batch

type Batch interface {
	Writer() WriteCloserError
	Reader() *bufio.Reader
	Close()
}

func NewBatch

func NewBatch(ctx context.Context, repoPath string) (Batch, error)

NewBatch creates a new cat-file --batch process for the provided repository path. The returned Batch must be closed once the caller has finished with it.

func NewBatchCheck

func NewBatchCheck(ctx context.Context, repoPath string) (Batch, error)

NewBatchCheck creates a cat-file --batch-check process for the provided repository path. The returned Batch must be closed once the caller has finished with it.

type ErrObjectNotFound

type ErrObjectNotFound struct {
	ID string
}

ErrObjectNotFound indicates that the requested object could not be read from cat-file

func (ErrObjectNotFound) Error

func (err ErrObjectNotFound) Error() string

type ObjectFormat

type ObjectFormat interface {
	FullLength() int
}

ObjectFormat abstracts the minimal information needed from git.ObjectFormat.

type WriteCloserError

type WriteCloserError interface {
	io.WriteCloser
	CloseWithError(err error) error
}

WriteCloserError wraps an io.WriteCloser with an additional CloseWithError function

Source Files

  • batch.go
  • reader.go

Jump to

Keyboard shortcuts

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