本文整理汇总了Golang中sourcegraph/com/sourcegraph/go-vcs/vcs/internal.Rel函数的典型用法代码示例。如果您正苦于以下问题:Golang Rel函数的具体用法?Golang Rel怎么用?Golang Rel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Rel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: lstat
func (fs *hgFSNative) lstat(path string) (*util.FileInfo, []byte, error) {
path = filepath.Clean(internal.Rel(path))
rec, ent, err := fs.getEntry(path)
if os.IsNotExist(err) {
// check if path is a dir (dirs are not in hg's manifest, so we need to
// hack around to get them).
fi, err := fs.dirStat(path)
return fi, nil, err
}
if err != nil {
return nil, nil, standardizeHgError(err)
}
fi := fs.fileInfo(ent)
// read data to determine file size
data, err := fs.readFile(rec)
if err != nil {
return nil, nil, err
}
fi.Size_ = int64(len(data))
return fi, data, nil
}
示例2: ReadDir
func (fs *gitFSCmd) ReadDir(path string) ([]os.FileInfo, error) {
fs.repoEditLock.RLock()
defer fs.repoEditLock.RUnlock()
// Trailing slash is necessary to ls-tree under the dir (not just
// to list the dir's tree entry in its parent dir).
return fs.lsTree(filepath.Clean(internal.Rel(path)) + "/")
}
示例3: Lstat
func (fs *gitFSLibGit2) Lstat(path string) (os.FileInfo, error) {
fs.repoEditLock.RLock()
defer fs.repoEditLock.RUnlock()
path = filepath.Clean(internal.Rel(path))
mtime, err := fs.getModTime()
if err != nil {
return nil, err
}
if path == "." {
return &util.FileInfo{Mode_: os.ModeDir, ModTime_: mtime}, nil
}
e, err := fs.getEntry(path)
if err != nil {
return nil, err
}
fi, err := fs.makeFileInfo(path, e)
if err != nil {
return nil, err
}
fi.ModTime_ = mtime
return fi, nil
}
示例4: Lstat
func (fs *gitFSCmd) Lstat(path string) (os.FileInfo, error) {
fs.repoEditLock.RLock()
defer fs.repoEditLock.RUnlock()
path = filepath.Clean(internal.Rel(path))
if path == "." {
// Special case root, which is not returned by `git ls-tree`.
mtime, err := fs.getModTimeFromGitLog(path)
if err != nil {
return nil, err
}
return &util.FileInfo{Mode_: os.ModeDir, ModTime_: mtime}, nil
}
fis, err := fs.lsTree(path)
if err != nil {
return nil, err
}
if len(fis) == 0 {
return nil, &os.PathError{Op: "ls-tree", Path: path, Err: os.ErrNotExist}
}
return fis[0], nil
}
示例5: ReadDir
func (fs *gitFSLibGit2) ReadDir(path string) ([]os.FileInfo, error) {
fs.repoEditLock.RLock()
defer fs.repoEditLock.RUnlock()
path = filepath.Clean(internal.Rel(path))
var subtree *git2go.Tree
if path == "." {
subtree = fs.tree
} else {
e, err := fs.getEntry(path)
if err != nil {
return nil, err
}
subtree, err = fs.repo.LookupTree(e.Id)
if err != nil {
return nil, err
}
}
fis := make([]os.FileInfo, int(subtree.EntryCount()))
for i := uint64(0); i < subtree.EntryCount(); i++ {
e := subtree.EntryByIndex(i)
fi, err := fs.makeFileInfo(filepath.Join(path, e.Name), e)
if err != nil {
return nil, err
}
fis[i] = fi
}
return fis, nil
}
示例6: Lstat
func (fs *filesystem) Lstat(path string) (os.FileInfo, error) {
path = filepath.Clean(internal.Rel(path))
mtime, err := fs.getModTime()
if err != nil {
return nil, err
}
if path == "." {
return &util.FileInfo{Mode_: os.ModeDir, ModTime_: mtime}, nil
}
e, err := fs.tree.GetTreeEntryByPath(path)
if err != nil {
return nil, err
}
fi, err := fs.makeFileInfo(path, e)
if err != nil {
return nil, err
}
fi.ModTime_ = mtime
return fi, nil
}
示例7: ReadDir
func (fs *filesystem) ReadDir(path string) ([]os.FileInfo, error) {
path = filepath.Clean(internal.Rel(path))
var subtree *git.Tree
if path == "." {
subtree = fs.tree
} else {
e, err := fs.tree.GetTreeEntryByPath(path)
if err != nil {
return nil, err
}
// FIXME: This looks redundant?
subtree, err = fs.repo.GetTree(e.Id.String())
if err != nil {
return nil, err
}
}
entries, err := subtree.ListEntries()
if err != nil {
return nil, err
}
fis := make([]os.FileInfo, 0, len(entries))
for _, e := range entries {
fi, err := fs.makeFileInfo(filepath.Join(path, e.Name()), e)
if err != nil {
return nil, err
}
fis = append(fis, fi)
}
return fis, nil
}
示例8: ReadDir
func (fs *hgFSCmd) ReadDir(path string) ([]os.FileInfo, error) {
path = filepath.Clean(internal.Rel(path))
// This combination of --include and --exclude opts gets all the files in
// the dir specified by path, plus all files one level deeper (but no
// deeper). This lets us list the files *and* subdirs in the dir without
// needlessly listing recursively.
cmd := exec.Command("hg", "locate", "--rev="+string(fs.at), "--include="+path, "--exclude="+filepath.Clean(path)+"/*/*/*")
cmd.Dir = fs.dir
out, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("exec `hg cat` failed: %s. Output was:\n\n%s", err, out)
}
subdirs := make(map[string]struct{})
prefix := []byte(path + "/")
files := bytes.Split(out, []byte{'\n'})
var fis []os.FileInfo
for _, nameb := range files {
nameb = bytes.TrimPrefix(nameb, prefix)
if len(nameb) == 0 {
continue
}
if bytes.Contains(nameb, []byte{'/'}) {
subdir := strings.SplitN(string(nameb), "/", 2)[0]
if _, seen := subdirs[subdir]; !seen {
fis = append(fis, &util.FileInfo{Name_: subdir, Mode_: os.ModeDir})
subdirs[subdir] = struct{}{}
}
continue
}
fis = append(fis, &util.FileInfo{Name_: filepath.Base(string(nameb))})
}
return fis, nil
}
示例9: Open
func (fs *filesystem) Open(name string) (vfs.ReadSeekCloser, error) {
name = internal.Rel(name)
b, err := fs.readFileBytes(name)
if err != nil {
return nil, err
}
return util.NopCloser{ReadSeeker: bytes.NewReader(b)}, nil
}
示例10: Open
func (fs *gitFSCmd) Open(name string) (vfs.ReadSeekCloser, error) {
name = internal.Rel(name)
fs.repoEditLock.RLock()
defer fs.repoEditLock.RUnlock()
b, err := fs.readFileBytes(name)
if err != nil {
return nil, err
}
return util.NopCloser{bytes.NewReader(b)}, nil
}
示例11: Open
func (fs *hgFSNative) Open(name string) (vfs.ReadSeekCloser, error) {
name = internal.Rel(name)
rec, _, err := fs.getEntry(name)
if err != nil {
return nil, standardizeHgError(err)
}
data, err := fs.readFile(rec)
if err != nil {
return nil, err
}
return util.NopCloser{bytes.NewReader(data)}, nil
}
示例12: Open
func (fs *hgFSCmd) Open(name string) (vfs.ReadSeekCloser, error) {
name = internal.Rel(name)
cmd := exec.Command("hg", "cat", "--rev="+string(fs.at), "--", name)
cmd.Dir = fs.dir
out, err := cmd.CombinedOutput()
if err != nil {
if bytes.Contains(out, []byte("no such file in rev")) {
return nil, os.ErrNotExist
}
return nil, fmt.Errorf("exec `hg cat` failed: %s. Output was:\n\n%s", err, out)
}
return util.NopCloser{bytes.NewReader(out)}, nil
}
示例13: Stat
func (fs *gitFSLibGit2) Stat(path string) (os.FileInfo, error) {
fs.repoEditLock.RLock()
defer fs.repoEditLock.RUnlock()
path = filepath.Clean(internal.Rel(path))
mtime, err := fs.getModTime()
if err != nil {
return nil, err
}
if path == "." {
return &util.FileInfo{Mode_: os.ModeDir, ModTime_: mtime}, nil
}
e, err := fs.getEntry(path)
if err != nil {
return nil, err
}
if e.Filemode == git2go.FilemodeLink {
// dereference symlink
b, err := fs.repo.LookupBlob(e.Id)
if err != nil {
return nil, err
}
derefPath := string(b.Contents())
fi, err := fs.Lstat(derefPath)
if err != nil {
return nil, err
}
// Use original filename.
fi.(*util.FileInfo).Name_ = filepath.Base(path)
return fi, nil
}
fi, err := fs.makeFileInfo(path, e)
if err != nil {
return nil, err
}
fi.ModTime_ = mtime
return fi, nil
}
示例14: Stat
func (fs *hgFSCmd) Stat(path string) (os.FileInfo, error) {
// TODO(sqs): follow symlinks (as Stat is required to do)
path = internal.Rel(path)
var mtime time.Time
cmd := exec.Command("hg", "log", "-l1", `--template={date|date}`,
"-r "+string(fs.at)+":0", "--", path)
cmd.Dir = fs.dir
out, err := cmd.CombinedOutput()
if err != nil {
return nil, err
}
mtime, err = time.Parse("Mon Jan 02 15:04:05 2006 -0700",
strings.Trim(string(out), "\n"))
if err != nil {
log.Println(err)
// return nil, err
}
// this just determines if the file exists.
cmd = exec.Command("hg", "locate", "--rev="+string(fs.at), "--", path)
cmd.Dir = fs.dir
err = cmd.Run()
if err != nil {
// hg doesn't track dirs, so use a workaround to see if path is a dir.
if _, err := fs.ReadDir(path); err == nil {
return &util.FileInfo{Name_: filepath.Base(path), Mode_: os.ModeDir,
ModTime_: mtime}, nil
}
return nil, os.ErrNotExist
}
// read file to determine file size
f, err := fs.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
data, err := ioutil.ReadAll(f)
return &util.FileInfo{Name_: filepath.Base(path), Size_: int64(len(data)),
ModTime_: mtime}, nil
}
示例15: Stat
func (fs *filesystem) Stat(path string) (os.FileInfo, error) {
path = filepath.Clean(internal.Rel(path))
mtime, err := fs.getModTime()
if err != nil {
return nil, err
}
if path == "." {
return &util.FileInfo{Mode_: os.ModeDir, ModTime_: mtime}, nil
}
e, err := fs.tree.GetTreeEntryByPath(path)
if err != nil {
return nil, err
}
if e.EntryMode() == git.ModeSymlink {
// Dereference symlink.
b, err := e.Blob().Data()
if err != nil {
return nil, err
}
fi, err := fs.Lstat(string(b))
if err != nil {
return nil, err
}
// Use original filename.
fi.(*util.FileInfo).Name_ = filepath.Base(path)
return fi, nil
}
fi, err := fs.makeFileInfo(path, e)
if err != nil {
return nil, err
}
fi.ModTime_ = mtime
return fi, nil
}