Go: cmd/go/internal/modfetch/codehost Index | Files

package codehost

import "cmd/go/internal/modfetch/codehost"

Package codehost defines the interface implemented by a code hosting source, along with support code for use by implementations.


Package Files

codehost.go git.go svn.go vcs.go


const (
    MaxGoMod   = 16 << 20  // maximum size of go.mod file
    MaxLICENSE = 16 << 20  // maximum size of LICENSE file
    MaxZipFile = 500 << 20 // maximum size of downloaded zip file

Downloaded size limits.


var ErrNoCommits error = noCommitsError{}

ErrNoCommits is an error equivalent to os.ErrNotExist indicating that a given repository or module contains no commits.

func AllHex Uses

func AllHex(rev string) bool

AllHex reports whether the revision rev is entirely lower-case hexadecimal digits.

func Run Uses

func Run(dir string, cmdline ...interface{}) ([]byte, error)

Run runs the command line in the given directory (an empty dir means the current directory). It returns the standard output and, for a non-zero exit, a *RunError indicating the command, exit status, and standard error. Standard error is unavailable for commands that exit successfully.

func RunWithStdin Uses

func RunWithStdin(dir string, stdin io.Reader, cmdline ...interface{}) ([]byte, error)

func ShortenSHA1 Uses

func ShortenSHA1(rev string) string

ShortenSHA1 shortens a SHA1 hash (40 hex digits) to the canonical length used in pseudo-versions (12 hex digits).

func WorkDir Uses

func WorkDir(typ, name string) (dir, lockfile string, err error)

WorkDir returns the name of the cached work directory to use for the given repository type and name.

type FileRev Uses

type FileRev struct {
    Rev  string // requested revision
    Data []byte // file data
    Err  error  // error if any; os.IsNotExist(Err)==true if rev exists but file does not exist in that rev

A FileRev describes the result of reading a file at a given revision.

type Repo Uses

type Repo interface {
    // List lists all tags with the given prefix.
    Tags(prefix string) (tags []string, err error)

    // Stat returns information about the revision rev.
    // A revision can be any identifier known to the underlying service:
    // commit hash, branch, tag, and so on.
    Stat(rev string) (*RevInfo, error)

    // Latest returns the latest revision on the default branch,
    // whatever that means in the underlying implementation.
    Latest() (*RevInfo, error)

    // ReadFile reads the given file in the file tree corresponding to revision rev.
    // It should refuse to read more than maxSize bytes.
    // If the requested file does not exist it should return an error for which
    // os.IsNotExist(err) returns true.
    ReadFile(rev, file string, maxSize int64) (data []byte, err error)

    // ReadFileRevs reads a single file at multiple versions.
    // It should refuse to read more than maxSize bytes.
    // The result is a map from each requested rev strings
    // to the associated FileRev. The map must have a non-nil
    // entry for every requested rev (unless ReadFileRevs returned an error).
    // A file simply being missing or even corrupted in revs[i]
    // should be reported only in files[revs[i]].Err, not in the error result
    // from ReadFileRevs.
    // The overall call should return an error (and no map) only
    // in the case of a problem with obtaining the data, such as
    // a network failure.
    // Implementations may assume that revs only contain tags,
    // not direct commit hashes.
    ReadFileRevs(revs []string, file string, maxSize int64) (files map[string]*FileRev, err error)

    // ReadZip downloads a zip file for the subdir subdirectory
    // of the given revision to a new file in a given temporary directory.
    // It should refuse to read more than maxSize bytes.
    // It returns a ReadCloser for a streamed copy of the zip file.
    // All files in the zip file are expected to be
    // nested in a single top-level directory, whose name is not specified.
    ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser, err error)

    // RecentTag returns the most recent tag on rev or one of its predecessors
    // with the given prefix and major version.
    // An empty major string matches any major version.
    RecentTag(rev, prefix, major string) (tag string, err error)

    // DescendsFrom reports whether rev or any of its ancestors has the given tag.
    // DescendsFrom must return true for any tag returned by RecentTag for the
    // same revision.
    DescendsFrom(rev, tag string) (bool, error)

A Repo represents a code hosting source. Typical implementations include local version control repositories, remote version control servers, and code hosting sites. A Repo must be safe for simultaneous use by multiple goroutines.

func LocalGitRepo Uses

func LocalGitRepo(remote string) (Repo, error)

LocalGitRepo is like Repo but accepts both Git remote references and paths to repositories on the local file system.

func NewRepo Uses

func NewRepo(vcs, remote string) (Repo, error)

type RevInfo Uses

type RevInfo struct {
    Name    string    // complete ID in underlying repository
    Short   string    // shortened ID, for use in pseudo-version
    Version string    // version used in lookup
    Time    time.Time // commit time
    Tags    []string  // known tags for commit

A Rev describes a single revision in a source code repository.

type RunError Uses

type RunError struct {
    Cmd      string
    Err      error
    Stderr   []byte
    HelpText string

func (*RunError) Error Uses

func (e *RunError) Error() string

type UnknownRevisionError Uses

type UnknownRevisionError struct {
    Rev string

UnknownRevisionError is an error equivalent to os.ErrNotExist, but for a revision rather than a file.

func (*UnknownRevisionError) Error Uses

func (e *UnknownRevisionError) Error() string

func (UnknownRevisionError) Is Uses

func (UnknownRevisionError) Is(err error) bool

type VCSError Uses

type VCSError struct {
    Err error

A VCSError indicates an error using a version control system. The implication of a VCSError is that we know definitively where to get the code, but we can't access it due to the error. The caller should report this error instead of continuing to probe other possible module paths.

TODO(golang.org/issue/31730): See if we can invert this. (Return a distinguished error for “repo not found” and treat everything else as terminal.)

func (*VCSError) Error Uses

func (e *VCSError) Error() string

Package codehost imports 25 packages (graph) and is imported by 6 packages. Updated 2020-12-06. Refresh now. Tools for package owners.