Skip to content

Commit

Permalink
scanner/revs: cache file names, not refs
Browse files Browse the repository at this point in the history
  • Loading branch information
ttaylorr committed Oct 20, 2016
1 parent cf8fac1 commit 53f2abb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions scanner/rev_cache.go → scanner/name_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ package scanner

import "sync"

type RevCache struct {
type NameCache struct {
m map[string]string
mu *sync.Mutex
}

func NewRevCache(m map[string]string) *RevCache {
return &RevCache{
func NewNameCache(m map[string]string) *NameCache {
return &NameCache{
m: m,
mu: &sync.Mutex{},
}
}

func (c *RevCache) GetName(sha string) (string, bool) {
func (c *NameCache) GetName(sha string) (string, bool) {
c.mu.Lock()
defer c.mu.Unlock()

rev, ok := c.m[sha]
return rev, ok
}

func (c *RevCache) Cache(sha, name string) {
func (c *NameCache) Cache(sha, name string) {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down
6 changes: 3 additions & 3 deletions scanner/revs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type RevListScanner struct {
// the range's end.
SkipDeletedBlobs bool

revCache *RevCache
nc *NameCache
}

// NewRevListScanner constructs a *RevListScanner using the given opts.
Expand All @@ -60,7 +60,7 @@ func NewRevListScanner(opts *ScanRefsOptions) *RevListScanner {
SkipDeletedBlobs: opts.SkipDeletedBlobs,

// TODO(taylor): fix dependency on having mutable data in "opts"
revCache: NewRevCache(opts.nameMap),
nc: NewNameCache(opts.nameMap),
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ func (r *RevListScanner) scanAndReport(cmd *wrappedCmd, revs chan<- string, errs
if len(line) > 40 {
name := line[41:]

r.revCache.Cache(sha1, name)
r.nc.Cache(sha1, name)
}

revs <- sha1
Expand Down

0 comments on commit 53f2abb

Please sign in to comment.