aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/git/repo.go')
-rw-r--r--modules/git/repo.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/modules/git/repo.go b/modules/git/repo.go
index 4306730920..f86c4aae5c 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -16,14 +16,20 @@ import (
"time"
"github.com/Unknwon/com"
+ "gopkg.in/src-d/go-billy.v4/osfs"
+ gogit "gopkg.in/src-d/go-git.v4"
+ "gopkg.in/src-d/go-git.v4/plumbing/cache"
+ "gopkg.in/src-d/go-git.v4/storage/filesystem"
)
// Repository represents a Git repository.
type Repository struct {
Path string
- commitCache *ObjectCache
- tagCache *ObjectCache
+ tagCache *ObjectCache
+
+ gogitRepo *gogit.Repository
+ gogitStorage *filesystem.Storage
}
const prettyLogFormat = `--pretty=format:%H`
@@ -77,10 +83,25 @@ func OpenRepository(repoPath string) (*Repository, error) {
return nil, errors.New("no such file or directory")
}
+ fs := osfs.New(repoPath)
+ _, err = fs.Stat(".git")
+ if err == nil {
+ fs, err = fs.Chroot(".git")
+ if err != nil {
+ return nil, err
+ }
+ }
+ storage := filesystem.NewStorageWithOptions(fs, cache.NewObjectLRUDefault(), filesystem.Options{KeepDescriptors: true})
+ gogitRepo, err := gogit.Open(storage, fs)
+ if err != nil {
+ return nil, err
+ }
+
return &Repository{
- Path: repoPath,
- commitCache: newObjectCache(),
- tagCache: newObjectCache(),
+ Path: repoPath,
+ gogitRepo: gogitRepo,
+ gogitStorage: storage,
+ tagCache: newObjectCache(),
}, nil
}