1package git23import (4 "os"5 "strings"6 "sync"7)89// objectCache provides thread-safe cache operations. TODO(@unknwon): Use10// sync.Map once requires Go 1.13.11type objectCache struct {12 lock sync.RWMutex13 cache map[string]interface{}14}1516func newObjectCache() *objectCache {17 return &objectCache{18 cache: make(map[string]interface{}),19 }20}2122func (oc *objectCache) Set(id string, obj interface{}) {23 oc.lock.Lock()24 defer oc.lock.Unlock()2526 oc.cache[id] = obj27}2829func (oc *objectCache) Get(id string) (interface{}, bool) {30 oc.lock.RLock()31 defer oc.lock.RUnlock()3233 obj, has := oc.cache[id]34 return obj, has35}3637// isDir returns true if given path is a directory, or returns false when it's a38// file or does not exist.39func isDir(dir string) bool {40 f, e := os.Stat(dir)41 if e != nil {42 return false43 }44 return f.IsDir()45}4647// isFile returns true if given path is a file, or returns false when it's a48// directory or does not exist.49func isFile(filePath string) bool {50 f, e := os.Stat(filePath)51 if e != nil {52 return false53 }54 return !f.IsDir()55}5657// isExist checks whether a file or directory exists. It returns false when the58// file or directory does not exist.59func isExist(path string) bool {60 _, err := os.Stat(path)61 return err == nil || os.IsExist(err)62}6364// bytesToStrings splits given bytes into strings by line separator ("\n"). It65// returns empty slice if the given bytes only contains line separators.66func bytesToStrings(in []byte) []string {67 s := strings.TrimRight(string(in), "\n")68 if s == "" { // empty (not {""}, len=1)69 return []string{}70 }71 return strings.Split(s, "\n")72}