fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

all: gofumpt -l -w .

gofumpt is a stricter gofmt. I took a look at the changes and in general
they are nice. I don't think we need to enforce the use of gofumpt, but
I like the idea of running it every once in a while.

Test Plan: go test ./...

+101 -128
+7 -5
api.go
··· 27 27 "github.com/sourcegraph/zoekt/query" 28 28 ) 29 29 30 - const mapHeaderBytes uint64 = 48 31 - const sliceHeaderBytes uint64 = 24 32 - const stringHeaderBytes uint64 = 16 33 - const pointerSize uint64 = 8 34 - const interfaceBytes uint64 = 16 30 + const ( 31 + mapHeaderBytes uint64 = 48 32 + sliceHeaderBytes uint64 = 24 33 + stringHeaderBytes uint64 = 16 34 + pointerSize uint64 = 8 35 + interfaceBytes uint64 = 16 36 + ) 35 37 36 38 // FileMatch contains all the matches within a file. 37 39 type FileMatch struct {
-1
api_proto.go
··· 405 405 Name: p.GetName(), 406 406 Version: p.GetVersion(), 407 407 } 408 - 409 408 } 410 409 411 410 func (r *RepositoryBranch) ToProto() *proto.RepositoryBranch {
+1 -1
api_test.go
··· 85 85 } 86 86 87 87 func TestSizeBytesSearchResult(t *testing.T) { 88 - var sr = SearchResult{ 88 + sr := SearchResult{ 89 89 Stats: Stats{}, // 129 bytes 90 90 Progress: Progress{}, // 16 bytes 91 91 Files: []FileMatch{{ // 24 bytes + 460 bytes
+4 -2
btree.go
··· 237 237 } 238 238 return &innerNode{ 239 239 keys: append(make([]ngram, 0, opts.v-1), n.keys[0:opts.v-1]...), 240 - children: append(make([]node, 0, opts.v), n.children[:opts.v]...)}, 240 + children: append(make([]node, 0, opts.v), n.children[:opts.v]...), 241 + }, 241 242 &innerNode{ 242 243 keys: append(make([]ngram, 0, (2*opts.v)-1), n.keys[opts.v:]...), 243 - children: append(make([]node, 0, 2*opts.v), n.children[opts.v:]...)}, 244 + children: append(make([]node, 0, 2*opts.v), n.children[opts.v:]...), 245 + }, 244 246 n.keys[opts.v-1], 245 247 true 246 248 }
+2 -3
build/builder_test.go
··· 71 71 if err != nil { 72 72 t.Fatal(err) 73 73 } 74 - err = os.WriteFile(wantP, data, 0644) 74 + err = os.WriteFile(wantP, data, 0o644) 75 75 if err != nil { 76 76 t.Fatal(err) 77 77 } ··· 798 798 func createTestShard(t *testing.T, indexDir string, r zoekt.Repository, numShards int, optFns ...func(options *Options)) []string { 799 799 t.Helper() 800 800 801 - if err := os.MkdirAll(filepath.Dir(indexDir), 0700); err != nil { 801 + if err := os.MkdirAll(filepath.Dir(indexDir), 0o700); err != nil { 802 802 t.Fatal(err) 803 803 } 804 804 ··· 897 897 } 898 898 899 899 func TestIgnoreSizeMax(t *testing.T) { 900 - 901 900 for _, test := range []struct { 902 901 name string 903 902 largeFiles []string
+1 -2
build/e2e_test.go
··· 132 132 t.Fatal(err) 133 133 } 134 134 135 - if err := os.WriteFile(p+".meta", b, 0600); err != nil { 135 + if err := os.WriteFile(p+".meta", b, 0o600); err != nil { 136 136 t.Fatal(err) 137 137 } 138 138 } ··· 682 682 expectedDocuments: []zoekt.Document{barAtMain, fooAtMainAndRelease}, 683 683 }, 684 684 { 685 - 686 685 name: "tombstone foo", 687 686 documents: nil, 688 687 optFn: func(t *testing.T, o *Options) {
+4 -4
build/scoring_test.go
··· 467 467 `), 468 468 query: &query.And{Children: []query.Q{ 469 469 &query.Symbol{Expr: &query.Substring{Pattern: "http", Content: true}}, 470 - &query.Symbol{Expr: &query.Substring{Pattern: "Get", Content: true}}}}, 470 + &query.Symbol{Expr: &query.Substring{Pattern: "Get", Content: true}}, 471 + }}, 471 472 language: "Go", 472 473 // 7000 (full base match) + 800 (Go func) + 50 (Exported Go) + 500 (word) + 200 (atom) + 10 (file order) 473 474 wantScore: 8560, ··· 516 517 Name: "repo", 517 518 }, 518 519 LanguageMap: ctags.LanguageMap{ 519 - normalizeLanguage(c.language): parserType}, 520 + normalizeLanguage(c.language): parserType, 521 + }, 520 522 } 521 523 522 524 epsilon := 0.01 ··· 628 630 DocumentRanksWeight: c.documentRanksWeight, 629 631 DebugScore: true, 630 632 }) 631 - 632 633 if err != nil { 633 634 t.Fatal(err) 634 635 } ··· 717 718 UseDocumentRanks: true, 718 719 DebugScore: true, 719 720 }) 720 - 721 721 if err != nil { 722 722 t.Fatal(err) 723 723 }
-4
cmd/zoekt-dynamic-indexserver/main.go
··· 148 148 dec.DisallowUnknownFields() 149 149 var req indexRequest 150 150 err := dec.Decode(&req) 151 - 152 151 if err != nil { 153 152 log.Printf("Error decoding index request: %v", err) 154 153 http.Error(w, "JSON parser error", http.StatusBadRequest) ··· 170 169 func (s *indexServer) serveTruncate(w http.ResponseWriter, r *http.Request) { 171 170 route := "truncate" 172 171 err := emptyDirectory(s.opts.repoDir) 173 - 174 172 if err != nil { 175 173 err = fmt.Errorf("Failed to empty repoDir repoDir: %v with error: %v", s.opts.repoDir, err) 176 174 ··· 179 177 } 180 178 181 179 err = emptyDirectory(s.opts.indexDir) 182 - 183 180 if err != nil { 184 181 err = fmt.Errorf("Failed to empty repoDir indexDir: %v with error: %v", s.opts.repoDir, err) 185 182 ··· 247 244 248 245 func emptyDirectory(dir string) error { 249 246 files, err := os.ReadDir(dir) 250 - 251 247 if err != nil { 252 248 return err 253 249 }
+1 -4
cmd/zoekt-dynamic-indexserver/main_test.go
··· 13 13 "time" 14 14 ) 15 15 16 - var ( 17 - cmdTimeout = 100 * time.Millisecond 18 - ) 16 + var cmdTimeout = 100 * time.Millisecond 19 17 20 18 func captureOutput(f func()) string { 21 19 var buf bytes.Buffer ··· 91 89 } 92 90 93 91 _, err := indexRepository(opts, req) 94 - 95 92 if err != nil { 96 93 t.Fatal(err) 97 94 }
+2 -1
cmd/zoekt-repo-index/main.go
··· 324 324 // iterateManifest constructs a complete tree from the given Manifest. 325 325 func iterateManifest(mf *manifest.Manifest, 326 326 baseURL url.URL, revPrefix string, 327 - cache *gitindex.RepoCache) (map[fileKey]gitindex.BlobLocation, map[string]plumbing.Hash, error) { 327 + cache *gitindex.RepoCache, 328 + ) (map[fileKey]gitindex.BlobLocation, map[string]plumbing.Hash, error) { 328 329 allFiles := map[fileKey]gitindex.BlobLocation{} 329 330 allVersions := map[string]plumbing.Hash{} 330 331 for _, p := range mf.Project {
+2 -1
cmd/zoekt-sourcegraph-indexserver/backoff.go
··· 1 1 package main 2 2 3 3 import ( 4 + "time" 5 + 4 6 "github.com/sourcegraph/log" 5 - "time" 6 7 ) 7 8 8 9 type backoff struct {
+2 -1
cmd/zoekt-sourcegraph-indexserver/backoff_test.go
··· 1 1 package main 2 2 3 3 import ( 4 - "github.com/sourcegraph/log/logtest" 5 4 "testing" 6 5 "time" 6 + 7 + "github.com/sourcegraph/log/logtest" 7 8 ) 8 9 9 10 func TestQueue_BackoffOnFail(t *testing.T) {
+1 -1
cmd/zoekt-sourcegraph-indexserver/cleanup.go
··· 30 30 func cleanup(indexDir string, repos []uint32, now time.Time, shardMerging bool) { 31 31 start := time.Now() 32 32 trashDir := filepath.Join(indexDir, ".trash") 33 - if err := os.MkdirAll(trashDir, 0755); err != nil { 33 + if err := os.MkdirAll(trashDir, 0o755); err != nil { 34 34 log.Printf("failed to create trash dir: %v", err) 35 35 } 36 36
+2 -2
cmd/zoekt-sourcegraph-indexserver/cleanup_test.go
··· 164 164 func createTestShard(t *testing.T, repo string, id uint32, path string, optFns ...func(in *zoekt.Repository)) { 165 165 t.Helper() 166 166 167 - if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil { 167 + if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil { 168 168 t.Fatal(err) 169 169 } 170 170 r := &zoekt.Repository{ ··· 178 178 if err != nil { 179 179 t.Fatal(err) 180 180 } 181 - f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0600) 181 + f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o600) 182 182 if err != nil { 183 183 t.Fatal(err) 184 184 }
+4 -3
cmd/zoekt-sourcegraph-indexserver/index.go
··· 221 221 metricFetchDuration.WithLabelValues(success, name).Observe(fetchDuration.Seconds()) 222 222 }() 223 223 224 - var runFetch = func(branches []zoekt.RepositoryBranch) error { 224 + runFetch := func(branches []zoekt.RepositoryBranch) error { 225 225 // We shallow fetch each commit specified in zoekt.Branches. This requires 226 226 // the server to have configured both uploadpack.allowAnySHA1InWant and 227 227 // uploadpack.allowFilter. (See gitservice.go in the Sourcegraph repository) ··· 229 229 "-C", gitDir, 230 230 "-c", "protocol.version=2", 231 231 "-c", "http.extraHeader=X-Sourcegraph-Actor-UID: internal", 232 - "fetch", "--depth=1", o.CloneURL} 232 + "fetch", "--depth=1", o.CloneURL, 233 + } 233 234 234 235 var commits []string 235 236 for _, b := range branches { ··· 359 360 return err 360 361 } 361 362 362 - if err := os.WriteFile(documentsRankFile, b, 0600); err != nil { 363 + if err := os.WriteFile(documentsRankFile, b, 0o600); err != nil { 363 364 return fmt.Errorf("failed to write %s to disk: %w", documentsRankFile, err) 364 365 } 365 366
-6
cmd/zoekt-sourcegraph-indexserver/index_test.go
··· 157 157 } 158 158 }) 159 159 } 160 - 161 160 }) 162 161 163 162 t.Run("REST", func(t *testing.T) { ··· 321 320 } 322 321 }) 323 322 } 324 - 325 323 }) 326 324 } 327 325 328 326 func TestGetIndexOptions(t *testing.T) { 329 327 t.Run("gRPC", func(t *testing.T) { 330 - 331 328 type testCase struct { 332 329 name string 333 330 response *proto.SearchConfigurationResponse ··· 465 462 // Mimic our fingerprint API, which doesn't return anything if the 466 463 // repo hasn't changed. 467 464 t.Run("unchanged", func(t *testing.T) { 468 - 469 465 called := false 470 466 mockClient := &mockGRPCClient{ 471 467 mockSearchConfiguration: func(_ context.Context, _ *proto.SearchConfigurationRequest, _ ...grpc.CallOption) (*proto.SearchConfigurationResponse, error) { ··· 506 502 t.Fatalf("expected no options, got %v", gotAtLeastOneOption) 507 503 } 508 504 }) 509 - 510 505 }) 511 506 t.Run("REST", func(t *testing.T) { 512 507 var response []byte ··· 834 829 835 830 for _, tc := range cases { 836 831 t.Run(tc.name, func(t *testing.T) { 837 - 838 832 var got []string 839 833 runCmd := func(c *exec.Cmd) error { 840 834 cmd := strings.Join(c.Args, " ")
+3 -5
cmd/zoekt-sourcegraph-indexserver/main.go
··· 902 902 // trigger an initial merge run. In the steady-state, merges happen rarely, even 903 903 // on busy instances, and users can rely on automatic merging instead. 904 904 func (s *Server) handleDebugMerge(w http.ResponseWriter, _ *http.Request) { 905 - 906 905 // A merge operation can take very long, depending on the number merges and the 907 906 // target size of the compound shards. We run the merge in the background and 908 907 // return immediately to the user. ··· 1027 1026 } 1028 1027 } 1029 1028 1030 - if err := os.MkdirAll(tmpRoot, 0755); err != nil { 1029 + if err := os.MkdirAll(tmpRoot, 0o755); err != nil { 1031 1030 return err 1032 1031 } 1033 1032 ··· 1275 1274 go func() { 1276 1275 debug.Printf("serving HTTP on %s", conf.listen) 1277 1276 log.Fatal(http.ListenAndServe(conf.listen, mux)) 1278 - 1279 1277 }() 1280 1278 1281 1279 // Serve mux on a unix domain socket on a best-effort-basis so that ··· 1303 1301 // it. 1304 1302 // 1305 1303 // See https://github.com/golang/go/issues/11822 for more context. 1306 - if err := os.Chmod(socket, 0777); err != nil { 1304 + if err := os.Chmod(socket, 0o777); err != nil { 1307 1305 return fmt.Errorf("failed to change permission of socket %s: %w", socket, err) 1308 1306 } 1309 1307 debug.Printf("serving HTTP on %s", socket) ··· 1362 1360 } 1363 1361 1364 1362 if _, err := os.Stat(conf.index); err != nil { 1365 - if err := os.MkdirAll(conf.index, 0755); err != nil { 1363 + if err := os.MkdirAll(conf.index, 0o755); err != nil { 1366 1364 return nil, fmt.Errorf("MkdirAll %s: %v", conf.index, err) 1367 1365 } 1368 1366 }
-2
cmd/zoekt-sourcegraph-indexserver/main_test.go
··· 134 134 135 135 func TestListRepoIDs(t *testing.T) { 136 136 t.Run("gRPC", func(t *testing.T) { 137 - 138 137 grpcClient := &mockGRPCClient{} 139 138 140 139 clientOptions := []SourcegraphClientOption{ ··· 247 246 248 247 msg := "deadbeaf deadbeaf" 249 248 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 250 - 251 249 // This is how Sourcegraph returns error messages to the caller. 252 250 http.Error(w, msg, http.StatusInternalServerError) 253 251 }))
-1
cmd/zoekt-sourcegraph-indexserver/merge.go
··· 57 57 58 58 // same as doMerge but with a configurable merge command. 59 59 func (s *Server) merge(mergeCmd func(args ...string) *exec.Cmd) { 60 - 61 60 // Guard against the user triggering competing merge jobs with the debug 62 61 // command. 63 62 if !mergeRunning.CompareAndSwap(false, true) {
-2
cmd/zoekt-sourcegraph-indexserver/merge_test.go
··· 118 118 } 119 119 120 120 func TestMerge(t *testing.T) { 121 - 122 121 // A fixed set of shards gives us reliable shard sizes which makes it easy to 123 122 // define a cutoff with targetSizeBytes. 124 123 m := []string{ ··· 197 196 checkCount(dir, "*_v16.00000.zoekt", tc.wantSimple) 198 197 }) 199 198 } 200 - 201 199 } 202 200 203 201 func copyTestShards(dstDir string, srcShards []string) ([]string, error) {
+1 -1
cmd/zoekt-sourcegraph-indexserver/owner.go
··· 67 67 `, o.Hostname)) 68 68 69 69 // Always write out since we may update the comment 70 - if err := os.WriteFile(o.Path, content, 0600); err != nil { 70 + if err := os.WriteFile(o.Path, content, 0o600); err != nil { 71 71 return fmt.Errorf("failed to write owner file %s: %w", o.Path, err) 72 72 } 73 73
+1 -1
cmd/zoekt-sourcegraph-indexserver/owner_test.go
··· 38 38 assertSuccess(bob.Check()) // bob is still the owner 39 39 40 40 // Test what happens if someone corrupts the file 41 - if err := os.WriteFile(path, []byte("!corrupt"), 0600); err != nil { 41 + if err := os.WriteFile(path, []byte("!corrupt"), 0o600); err != nil { 42 42 t.Fatal(err) 43 43 } 44 44 assertFailed(alice.Check()) // corrupt so fail
-1
cmd/zoekt-sourcegraph-indexserver/queue_test.go
··· 129 129 } 130 130 131 131 func TestQueue_Integration_DebugQueue(t *testing.T) { 132 - 133 132 // helper function to normalize the queue's debug output - this makes the test less brittle 134 133 // + makes it much less annoying to make edits to the expected output in a way that doesn't 135 134 // materially affect the caller
-3
cmd/zoekt-sourcegraph-indexserver/sg.go
··· 141 141 } 142 142 143 143 return client 144 - 145 144 } 146 145 147 146 // sourcegraphClient contains methods which interact with the sourcegraph API. ··· 763 762 func (s *sourcegraphClient) updateIndexStatusGRPC(r updateIndexStatusRequest) error { 764 763 request := r.ToProto() 765 764 _, err := s.grpcClient.UpdateIndexStatus(context.Background(), request) 766 - 767 765 if err != nil { 768 766 return fmt.Errorf("failed to update index status: %w", err) 769 767 } ··· 924 922 items[idx] = indexOptionsItem{IndexOptions: opts} 925 923 } 926 924 }) 927 - 928 925 if err != nil { 929 926 return nil, err 930 927 }
+4 -2
cmd/zoekt-test/main.go
··· 169 169 return nil 170 170 } 171 171 172 - var memprofile = flag.String("memprofile", "", "write memory profile to `file`") 173 - var cpuprofile = flag.String("cpuprofile", "", "write memory profile to `file`") 172 + var ( 173 + memprofile = flag.String("memprofile", "", "write memory profile to `file`") 174 + cpuprofile = flag.String("cpuprofile", "", "write memory profile to `file`") 175 + ) 174 176 175 177 func testLoadIndexDir(indexDir string) { 176 178 var a, b runtime.MemStats
-2
cmd/zoekt-webserver/grpc/server/server_test.go
··· 129 129 if diff := cmp.Diff(expectedResult.GetProgress(), receivedResponse.GetProgress(), protocmp.Transform()); diff != "" { 130 130 return fmt.Errorf("unexpected difference in progress (-want +got):\n%s", diff) 131 131 } 132 - 133 132 } else { 134 133 // All other responses should ensure that the progress' priority is less than the max-pending priority, to 135 134 // ensure that the client consumes the entire set of chunks ··· 140 139 i, receivedResponse, 141 140 receivedResponse.GetProgress().GetPriority(), receivedResponse.GetProgress().GetMaxPendingPriority(), 142 141 ) 143 - 144 142 } 145 143 } 146 144
+1 -3
cmd/zoekt-webserver/main.go
··· 551 551 opts *zoekt.SearchOptions, 552 552 sender zoekt.Sender, 553 553 ) error { 554 - var ( 555 - stats zoekt.Stats 556 - ) 554 + var stats zoekt.Stats 557 555 558 556 metricSearchRequestsTotal.Inc() 559 557 err := s.Streamer.StreamSearch(ctx, q, opts, stream.SenderFunc(func(event *zoekt.SearchResult) {
+2 -1
cmd/zoekt-webserver/main_linux.go
··· 1 1 package main 2 2 3 3 import ( 4 + "path" 5 + 4 6 "github.com/prometheus/client_golang/prometheus" 5 7 "github.com/prometheus/procfs" 6 8 sglog "github.com/sourcegraph/log" 7 - "path" 8 9 ) 9 10 10 11 func mustRegisterMemoryMapMetrics(logger sglog.Logger) {
+2 -1
eval_test.go
··· 351 351 {"main", "v1"}, 352 352 {"bar", "v1"}, 353 353 {"quz", "v1"}, 354 - }}, 354 + }, 355 + }, 355 356 Document{Name: "f1", Content: content, Branches: []string{"foo", "bar", "quz"}}, 356 357 Document{Name: "f2", Content: content, Branches: []string{"foo", "foo-2"}}, 357 358 Document{Name: "f3", Content: content, Branches: []string{"main"}})
-1
gitindex/filter.go
··· 42 42 var err error 43 43 if includeRegex != "" { 44 44 f.inc, err = regexp.Compile(includeRegex) 45 - 46 45 if err != nil { 47 46 return nil, err 48 47 }
+1 -1
gitindex/ignore_test.go
··· 17 17 ) 18 18 19 19 func createSourcegraphignoreRepo(dir string) error { 20 - if err := os.MkdirAll(dir, 0755); err != nil { 20 + if err := os.MkdirAll(dir, 0o755); err != nil { 21 21 return err 22 22 } 23 23 script := `mkdir repo
+3 -3
gitindex/index_test.go
··· 562 562 563 563 file := filepath.Join(repositoryDir, d.Name) 564 564 565 - err := os.MkdirAll(filepath.Dir(file), 0755) 565 + err := os.MkdirAll(filepath.Dir(file), 0o755) 566 566 if err != nil { 567 567 t.Fatalf("ensuring that folders exist for file %q: %s", file, err) 568 568 } 569 569 570 - err = os.WriteFile(file, d.Content, 0644) 570 + err = os.WriteFile(file, d.Content, 0o644) 571 571 if err != nil { 572 572 t.Fatalf("writing file %q: %s", d.Name, err) 573 573 } ··· 753 753 } 754 754 755 755 func runScript(t *testing.T, cwd string, script string) { 756 - err := os.MkdirAll(cwd, 0755) 756 + err := os.MkdirAll(cwd, 0o755) 757 757 if err != nil { 758 758 t.Fatalf("ensuring path %q exists: %s", cwd, err) 759 759 }
+12 -9
gitindex/submodule_test.go
··· 23 23 cases := []struct { 24 24 data string 25 25 want map[string]*SubmoduleEntry 26 - }{{ 27 - `[submodule "plugins/abc"] 26 + }{ 27 + { 28 + `[submodule "plugins/abc"] 28 29 path = plugins/abc 29 30 url = ../plugins/abc 30 31 branch = .`, 31 - map[string]*SubmoduleEntry{ 32 - "plugins/abc": { 33 - Path: "plugins/abc", 34 - URL: "../plugins/abc", 35 - Branch: ".", 32 + map[string]*SubmoduleEntry{ 33 + "plugins/abc": { 34 + Path: "plugins/abc", 35 + URL: "../plugins/abc", 36 + Branch: ".", 37 + }, 36 38 }, 37 - }}, 39 + }, 38 40 { 39 41 "\uFEFF" + `[submodule "plugins/abc"] 40 42 path = plugins/abc ··· 46 48 URL: "../plugins/abc", 47 49 Branch: ".", 48 50 }, 49 - }}, 51 + }, 52 + }, 50 53 {"", map[string]*SubmoduleEntry{}}, 51 54 } 52 55
+2 -1
gitindex/tree.go
··· 98 98 // non-nil, recurse into submodules. In addition, it returns a mapping 99 99 // that indicates in which repo each SHA1 can be found. 100 100 func TreeToFiles(r *git.Repository, t *object.Tree, 101 - repoURL string, repoCache *RepoCache) (map[fileKey]BlobLocation, map[string]plumbing.Hash, error) { 101 + repoURL string, repoCache *RepoCache, 102 + ) (map[fileKey]BlobLocation, map[string]plumbing.Hash, error) { 102 103 rw := newRepoWalker(r, repoURL, repoCache) 103 104 104 105 if err := rw.parseModuleMap(t); err != nil {
-1
grpc/chunk/chunker_test.go
··· 201 201 receivedPayloadSizeBytes, humanize.Bytes(uint64(receivedPayloadSizeBytes)), 202 202 ) 203 203 } 204 - 205 204 }) 206 205 } 207 206 }
-2
grpc/internalerrs/common.go
··· 208 208 209 209 return nil 210 210 }) 211 - 212 211 if err != nil { 213 212 return nil, fmt.Errorf("iterating over proto message: %w", err) 214 213 } ··· 228 227 229 228 if errors.Is(err, context.Canceled) { 230 229 return status.New(codes.Canceled, context.Canceled.Error()), true 231 - 232 230 } 233 231 234 232 if errors.Is(err, context.DeadlineExceeded) {
-1
grpc/internalerrs/prometheus.go
··· 87 87 } 88 88 }, 89 89 } 90 - 91 90 } 92 91 93 92 func doObservation(serviceName, methodName string, rpcErr error) {
-2
grpc/messagesize/messagesize_test.go
··· 9 9 ) 10 10 11 11 func TestGetMessageSizeBytesFromString(t *testing.T) { 12 - 13 12 t.Run("8 MB", func(t *testing.T) { 14 13 sizeString := "8MB" 15 14 16 15 size, err := getMessageSizeBytesFromString(sizeString, 0, math.MaxInt) 17 - 18 16 if err != nil { 19 17 t.Fatalf("unexpected error: %s", err) 20 18 }
+6 -4
grpc/messagesize/prometheus_test.go
··· 161 161 } 162 162 163 163 func TestStreamServerInterceptor(t *testing.T) { 164 - 165 164 response1 := &newspb.BinaryAttachment{ 166 165 Name: "", 167 166 Data: []byte("response"), ··· 666 665 "key2": "value2", 667 666 }, 668 667 }, 669 - }}, 668 + }, 669 + }, 670 670 } 671 671 672 672 for _, tc := range testCases { ··· 754 754 return errors.New("close send not implemented") 755 755 } 756 756 757 - var _ grpc.ServerStream = &mockServerStream{} 758 - var _ grpc.ClientStream = &mockClientStream{} 757 + var ( 758 + _ grpc.ServerStream = &mockServerStream{} 759 + _ grpc.ClientStream = &mockClientStream{} 760 + )
+4 -2
ignore/ignore_test.go
··· 18 18 ignoreFile: []byte("# ignore this \n \n foo\n bar/"), 19 19 wantIgnoreList: []glob.Glob{ 20 20 glob.MustCompile("foo**", '/'), 21 - glob.MustCompile("bar/**", '/')}, 21 + glob.MustCompile("bar/**", '/'), 22 + }, 22 23 }, 23 24 { 24 25 ignoreFile: []byte("/foo/bar \n /qux \n *.go\nfoo.go"), ··· 26 27 glob.MustCompile("foo/bar**", '/'), 27 28 glob.MustCompile("qux**", '/'), 28 29 glob.MustCompile("*.go", '/'), 29 - glob.MustCompile("foo.go", '/')}, 30 + glob.MustCompile("foo.go", '/'), 31 + }, 30 32 }, 31 33 } 32 34
-7
index_test.go
··· 595 595 } 596 596 }) 597 597 } 598 - 599 598 }) 600 599 } 601 600 ··· 977 976 if len(matches[0].LineMatches[0].Line) != 4 || len(matches[1].LineMatches[0].Line) != 4 { 978 977 t.Fatalf("want 4 chars in every file, got %#v", matches) 979 978 } 980 - 981 979 }) 982 980 983 981 t.Run("ChunkMatches", func(t *testing.T) { ··· 990 988 if len(matches[0].ChunkMatches[0].Content) != 4 || len(matches[1].ChunkMatches[0].Content) != 4 { 991 989 t.Fatalf("want 4 chars in every file, got %#v", matches) 992 990 } 993 - 994 991 }) 995 992 } 996 993 ··· 1228 1225 t.Fatalf("got branches %q, want %q", f.Branches, branches) 1229 1226 } 1230 1227 }) 1231 - 1232 1228 } 1233 1229 1234 1230 func TestBranchVersions(t *testing.T) { ··· 3582 3578 if diff := cmp.Diff(want, got, ignored...); diff != "" { 3583 3579 t.Fatalf("mismatch (-want +got):\n%s", diff) 3584 3580 } 3585 - 3586 3581 }) 3587 3582 3588 3583 t.Run("one simple shard", func(t *testing.T) { ··· 3609 3604 if diff := cmp.Diff(want, got, ignored...); diff != "" { 3610 3605 t.Fatalf("mismatch (-want +got):\n%s", diff) 3611 3606 } 3612 - 3613 3607 }) 3614 3608 3615 3609 t.Run("one compound shard", func(t *testing.T) { ··· 3703 3697 if diff := cmp.Diff(want, got, ignored...); diff != "" { 3704 3698 t.Fatalf("mismatch (-want +got):\n%s", diff) 3705 3699 } 3706 - 3707 3700 }) 3708 3701 } 3709 3702
+7 -5
internal/e2e/e2e_rank_test.go
··· 187 187 188 188 wantPath := filepath.Join("testdata", name+".txt") 189 189 if *update { 190 - if err := os.WriteFile(wantPath, got, 0600); err != nil { 190 + if err := os.WriteFile(wantPath, got, 0o600); err != nil { 191 191 t.Fatal(err) 192 192 } 193 193 } ··· 206 206 Target string 207 207 } 208 208 209 - var tarballCache = "/tmp/zoekt-test-ranking-tarballs-" + os.Getenv("USER") 210 - var shardCache = "/tmp/zoekt-test-ranking-shards-" + os.Getenv("USER") 209 + var ( 210 + tarballCache = "/tmp/zoekt-test-ranking-tarballs-" + os.Getenv("USER") 211 + shardCache = "/tmp/zoekt-test-ranking-shards-" + os.Getenv("USER") 212 + ) 211 213 212 214 func indexURL(indexDir, u string) error { 213 - if err := os.MkdirAll(tarballCache, 0700); err != nil { 215 + if err := os.MkdirAll(tarballCache, 0o700); err != nil { 214 216 return err 215 217 } 216 218 ··· 264 266 } 265 267 defer rc.Close() 266 268 267 - f, err := os.OpenFile(tmpPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) 269 + f, err := os.OpenFile(tmpPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600) 268 270 if err != nil { 269 271 return err 270 272 }
+2 -2
json/json.go
··· 115 115 func CalculateDefaultSearchLimits(ctx context.Context, 116 116 q query.Q, 117 117 searcher zoekt.Searcher, 118 - opts *zoekt.SearchOptions) error { 118 + opts *zoekt.SearchOptions, 119 + ) error { 119 120 if opts.MaxDocDisplayCount == 0 || opts.ShardMaxMatchCount != 0 { 120 121 return nil 121 122 } ··· 134 135 135 136 // 10k docs, 50 maxResultDocs -> max match = (250 + 250 / 10) 136 137 opts.ShardMaxMatchCount = maxResultDocs*5 + (5*maxResultDocs)/(numdocs/1000) 137 - 138 138 } else { 139 139 // Virtually no limits for a small corpus. 140 140 n := numdocs + maxResultDocs*100
-1
matchtree.go
··· 1058 1058 } 1059 1059 masks = append(masks, mask) 1060 1060 } 1061 - 1062 1061 } 1063 1062 return &branchQueryMatchTree{ 1064 1063 masks: masks,
+1 -1
merge_test.go
··· 115 115 116 116 if *update { 117 117 t.Logf("updating %s", shard1) 118 - err := os.WriteFile(shard1, b2, 0600) 118 + err := os.WriteFile(shard1, b2, 0o600) 119 119 if err != nil { 120 120 t.Fatal(err) 121 121 }
-1
query/parse.go
··· 119 119 expr = &caseQ{text} 120 120 case tokRepo: 121 121 r, err := regexp.Compile(text) 122 - 123 122 if err != nil { 124 123 return nil, 0, err 125 124 }
-1
query/query_proto_test.go
··· 101 101 } 102 102 }) 103 103 } 104 - 105 104 } 106 105 107 106 func regexpMustParse(s string) *syntax.Regexp {
+2 -4
read_test.go
··· 58 58 59 59 var toc indexTOC 60 60 err = r.readTOC(&toc) 61 - 62 61 if err != nil { 63 62 t.Errorf("got read error %v", err) 64 63 } ··· 272 271 if raw, err := json.MarshalIndent(got, "", " "); err != nil { 273 272 t.Errorf("failed marshalling search results for %s during updating: %v", name, err) 274 273 continue 275 - } else if err := os.WriteFile(golden, raw, 0644); err != nil { 274 + } else if err := os.WriteFile(golden, raw, 0o644); err != nil { 276 275 t.Errorf("failed writing search results for %s during updating: %v", name, err) 277 276 continue 278 277 } ··· 376 375 outname := fmt.Sprintf("testdata/backcompat/new_v%d.%05d.zoekt", IndexFormatVersion, 0) 377 376 t.Log("writing new file", outname) 378 377 379 - err = os.WriteFile(outname, buf.Bytes(), 0644) 378 + err = os.WriteFile(outname, buf.Bytes(), 0o644) 380 379 if err != nil { 381 380 t.Fatalf("Creating output file: %v", err) 382 381 } ··· 402 401 403 402 var toc indexTOC 404 403 err = r.readTOC(&toc) 405 - 406 404 if err != nil { 407 405 t.Errorf("got read error %v", err) 408 406 }
+5 -7
shards/aggregate.go
··· 12 12 "github.com/sourcegraph/zoekt/stream" 13 13 ) 14 14 15 - var ( 16 - metricFinalAggregateSize = promauto.NewHistogramVec(prometheus.HistogramOpts{ 17 - Name: "zoekt_final_aggregate_size", 18 - Help: "The number of file matches we aggregated before flushing", 19 - Buckets: prometheus.ExponentialBuckets(1, 2, 20), 20 - }, []string{"reason"}) 21 - ) 15 + var metricFinalAggregateSize = promauto.NewHistogramVec(prometheus.HistogramOpts{ 16 + Name: "zoekt_final_aggregate_size", 17 + Help: "The number of file matches we aggregated before flushing", 18 + Buckets: prometheus.ExponentialBuckets(1, 2, 20), 19 + }, []string{"reason"}) 22 20 23 21 // collectSender is a sender that will aggregate results. Once sending is 24 22 // done, you call Done to return the aggregated result which are ranked.
-1
shards/shards.go
··· 770 770 // We split by repository instead of by priority because it is easier to set 771 771 // RepoURLs and LineFragments in zoekt.SearchResult. 772 772 func sendByRepository(result *zoekt.SearchResult, opts *zoekt.SearchOptions, sender zoekt.Sender) { 773 - 774 773 if len(result.RepoURLs) <= 1 || len(result.Files) == 0 { 775 774 zoekt.SortFiles(result.Files) 776 775 sender.Send(result)
-2
shards/shards_test.go
··· 261 261 stream.SenderFunc(func(event *zoekt.SearchResult) { 262 262 results = append(results, event) 263 263 })) 264 - 265 264 if err != nil { 266 265 t.Fatal(err) 267 266 } ··· 863 862 // n1, n2, n3 are the number of file matches for each of the 3 repositories in this 864 863 // test. 865 864 f := func(n1, n2, n3 uint8) bool { 866 - 867 865 sr := createMockSearchResult(n1, n2, n3, wantStats) 868 866 869 867 mock := &mockSender{}
+1 -1
shards/watcher_test.go
··· 188 188 for delta := -1; delta <= 1; delta++ { 189 189 repo := fmt.Sprintf("foo_v%d.00000.zoekt", want+delta) 190 190 shard := filepath.Join(dir, repo) 191 - if err := os.WriteFile(shard, []byte("hello"), 0644); err != nil { 191 + if err := os.WriteFile(shard, []byte("hello"), 0o644); err != nil { 192 192 t.Fatalf("WriteFile: %v", err) 193 193 } 194 194 }
+6
trace/trace.go
··· 163 163 func (e *encoder) EmitInt32(key string, value int32) { 164 164 e.EmitString(key, strconv.FormatInt(int64(value), 10)) 165 165 } 166 + 166 167 func (e *encoder) EmitInt64(key string, value int64) { 167 168 e.EmitString(key, strconv.FormatInt(value, 10)) 168 169 } 170 + 169 171 func (e *encoder) EmitUint32(key string, value uint32) { 170 172 e.EmitString(key, strconv.FormatUint(uint64(value), 10)) 171 173 } 174 + 172 175 func (e *encoder) EmitUint64(key string, value uint64) { 173 176 e.EmitString(key, strconv.FormatUint(value, 10)) 174 177 } 178 + 175 179 func (e *encoder) EmitFloat32(key string, value float32) { 176 180 e.EmitString(key, strconv.FormatFloat(float64(value), 'E', -1, 64)) 177 181 } 182 + 178 183 func (e *encoder) EmitFloat64(key string, value float64) { 179 184 e.EmitString(key, strconv.FormatFloat(value, 'E', -1, 64)) 180 185 } 186 + 181 187 func (e *encoder) EmitObject(key string, value interface{}) { 182 188 e.EmitString(key, fmt.Sprintf("%+v", value)) 183 189 }
-1
web/server.go
··· 563 563 } 564 564 565 565 repoRe, err := regexp.Compile("^" + regexp.QuoteMeta(repoStr) + "$") 566 - 567 566 if err != nil { 568 567 return err 569 568 }
+2 -1
write.go
··· 67 67 } 68 68 69 69 func writePostings(w *writer, s *postingsBuilder, ngramText *simpleSection, 70 - charOffsets *simpleSection, postings *compoundSection, endRunes *simpleSection) { 70 + charOffsets *simpleSection, postings *compoundSection, endRunes *simpleSection, 71 + ) { 71 72 keys := make(ngramSlice, 0, len(s.postings)) 72 73 for k := range s.postings { 73 74 keys = append(keys, k)