Ai
1 Star 0 Fork 0

goproxies/github.com-kardianos-govendor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vcs.go 1.63 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// package vcs gets version control information from the file system.
package vcs
import (
"path/filepath"
"sync"
"time"
"github.com/kardianos/govendor/internal/pathos"
)
// VcsInfo returns information about a given repo.
type VcsInfo struct {
Dirty bool
Revision string
RevisionTime *time.Time
}
// Vcs represents a version control system.
type Vcs interface {
// Return nil VcsInfo if unable to determine VCS from directory.
Find(dir string) (*VcsInfo, error)
}
var vcsRegistry = []Vcs{
VcsGit{},
VcsHg{},
VcsSvn{},
VcsBzr{},
}
var registerSync = sync.Mutex{}
// RegisterVCS adds a new VCS to use.
func RegisterVCS(vcs Vcs) {
registerSync.Lock()
defer registerSync.Unlock()
vcsRegistry = append(vcsRegistry, vcs)
}
const looplimit = 10000
// FindVcs determines the version control information given a package dir and
// lowest root dir.
func FindVcs(root, packageDir string) (info *VcsInfo, err error) {
if !filepath.IsAbs(root) {
return nil, nil
}
if !filepath.IsAbs(packageDir) {
return nil, nil
}
path := packageDir
for i := 0; i <= looplimit; i++ {
for _, vcs := range vcsRegistry {
info, err = vcs.Find(path)
if err != nil {
return nil, err
}
if info != nil {
return info, nil
}
}
nextPath := filepath.Clean(filepath.Join(path, ".."))
// Check for root.
if nextPath == path {
return nil, nil
}
if pathos.FileHasPrefix(nextPath, root) == false {
return nil, nil
}
path = nextPath
}
panic("loop limit")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/goproxies/github.com-kardianos-govendor.git
git@gitee.com:goproxies/github.com-kardianos-govendor.git
goproxies
github.com-kardianos-govendor
github.com-kardianos-govendor
v1.0.9

搜索帮助