Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search: support doublestar for largeFiles #35411

Merged
merged 1 commit into from May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@ All notable changes to Sourcegraph are documented in this file.
- Search: `-language` is a valid filter, but the web app displays it as invalid. The web app is fixed to reflect validity. [#34949](https://github.com/sourcegraph/sourcegraph/pull/34949)
- Search-based code intelligence now recognizes local variables in Python, Java, JavaScript, TypeScript, C/C++, C#, Go, and Ruby. [#33689](https://github.com/sourcegraph/sourcegraph/pull/33689)
- GraphQL API: Added support for async external service deletion. This should be used to delete an external service which cannot be deleted within 75 seconds timeout due to a large number of repos. Usage: add `async` boolean field to `deleteExternalService` mutation. Example: `mutation deleteExternalService(externalService: "id", async: true) { alwaysNil }`
- [search.largeFiles](https://docs.sourcegraph.com/admin/config/site_config#search-largeFiles) now supports recursive globs. For example it is now possible to specify a pattern like `**/*.lock` to match a lock file anywhere in a repository. [#35411](https://github.com/sourcegraph/sourcegraph/pull/35411)

### Changed

Expand Down
4 changes: 2 additions & 2 deletions cmd/searcher/internal/search/store.go
Expand Up @@ -10,11 +10,11 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"sync"
"time"

"github.com/bmatcuk/doublestar"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -421,7 +421,7 @@ func (s *Store) watchConfig() {
func ignoreSizeMax(name string, patterns []string) bool {
for _, pattern := range patterns {
pattern = strings.TrimSpace(pattern)
if m, _ := filepath.Match(pattern, name); m {
if m, _ := doublestar.Match(pattern, name); m {
return true
}
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/searcher/internal/search/store_test.go
Expand Up @@ -139,6 +139,7 @@ func TestIngoreSizeMax(t *testing.T) {
"foo_*",
"*.foo",
"bar.baz",
"**/*.bam",
}
tests := []struct {
name string
Expand All @@ -150,10 +151,14 @@ func TestIngoreSizeMax(t *testing.T) {
{"foo_bar", true},
{"bar.baz", true},
{"bar.foo", true},
{"hello.bam", true},
{"sub/dir/hello.bam", true},
{"/sub/dir/hello.bam", true},
// Fail
{"baz.foo.bar", false},
{"bar_baz", false},
{"baz.baz", false},
{"sub/dir/bar.foo", false},
}

for _, test := range tests {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -261,7 +261,7 @@ require (
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.2
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/bmatcuk/doublestar v1.3.4
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
github.com/cockroachdb/redact v1.1.3
Expand Down
2 changes: 1 addition & 1 deletion schema/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions schema/site.schema.json
Expand Up @@ -30,13 +30,13 @@
"group": "Search"
},
"search.largeFiles": {
"description": "A list of file glob patterns where matching files will be indexed and searched regardless of their size. Files still need to be valid utf-8 to be indexed. The glob pattern syntax can be found here: https://golang.org/pkg/path/filepath/#Match.",
"description": "A list of file glob patterns where matching files will be indexed and searched regardless of their size. Files still need to be valid utf-8 to be indexed. The glob pattern syntax can be found here: https://github.com/bmatcuk/doublestar#patterns.",
"type": "array",
"items": {
"type": "string"
},
"group": "Search",
"examples": [["go.sum", "package-lock.json", "*.thrift"]]
"examples": [["go.sum", "package-lock.json", "**/*.thrift"]]
},
"debug.search.symbolsParallelism": {
"description": "(debug) controls the amount of symbol search parallelism. Defaults to 20. It is not recommended to change this outside of debugging scenarios. This option will be removed in a future version.",
Expand Down