vcs

package
v0.0.0-...-af24b05 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 23 Imported by: 86

Documentation

Overview

Package vcs provides helper functions for working with various repositories (e.g. git).

Index

Constants

View Source
const HEAD = "HEAD"
View Source
const SyzkallerRepo = "https://github.com/google/syzkaller"

Variables

View Source
var ErrBadKconfig = errors.New("failed to parse Kconfig")

Functions

func CanonicalizeCommit

func CanonicalizeCommit(title string) string

CanonicalizeCommit returns commit title that can be used when checking if a particular commit is present in a git tree. Some trees add prefixes to commit titles during backporting, so we want e.g. commit "foo bar" match "BACKPORT: foo bar".

func CheckBranch

func CheckBranch(branch string) bool

CheckBranch does a best-effort approximate check of a git branch name.

func CheckCommitHash

func CheckCommitHash(hash string) bool

func CheckRepoAddress

func CheckRepoAddress(repo string) bool

CheckRepoAddress does a best-effort approximate check of a git repo address.

func CommitLink(url, hash string) string
func FileLink(url, hash, file string, line int) string
func LogLink(url, hash string) string

func ParseReleaseTag

func ParseReleaseTag(tag string) (v1, v2, rc, v3 int)

func Patch

func Patch(dir string, patch []byte) error
func TreeLink(url, hash string) string

Types

type BackportCommit

type BackportCommit struct {
	// Backport is only applied if the commit is reachable from HEAD.
	GuiltyHash string `json:"guilty_hash"`
	// The hash of the commit to cherry-pick.
	FixHash string `json:"fix_hash"`
	// The title of the commit to cherry-pick.
	// It's used to determine whether the fix is already in place.
	FixTitle string `json:"fix_title"`
	// The field is only intended to make config files less cryptic.
	Comment string `json:"comment"`
}

BackportCommit describes a fix commit that must be cherry-picked to an older kernel revision in order to enable kernel build / boot.

type BisectEnv

type BisectEnv struct {
	Compiler     string
	KernelConfig []byte
}

type BisectResult

type BisectResult int
const (
	BisectBad BisectResult = iota
	BisectGood
	BisectSkip
)

type Bisecter

type Bisecter interface {
	// Can be used for last minute preparations like pulling release tags into the bisected repo, which
	// is required to determin the compiler version to use on linux. Can be an empty function.
	PrepareBisect() error

	// Bisect bisects good..bad commit range against the provided predicate (wrapper around git bisect).
	// The predicate should return an error only if there is no way to proceed
	// (it will abort the process), if possible it should prefer to return BisectSkip.
	// Progress of the process is streamed to the provided trace.
	// Returns the first commit on which the predicate returns BisectBad,
	// or multiple commits if bisection is inconclusive due to BisectSkip.
	Bisect(bad, good string, dt debugtracer.DebugTracer, pred func() (BisectResult, error)) ([]*Commit, error)

	// PreviousReleaseTags returns list of preceding release tags that are reachable from the given commit.
	// If the commit itself has a release tag, this tag is not included.
	PreviousReleaseTags(commit, compilerType string) ([]string, error)

	IsRelease(commit string) (bool, error)

	EnvForCommit(defaultCompiler, compilerType, binDir, commit string,
		kernelConfig []byte, backports []BackportCommit) (*BisectEnv, error)
}

Bisecter may be optionally implemented by Repo.

type Commit

type Commit struct {
	Hash       string
	Title      string
	Author     string
	AuthorName string
	Recipients Recipients
	Tags       []string
	Parents    []string
	Date       time.Time
	CommitDate time.Time
}

type ConfigMinimizer

type ConfigMinimizer interface {
	Minimize(target *targets.Target, original, baseline []byte, types []crash.Type,
		dt debugtracer.DebugTracer, pred func(test []byte) (BisectResult, error)) ([]byte, error)
}

type RecipientInfo

type RecipientInfo struct {
	Address mail.Address
	Type    RecipientType
}

type RecipientType

type RecipientType int
const (
	To RecipientType = iota
	Cc
)

func (RecipientType) String

func (t RecipientType) String() string

type Recipients

type Recipients []RecipientInfo

func NewRecipients

func NewRecipients(emails []string, t RecipientType) Recipients

func ParseMaintainersLinux

func ParseMaintainersLinux(text []byte) Recipients

