gitrepo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package gitrepo drives git plumbing for a repository patty scans. It works on the object database directly (bare mirrors or a working tree's .git) so that objects no ref points at anymore -- rewritten, force-pushed or otherwise orphaned commits -- are scanned like everything else.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirSize

func DirSize(dir string) int64

DirSize sums the size of all regular files under dir.

Types

type Auth

type Auth struct {
	Token string
}

Auth carries the token used for HTTPS access to a remote.

type Commit

type Commit struct {
	SHA     string `json:"sha"`
	Author  string `json:"author"`
	Email   string `json:"email"`
	Date    string `json:"date"`
	Subject string `json:"subject"`
}

Commit describes a commit for a report.

type Object

type Object struct {
	SHA  string
	Type string
	Size int64
}

Object is one entry of the object database.

type Repo

type Repo struct {
	// GitDir is the absolute path of the git directory.
	GitDir string
	// contains filtered or unexported fields
}

Repo is an opened repository.

func Mirror

func Mirror(ctx context.Context, url, dir string, auth *Auth) (*Repo, error)

Mirror clones url as a bare mirror into dir, or refreshes the mirror if dir already holds one. A mirror carries every ref the server advertises (heads, tags and on GitHub also refs/pull/*), not just the branches.

func Open

func Open(ctx context.Context, path string) (*Repo, error)

Open opens the repository at path (a working tree or a bare/git directory).

func (*Repo) Commit

func (r *Repo) Commit(ctx context.Context, sha string) (*Commit, error)

Commit returns the metadata of one commit.

func (*Repo) DiskUsage

func (r *Repo) DiskUsage() int64

DiskUsage returns the size of the git directory in bytes.

func (*Repo) FetchSHAs

func (r *Repo) FetchSHAs(ctx context.Context, shas []string) (fetched, unavailable []string, err error)

FetchSHAs fetches the given commits from origin by SHA -- GitHub serves any object it still holds, including commits that were force-pushed away. Objects already present are skipped. It returns the SHAs fetched and the ones the server no longer has.

func (*Repo) Has

func (r *Repo) Has(ctx context.Context, shas []string) (map[string]bool, error)

Has reports which of the given objects exist in the database.

func (*Repo) IntroducingCommit

func (r *Repo) IntroducingCommit(ctx context.Context, object string, roots []string) (*Commit, error)

IntroducingCommit returns the oldest commit that added the given object, searched from all refs and reflogs, or from roots when given.

func (*Repo) IsAncestor

func (r *Repo) IsAncestor(ctx context.Context, a, b string) bool

IsAncestor reports whether a is an ancestor of b.

func (*Repo) ObjectPaths

func (r *Repo) ObjectPaths(ctx context.Context, roots []string) (map[string]string, error)

ObjectPaths maps trees and blobs to a path they were seen at. With no roots it walks everything reachable from refs and reflogs; with roots it walks from those commits only and excludes everything reachable from refs, which yields the objects that exist solely in orphaned history.

func (*Repo) Objects

func (r *Repo) Objects(ctx context.Context) ([]Object, error)

Objects lists every object in the database, reachable or not.

func (*Repo) ReachableCommits

func (r *Repo) ReachableCommits(ctx context.Context) (map[string]bool, error)

ReachableCommits returns the set of commits reachable from any ref or reflog entry.

func (*Repo) ReadObjects

func (r *Repo) ReadObjects(ctx context.Context, shas []string, fn func(Object, []byte) error) error

ReadObjects streams the content of the given objects through one `git cat-file --batch` process and calls fn for each. The content slice is reused between calls; fn must copy what it wants to keep.

func (*Repo) RefCount

func (r *Repo) RefCount(ctx context.Context) (int, error)

RefCount returns the number of refs in the repository.

func (*Repo) RefsContaining

func (r *Repo) RefsContaining(ctx context.Context, commit string) ([]string, error)

RefsContaining lists the refs whose history contains the commit.

Jump to

Keyboard shortcuts

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