diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2016-12-22 17:30:52 +0800 |
---|---|---|
committer | Thomas Boerger <thomas@webhippie.de> | 2016-12-22 10:30:52 +0100 |
commit | 47a7529d9655e11471bbe39958222a13854a6133 (patch) | |
tree | 98e597255245e17d39a0062c3977fb8a510cf413 /vendor/code.gitea.io/git/utils.go | |
parent | 0c5c34d7ddaf31a6d8123dac36b221de61f5ff96 (diff) | |
download | gitea-47a7529d9655e11471bbe39958222a13854a6133.tar.gz gitea-47a7529d9655e11471bbe39958222a13854a6133.zip |
update code.gitea.io/git (#450)
Diffstat (limited to 'vendor/code.gitea.io/git/utils.go')
-rw-r--r-- | vendor/code.gitea.io/git/utils.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/vendor/code.gitea.io/git/utils.go b/vendor/code.gitea.io/git/utils.go index da8c58170e..8f010321cf 100644 --- a/vendor/code.gitea.io/git/utils.go +++ b/vendor/code.gitea.io/git/utils.go @@ -12,26 +12,28 @@ import ( "sync" ) -// objectCache provides thread-safe cache opeations. -type objectCache struct { +// ObjectCache provides thread-safe cache opeations. +type ObjectCache struct { lock sync.RWMutex cache map[string]interface{} } -func newObjectCache() *objectCache { - return &objectCache{ +func newObjectCache() *ObjectCache { + return &ObjectCache{ cache: make(map[string]interface{}, 10), } } -func (oc *objectCache) Set(id string, obj interface{}) { +// Set add obj to cache +func (oc *ObjectCache) Set(id string, obj interface{}) { oc.lock.Lock() defer oc.lock.Unlock() oc.cache[id] = obj } -func (oc *objectCache) Get(id string) (interface{}, bool) { +// Get get cached obj by id +func (oc *ObjectCache) Get(id string) (interface{}, bool) { oc.lock.RLock() defer oc.lock.RUnlock() @@ -80,13 +82,14 @@ func filepathFromSHA1(rootdir, sha1 string) string { return filepath.Join(rootdir, "objects", sha1[:2], sha1[2:]) } +// RefEndName return the end name of a ref name func RefEndName(refStr string) string { - if strings.HasPrefix(refStr, BRANCH_PREFIX) { - return refStr[len(BRANCH_PREFIX):] + if strings.HasPrefix(refStr, BranchPrefix) { + return refStr[len(BranchPrefix):] } - if strings.HasPrefix(refStr, TAG_PREFIX) { - return refStr[len(TAG_PREFIX):] + if strings.HasPrefix(refStr, TagPrefix) { + return refStr[len(TagPrefix):] } return refStr |