Skip to content

Commit 234979f

Browse files
authored
Merge pull request #983 from erizocosmico/fix/loc-panic
function: use getLanguageCache helper in LOC function
2 parents 1dc245a + 2b5bc27 commit 234979f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Only optimize sorted DISTINCT if the first column on the order by is on the distinct schema. ([#976](https://github.com/src-d/gitbase/issues/976))
1212
- Removed redundant commit information from BLAME results.
1313
- Don't abort, just warn, on git.Blame errors.
14+
- Avoid possible panics in LOC by using a safe cache accessor.
1415

1516
### Added
1617

internal/function/loc.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (f *LOC) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
7575
return nil, err
7676
}
7777

78-
lang, err := f.getLanguage(path, blob)
78+
lang, err := getLanguage(ctx, path, blob)
7979
if err != nil {
8080
return nil, err
8181
}
@@ -142,9 +142,10 @@ func (f *LOC) getInputValues(ctx *sql.Context, row sql.Row) (string, []byte, err
142142
return path, blob, nil
143143
}
144144

145-
func (f *LOC) getLanguage(path string, blob []byte) (string, error) {
145+
func getLanguage(ctx *sql.Context, path string, blob []byte) (string, error) {
146146
hash := languageHash(path, blob)
147147

148+
languageCache := getLanguageCache(ctx)
148149
value, err := languageCache.Get(hash)
149150
if err == nil {
150151
return value.(string), nil

0 commit comments

Comments
 (0)