diff --git a/build/builder_unix.go b/build/builder_unix.go index fde31d55c..1e099e337 100644 --- a/build/builder_unix.go +++ b/build/builder_unix.go @@ -11,6 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +//go:build !windows // +build !windows package build diff --git a/cmd/zoekt-archive-index/main.go b/cmd/zoekt-archive-index/main.go index 0a8015cd3..491233e3a 100644 --- a/cmd/zoekt-archive-index/main.go +++ b/cmd/zoekt-archive-index/main.go @@ -2,9 +2,9 @@ // // Example via github.com: // -// zoekt-archive-index -incremental -commit b57cb1605fd11ba2ecfa7f68992b4b9cc791934d -name github.com/gorilla/mux -strip_components 1 https://codeload.github.com/gorilla/mux/legacy.tar.gz/b57cb1605fd11ba2ecfa7f68992b4b9cc791934d +// zoekt-archive-index -incremental -commit b57cb1605fd11ba2ecfa7f68992b4b9cc791934d -name github.com/gorilla/mux -strip_components 1 https://codeload.github.com/gorilla/mux/legacy.tar.gz/b57cb1605fd11ba2ecfa7f68992b4b9cc791934d // -// zoekt-archive-index -branch master https://github.com/gorilla/mux/commit/b57cb1605fd11ba2ecfa7f68992b4b9cc791934d +// zoekt-archive-index -branch master https://github.com/gorilla/mux/commit/b57cb1605fd11ba2ecfa7f68992b4b9cc791934d package main import ( diff --git a/cmd/zoekt-mirror-gerrit/main.go b/cmd/zoekt-mirror-gerrit/main.go index 7ed887c60..04649190b 100644 --- a/cmd/zoekt-mirror-gerrit/main.go +++ b/cmd/zoekt-mirror-gerrit/main.go @@ -203,7 +203,7 @@ func deleteStaleRepos(destDir string, filter *gitindex.Filter, repos map[string] } names := map[string]struct{}{} - for name, _ := range repos { + for name := range repos { u, err := url.Parse(strings.Replace(projectURL, "${project}", name, 1)) if err != nil { return err diff --git a/cmd/zoekt-mirror-gitlab/main.go b/cmd/zoekt-mirror-gitlab/main.go index 8b13c62e0..3728f0c61 100644 --- a/cmd/zoekt-mirror-gitlab/main.go +++ b/cmd/zoekt-mirror-gitlab/main.go @@ -18,9 +18,9 @@ // In addition, the token should be present in the ~/.netrc of the user running // the mirror command. For example, the ~/.netrc may look like: // -// machine gitlab.com -// login oauth -// password +// machine gitlab.com +// login oauth +// password package main import ( diff --git a/cmd/zoekt-repo-index/main.go b/cmd/zoekt-repo-index/main.go index 772378046..5e7517f20 100644 --- a/cmd/zoekt-repo-index/main.go +++ b/cmd/zoekt-repo-index/main.go @@ -12,20 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -/* zoekt-repo-index indexes a repo-based repository. The constituent -git repositories should already have been downloaded to the ---repo_cache directory, eg. - - go install github.com/sourcegraph/zoekt/cmd/zoekt-repo-index && - - zoekt-repo-index -base_url https://gfiber.googlesource.com/ \ - -manifest_repo_url https://gfiber.googlesource.com/manifests \ - -manifest_rev_prefix=refs/heads/ \ - -rev_prefix="refs/remotes/" \ - -repo_cache ~/zoekt-serving/repos/ \ - -shard_limit 50000000 \ - master:default_unrestricted.xml -*/ +// zoekt-repo-index indexes a repo-based repository. The constituent git +// repositories should already have been downloaded to the --repo_cache +// directory, eg. +// +// go install github.com/sourcegraph/zoekt/cmd/zoekt-repo-index && +// +// zoekt-repo-index -base_url https://gfiber.googlesource.com/ \ +// -manifest_repo_url https://gfiber.googlesource.com/manifests \ +// -manifest_rev_prefix=refs/heads/ \ +// -rev_prefix="refs/remotes/" \ +// -repo_cache ~/zoekt-serving/repos/ \ +// -shard_limit 50000000 \ +// master:default_unrestricted.xml package main import ( diff --git a/cmd/zoekt-sourcegraph-indexserver/cleanup.go b/cmd/zoekt-sourcegraph-indexserver/cleanup.go index 5d14c8994..a7d5f86b8 100644 --- a/cmd/zoekt-sourcegraph-indexserver/cleanup.go +++ b/cmd/zoekt-sourcegraph-indexserver/cleanup.go @@ -63,7 +63,7 @@ func cleanup(indexDir string, repos []uint32, now time.Time, shardMerging bool) // tombstones: Remove tombstones that conflict with index or trash. After this, // tombstones only contain repos that are neither in the trash nor in the index. - for repo, _ := range tombtones { + for repo := range tombtones { if _, conflicts := index[repo]; conflicts { delete(tombtones, repo) } diff --git a/cmd/zoekt-sourcegraph-indexserver/cleanup_test.go b/cmd/zoekt-sourcegraph-indexserver/cleanup_test.go index f0102d890..84dab7edd 100644 --- a/cmd/zoekt-sourcegraph-indexserver/cleanup_test.go +++ b/cmd/zoekt-sourcegraph-indexserver/cleanup_test.go @@ -319,20 +319,29 @@ func TestGetTombstonedRepos(t *testing.T) { // ---- // index/ // CS 1 -// r1, tombstoned, old -// r2, tombstoned, old -// r3, tombstoned, old +// +// r1, tombstoned, old +// r2, tombstoned, old +// r3, tombstoned, old +// // CS 2 -// r1, tombstoned, recent -// r2, tombstoned, recent -// r4, tombstoned, recent +// +// r1, tombstoned, recent +// r2, tombstoned, recent +// r4, tombstoned, recent +// // SS 1 -// r1, now +// +// r1, now +// // .trash/ // SS 3 -// r3, now +// +// r3, now +// // SS 5 -// r5, now +// +// r5, now // // TO BE INDEXED // ------------- @@ -342,21 +351,30 @@ func TestGetTombstonedRepos(t *testing.T) { // ---- // index/ // CS 1 -// r1, tombstoned, old -// r2, tombstoned, old -// r3, tombstoned, old +// +// r1, tombstoned, old +// r2, tombstoned, old +// r3, tombstoned, old +// // CS 2 -// r1, tombstoned, recent -// r2, recent -// r4, recent +// +// r1, tombstoned, recent +// r2, recent +// r4, recent +// // SS 1 -// r1, now +// +// r1, now +// // SS 3 -// r3, now +// +// r3, now +// // SS 5 -// r5, now -// .trash/ --> empty // +// r5, now +// +// .trash/ --> empty func TestCleanupCompoundShards(t *testing.T) { dir := t.TempDir() @@ -402,27 +420,27 @@ func TestCleanupCompoundShards(t *testing.T) { } wantIndex := map[uint32][]shard{ - 1: []shard{{ + 1: {{ RepoID: 1, RepoName: "repo1", Path: filepath.Join(dir, "repo1.zoekt"), }}, - 2: []shard{{ + 2: {{ RepoID: 2, RepoName: "repo2", Path: cs2, }}, - 3: []shard{{ + 3: {{ RepoID: 3, RepoName: "repo3", Path: filepath.Join(dir, "repo3.zoekt"), }}, - 4: []shard{{ + 4: {{ RepoID: 4, RepoName: "repo4", Path: cs2, }}, - 5: []shard{{ + 5: {{ RepoID: 5, RepoName: "repo5", Path: filepath.Join(dir, "repo5.zoekt"), @@ -484,17 +502,17 @@ func TestTombstoneDuplicateShards(t *testing.T) { } wantIndex := map[uint32][]shard{ - 1: []shard{{ + 1: {{ RepoID: 1, RepoName: "repo1", Path: cs2, }}, - 2: []shard{{ + 2: {{ RepoID: 2, RepoName: "repo2", Path: cs2, }}, - 3: []shard{{ + 3: {{ RepoID: 3, RepoName: "repo3", Path: cs1, diff --git a/cmd/zoekt-sourcegraph-indexserver/queue.go b/cmd/zoekt-sourcegraph-indexserver/queue.go index 7b442854e..24f6a3e81 100644 --- a/cmd/zoekt-sourcegraph-indexserver/queue.go +++ b/cmd/zoekt-sourcegraph-indexserver/queue.go @@ -41,7 +41,7 @@ type queueItem struct { // Queue is a priority queue which returns the next repo to index. It is safe // to use concurrently. It is a min queue on: // -// (!indexed, time added to the queue) +// (!indexed, time added to the queue) // // We use the above since: // diff --git a/eval_test.go b/eval_test.go index c90f9ebe3..eea9f465e 100644 --- a/eval_test.go +++ b/eval_test.go @@ -24,8 +24,8 @@ import ( "github.com/RoaringBitmap/roaring" "github.com/google/go-cmp/cmp" - "github.com/sourcegraph/zoekt/query" "github.com/grafana/regexp" + "github.com/sourcegraph/zoekt/query" ) var opnames = map[syntax.Op]string{ @@ -179,8 +179,8 @@ func compoundReposShard(t *testing.T, names ...string) *indexData { for _, name := range names { repos = append(repos, &Repository{ID: hash(name), Name: name}) ds := []Document{ - Document{Name: name + ".txt", Content: []byte(name + " content")}, - Document{Name: name + ".2.txt", Content: []byte(name + " content 2")}, + {Name: name + ".txt", Content: []byte(name + " content")}, + {Name: name + ".2.txt", Content: []byte(name + " content 2")}, } docs = append(docs, ds) } diff --git a/gitindex/tree_test.go b/gitindex/tree_test.go index f7baa5cf2..123f07252 100644 --- a/gitindex/tree_test.go +++ b/gitindex/tree_test.go @@ -28,11 +28,11 @@ import ( "time" "github.com/google/go-cmp/cmp" + "github.com/grafana/regexp" "github.com/sourcegraph/zoekt" "github.com/sourcegraph/zoekt/build" "github.com/sourcegraph/zoekt/query" "github.com/sourcegraph/zoekt/shards" - "github.com/grafana/regexp" ) func createSubmoduleRepo(dir string) error { diff --git a/index_test.go b/index_test.go index 9902baf31..c06dd09c6 100644 --- a/index_test.go +++ b/index_test.go @@ -26,9 +26,9 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/sourcegraph/zoekt/query" "github.com/grafana/regexp" "github.com/kylelemons/godebug/pretty" + "github.com/sourcegraph/zoekt/query" ) func clearScores(r *SearchResult) { @@ -2863,13 +2863,13 @@ func TestSymbolRegexpPartial(t *testing.T) { func TestSymbolRegexpAll(t *testing.T) { docs := []Document{ - Document{ + { Name: "f1", Content: []byte("Hello Zoekt"), // --------------01234567890 Symbols: []DocumentSection{{0, 5}, {6, 11}}, }, - Document{ + { Name: "f2", Content: []byte("Second Zoekt Third"), // --------------012345678901234567 @@ -3434,7 +3434,7 @@ func TestStats(t *testing.T) { b := testIndexBuilder(t, nil) got := repoListEntries(b) want := []RepoListEntry{ - RepoListEntry{ + { Stats: RepoStats{ Repos: 0, Shards: 1, @@ -3461,7 +3461,7 @@ func TestStats(t *testing.T) { ) got := repoListEntries(b) want := []RepoListEntry{ - RepoListEntry{ + { Stats: RepoStats{ Repos: 0, Shards: 1, @@ -3484,23 +3484,23 @@ func TestStats(t *testing.T) { t.Run("one compound shard", func(t *testing.T) { b := testIndexBuilderCompound(t, []*Repository{ - &Repository{Name: "repo 0"}, - &Repository{Name: "repo 1"}, + {Name: "repo 0"}, + {Name: "repo 1"}, }, [][]Document{ - []Document{ - Document{Name: "doc 0", Content: []byte("content 0")}, - Document{Name: "doc 1", Content: []byte("content 1")}, + { + {Name: "doc 0", Content: []byte("content 0")}, + {Name: "doc 1", Content: []byte("content 1")}, }, - []Document{ - Document{Name: "doc 2", Content: []byte("content 2")}, - Document{Name: "doc 3", Content: []byte("content 3")}, + { + {Name: "doc 2", Content: []byte("content 2")}, + {Name: "doc 3", Content: []byte("content 3")}, }, }, ) got := repoListEntries(b) want := []RepoListEntry{ - RepoListEntry{ + { Stats: RepoStats{ Repos: 0, Shards: 1, @@ -3512,7 +3512,7 @@ func TestStats(t *testing.T) { OtherBranchesNewLinesCount: 0, }, }, - RepoListEntry{ + { Stats: RepoStats{ Repos: 0, Shards: 1, @@ -3534,16 +3534,16 @@ func TestStats(t *testing.T) { t.Run("compound shard with empty repos", func(t *testing.T) { b := testIndexBuilderCompound(t, []*Repository{ - &Repository{Name: "repo 0"}, - &Repository{Name: "repo 1"}, - &Repository{Name: "repo 2"}, - &Repository{Name: "repo 3"}, - &Repository{Name: "repo 4"}, + {Name: "repo 0"}, + {Name: "repo 1"}, + {Name: "repo 2"}, + {Name: "repo 3"}, + {Name: "repo 4"}, }, [][]Document{ - []Document{Document{Name: "doc 0", Content: []byte("content 0")}}, + {{Name: "doc 0", Content: []byte("content 0")}}, nil, - []Document{Document{Name: "doc 1", Content: []byte("content 1")}}, + {{Name: "doc 1", Content: []byte("content 1")}}, nil, nil, }, diff --git a/indexfile_other.go b/indexfile_other.go index 1c03fe811..f192d9beb 100644 --- a/indexfile_other.go +++ b/indexfile_other.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !linux && !darwin // +build !linux,!darwin package zoekt diff --git a/matchtree.go b/matchtree.go index 679458805..8ad0f55bd 100644 --- a/matchtree.go +++ b/matchtree.go @@ -20,8 +20,8 @@ import ( "strings" "unicode/utf8" - "github.com/sourcegraph/zoekt/query" "github.com/grafana/regexp" + "github.com/sourcegraph/zoekt/query" ) // A docIterator iterates over documents in order. @@ -58,7 +58,7 @@ const ( // matches). The matchtree iterates over the documents as they are // ordered in the shard. // -// The general process for a given (shard, query) is +// The general process for a given (shard, query) is: // // - construct matchTree for the query // @@ -74,7 +74,6 @@ const ( // // - if the complete tree returns (matches() == true) for the document, // collect all text matches by looking at leaf matchTrees -// type matchTree interface { docIterator diff --git a/matchtree_test.go b/matchtree_test.go index a0ecea8b1..be0427c38 100644 --- a/matchtree_test.go +++ b/matchtree_test.go @@ -19,8 +19,8 @@ import ( "testing" "github.com/RoaringBitmap/roaring" - "github.com/sourcegraph/zoekt/query" "github.com/grafana/regexp" + "github.com/sourcegraph/zoekt/query" ) func Test_breakOnNewlines(t *testing.T) { diff --git a/read.go b/read.go index fb54a2485..9aed3eddc 100644 --- a/read.go +++ b/read.go @@ -690,9 +690,11 @@ func loadIndexData(r IndexFile) (*indexData, error) { } // PrintNgramStats outputs a list of the form -// n_1 trigram_1 -// n_2 trigram_2 -// ... +// +// n_1 trigram_1 +// n_2 trigram_2 +// ... +// // where n_i is the length of the postings list of trigram_i stored in r. func PrintNgramStats(r IndexFile) error { id, err := loadIndexData(r) diff --git a/shards/sched.go b/shards/sched.go index 9f5083d24..1a5914cb1 100644 --- a/shards/sched.go +++ b/shards/sched.go @@ -28,14 +28,14 @@ type scheduler interface { // scheduler. It is a comma-separated list of name=val pairs setting these // named variables: // -// disable: setting disable=1 will use the old zoekt scheduler. +// disable: setting disable=1 will use the old zoekt scheduler. // -// batchdiv: settings batchDiv=X will make the batch queue size 1/X of the -// interactive queue size. By default it is 4. +// batchdiv: settings batchDiv=X will make the batch queue size 1/X of the +// interactive queue size. By default it is 4. // -// interactiveseconds: settings interactiveseconds=X will allow search -// queries to run in the larger interactive queue for Xs before moving them -// to the batch queue. +// interactiveseconds: settings interactiveseconds=X will allow search +// queries to run in the larger interactive queue for Xs before moving them +// to the batch queue. // // Note: these tuneables should be regarded as temporary while we experiment // with our scheduler in production. They should not be relied upon in @@ -58,16 +58,15 @@ func newScheduler(capacity int64) scheduler { // multiScheduler is for managing concurrent searches. Its goals are: // -// 1. Limit the number of concurrent searches. -// 2. Co-operatively limit long running searches. -// 3. No tuneables. +// 1. Limit the number of concurrent searches. +// 2. Co-operatively limit long running searches. +// 3. No tuneables. // // ### Limit the number of concurrent searches // // Searching is CPU bound, so we can't do better than #CPU queries // concurrently. If we do so, we just create more memory pressure. // -// // ### Co-operatively limit long running searches // // Some searches are slow. Either due to a hard to execute search query (can't @@ -311,11 +310,11 @@ func parseTuneables(v string) map[string]int { // We use a gauge and counter to track the number of processes in each // state. They can be one of the following states: // -// 1. global queued -// 2. interactive queued -// 3. interactive running -// 4. batch queued -// 5. batch running +// 1. global queued +// 2. interactive queued +// 3. interactive running +// 4. batch queued +// 5. batch running // // From each state you either transition to the next state or the process // ends. diff --git a/shards/shards_test.go b/shards/shards_test.go index 43920c172..3fe01e9a5 100644 --- a/shards/shards_test.go +++ b/shards/shards_test.go @@ -33,10 +33,10 @@ import ( "github.com/RoaringBitmap/roaring" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" + "github.com/grafana/regexp" "github.com/sourcegraph/zoekt" "github.com/sourcegraph/zoekt/query" "github.com/sourcegraph/zoekt/stream" - "github.com/grafana/regexp" ) type crashSearcher struct{} diff --git a/web/server.go b/web/server.go index 45cd9f40c..fca34d69b 100644 --- a/web/server.go +++ b/web/server.go @@ -32,9 +32,9 @@ import ( "github.com/grafana/regexp" "github.com/sourcegraph/zoekt" + zjson "github.com/sourcegraph/zoekt/json" "github.com/sourcegraph/zoekt/query" "github.com/sourcegraph/zoekt/rpc" - zjson "github.com/sourcegraph/zoekt/json" "github.com/sourcegraph/zoekt/stream" ) diff --git a/web/trace.go b/web/trace.go index c1a94ab9f..b579e3629 100644 --- a/web/trace.go +++ b/web/trace.go @@ -4,10 +4,10 @@ import ( "context" "log" + "github.com/opentracing/opentracing-go" "github.com/sourcegraph/zoekt" "github.com/sourcegraph/zoekt/query" "github.com/sourcegraph/zoekt/trace" - "github.com/opentracing/opentracing-go" ) // traceAwareSearcher wraps a zoekt.Searcher instance so that the tracing context item is set in the