示例#1
0
func (repo *DiskRepository) PackedRefs() ([]objects.Ref, error) {
	if repo.packedRefs == nil {
		file, e := relativeFile(repo, PackedRefsFile)
		if e != nil {
			return nil, e
		}
		defer file.Close()
		p := parse.NewRefParser(bufio.NewReader(file), "")
		var refs []objects.Ref
		if refs, e = p.ParsePackedRefs(); e != nil {
			return nil, e
		}
		repo.packedRefs = refs
	}
	return repo.packedRefs, nil
}
示例#2
0
// Ref is a repository-based baseline method for getting refs. The
// ref spec is the full path of the ref that is relative to the .git
// directory.
//
// This will attempt to open the file pointed to by the spec. If this
// file is unavailable, packed refs are loaded into memory (and cached)
// and it attempts to find the ref there.
//
// For smart disambiguation of refs, or ref peeling, thou shalt
// use helper operations.
func (repo *DiskRepository) Ref(spec string) (objects.Ref, error) {
	file, e := relativeFile(repo, spec)
	if e == nil {
		defer file.Close()
		p := parse.NewRefParser(bufio.NewReader(file), spec)
		return p.ParseRef()
	}
	if os.IsNotExist(e) {
		refs, err := repo.PackedRefs()
		if err != nil {
			return nil, noSuchRefErrf(spec)
		}
		for _, r := range refs {
			if r.Name() == spec {
				return r, nil
			}
		}
		return nil, noSuchRefErrf(spec)
	}
	return nil, e
}