catfile

package
v14.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: MIT Imports: 23 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 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, 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 TrimTagMessage added in v14.5.0

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, 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
	// contains filtered or unexported fields
}

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

func (*Object) Read added in v14.5.0

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

func (*Object) WriteTo added in v14.5.0

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(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"

func (*ObjectInfo) ObjectID added in v14.5.0

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

ObjectID is the ID of the object.

func (*ObjectInfo) ObjectSize added in v14.5.0

func (o *ObjectInfo) ObjectSize() int64

ObjectSize is the size of the object.

func (*ObjectInfo) ObjectType added in v14.5.0

func (o *ObjectInfo) ObjectType() string

ObjectType is the type of the object.

type ObjectInfoQueue added in v14.5.0

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

	// 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 added in v14.5.0

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

	// 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 added in v14.5.0

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 added in v14.5.0

func NewParser() Parser

NewParser creates a new parser 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) 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