Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2019-06-24 20:18:22 +0300
committerJacob Vosmaer <jacob@gitlab.com>2019-06-24 20:18:22 +0300
commitc5267a124a5d8b92f0a97fd76f48d613ab75dfb5 (patch)
treebc4b0a043b3d7a414419d2008d793f2bba416be6
parentd96b49c176a7b3db727b1704fada89da0b84595a (diff)
Sketch ref cache in catfilejv-sketch-ref-cache
-rw-r--r--internal/git/catfile/batchcheck.go31
-rw-r--r--internal/git/catfile/catfile.go5
2 files changed, 32 insertions, 4 deletions
diff --git a/internal/git/catfile/batchcheck.go b/internal/git/catfile/batchcheck.go
index 77f49a05b..0bb874aef 100644
--- a/internal/git/catfile/batchcheck.go
+++ b/internal/git/catfile/batchcheck.go
@@ -12,13 +12,14 @@ import (
// batchCheck encapsulates a 'git cat-file --batch-check' process
type batchCheck struct {
- r *bufio.Reader
- w io.WriteCloser
+ r *bufio.Reader
+ w io.WriteCloser
+ cache map[string]ObjectInfo
sync.Mutex
}
func newBatchCheck(ctx context.Context, repoPath string, env []string) (*batchCheck, error) {
- bc := &batchCheck{}
+ bc := &batchCheck{cache: make(map[string]ObjectInfo)}
var stdinReader io.Reader
stdinReader, bc.w = io.Pipe()
@@ -39,6 +40,10 @@ func newBatchCheck(ctx context.Context, repoPath string, env []string) (*batchCh
}
func (bc *batchCheck) info(spec string) (*ObjectInfo, error) {
+ if oi, ok := bc.cachedInfo(spec); ok {
+ return oi, nil
+ }
+
bc.Lock()
defer bc.Unlock()
@@ -46,5 +51,23 @@ func (bc *batchCheck) info(spec string) (*ObjectInfo, error) {
return nil, err
}
- return parseObjectInfo(bc.r)
+ oi, err := parseObjectInfo(bc.r)
+ if err != nil {
+ return nil, err
+ }
+
+ bc.cache[spec] = *oi
+
+ return oi, nil
+}
+
+func (bc *batchCheck) cachedInfo(spec string) (*ObjectInfo, bool) {
+ bc.Lock()
+ defer bc.Unlock()
+
+ if oi, ok := bc.cache[spec]; ok {
+ return &oi, true
+ }
+
+ return nil, false
}
diff --git a/internal/git/catfile/catfile.go b/internal/git/catfile/catfile.go
index 288470170..fd5c4a4ab 100644
--- a/internal/git/catfile/catfile.go
+++ b/internal/git/catfile/catfile.go
@@ -78,6 +78,11 @@ func (c *Batch) Tree(revspec string) (io.Reader, error) {
// and check the object type. Caller must consume the Reader before
// making another call on C.
func (c *Batch) Commit(revspec string) (io.Reader, error) {
+ oi, ok := c.batchCheck.cachedInfo(revspec)
+ if ok {
+ revspec = oi.Oid
+ }
+
return c.batchProcess.reader(revspec, "commit")
}