From 1e1a7d0623459807d6f1e871492147f971f7540c Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 30 Aug 2018 15:29:51 +0200 Subject: git: add Static option to PlainOpen Also adds Static configuration to Storage and DotGit. This option means that the git repository is not expected to be modified while open and enables some optimizations. Each time a file is accessed the storer tries to open an object file for the requested hash. When this is done for a lot of objects it is expensive. With Static option a list of object files is generated the first time an object is accessed and used to check if exists instead of using system calls. A similar optimization is done for packfiles. Signed-off-by: Javi Fontan --- repository.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'repository.go') diff --git a/repository.go b/repository.go index 818cfb3..d99d6eb 100644 --- a/repository.go +++ b/repository.go @@ -235,9 +235,8 @@ func PlainOpen(path string) (*Repository, error) { return PlainOpenWithOptions(path, &PlainOpenOptions{}) } -// PlainOpen opens a git repository from the given path. It detects if the -// repository is bare or a normal one. If the path doesn't contain a valid -// repository ErrRepositoryNotExists is returned +// PlainOpenWithOptions opens a git repository from the given path with specific +// options. See PlainOpen for more info. func PlainOpenWithOptions(path string, o *PlainOpenOptions) (*Repository, error) { dot, wt, err := dotGitToOSFilesystems(path, o.DetectDotGit) if err != nil { @@ -252,7 +251,11 @@ func PlainOpenWithOptions(path string, o *PlainOpenOptions) (*Repository, error) return nil, err } - s, err := filesystem.NewStorage(dot) + so := filesystem.StorageOptions{ + Static: o.Static, + } + + s, err := filesystem.NewStorageWithOptions(dot, so) if err != nil { return nil, err } -- cgit From 82945e31dd8bce5fc51d4fd16d696a6d326e5f44 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 30 Aug 2018 18:33:37 +0200 Subject: git, storer: use a common storer.Options for storer and PlainOpen Signed-off-by: Javi Fontan --- repository.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'repository.go') diff --git a/repository.go b/repository.go index d99d6eb..4ad5252 100644 --- a/repository.go +++ b/repository.go @@ -251,11 +251,7 @@ func PlainOpenWithOptions(path string, o *PlainOpenOptions) (*Repository, error) return nil, err } - so := filesystem.StorageOptions{ - Static: o.Static, - } - - s, err := filesystem.NewStorageWithOptions(dot, so) + s, err := filesystem.NewStorageWithOptions(dot, o.Storage) if err != nil { return nil, err } -- cgit From 2a7c664b62dd0d87f7ab67b30b1952727788cffa Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 31 Aug 2018 12:29:27 +0200 Subject: git: do not expose storage options in PlainOpen Signed-off-by: Javi Fontan --- repository.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'repository.go') diff --git a/repository.go b/repository.go index 4ad5252..f619934 100644 --- a/repository.go +++ b/repository.go @@ -251,7 +251,7 @@ func PlainOpenWithOptions(path string, o *PlainOpenOptions) (*Repository, error) return nil, err } - s, err := filesystem.NewStorageWithOptions(dot, o.Storage) + s, err := filesystem.NewStorage(dot) if err != nil { return nil, err } -- cgit From 8f6b3127c1ff7661113fff2662416c328971a285 Mon Sep 17 00:00:00 2001 From: kuba-- Date: Fri, 7 Sep 2018 09:27:35 +0200 Subject: Expose Storage cache. Signed-off-by: kuba-- --- repository.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'repository.go') diff --git a/repository.go b/repository.go index f619934..bfe06a3 100644 --- a/repository.go +++ b/repository.go @@ -13,6 +13,7 @@ import ( "gopkg.in/src-d/go-git.v4/config" "gopkg.in/src-d/go-git.v4/internal/revision" "gopkg.in/src-d/go-git.v4/plumbing" + "gopkg.in/src-d/go-git.v4/plumbing/cache" "gopkg.in/src-d/go-git.v4/plumbing/format/packfile" "gopkg.in/src-d/go-git.v4/plumbing/object" "gopkg.in/src-d/go-git.v4/plumbing/storer" @@ -220,10 +221,7 @@ func PlainInit(path string, isBare bool) (*Repository, error) { dot, _ = wt.Chroot(GitDirName) } - s, err := filesystem.NewStorage(dot) - if err != nil { - return nil, err - } + s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault()) return Init(s, wt) } @@ -251,10 +249,7 @@ func PlainOpenWithOptions(path string, o *PlainOpenOptions) (*Repository, error) return nil, err } - s, err := filesystem.NewStorage(dot) - if err != nil { - return nil, err - } + s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault()) return Open(s, wt) } -- cgit