// formatRefName returns the fully-qualified name for the given Git reference
// "ref".
436087
func formatRefName(ref *git.Ref, remote string) string {
	if ref.Type == git.RefTypeRemoteBranch {
		return strings.Join([]string{
			"refs", "remotes", remote, ref.Name}, "/")
	}
	return ref.Refspec()

}
938369
func (branch *GitBranch) LocalRef() string {
	if branch.BranchName == "" {
		return ""
	}
	return fmt.Sprintf("refs/heads/%v", branch.BranchName)
}
1178965
func IsReferenceExist(repoPath, name string) bool {
	_, err := NewCommand("show-ref", "--verify", name).RunInDir(repoPath)
	return err == nil
}
396503
func Ref(packageName, typeName string) *Type {
	return &Type{Name: Name{
		Name:    typeName,
		Package: packageName,
	}}
}
319340
func format(name string) string {
	return fmt.Sprintf("%v%v", strings.ToLower(name[0:1]), name[1:])
}
443168
func (d *Deployment) GetRef() string {
	if d == nil || d.Ref == nil {
		return ""
	}
	return *d.Ref
}
812716
func cleanRepoName(name string) (string, error) {
	if len(name) == 0 {
		return name, errors.New("Empty repo name.")
	}
	if strings.Contains(name, "..") {
		return "", errors.New("Cannot change directory in file name.")
	}
	name = strings.Replace(name, "'", "", -1)
	return strings.TrimPrefix(strings.TrimSuffix(name, ".git"), "/"), nil
}
998240
func AllRefsIn(wd string) ([]*Ref, error) {
	cmd := gitNoLFS(
		"for-each-ref", "--format=%(objectname)%00%(refname)")
	cmd.Dir = wd

	outp, err := cmd.StdoutPipe()
	if err != nil {
		return nil, lfserrors.Wrap(err, "cannot open pipe")
	}
	cmd.Start()

	refs := make([]*Ref, 0)

	scanner := bufio.NewScanner(outp)
	for scanner.Scan() {
		parts := strings.SplitN(scanner.Text(), "\x00", 2)
		if len(parts) != 2 {
			return nil, lfserrors.Errorf(
				"git: invalid for-each-ref line: %q", scanner.Text())
		}

		sha := parts[0]
		typ, name := ParseRefToTypeAndName(parts[1])

		refs = append(refs, &Ref{
			Name: name,
			Type: typ,
			Sha:  sha,
		})
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}

	return refs, nil
}
121433
func formatProcName(fullURI string) string {
	// remove leading `/`
	fullURI = fullURI[1:]

	// When meet `/{`
	// - replace it with `By`
	// - make uppercase the first char after `/{`
	spl := strings.Split(fullURI, "/{")
	tmp := []string{}
	for i, v := range spl {
		if i != 0 {
			v = strings.Title(v)
		}
		tmp = append(tmp, v)
	}
	name := strings.Join(tmp, "By")

	// when meet `/`
	// - make uppercase the first char after `/`
	// - remove the `/`
	spl = strings.Split(name, "/")
	tmp = []string{}
	for i, v := range spl {
		if i != 0 {
			v = strings.Title(v)
		}
		tmp = append(tmp, v)
	}

	return strings.Join(tmp, "")
}
973730
func (s *VolumeStore) getRefs(name string) []string {
	s.globalLock.RLock()
	defer s.globalLock.RUnlock()

	refs := make([]string, 0, len(s.refs[name]))
	for r := range s.refs[name] {
		refs = append(refs, r)
	}

	return refs
}
504648
func RepoNameForReference(ref reference.Named) (string, error) {
	// insecure is fine since this only returns the name
	repo, err := newDefaultRepositoryEndpoint(ref, false)
	if err != nil {
		return "", err
	}
	return repo.Name(), nil
}
298899
func NewRemoteReferenceName(remote, name string) ReferenceName {
	return ReferenceName(refRemotePrefix + fmt.Sprintf("%s/%s", remote, name))
}
1150866
func (v *Reference) Name() string {
	ret := C.GoString(C.git_reference_name(v.ptr))
	runtime.KeepAlive(v)
	return ret
}
800259
func WithName(name string) (Named, error) {
	name, err := normalize(name)
	if err != nil {
		return nil, err
	}
	if err := validateName(name); err != nil {
		return nil, err
	}
	r, err := reference.WithName(name)
	if err != nil {
		return nil, err
	}
	return &namedRef{r}, nil
}
462096
func (r *Ref) Refspec() string {
	if r == nil {
		return ""
	}

	prefix, ok := r.Type.Prefix()
	if ok {
		return fmt.Sprintf("%s/%s", prefix, r.Name)
	}

	return r.Name
}
13937
func GetGitRepoName(url string) (string, error) {
	if !(strings.Contains(url, "git@") || strings.Contains(url, "gitlab@") || strings.Contains(url, "https://")) ||
		!strings.HasSuffix(url, ".git") {
		return "", fmt.Errorf("Bad git url format %q", url)
	}

	return strings.TrimSuffix(Tail(url), ".git"), nil
}
231213
func parseRefFile(filename string) (*Ref, error) {
	bytes, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, err
	}
	contents := strings.TrimSpace(string(bytes))
	if strings.HasPrefix(contents, "ref:") {
		contents = strings.TrimSpace(contents[4:])
	}
	return ResolveRef(contents)
}