repo.go 681 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "errors"
  7. "path/filepath"
  8. )
  9. // Repository represents a Git repository.
  10. type Repository struct {
  11. Path string
  12. commitCache map[sha1]*Commit
  13. tagCache map[sha1]*Tag
  14. }
  15. // OpenRepository opens the repository at the given path.
  16. func OpenRepository(repoPath string) (*Repository, error) {
  17. repoPath, err := filepath.Abs(repoPath)
  18. if err != nil {
  19. return nil, err
  20. } else if !isDir(repoPath) {
  21. return nil, errors.New("no such file or directory")
  22. }
  23. return &Repository{Path: repoPath}, nil
  24. }