// findGitDir returns first directory containing .git file checking the dir and parent dirs.
773246
func findGitDir(dir string) (string, bool) {
	dir, err := filepath.Abs(dir)
	if err != nil || !exists(dir) {
		return "", false
	}

	for i := 0; i < 10; i++ {
		path := filepath.Join(dir, ".git")
		if exists(path) {
			return dir, true
		}

		if dir == "." || dir == "/" {
			return "", false
		}

		dir = filepath.Dir(dir)
	}

	return "", false
}
1212347
func find(file string, paths []string) string {
	for _, dir := range paths {
		p := join(dir, file)
		if _, err := os.Stat(p); err != nil {
			continue
		}
		return p
	}
	return ""
}
447746
func getGitCommitTime(projroot string) (hash string, err error) {
	gitdir := filepath.Join(projroot, ".git")
	cmd := exec.Command("git", "--git-dir", gitdir, "log", "-1", "--format=%cd", "HEAD")
	output, err := cmd.CombinedOutput()
	if err != nil {
		return
	}
	return strings.TrimSpace(string(output)), nil
}
216509
func (fs *FSObjects) getUploadIDDir(bucket, object, uploadID string) string {
	return pathJoin(fs.fsPath, minioMetaMultipartBucket, getSHA256Hash([]byte(pathJoin(bucket, object))), uploadID)
}
520101
func (m *Manager) FindFolder(name string) string {
	for _, dir := range m.dirs {
		p := filepath.Join(dir, name)
		if files.Exist(p) {
			return p
		}
	}
	return ""
}
1011594
func IsDir(path string) bool {
	fi, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			// not found
			return false
		}
		fmt.Printf("failed to check dir %s: %s\n", path, err)
		return false
	}

	return fi.IsDir()
}
643764
func (p *SwiftPath) ReadDir() ([]Path, error) {
	prefix := p.key
	if !strings.HasSuffix(prefix, "/") {
		prefix += "/"
	}
	opt := swiftobject.ListOpts{
		Full: true,
		Path: prefix,
	}
	return p.readPath(opt)
}
1247588
func main() {
	CheckArgs("<path>")
	path := os.Args[1]

	// We instanciate a new repository targeting the given path (the .git folder)
	r, err := git.PlainOpen(path)
	CheckIfError(err)

	// Length of the HEAD history
	Info("git rev-list HEAD --count")

	// ... retrieving the HEAD reference
	ref, err := r.Head()
	CheckIfError(err)

	// ... retrieves the commit history
	cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
	CheckIfError(err)

	// ... just iterates over the commits
	var cCount int
	err = cIter.ForEach(func(c *object.Commit) error {
		cCount++

		return nil
	})
	CheckIfError(err)

	fmt.Println(cCount)
}
151725
func (r *Repository) GetGitURL() string {
	if r == nil || r.GitURL == nil {
		return ""
	}
	return *r.GitURL
}
614686
func (k *Kloneable) findKloner() error {
	if k.gitServer == nil {
		return errors.New("nil getServer")
	}
	if ForceKloner != "" {
		//local.Printf("Trying force kloner [%s]", ForceKloner)
		switch ForceKloner {
		case "simple":
			k.kloner = simple.NewKloner(k.gitServer)
			local.Printf("Using kloner [%s]", "simple")
			return nil
		case "gogit":
			k.kloner = gogit.NewKloner(k.gitServer)
			local.Printf("Using kloner [%s]", "golang")
			return nil
		case "golang":
			k.kloner = gogit.NewKloner(k.gitServer)
			local.Printf("Using kloner [%s]", "golang")
			return nil
		case "go":
			k.kloner = gogit.NewKloner(k.gitServer)
			local.Printf("Using kloner [%s]", "golang")
			return nil
		default:
			local.Printf("Unable to force kloner [%s] (not defined)", ForceKloner)
		}
	}

	var lang string
	if k.repo.Language() == "" {
		// Then check for a parent
		if k.repo.ForkedFrom() != nil && k.repo.ForkedFrom().Language() != "" {
			lang = k.repo.ForkedFrom().Language()
			local.Printf("Found language from parent repository [%s/%s] [%s]", k.repo.ForkedFrom().Owner(), k.repo.ForkedFrom().Name(), k.repo.ForkedFrom().Language())
		} else {
			local.Printf("Unable to detect language, using Kloner [simple]")
			k.kloner = simple.NewKloner(k.gitServer)
			return nil
		}
	} else {
		lang = k.repo.Language()
	}
	lowerlang := strings.ToLower(lang)
	if newKlonerFunc, ok := LanguageToKloner[lowerlang]; ok {
		kloner := newKlonerFunc(k.gitServer)
		local.Printf("Found Kloner [%s]", k.repo.Language())
		k.kloner = kloner
	} else {
		local.Printf("Unsupported language [%s], using Kloner [simple]", lowerlang)
		k.kloner = simple.NewKloner(k.gitServer)
	}
	return nil
}
1211131
func cpDir(src, dst string, filter []string) error {
	return filepath.Walk(src, func(fullpath string, fi os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		for _, suffix := range filter {
			if strings.HasSuffix(fi.Name(), suffix) {
				return nil
			}
		}
		suffix, err := filepath.Rel(src, fullpath)
		if err != nil {
			return fmt.Errorf("Failed to find Rel(%q, %q): %v", src, fullpath, err)
		}
		if fi.IsDir() {
			return nil
		}
		return cpFile(fullpath, filepath.Join(dst, suffix))
	})
}
518098
func (f *File) Readdir() ([]*File, error) {
	if !f.IsDir() {
		return nil, errors.New("not a directory")
	}
	return f.img.readdir(f.subdirOffset)
}
1244434
func (h *charmsHandler) findArchiveRootDir(zipr *zip.Reader) (string, error) {
	paths, err := ziputil.Find(zipr, "metadata.yaml")
	if err != nil {
		return "", err
	}
	switch len(paths) {
	case 0:
		return "", errors.Errorf("invalid charm archive: missing metadata.yaml")
	case 1:
	default:
		sort.Sort(byDepth(paths))
		if depth(paths[0]) == depth(paths[1]) {
			return "", errors.Errorf("invalid charm archive: ambiguous root directory")
		}
	}
	return filepath.Dir(paths[0]), nil
}
1223561
func (p *PushEventRepository) GetGitURL() string {
	if p == nil || p.GitURL == nil {
		return ""
	}
	return *p.GitURL
}
123586
func (r *repository) Relative(path string, isdir bool) Match {
	// if there's no path, then there's nothing to match
	_path := filepath.Clean(path)
	if _path == "." {
		return nil
	}

	// repository matching:
	//		- a child path cannot be considered if its parent is ignored
	//		- a .gitignore in a lower directory overrides a .gitignore in a
	//		  higher directory

	// first, is the parent directory ignored?
	//		- extract the parent directory from the current path
	_parent, _local := filepath.Split(_path)
	_match := r.Relative(_parent, true)
	if _match != nil {
		if _match.Ignore() {
			return _match
		}
	}
	_parent = filepath.Clean(_parent)

	// the parent directory isn't ignored, so we now look at the original path
	//		- we consider .gitignore files in the current directory first, then
	//		  move up the path hierarchy
	var _last string
	for {
		_file := filepath.Join(r._base, _parent, r._file)
		_ignore := NewWithCache(_file, r._cache, r._errors)
		if _ignore != nil {
			_match := _ignore.Relative(_local, isdir)
			if _match != nil {
				return _match
			}
		}

		// if there's no parent, then we're done
		//		- since we use filepath.Clean() we look for "."
		if _parent == "." {
			break
		}

		// we don't have a match for this file, so we progress up the
		// path hierarchy
		//		- we are manually building _local using the .gitignore
		//		  separator "/", which is how we handle operating system
		//		  file system differences
		_parent, _last = filepath.Split(_parent)
		_parent = filepath.Clean(_parent)
		_local = _last + string(_SEPARATOR) + _local
	}

	// do we have a global exclude file? (i.e. GIT_DIR/info/exclude)
	if r._exclude != nil {
		return r._exclude.Relative(path, isdir)
	}

	// we have no match
	return nil
}
1196298
func isRepositoryGitPath(path string) bool {
	return strings.HasSuffix(path, ".git") || strings.Contains(path, ".git"+string(os.PathSeparator))
}
1267464
func (u *FakeVolumeUtil) ReadDir(fullPath string) ([]string, error) {
	fileNames := []string{}
	files, found := u.directoryFiles[fullPath]
	if !found {
		return nil, fmt.Errorf("Directory %q not found", fullPath)
	}
	for _, file := range files {
		fileNames = append(fileNames, file.Name)
	}
	return fileNames, nil
}