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

Configure Feed

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

all: fix golangci-lint errors

Only ignored errcheck and composites.

+9 -125
+1 -1
build/ctags.go
··· 210 210 // "start and "end" into "symOffsets". It returns -1 if the new section overlaps 211 211 // with one of the existing ones. 212 212 func overlaps(symOffsets []zoekt.DocumentSection, start, end uint32) int { 213 - var i = 0 213 + i := 0 214 214 for i = len(symOffsets) - 1; i >= 0; i-- { 215 215 // The most common case is that we exit here, because symOffsets is sorted by 216 216 // construction and start is in many cases monotonically increasing.
-1
build/e2e_test.go
··· 579 579 type step struct { 580 580 name string 581 581 documents []zoekt.Document 582 - branches []zoekt.RepositoryBranch 583 582 optFn func(t *testing.T, o *Options) 584 583 585 584 query string
+1 -1
cmd/zoekt-mirror-gerrit/main.go
··· 144 144 } 145 145 146 146 for k, v := range *page { 147 - if *active == false || "ACTIVE" == v.State { 147 + if !*active || "ACTIVE" == v.State { 148 148 projects[k] = v 149 149 } 150 150 skip = skip + 1
+1 -1
cmd/zoekt-sourcegraph-indexserver/merge.go
··· 62 62 63 63 // Guard against the user triggering competing merge jobs with the debug 64 64 // command. 65 - if !mergeRunning.CAS(false, true) { 65 + if !mergeRunning.CompareAndSwap(false, true) { 66 66 log.Printf("merge already running") 67 67 return 68 68 }
+6 -3
json/json_test.go
··· 3 3 import ( 4 4 "bytes" 5 5 "encoding/json" 6 - "io/ioutil" 6 + "io" 7 7 "net/http" 8 8 "net/http/httptest" 9 9 "reflect" ··· 50 50 t.Fatal(err) 51 51 } 52 52 if r.StatusCode != 200 { 53 - body, _ := ioutil.ReadAll(r.Body) 53 + body, _ := io.ReadAll(r.Body) 54 54 t.Fatalf("Got status code %d, err %s", r.StatusCode, string(body)) 55 55 } 56 56 ··· 72 72 t.Fatal(err) 73 73 } 74 74 if r.StatusCode != 200 { 75 - body, _ := ioutil.ReadAll(r.Body) 75 + body, _ := io.ReadAll(r.Body) 76 76 t.Fatalf("Got status code %d, err %s", r.StatusCode, string(body)) 77 77 } 78 78 79 79 var listResult struct{ List *zoekt.RepoList } 80 80 err = json.NewDecoder(r.Body).Decode(&listResult) 81 + if err != nil { 82 + t.Fatal(err) 83 + } 81 84 if !reflect.DeepEqual(listResult.List, mock.RepoList) { 82 85 t.Fatalf("got %+v, want %+v", listResult, mock.RepoList) 83 86 }
-106
query/marshal.go
··· 11 11 "github.com/RoaringBitmap/roaring" 12 12 ) 13 13 14 - // We implement a custom binary marshaller for a list of repos to 15 - // branches. When profiling Sourcegraph this is one of the dominant items. 16 - // 17 - // Wire-format of map[string][]string is pretty straightforward: 18 - // 19 - // byte(1) version 20 - // uvarint(len(map)) 21 - // for k, vs in map: 22 - // str(k) 23 - // uvarint(len(vs)) 24 - // for v in vs: 25 - // str(v) 26 - // 27 - // where str(v) is uvarint(len(v)) bytes(v) 28 - // 29 - // The above format gives about the same size encoding as gob does. However, 30 - // gob doesn't have a specialization for map[string][]string so we get to 31 - // avoid a lot of intermediate allocations. 32 - // 33 - // The only other specialization we add is treating []string{"HEAD"} as if it 34 - // was []string{}. This is the most common value for branches so avoids the 35 - // need to write it on the wire. This makes us beat gob for encoded size. 36 - // 37 - // The above adds up to a huge improvement, worth the extra complexity: 38 - // 39 - // name old time/op new time/op delta 40 - // RepoBranches_Encode-8 2.37ms ± 3% 0.62ms ± 0% -73.77% (p=0.000 n=10+8) 41 - // RepoBranches_Decode-8 4.19ms ± 2% 0.74ms ± 1% -82.37% (p=0.000 n=10+9) 42 - // 43 - // name old bytes new bytes delta 44 - // RepoBranches_Encode-8 393kB ± 0% 344kB ± 0% -12.48% (p=0.000 n=10+10) 45 - // 46 - // name old alloc/op new alloc/op delta 47 - // RepoBranches_Encode-8 726kB ± 0% 344kB ± 0% -52.60% (p=0.000 n=10+9) 48 - // RepoBranches_Decode-8 2.31MB ± 0% 1.44MB ± 0% -37.51% (p=0.000 n=9+10) 49 - // 50 - // name old allocs/op new allocs/op delta 51 - // RepoBranches_Encode-8 20.0k ± 0% 0.0k ± 0% -100.00% (p=0.000 n=10+10) 52 - // RepoBranches_Decode-8 50.6k ± 0% 0.4k ± 0% -99.26% (p=0.000 n=10+10) 53 - 54 - // repoBranchesEncode implements an efficient encoder for RepoBranches. 55 - func repoBranchesEncode(repoBranches map[string][]string) ([]byte, error) { 56 - var b bytes.Buffer 57 - var enc [binary.MaxVarintLen64]byte 58 - varint := func(n int) { 59 - m := binary.PutUvarint(enc[:], uint64(n)) 60 - b.Write(enc[:m]) 61 - } 62 - str := func(s string) { 63 - varint(len(s)) 64 - b.WriteString(s) 65 - } 66 - strSize := func(s string) int { 67 - return binary.PutUvarint(enc[:], uint64(len(s))) + len(s) 68 - } 69 - 70 - // Calculate size 71 - size := 1 // version 72 - size += binary.PutUvarint(enc[:], uint64(len(repoBranches))) 73 - for name, branches := range repoBranches { 74 - size += strSize(name) + 1 75 - if l := len(branches); l == 1 && branches[0] == "HEAD" { 76 - continue 77 - } else if l == 0 { 78 - // We reserve "0" for the "HEAD" special case. 79 - return nil, fmt.Errorf("repo with no branches: %q", name) 80 - } else if l > 255 { 81 - // We encode branches len as a byte (saves 11% cpu vs varint). This is 82 - // fine sinze Zoekt can only index upto 64 branches (uses a bitmask on a 83 - // 64bit int to encode branch information for a document) 84 - return nil, fmt.Errorf("can't encode more than 255 branches: %d", l) 85 - } 86 - for _, branch := range branches { 87 - size += strSize(branch) 88 - } 89 - } 90 - b.Grow(size) 91 - 92 - // Version 93 - b.WriteByte(1) 94 - 95 - // Length 96 - varint(len(repoBranches)) 97 - 98 - for name, branches := range repoBranches { 99 - str(name) 100 - 101 - // Special case "HEAD" 102 - if len(branches) == 1 && branches[0] == "HEAD" { 103 - branches = nil 104 - } 105 - 106 - b.WriteByte(byte(len(branches))) 107 - for _, branch := range branches { 108 - str(branch) 109 - } 110 - } 111 - 112 - return b.Bytes(), nil 113 - } 114 - 115 - // head is the most common slice of branches we search. We re-use it to avoid 116 - // allocations when decoding. We know that zoekt never mutates the 117 - // repoBranches slice, so it is safe to share this slice. 118 - var head = []string{"HEAD"} 119 - 120 14 func branchesReposEncode(brs []BranchRepos) ([]byte, error) { 121 15 var b bytes.Buffer 122 16 var enc [binary.MaxVarintLen64]byte
-12
shards/shards.go
··· 1055 1055 return s, nil 1056 1056 } 1057 1057 1058 - func strSliceEqual(a, b []string) bool { 1059 - if len(a) != len(b) { 1060 - return false 1061 - } 1062 - for i := range a { 1063 - if a[i] != b[i] { 1064 - return false 1065 - } 1066 - } 1067 - return true 1068 - } 1069 - 1070 1058 // prioritySlice is a trivial implementation of an array that provides three 1071 1059 // things: appending a value, removing a value, and getting the array's max. 1072 1060 // Operations take O(n) time, which is acceptable because N is restricted to