github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/vcs/vcs.go (about)

     1  // Copyright 2012 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package vcs
     6  
     7  import (
     8  	"github.com/shogo82148/std/time"
     9  
    10  	"github.com/shogo82148/std/cmd/go/internal/web"
    11  )
    12  
    13  // A Cmd describes how to use a version control system
    14  // like Mercurial, Git, or Subversion.
    15  type Cmd struct {
    16  	Name      string
    17  	Cmd       string
    18  	RootNames []rootName
    19  
    20  	CreateCmd   []string
    21  	DownloadCmd []string
    22  
    23  	TagCmd         []tagCmd
    24  	TagLookupCmd   []tagCmd
    25  	TagSyncCmd     []string
    26  	TagSyncDefault []string
    27  
    28  	Scheme  []string
    29  	PingCmd string
    30  
    31  	RemoteRepo  func(v *Cmd, rootDir string) (remoteRepo string, err error)
    32  	ResolveRepo func(v *Cmd, rootDir, remoteRepo string) (realRepo string, err error)
    33  	Status      func(v *Cmd, rootDir string) (Status, error)
    34  }
    35  
    36  // Status is the current state of a local repository.
    37  type Status struct {
    38  	Revision    string
    39  	CommitTime  time.Time
    40  	Uncommitted bool
    41  }
    42  
    43  var (
    44  	// VCSTestRepoURL is the URL of the HTTP server that serves the repos for
    45  	// vcs-test.golang.org.
    46  	//
    47  	// In tests, this is set to the URL of an httptest.Server hosting a
    48  	// cmd/go/internal/vcweb.Server.
    49  	VCSTestRepoURL string
    50  
    51  	// VCSTestHosts is the set of hosts supported by the vcs-test server.
    52  	VCSTestHosts []string
    53  
    54  	// VCSTestIsLocalHost reports whether the given URL refers to a local
    55  	// (loopback) host, such as "localhost" or "127.0.0.1:8080".
    56  	VCSTestIsLocalHost func(*urlpkg.URL) bool
    57  )
    58  
    59  func (v *Cmd) IsSecure(repo string) bool
    60  
    61  func (v *Cmd) String() string
    62  
    63  // Ping pings to determine scheme to use.
    64  func (v *Cmd) Ping(scheme, repo string) error
    65  
    66  // Create creates a new copy of repo in dir.
    67  // The parent of dir must exist; dir must not.
    68  func (v *Cmd) Create(dir, repo string) error
    69  
    70  // Download downloads any new changes for the repo in dir.
    71  func (v *Cmd) Download(dir string) error
    72  
    73  // Tags returns the list of available tags for the repo in dir.
    74  func (v *Cmd) Tags(dir string) ([]string, error)
    75  
    76  // TagSync syncs the repo in dir to the named tag,
    77  // which either is a tag returned by tags or is v.tagDefault.
    78  func (v *Cmd) TagSync(dir, tag string) error
    79  
    80  // FromDir inspects dir and its parents to determine the
    81  // version control system and code repository to use.
    82  // If no repository is found, FromDir returns an error
    83  // equivalent to os.ErrNotExist.
    84  func FromDir(dir, srcRoot string, allowNesting bool) (repoDir string, vcsCmd *Cmd, err error)
    85  
    86  // RepoRoot describes the repository root for a tree of source code.
    87  type RepoRoot struct {
    88  	Repo     string
    89  	Root     string
    90  	IsCustom bool
    91  	VCS      *Cmd
    92  }
    93  
    94  // ModuleMode specifies whether to prefer modules when looking up code sources.
    95  type ModuleMode int
    96  
    97  const (
    98  	IgnoreMod ModuleMode = iota
    99  	PreferMod
   100  )
   101  
   102  // RepoRootForImportPath analyzes importPath to determine the
   103  // version control system, and code repository to use.
   104  func RepoRootForImportPath(importPath string, mod ModuleMode, security web.SecurityMode) (*RepoRoot, error)
   105  
   106  // An ImportMismatchError is returned where metaImport/s are present
   107  // but none match our import path.
   108  type ImportMismatchError struct {
   109  	importPath string
   110  	mismatches []string
   111  }
   112  
   113  func (m ImportMismatchError) Error() string