catfile

package
v14.1.0-rc42 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxTagReferenceDepth is the maximum depth of tag references we will dereference
	MaxTagReferenceDepth = 10
)
View Source
const (
	// SessionIDField is the gRPC metadata field we use to store the gitaly session ID.
	SessionIDField = "gitaly-session-id"
)

Variables

This section is empty.

Functions

func GetCommit

func GetCommit(ctx context.Context, c Batch, revision git.Revision) (*gitalypb.GitCommit, error)

GetCommit looks up a commit by revision using an existing Batch instance.

func GetCommitMessage

func GetCommitMessage(ctx context.Context, c Batch, repo repository.GitRepo, revision git.Revision) ([]byte, error)

GetCommitMessage looks up a commit message and returns it in its entirety.

func GetCommitWithTrailers

func GetCommitWithTrailers(ctx context.Context, gitCmdFactory git.CommandFactory, repo repository.GitRepo, c Batch, revision git.Revision) (*gitalypb.GitCommit, error)

GetCommitWithTrailers looks up a commit by revision using an existing Batch instance, and includes Git trailers in the returned commit.

func GetTag

func GetTag(ctx context.Context, c Batch, tagID git.Revision, tagName string, trimLen, trimRightNewLine bool) (*gitalypb.Tag, error)

GetTag looks up a commit by tagID using an existing catfile.Batch instance. When 'trim' is 'true', the tag message will be trimmed to fit in a gRPC message. When 'trimRightNewLine' is 'true', the tag message will be trimmed to remove all '\n' characters from right. note: we pass in the tagName because the tag name from refs/tags may be different than the name found in the actual tag object. We want to use the tagName found in refs/tags

func IsNotFound

func IsNotFound(err error) bool

IsNotFound tests whether err has type NotFoundError.

func ParseCommit added in v14.1.0

func ParseCommit(r io.Reader, info *ObjectInfo) (*gitalypb.GitCommit, error)

ParseCommit parses the commit data from the Reader.

func ParseTag added in v14.1.0

func ParseTag(r io.Reader, oid git.ObjectID) (*gitalypb.Tag, error)

ParseTag parses the tag from the given Reader. The tag's tagged commit is not populated. The given object ID shall refer to the tag itself such that the returned Tag structure has the correct OID.

Types

type Batch

type Batch interface {
	Info(ctx context.Context, revision git.Revision) (*ObjectInfo, error)
	Tree(ctx context.Context, revision git.Revision) (*Object, error)
	Commit(ctx context.Context, revision git.Revision) (*Object, error)
	Blob(ctx context.Context, revision git.Revision) (*Object, error)
	Tag(ctx context.Context, revision git.Revision) (*Object, error)
}

Batch abstracts 'git cat-file --batch' and 'git cat-file --batch-check'. It lets you retrieve object metadata and raw objects from a Git repo.

A Batch instance can only serve single request at a time. If you want to use it across multiple goroutines you need to add your own locking.

type BatchCache

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

BatchCache entries always get added to the back of the list. If the list gets too long, we evict entries from the front of the list. When an entry gets added it gets an expiry time based on a fixed TTL. A monitor goroutine periodically evicts expired entries.

func NewCache

func NewCache(cfg config.Cfg) *BatchCache

NewCache creates a new catfile process cache.

func (*BatchCache) BatchProcess

func (bc *BatchCache) BatchProcess(ctx context.Context, repo git.RepositoryExecutor) (Batch, error)

BatchProcess creates a new Batch process for the given repository.

func (*BatchCache) Collect

func (bc *BatchCache) Collect(metrics chan<- prometheus.Metric)

Collect collects all metrics exposed by BatchCache.

func (*BatchCache) Describe

func (bc *BatchCache) Describe(descs chan<- *prometheus.Desc)

Describe describes all metrics exposed by BatchCache.

func (*BatchCache) Evict

func (bc *BatchCache) Evict()

Evict evicts all cached processes from the cache.

func (*BatchCache) Stop

func (bc *BatchCache) Stop()

Stop stops the monitoring Goroutine and evicts all cached processes. This must only be called once.

type Cache

type Cache interface {
	// BatchProcess either creates a new git-cat-file(1) process or returns a cached one for
	// the given repository.
	BatchProcess(context.Context, git.RepositoryExecutor) (Batch, error)
	// Evict evicts all cached processes from the cache.
	Evict()
}

Cache is a cache for git-cat-file(1) processes.

type NotFoundError

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

NotFoundError is returned when requesting an object that does not exist.

type Object

type Object struct {
	// ObjectInfo represents main information about object
	ObjectInfo
	// Reader provides raw data about object. It differs for each type of object(tag, commit, tree, log, etc.)
	io.Reader
}

Object represents data returned by `git cat-file --batch`

type ObjectInfo

type ObjectInfo struct {
	Oid  git.ObjectID
	Type string
	Size int64
}

ObjectInfo represents a header returned by `git cat-file --batch`

func ParseObjectInfo

func ParseObjectInfo(stdout *bufio.Reader) (*ObjectInfo, error)

ParseObjectInfo reads from a reader and parses the data into an ObjectInfo struct

func (*ObjectInfo) IsBlob

func (o *ObjectInfo) IsBlob() bool

IsBlob returns true if object type is "blob"

Jump to

Keyboard shortcuts

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