localrepo

package
v15.11.13 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotExist indicates that the requested tree does not exist, either because the revision
	// is invalid or because the path is not valid.
	ErrNotExist = errors.New("invalid object name")
	// ErrNotTreeish indicates that the requested revision or path does not resolve to a tree
	// object.
	ErrNotTreeish = errors.New("not treeish")
)
View Source
var (
	// FetchOptsTagsDefault enables importing of tags only on fetched branches.
	FetchOptsTagsDefault = FetchOptsTags("")
	// FetchOptsTagsAll enables importing of every tag from the remote repository.
	FetchOptsTagsAll = FetchOptsTags("--tags")
	// FetchOptsTagsNone disables importing of tags from the remote repository.
	FetchOptsTagsNone = FetchOptsTags("--no-tags")
)
View Source
var ErrEmptyBundle = errors.New("refusing to create empty bundle")

ErrEmptyBundle is returned when the bundle to be created would have been empty.

View Source
var ErrMissingAuthorName = errors.New("missing author name")

ErrMissingAuthorName indicates an attempt to write a commit without a comitter name

View Source
var ErrMissingCommitterName = errors.New("missing committer name")

ErrMissingCommitterName indicates an attempt to write a commit without a comitter name

View Source
var ErrMissingTree = errors.New("missing tree")

ErrMissingTree indicates a missing tree when attemping to write a commit

View Source
var ErrObjectNotFound = errors.New("object not found")

ErrObjectNotFound is returned in case an object could not be found.

View Source
var ErrParse = errors.New("failed to parse git ls-tree response")

ErrParse is returned when the parse of an entry was unsuccessful

Functions

func FormatTag

func FormatTag(
	objectID git.ObjectID,
	objectType string,
	tagName, tagBody []byte,
	committer *gitalypb.User,
	committerDate time.Time,
) (string, error)

FormatTag is used by WriteTag (or for testing) to make the tag signature to feed to git-mktag, i.e. the plain-text mktag format. This does not create an object, just crafts input for "git mktag" to consume.

We are not being paranoid about exhaustive input validation here because we're just about to run git's own "fsck" check on this.

