catfile

package
v14.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 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 ExtractTagSignature added in v14.2.0

func ExtractTagSignature(content []byte) ([]byte, []byte)

ExtractTagSignature extracts the signature from a content and returns both the signature and the remaining content. If no signature is found, nil as the signature and the entire content are returned. note: tags contain the signature block at the end of the message https://github.com/git/git/blob/master/Documentation/technical/signature-format.txt#L12

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, oid git.ObjectID) (*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 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)
	// ObjectReader either creates a new object reader or returns a cached one for the given
	// repository.
	ObjectReader(context.Context, git.RepositoryExecutor) (ObjectReader, error)
	// ObjectInfoReader either creates a new object info reader or returns a cached one for the
	// given repository.
	ObjectInfoReader(context.Context, git.RepositoryExecutor) (ObjectInfoReader, 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"

type ObjectInfoReader added in v14.4.0

type ObjectInfoReader interface {

	// Info requests information about the revision pointed to by the given revision.
	Info(context.Context, git.Revision) (*ObjectInfo, error)
	// contains filtered or unexported methods
}

ObjectInfoReader returns information about an object referenced by a given revision.

type ObjectReader added in v14.4.0

type ObjectReader interface {

	// Reader returns a new Object for the given revision. The Object must be fully consumed
	// before another object is requested.
	Object(_ context.Context, _ git.Revision) (*Object, error)
	// contains filtered or unexported methods
}

ObjectReader is a reader for Git objects.

type ProcessCache added in v14.4.0

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

ProcessCache 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) *ProcessCache

NewCache creates a new catfile process cache.

func (*ProcessCache) BatchProcess added in v14.4.0

func (c *ProcessCache) BatchProcess(ctx context.Context, repo git.RepositoryExecutor) (_ Batch,
	returnedErr error)

BatchProcess creates a new Batch process for the given repository.

func (*ProcessCache) Collect added in v14.4.0

func (c *ProcessCache) Collect(metrics chan<- prometheus.Metric)

Collect collects all metrics exposed by ProcessCache.

func (*ProcessCache) Describe added in v14.4.0

func (c *ProcessCache) Describe(descs chan<- *prometheus.Desc)

Describe describes all metrics exposed by ProcessCache.

func (*ProcessCache) Evict added in v14.4.0

func (c *ProcessCache) Evict()

Evict evicts all cached processes from the cache.

func (*ProcessCache) ObjectInfoReader added in v14.4.0

func (c *ProcessCache) ObjectInfoReader(ctx context.Context, repo git.RepositoryExecutor) (ObjectInfoReader, error)

ObjectInfoReader creates a new ObjectInfoReader process for the given repository.

func (*ProcessCache) ObjectReader added in v14.4.0

func (c *ProcessCache) ObjectReader(ctx context.Context, repo git.RepositoryExecutor) (ObjectReader, error)

ObjectReader creates a new ObjectReader process for the given repository.

func (*ProcessCache) Stop added in v14.4.0

func (c *ProcessCache) Stop()

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

Jump to

Keyboard shortcuts

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