func (Recipients) GetEmails

func (r Recipients) GetEmails(filter RecipientType) []string

func (Recipients) Len

func (r Recipients) Len() int

func (Recipients) Less

func (r Recipients) Less(i, j int) bool

func (Recipients) Swap

func (r Recipients) Swap(i, j int)

func (Recipients) ToDash

func (r Recipients) ToDash() dashapi.Recipients

type Repo

type Repo interface {
	// Poll checkouts the specified repository/branch.
	// This involves fetching/resetting/cloning as necessary to recover from all possible problems.
	// Returns hash of the HEAD commit in the specified branch.
	Poll(repo, branch string) (*Commit, error)

	// CheckoutBranch checkouts the specified repository/branch.
	CheckoutBranch(repo, branch string) (*Commit, error)

	// CheckoutCommit checkouts the specified repository on the specified commit.
	CheckoutCommit(repo, commit string) (*Commit, error)

	// SwitchCommit checkouts the specified commit without fetching.
	SwitchCommit(commit string) (*Commit, error)

	// HeadCommit returns info about the HEAD commit of the current branch of git repository.
	HeadCommit() (*Commit, error)

	// GetCommitByTitle finds commit info by the title. If the commit is not found, nil is returned.
	// Remote is not fetched and only commits reachable from the checked out HEAD are searched
	// (e.g. do CheckoutBranch before).
	GetCommitByTitle(title string) (*Commit, error)

	// GetCommitsByTitles is a batch version of GetCommitByTitle.
	// Returns list of commits and titles of commits that are not found.
	GetCommitsByTitles(titles []string) ([]*Commit, []string, error)

	// ExtractFixTagsFromCommits extracts fixing tags for bugs from git log.
	// Given email = "user@domain.com", it searches for tags of the form "user+tag@domain.com"
	// and returns commits with these tags.
	ExtractFixTagsFromCommits(baseCommit, email string) ([]*Commit, error)

	// ReleaseTag returns the latest release tag that is reachable from the given commit.
	ReleaseTag(commit string) (string, error)

	// Returns true if the current tree contains the specified commit.
	// Remote is not fetched and only commits reachable from the checked out HEAD are searched
	// (e.g. do CheckoutBranch before).
	Contains(commit string) (bool, error)

	// ListCommitHashes lists all commit hashes reachable from baseCommit.
	ListCommitHashes(baseCommit string) ([]string, error)

	// Object returns the contents of a git repository object at the particular moment in history.
	Object(name, commit string) ([]byte, error)

	// MergeBases returns good common ancestors of the two commits.
	MergeBases(firstCommit, secondCommit string) ([]*Commit, error)
}

func NewLKMLRepo

func NewLKMLRepo(dir string) Repo

func NewRepo

func NewRepo(os, vmType, dir string, opts ...RepoOpt) (Repo, error)

func NewSyzkallerRepo

func NewSyzkallerRepo(dir string, opts ...RepoOpt) Repo

type RepoOpt

type RepoOpt int
const (
	// RepoPrecious is intended for command-line tools that work with a user-provided repo.
	// Such repo won't be re-created to recover from errors, but rather return errors.
	// If this option is not specified, the repo can be re-created from scratch to recover from any errors.
	OptPrecious RepoOpt = iota
	// Don't use sandboxing suitable for pkg/build.
	OptDontSandbox
)

type TestRepo

type TestRepo struct {
	Dir string

	Commits map[string]map[string]*Commit
	// contains filtered or unexported fields
}

func CloneTestRepo

func CloneTestRepo(t *testing.T, baseDir, name string, originRepo *TestRepo) *TestRepo

func CreateTestRepo

func CreateTestRepo(t *testing.T, baseDir, name string) *TestRepo

func MakeTestRepo

func MakeTestRepo(t *testing.T, dir string) *TestRepo

func (*TestRepo) CommitChange

func (repo *TestRepo) CommitChange(description string) *Commit

func (*TestRepo) CommitFileChange

func (repo *TestRepo) CommitFileChange(branch, change string)

func (*TestRepo) Git

func (repo *TestRepo) Git(args ...string)

func (*TestRepo) SetTag

func (repo *TestRepo) SetTag(tag string)

func (*TestRepo) SupportsBisection

func (repo *TestRepo) SupportsBisection() bool

Jump to

Keyboard shortcuts

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