gitindex

package
v0.0.0-...-556319c Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package gitindex provides functions for indexing Git repositories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneRepo

func CloneRepo(destDir, name, cloneURL string, settings map[string]string) (string, error)

CloneRepo clones one repository, adding the given config settings. It returns the bare repo directory. The `name` argument determines where the repo is stored relative to `destDir`. Returns the directory of the repository.

func DeleteRepos

func DeleteRepos(baseDir string, urlPrefix *url.URL, names map[string]struct{}, filter *Filter) error

DeleteRepos deletes stale repos under a specific path in disk. The `names` argument stores names of repos retrieved from the git hosting site and is used along with the `filter` argument to decide on repo deletion.

func FindGitRepos

func FindGitRepos(dir string) ([]string, error)

FindGitRepos finds directories holding git repositories below the given directory. It will find both bare and the ".git" dirs in non-bare repositories. It returns the full path including the dir passed in.

func IndexGitRepo

func IndexGitRepo(opts Options) error

IndexGitRepo indexes the git repository as specified by the options.

func ListRepos

func ListRepos(baseDir string, u *url.URL) ([]string, error)

ListRepos returns paths to repos on disk that start with the given URL prefix. The paths are relative to baseDir, and typically include a ".git" suffix.

func ParseGitModules

func ParseGitModules(content []byte) (map[string]*SubmoduleEntry, error)

ParseGitModules parses the contents of a .gitmodules file.

func Path

func Path(baseDir string, name string) string

Path returns the absolute path of the bare repository.

func RepoModTime

func RepoModTime(dir string) (time.Time, error)

RepoModTime returns the time of last fetch of a git repository.

func SetTemplatesFromOrigin

func SetTemplatesFromOrigin(desc *zoekt.Repository, u *url.URL) error

SetTemplatesFromOrigin fills in templates based on the origin URL.

func TreeToFiles

func TreeToFiles(r *git.Repository, t *object.Tree,
	repoURL string, repoCache *RepoCache) (map[fileKey]BlobLocation, map[string]plumbing.Hash, error)

TreeToFiles fetches the blob SHA1s for a tree. If repoCache is non-nil, recurse into submodules. In addition, it returns a mapping that indicates in which repo each SHA1 can be found.

Types

type BlobLocation

type BlobLocation struct {
	Repo *git.Repository
	URL  *url.URL
}

BlobLocation holds data where a blob can be found.

func (*BlobLocation) Blob

func (l *BlobLocation) Blob(id *plumbing.Hash) ([]byte, error)

type Filter

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

Filter is a include/exclude filter to be used for repo names.

func NewFilter

func NewFilter(includeRegex, excludeRegex string) (*Filter, error)

NewFilter creates a new filter.

func (*Filter) Include

func (f *Filter) Include(name string) bool

Include returns true if the name passes the filter.

type Options

type Options struct {
	// The repository to be indexed.
	RepoDir string

	// If set, follow submodule links. This requires RepoCacheDir to be set.
	Submodules bool

	// If set, skip indexing if the existing index shard is newer
	// than the refs in the repository.
	Incremental bool

	// Don't error out if some branch is missing
	AllowMissingBranch bool

	// Specifies the root of a Repository cache. Needed for submodule indexing.
	RepoCacheDir string

	// Indexing options.
	BuildOptions build.Options

	// Prefix of the branch to index, e.g. `remotes/origin`.
	BranchPrefix string

	// List of branch names to index, e.g. []string{"HEAD", "stable"}
	Branches []string

	// DeltaShardNumberFallbackThreshold defines an upper limit (inclusive) on the number of preexisting shards
	// that can exist before attempting another delta build. If the number of preexisting shards exceeds this threshold,
	// then a normal build will be performed instead.
	//
	// If DeltaShardNumberFallbackThreshold is 0, then this fallback behavior is disabled:
	// a delta build will always be performed regardless of the number of preexisting shards.
	DeltaShardNumberFallbackThreshold uint64
}

The Options structs controls details of the indexing process.

type RepoCache

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

RepoCache is a set of repositories on the file system, named and stored by URL.

func NewRepoCache

func NewRepoCache(dir string) *RepoCache

NewRepoCache creates a new RepoCache rooted at the given directory.

func (*RepoCache) Open

func (rc *RepoCache) Open(u *url.URL) (*git.Repository, error)

Open opens a git repository. The cache retains a pointer to the repository.

func (*RepoCache) Path

func (rc *RepoCache) Path(u *url.URL) string

type SubmoduleEntry

type SubmoduleEntry struct {
	Path   string
	URL    string
	Branch string
}

SubmoduleEntry represent one entry in a .gitmodules file

Jump to

Keyboard shortcuts

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