catfile

package
v16.11.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 30 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 GetCommitMessage

func GetCommitMessage(ctx context.Context, objectReader ObjectContentReader, repo storage.Repository, 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 storage.Repository,
	objectReader ObjectContentReader,
	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 ObjectContentReader, 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 TreeEntries

func TreeEntries(
	ctx context.Context,
	objectReader ObjectContentReader,
	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) (ObjectContentReader, 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 Commit added in v16.5.6

type Commit struct {
	*gitalypb.GitCommit
	SignatureData SignatureData
}

Commit wraps the gitalypb.GitCommit structure and includes signature information.

func GetCommit

func GetCommit(ctx context.Context, objectReader ObjectContentReader, revision git.Revision) (*Commit, error)

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

type NotFoundError

type NotFoundError struct {
	// Revision is the requested revision that could not be found.
	Revision string
}

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

func (NotFoundError) Error added in v16.4.0

func (NotFoundError) Error() string

func (NotFoundError) ErrorMetadata added in v16.4.0

func (e NotFoundError) ErrorMetadata() []structerr.MetadataItem

ErrorMetadata returns the error metadata attached to this error, indicating which revision could not be found.

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 ObjectContentReader

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

	// Queue returns an Queue 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 Queue has
	// finished.
	Queue(context.Context) (Queue, func(), error)
	// contains filtered or unexported methods
}

ObjectContentReader is a reader for Git objects.

type ObjectInfo

type ObjectInfo struct {
	Oid  git.ObjectID
	Type string
	Size int64
	// Format is the object format used by this object, e.g. "sha1" or "sha256".
	Format string
}

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

func ParseObjectInfo

func ParseObjectInfo(objectHash git.ObjectHash, stdout *bufio.Reader, nulTerminated bool) (*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 ObjectInfoReader

type ObjectInfoReader interface {

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

	// Queue returns an Queue 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 Queue has
	// finished.
	Queue(context.Context) (Queue, func(), error)
	// contains filtered or unexported methods
}

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

type ObjectReader added in v16.2.0

type ObjectReader interface {

	// Info returns object information for the given revision.
	Info(context.Context, git.Revision) (*ObjectInfo, error)

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

	// Queue returns an Queue that can be used to batch multiple requests. Using the
	// queue is more efficient than using `Object()` when requesting a bunch of requests.
	// The returned function must be executed after use of the Queue has finished. Object
	// Content and information can be requested from the queue but their respective
	// ordering must be maintained.
	Queue(context.Context) (Queue, func(), error)
	// contains filtered or unexported methods
}

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

type Parser

type Parser interface {
	ParseCommit(object git.Object) (*Commit, 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) (ObjectContentReader, 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 Queue added in v16.11.0

type Queue interface {
	// RequestObject requests the given revision from git-cat-file(1).
	RequestObject(context.Context, git.Revision) error
	// ReadObject reads an object which has previously been requested.
	ReadObject(context.Context) (*Object, error)
	// RequestInfo requests the given revision from git-cat-file(1).
	RequestInfo(context.Context, git.Revision) error
	// ReadInfo reads object info which has previously been requested.
	ReadInfo(context.Context) (*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(context.Context) error
}

Queue allows for requesting and reading objects independently of each other. The number of RequestObject+RequestInfo and ReadObject+RequestInfo calls must match and their ordering must be maintained. ReadObject/ReadInfo must be executed after the object has been requested already. The order of objects returned by ReadObject/ReadInfo 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 SignatureData added in v16.5.6

type SignatureData struct {
	// Signatures refers to the signatures present in the commit. Note that
	// Git only considers the first signature when parsing commits
	Signatures [][]byte
	// Payload refers to the commit data which is signed by the signature,
	// generally this is everything apart from the signature in the commit.
	// Headers present after the signature are not considered in the payload.
	Payload []byte
}

SignatureData holds the raw data used to validate a signed commit.

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