catfile

package
v15.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

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

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, objectReader ObjectReader, 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, objectReader ObjectReader, 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,
	objectReader ObjectReader,
	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, objectReader ObjectReader, tagID git.Revision, tagName string) (*gitalypb.Tag, error)

GetTag looks up a commit by tagID using an existing catfile.Batch instance. 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 TreeEntries

func TreeEntries(
	ctx context.Context,
	objectReader ObjectReader,
	objectInfoReader ObjectInfoReader,
	revision, path string,
) (_ []*gitalypb.TreeEntry, returnedErr error)

TreeEntries returns the entries of a tree in given revision and path.

func TrimTagMessage

func TrimTagMessage(tag *gitalypb.Tag)

TrimTagMessage trims the tag's message. The message length will be trimmed such that it fits into a single gRPC message and all trailing newline characters will be stripped.

Types

type Cache

type Cache interface {
	// ObjectReader either creates a new object reader or returns a cached one for the given
	// repository.
	ObjectReader(context.Context, git.RepositoryExecutor) (ObjectReader, func(), error)
	// ObjectInfoReader either creates a new object info reader or returns a cached one for the
	// given repository.
	ObjectInfoReader(context.Context, git.RepositoryExecutor) (ObjectInfoReader, func(), 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
	// contains filtered or unexported fields
}

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

func (*Object) Read

func (o *Object) Read(p []byte) (int, error)

func (*Object) WriteTo

func (o *Object) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface. It defers the write to the embedded object reader via `io.Copy()`, which in turn will use `WriteTo()` or `ReadFrom()` in case these interfaces are implemented by the respective reader or writer.

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(objectHash git.ObjectHash, stdout *bufio.Reader) (*ObjectInfo, error)

ParseObjectInfo reads from a reader and parses the data into an ObjectInfo struct with the given object hash.

func (*ObjectInfo) IsBlob

func (o *ObjectInfo) IsBlob() bool

IsBlob returns true if object type is "blob"

func (*ObjectInfo) ObjectID

func (o *ObjectInfo) ObjectID() git.ObjectID

ObjectID is the ID of the object.

func (*ObjectInfo) ObjectSize

func (o *ObjectInfo) ObjectSize() int64

ObjectSize is the size of the object.

func (*ObjectInfo) ObjectType

func (o *ObjectInfo) ObjectType() string

ObjectType is the type of the object.

type ObjectInfoQueue

type ObjectInfoQueue interface {
	// RequestRevision requests the given revision from git-cat-file(1).
	RequestRevision(git.Revision) error
	// ReadInfo reads object info which has previously been requested.
	ReadInfo() (*ObjectInfo, error)
	// Flush flushes all queued requests and asks git-cat-file(1) to print all objects which
	// have been requested up to this point.
	Flush() error
}

ObjectInfoQueue allows for requesting and reading object info independently of each other. The number of RequestInfo and ReadInfo calls must match. ReadObject must be executed after the object has been requested already. The order of objects returned by ReadInfo is the same as the order in which object info has been requested. Users of this interface must call `Flush()` after all requests have been queued up such that all requested objects will be readable.

type ObjectInfoReader

type ObjectInfoReader interface {

	// Info requests information about the revision pointed to by the given revision.
	Info(context.Context, git.Revision) (*ObjectInfo, error)

	// InfoQueue returns an ObjectInfoQueue that can be used to batch multiple object info
	// requests. Using the queue is more efficient than using `Info()` when requesting a bunch
	// of objects. The returned function must be executed after use of the ObjectInfoQueue has
	// finished.
	InfoQueue(context.Context) (ObjectInfoQueue, func(), error)
	// contains filtered or unexported methods
}

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

type ObjectQueue

type ObjectQueue interface {
	// RequestRevision requests the given revision from git-cat-file(1).
	RequestRevision(git.Revision) error
	// ReadObject reads an object which has previously been requested.
	ReadObject() (*Object, error)
	// Flush flushes all queued requests and asks git-cat-file(1) to print all objects which
	// have been requested up to this point.
	Flush() error
}

ObjectQueue allows for requesting and reading objects independently of each other. The number of RequestObject and ReadObject calls must match. ReadObject must be executed after the object has been requested already. The order of objects returned by ReadObject is the same as the order in which objects have been requested. Users of this interface must call `Flush()` after all requests have been queued up such that all requested objects will be readable.

type ObjectReader

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)

	// ObjectQueue returns an ObjectQueue that can be used to batch multiple object requests.
	// Using the queue is more efficient than using `Object()` when requesting a bunch of
	// objects. The returned function must be executed after use of the ObjectQueue has
	// finished.
	ObjectQueue(context.Context) (ObjectQueue, func(), error)
	// contains filtered or unexported methods
}

ObjectReader is a reader for Git objects.

type Parser

type Parser interface {
	ParseCommit(object git.Object) (*gitalypb.GitCommit, error)
	ParseTag(object git.Object) (*gitalypb.Tag, error)
}

Parser parses Git objects into their gitalypb representations.

func NewParser

func NewParser() Parser

NewParser creates a new parser for Git objects.

type ProcessCache

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) Collect

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

Collect collects all metrics exposed by ProcessCache.

func (*ProcessCache) Describe

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

Describe describes all metrics exposed by ProcessCache.

func (*ProcessCache) Evict

func (c *ProcessCache) Evict()

Evict evicts all cached processes from the cache.

func (*ProcessCache) ObjectInfoReader

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

ObjectInfoReader creates a new ObjectInfoReader process for the given repository.

func (*ProcessCache) ObjectReader

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

ObjectReader creates a new ObjectReader process for the given repository.

func (*ProcessCache) Stop

func (c *ProcessCache) Stop()

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

type TreeEntryFinder

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

TreeEntryFinder is a struct for searching through a tree with caching.

func NewTreeEntryFinder

func NewTreeEntryFinder(objectReader ObjectReader, objectInfoReader ObjectInfoReader) *TreeEntryFinder

NewTreeEntryFinder initializes a TreeEntryFinder with an empty tree cache.

func (*TreeEntryFinder) FindByRevisionAndPath

func (tef *TreeEntryFinder) FindByRevisionAndPath(ctx context.Context, revision, path string) (*gitalypb.TreeEntry, error)

FindByRevisionAndPath returns a TreeEntry struct for the object present at the revision/path pair.

Jump to

Keyboard shortcuts

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