However, if someone injected parameters with extra newlines they could cause subsequent values to be ignored via a crafted message. This someone could also locally craft a tag locally and "git push" it. But allowing e.g. someone to provide their own timestamp here would at best be annoying, and at worst run up against some other assumption (e.g. that some hook check isn't as strict on locally generated data).

Types

type BadObjectError added in v15.11.0

type BadObjectError struct {
	// ObjectID is the object id of the object that was bad.
	ObjectID git.ObjectID
}

BadObjectError is returned when attempting to walk a bad object.

func (BadObjectError) Error added in v15.11.0

func (err BadObjectError) Error() string

Error returns the error message.

type CreateBundleOpts added in v15.11.0

type CreateBundleOpts struct {
	// Patterns contains all patterns which shall be bundled. Patterns should
	// be in the format accepted by git-rev-list(1) over stdin. Patterns which
	// don't match any reference will be silently ignored.
	Patterns io.Reader
}

CreateBundleOpts are optional configurations used when creating a bundle

type Entries added in v15.10.0

type Entries []TreeEntry

Entries holds every ls-tree Entry

func (Entries) Len added in v15.10.0

func (e Entries) Len() int

func (Entries) Less added in v15.10.0

func (e Entries) Less(i, j int) bool

Less sorts entries by type in the order [*tree *blobs *submodules]

func (Entries) Swap added in v15.10.0

func (e Entries) Swap(i, j int)

type FetchFailedError added in v15.11.0

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

FetchFailedError indicates that the fetch has failed.

func (FetchFailedError) Error added in v15.11.0

func (e FetchFailedError) Error() string

Error returns the error message.

type FetchOpts

type FetchOpts struct {
	// Env is a list of env vars to pass to the cmd.
	Env []string
	// CommandOptions is a list of options to use with 'git' command.
	CommandOptions []git.CmdOpt
	// Prune if set fetch removes any remote-tracking references that no longer exist on the remote.
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---prune
	Prune bool
	// Force if set fetch overrides local references with values from remote that's
	// doesn't have the previous commit as an ancestor.
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---force
	Force bool
	// Verbose controls how much information is written to stderr. The list of
	// refs updated by the fetch will only be listed if verbose is true.
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---quiet
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---verbose
	Verbose bool
	// Tags controls whether tags will be fetched as part of the remote or not.
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---tags
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---no-tags
	Tags FetchOptsTags
	// Stderr if set it would be used to redirect stderr stream into it.
	Stderr io.Writer
	// DisableTransactions will disable the reference-transaction hook and atomic transactions.
	DisableTransactions bool
}

FetchOpts is used to configure invocation of the 'FetchRemote' command.

type FetchOptsTags

type FetchOptsTags string

FetchOptsTags controls what tags needs to be imported on fetch.

func (FetchOptsTags) String

func (t FetchOptsTags) String() string

type FormatTagError

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

FormatTagError is used by FormatTag() below

func (FormatTagError) Error

func (e FormatTagError) Error() string

type GetRemoteReferencesOption

type GetRemoteReferencesOption func(*getRemoteReferenceConfig)

GetRemoteReferencesOption is an option which can be passed to GetRemoteReferences.

func WithConfig

func WithConfig(config ...git.ConfigPair) GetRemoteReferencesOption

WithConfig sets up Git configuration for the git-ls-remote(1) invocation. The config pairs are set up via `WithConfigEnv()` and are thus not exposed via the command line.

func WithPatterns

func WithPatterns(patterns ...string) GetRemoteReferencesOption

WithPatterns sets up a set of patterns which are then used to filter the list of returned references.

func WithSSHCommand

func WithSSHCommand(cmd string) GetRemoteReferencesOption

WithSSHCommand sets the SSH invocation to use when communicating with the remote.

type InvalidCommitError

type InvalidCommitError git.Revision

InvalidCommitError is returned when the revision does not point to a valid commit object.

func (InvalidCommitError) Error

func (err InvalidCommitError) Error() string

type InvalidObjectError

type InvalidObjectError string

InvalidObjectError is returned when trying to get an object id that is invalid or does not exist.

func (InvalidObjectError) Error

func (err InvalidObjectError) Error() string

type ListEntriesConfig added in v15.11.0

type ListEntriesConfig struct {
	// Recursive indicates whether the listing shall be recursive or not.
	Recursive bool
	// RelativePath is the relative path at which listing of entries should be started.
	RelativePath string
}

ListEntriesConfig is configuration that can be passed to ListEntries.

type MergeTreeError added in v15.9.0

type MergeTreeError struct {
	ConflictingFiles []string
	InfoMessage      string
}

MergeTreeError encapsulates any conflicting files and messages that occur when a merge-tree(1) command fails.

func (*MergeTreeError) Error added in v15.9.0

func (c *MergeTreeError) Error() string

Error returns the error string for a conflict error.

type MergeTreeOption added in v15.9.0

type MergeTreeOption func(*mergeTreeConfig)

MergeTreeOption is a function that sets a config in mergeTreeConfig.

func WithAllowUnrelatedHistories added in v15.9.0

func WithAllowUnrelatedHistories() MergeTreeOption

WithAllowUnrelatedHistories lets MergeTree accept two commits that do not share a common ancestor.

type MktagError

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

MktagError is used by WriteTag() below

func (MktagError) Error

func (e MktagError) Error() string

type ObjectReadError added in v15.11.0

type ObjectReadError struct {
	// ObjectID is the object id of the object that git failed to read
	ObjectID git.ObjectID
}

ObjectReadError is returned when reading an object fails.

func (ObjectReadError) Error added in v15.11.0

func (err ObjectReadError) Error() string

Error returns the error message.

type ObjectType added in v15.10.0

type ObjectType int

ObjectType is an Enum for the type of object of the ls-tree entry, which can be can be tree, blob or commit

const (
	Unknown ObjectType = iota
	Tree
	Blob
	Submodule
)

Enum values for ObjectType

func ToEnum added in v15.10.0

func ToEnum(s string) ObjectType

ToEnum translates a string representation of the object type into an ObjectType enum.

type Parser added in v15.11.0

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

Parser holds the necessary state for parsing the ls-tree output

func NewParser added in v15.11.0

func NewParser(src io.Reader, objectHash git.ObjectHash) *Parser

NewParser returns a new Parser

func (*Parser) NextEntry added in v15.11.0

func (p *Parser) NextEntry() (*TreeEntry, error)

NextEntry reads a tree entry as it would be written by `git ls-tree -z`.

func (*Parser) NextEntryPath added in v15.11.0

func (p *Parser) NextEntryPath() ([]byte, error)

NextEntryPath reads the path of next entry as it would be written by `git ls-tree --name-only -z`.

type PushOptions

type PushOptions struct {
	// SSHCommand is the command line to use for git's SSH invocation. The command line is used
	// as is and must be verified by the caller to be safe.
	SSHCommand string
	// Force decides whether to force push all of the refspecs.
	Force bool
	// Config is the Git configuration which gets passed to the git-push(1) invocation.
	// Configuration is set up via `WithConfigEnv()`, so potential credentials won't be leaked
	// via the command line.
	Config []git.ConfigPair
}

PushOptions are options that can be configured for a push.

type ReadCommitOpt

type ReadCommitOpt func(*readCommitConfig)

ReadCommitOpt is an option for ReadCommit.

func WithTrailers

func WithTrailers() ReadCommitOpt

WithTrailers will cause ReadCommit to parse commit trailers.

type Repo

type Repo struct {
	repository.GitRepo
	// contains filtered or unexported fields
}

Repo represents a local Git repository.

func New

func New(locator storage.Locator, gitCmdFactory git.CommandFactory, catfileCache catfile.Cache, repo repository.GitRepo) *Repo

New creates a new Repo from its protobuf representation.

func NewTestRepo

func NewTestRepo(tb testing.TB, cfg config.Cfg, repo repository.GitRepo, factoryOpts ...git.ExecCommandFactoryOption) *Repo

NewTestRepo constructs a Repo. It is intended as a helper function for tests which assembles dependencies ad-hoc from the given config.

func (*Repo) CreateBundle added in v15.11.0

func (repo *Repo) CreateBundle(ctx context.Context, out io.Writer, opts *CreateBundleOpts) error

CreateBundle creates a bundle that contains all refs. When the bundle would be empty ErrEmptyBundle is returned.

func (*Repo) Exec

func (repo *Repo) Exec(ctx context.Context, cmd git.Command, opts ...git.CmdOpt) (*command.Command, error)

Exec creates a git command with the given args and Repo, executed in the Repo. It validates the arguments in the command before executing.

func (*Repo) ExecAndWait

func (repo *Repo) ExecAndWait(ctx context.Context, cmd git.Command, opts ...git.CmdOpt) error

ExecAndWait is similar to Exec, but waits for the command to exit before returning.

func (*Repo) FetchInternal

func (repo *Repo) FetchInternal(
	ctx context.Context,
	remoteRepo *gitalypb.Repository,
	refspecs []string,
	opts FetchOpts,
) error

FetchInternal performs a fetch from an internal Gitaly-hosted repository. Returns an FetchFailedError error in case git-fetch(1) failed.

func (*Repo) FetchRemote

func (repo *Repo) FetchRemote(ctx context.Context, remoteName string, opts FetchOpts) error

FetchRemote fetches changes from the specified remote. Returns an FetchFailedError error in case the fetch itself failed.

func (*Repo) GetBranches

func (repo *Repo) GetBranches(ctx context.Context) ([]git.Reference, error)

GetBranches returns all branches.

func (*Repo) GetDefaultBranch

func (repo *Repo) GetDefaultBranch(ctx context.Context) (git.ReferenceName, error)

GetDefaultBranch determines the default branch name

func (*Repo) GetReference

func (repo *Repo) GetReference(ctx context.Context, reference git.ReferenceName) (git.Reference, error)

GetReference looks up and returns the given reference. Returns a ReferenceNotFound error if the reference was not found.

func (*Repo) GetReferences

func (repo *Repo) GetReferences(ctx context.Context, patterns ...string) ([]git.Reference, error)

GetReferences returns references matching any of the given patterns. If no patterns are given, all references are returned.

func (*Repo) GetRemoteReferences

func (repo *Repo) GetRemoteReferences(ctx context.Context, remote string, opts ...GetRemoteReferencesOption) ([]git.Reference, error)

GetRemoteReferences lists references of the remote. Peeled tags are not returned.

func (*Repo) GitVersion

func (repo *Repo) GitVersion(ctx context.Context) (git.Version, error)

GitVersion returns the Git version in use.

func (*Repo) GuessHead

func (repo *Repo) GuessHead(ctx context.Context, head git.Reference) (git.ReferenceName, error)

GuessHead tries to guess what branch HEAD would be pointed at. If no reference is found git.ErrReferenceNotFound is returned.

This function should be roughly equivalent to the corresponding function in git: https://github.com/git/git/blob/2a97289ad8b103625d3a1a12f66c27f50df822ce/remote.c#L2198

func (*Repo) HasBranches

func (repo *Repo) HasBranches(ctx context.Context) (bool, error)

HasBranches determines whether there is at least one branch in the repository.

func (*Repo) HasRevision

func (repo *Repo) HasRevision(ctx context.Context, revision git.Revision) (bool, error)

HasRevision checks if a revision in the repository exists. This will not verify whether the target object exists. To do so, you can peel the revision to a given object type, e.g. by passing `refs/heads/master^{commit}`.

func (*Repo) InfoAlternatesPath

func (repo *Repo) InfoAlternatesPath() (string, error)

InfoAlternatesPath returns the full path of the alternates file.

func (*Repo) IsAncestor

func (repo *Repo) IsAncestor(ctx context.Context, parent, child git.Revision) (bool, error)

IsAncestor returns whether the parent is an ancestor of the child. InvalidCommitError is returned if either revision does not point to a commit in the repository.

func (*Repo) ListEntries added in v15.11.0

func (repo *Repo) ListEntries(
	ctx context.Context,
	treeish git.Revision,
	cfg *ListEntriesConfig,
) ([]*TreeEntry, error)

ListEntries lists tree entries for the given treeish. By default, this will do a non-recursive listing starting from the root of the given treeish. This behaviour can be changed by passing a config.

func (*Repo) MergeTree added in v15.9.0

func (repo *Repo) MergeTree(
	ctx context.Context,
	ours, theirs string,
	mergeTreeOptions ...MergeTreeOption,
) (git.ObjectID, error)

MergeTree calls git-merge-tree(1) with arguments, and parses the results from stdout.

func (*Repo) ObjectDirectoryPath

func (repo *Repo) ObjectDirectoryPath() (string, error)

ObjectDirectoryPath returns the full path of the object directory. The errors returned are gRPC errors with relevant error codes and should be passed back to gRPC without further decoration.

func (*Repo) ObjectHash added in v15.3.0

func (repo *Repo) ObjectHash(ctx context.Context) (git.ObjectHash, error)

ObjectHash detects the object hash used by this particular repository.

func (*Repo) PackObjects added in v15.11.0

func (repo *Repo) PackObjects(ctx context.Context, objectIDs io.Reader, output io.Writer) error

PackObjects takes in object IDs separated by newlines. It packs the objects into a pack file and writes it into the output.

func (*Repo) Path

func (repo *Repo) Path() (string, error)

Path returns the on-disk path of the repository.

func (*Repo) Push

func (repo *Repo) Push(ctx context.Context, remote string, refspecs []string, options PushOptions) error

Push force pushes the refspecs to the remote.

func (*Repo) Quarantine added in v15.11.0

func (repo *Repo) Quarantine(quarantineDirectory string) (*Repo, error)

Quarantine return the repository quarantined. The quarantine directory becomes the repository's main object directory and the original object directory is configured as an alternate.

func (*Repo) ReadCommit

func (repo *Repo) ReadCommit(ctx context.Context, revision git.Revision, opts ...ReadCommitOpt) (*gitalypb.GitCommit, error)

ReadCommit reads the commit specified by the given revision. If no such revision exists, it will return an ErrObjectNotFound error.

func (*Repo) ReadObject

func (repo *Repo) ReadObject(ctx context.Context, oid git.ObjectID) ([]byte, error)

ReadObject reads an object from the repository's object database. InvalidObjectError is returned if the oid does not refer to a valid object.

func (*Repo) ResolveRevision

func (repo *Repo) ResolveRevision(ctx context.Context, revision git.Revision) (git.ObjectID, error)

ResolveRevision resolves the given revision to its object ID. This will not verify whether the target object exists. To do so, you can peel the reference to a given object type, e.g. by passing `refs/heads/master^{commit}`. Returns an ErrReferenceNotFound error in case the revision does not exist.

func (*Repo) SetConfig

func (repo *Repo) SetConfig(ctx context.Context, key, value string, txManager transaction.Manager) (returnedErr error)

SetConfig will set a configuration value. Any preexisting values will be overwritten with the new value. The change will use transactional semantics.

func (*Repo) SetDefaultBranch

func (repo *Repo) SetDefaultBranch(ctx context.Context, txManager transaction.Manager, reference git.ReferenceName) error

SetDefaultBranch sets the repository's HEAD to point to the given reference. It will not verify the reference actually exists.

func (*Repo) StorageTempDir added in v15.2.0

func (repo *Repo) StorageTempDir() (string, error)

StorageTempDir returns the temporary dir for the storage where the repo is on. When this directory does not exist yet, it's being created.

func (*Repo) UnpackObjects added in v15.11.0

func (repo *Repo) UnpackObjects(ctx context.Context, packFile io.Reader) error

UnpackObjects unpacks the objects from the pack file to the repository's object database.

func (*Repo) UnsetMatchingConfig

func (repo *Repo) UnsetMatchingConfig(
	ctx context.Context,
	regex string,
	txManager transaction.Manager,
) (returnedErr error)

UnsetMatchingConfig removes all config entries whose key match the given regular expression. If no matching keys are found, then this function returns an `git.ErrNotFound` error. The change will use transactional semantics.

func (*Repo) UpdateRef

func (repo *Repo) UpdateRef(ctx context.Context, reference git.ReferenceName, newValue, oldValue git.ObjectID) error

UpdateRef updates reference from oldValue to newValue. If oldValue is a non-empty string, the update will fail it the reference is not currently at that revision. If newValue is the ZeroOID, the reference will be deleted. If oldValue is the ZeroOID, the reference will created.

func (*Repo) WalkUnreachableObjects added in v15.11.0

func (repo *Repo) WalkUnreachableObjects(ctx context.Context, heads io.Reader, output io.Writer) error

WalkUnreachableObjects walks the object graph starting from heads and writes to the output object IDs that are included in the walk but unreachable from any of the repository's references. Heads should return object IDs separated with a newline. Output is object IDs separated by newlines.

func (*Repo) WriteBlob

func (repo *Repo) WriteBlob(ctx context.Context, path string, content io.Reader) (git.ObjectID, error)

WriteBlob writes a blob to the repository's object database and returns its object ID. Path is used by git to decide which filters to run on the content.

func (*Repo) WriteCommit added in v15.9.0

func (repo *Repo) WriteCommit(ctx context.Context, cfg WriteCommitConfig) (git.ObjectID, error)

WriteCommit writes a new commit into the target repository.

func (*Repo) WriteTag

func (repo *Repo) WriteTag(
	ctx context.Context,
	objectID git.ObjectID,
	objectType string,
	tagName, tagBody []byte,
	committer *gitalypb.User,
	committerDate time.Time,
) (git.ObjectID, error)

WriteTag writes a tag to the repository's object database with git-mktag and returns its object ID.

It's important that this be git-mktag and not git-hash-object due to its fsck sanity checking semantics.

func (*Repo) WriteTree added in v15.9.0

func (repo *Repo) WriteTree(ctx context.Context, entries []TreeEntry) (git.ObjectID, error)

WriteTree writes a new tree object to the given path. This function does not verify whether OIDs referred to by tree entries actually exist in the repository.

type TreeEntry added in v15.9.0

type TreeEntry struct {
	// OID is the object ID the tree entry refers to.
	OID git.ObjectID
	// Mode is the file mode of the tree entry.
	Mode string
	// Path is the full path of the tree entry.
	Path string
	// Type is the type of the tree entry.
	Type ObjectType
}

TreeEntry represents an entry of a git tree object.

func (*TreeEntry) IsBlob added in v15.10.0

func (t *TreeEntry) IsBlob() bool

IsBlob returns whether or not the TreeEntry is a blob.

type WriteCommitConfig added in v15.9.0

type WriteCommitConfig struct {
	Reference          string
	Parents            []git.ObjectID
	AuthorDate         time.Time
	AuthorName         string
	AuthorEmail        string
	CommitterName      string
	CommitterEmail     string
	CommitterDate      time.Time
	Message            string
	TreeEntries        []TreeEntry
	TreeID             git.ObjectID
	AlternateObjectDir string
}

WriteCommitConfig contains fields for writing a commit

Jump to

Keyboard shortcuts

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