gitindex

package
v0.0.0-...-cb9599a Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 32 Imported by: 9

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) (bool, error)

IndexGitRepo indexes the git repository as specified by the options. The returned bool indicates whether the index was updated as a result. This can be informative if doing incremental indexing.

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 SetTemplatesFromOrigin

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

SetTemplatesFromOrigin fills in templates based on the origin URL.

Types

type BlobLocation

type BlobLocation struct {
	GitRepo *git.Repository
	URL     *url.URL

	// Branches is the list of branches that contain the blob.
	Branches []string
}

BlobLocation holds the repo where the blob can be found, plus other information needed for indexing like its branches.

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 RepoWalker

type RepoWalker struct {
	Files map[fileKey]BlobLocation
	// contains filtered or unexported fields
}

RepoWalker walks one or more commit trees, collecting the files to index in its Files map.

It also recurses into submodules if Options.Submodules is enabled.

func NewRepoWalker

func NewRepoWalker(r *git.Repository, repoURL string, repoCache *RepoCache) *RepoWalker

NewRepoWalker creates a new RepoWalker.

func (*RepoWalker) CollectFiles

func (rw *RepoWalker) CollectFiles(t *object.Tree, branch string, ig *ignore.Matcher) (map[string]plumbing.Hash, error)

CollectFiles fetches the blob SHA1s for the 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.

The collected files are available through the RepoWalker.Files map.

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