Skip to content

Commit

Permalink
all: gofumpt -l -w .
Browse files Browse the repository at this point in the history
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 ./...
  • Loading branch information
keegancsmith committed Feb 5, 2024
1 parent 245e0ce commit b227501
Show file tree
Hide file tree
Showing 55 changed files with 101 additions and 128 deletions.
12 changes: 7 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ import (
"github.com/sourcegraph/zoekt/query"
)

const mapHeaderBytes uint64 = 48
const sliceHeaderBytes uint64 = 24
const stringHeaderBytes uint64 = 16
const pointerSize uint64 = 8
const interfaceBytes uint64 = 16
const (
mapHeaderBytes uint64 = 48
sliceHeaderBytes uint64 = 24
stringHeaderBytes uint64 = 16
pointerSize uint64 = 8
interfaceBytes uint64 = 16
)

// FileMatch contains all the matches within a file.
type FileMatch struct {
Expand Down
1 change: 0 additions & 1 deletion api_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ func RepositoryBranchFromProto(p *proto.RepositoryBranch) RepositoryBranch {
Name: p.GetName(),
Version: p.GetVersion(),
}

}

func (r *RepositoryBranch) ToProto() *proto.RepositoryBranch {
Expand Down
2 changes: 1 addition & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func benchmarkEncoding(data interface{}) func(*testing.B) {
}

func TestSizeBytesSearchResult(t *testing.T) {
var sr = SearchResult{
sr := SearchResult{
Stats: Stats{}, // 129 bytes
Progress: Progress{}, // 16 bytes
Files: []FileMatch{{ // 24 bytes + 460 bytes
Expand Down
6 changes: 4 additions & 2 deletions btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,12 @@ func (n *innerNode) maybeSplit(opts btreeOpts) (left node, right node, newKey ng
}
return &innerNode{
keys: append(make([]ngram, 0, opts.v-1), n.keys[0:opts.v-1]...),
children: append(make([]node, 0, opts.v), n.children[:opts.v]...)},
children: append(make([]node, 0, opts.v), n.children[:opts.v]...),
},
&innerNode{
keys: append(make([]ngram, 0, (2*opts.v)-1), n.keys[opts.v:]...),
children: append(make([]node, 0, 2*opts.v), n.children[opts.v:]...)},
children: append(make([]node, 0, 2*opts.v), n.children[opts.v:]...),
},
n.keys[opts.v-1],
true
}
Expand Down
5 changes: 2 additions & 3 deletions build/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestBuildv16(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = os.WriteFile(wantP, data, 0644)
err = os.WriteFile(wantP, data, 0o644)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestIsLowPriority(t *testing.T) {
func createTestShard(t *testing.T, indexDir string, r zoekt.Repository, numShards int, optFns ...func(options *Options)) []string {
t.Helper()

if err := os.MkdirAll(filepath.Dir(indexDir), 0700); err != nil {
if err := os.MkdirAll(filepath.Dir(indexDir), 0o700); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -897,7 +897,6 @@ func createTestCompoundShard(t *testing.T, indexDir string, repositories []zoekt
}

func TestIgnoreSizeMax(t *testing.T) {

for _, test := range []struct {
name string
largeFiles []string
Expand Down
3 changes: 1 addition & 2 deletions build/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestBasic(t *testing.T) {
t.Fatal(err)
}

if err := os.WriteFile(p+".meta", b, 0600); err != nil {
if err := os.WriteFile(p+".meta", b, 0o600); err != nil {
t.Fatal(err)
}
}
Expand Down Expand Up @@ -682,7 +682,6 @@ func TestDeltaShards(t *testing.T) {
expectedDocuments: []zoekt.Document{barAtMain, fooAtMainAndRelease},
},
{

name: "tombstone foo",
documents: nil,
optFn: func(t *testing.T, o *Options) {
Expand Down
8 changes: 4 additions & 4 deletions build/scoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ func Get() {
`),
query: &query.And{Children: []query.Q{
&query.Symbol{Expr: &query.Substring{Pattern: "http", Content: true}},
&query.Symbol{Expr: &query.Substring{Pattern: "Get", Content: true}}}},
&query.Symbol{Expr: &query.Substring{Pattern: "Get", Content: true}},
}},
language: "Go",
// 7000 (full base match) + 800 (Go func) + 50 (Exported Go) + 500 (word) + 200 (atom) + 10 (file order)
wantScore: 8560,
Expand Down Expand Up @@ -516,7 +517,8 @@ func checkScoring(t *testing.T, c scoreCase, parserType ctags.CTagsParserType) {
Name: "repo",
},
LanguageMap: ctags.LanguageMap{
normalizeLanguage(c.language): parserType},
normalizeLanguage(c.language): parserType,
},
}

epsilon := 0.01
Expand Down Expand Up @@ -628,7 +630,6 @@ func TestDocumentRanks(t *testing.T) {
DocumentRanksWeight: c.documentRanksWeight,
DebugScore: true,
})

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -717,7 +718,6 @@ func TestRepoRanks(t *testing.T) {
UseDocumentRanks: true,
DebugScore: true,
})

if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/zoekt-dynamic-indexserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ func (s *indexServer) serveIndex(w http.ResponseWriter, r *http.Request) {
dec.DisallowUnknownFields()
var req indexRequest
err := dec.Decode(&req)

if err != nil {
log.Printf("Error decoding index request: %v", err)
http.Error(w, "JSON parser error", http.StatusBadRequest)
Expand All @@ -170,7 +169,6 @@ func (s *indexServer) serveIndex(w http.ResponseWriter, r *http.Request) {
func (s *indexServer) serveTruncate(w http.ResponseWriter, r *http.Request) {
route := "truncate"
err := emptyDirectory(s.opts.repoDir)

if err != nil {
err = fmt.Errorf("Failed to empty repoDir repoDir: %v with error: %v", s.opts.repoDir, err)

Expand All @@ -179,7 +177,6 @@ func (s *indexServer) serveTruncate(w http.ResponseWriter, r *http.Request) {
}

err = emptyDirectory(s.opts.indexDir)

if err != nil {
err = fmt.Errorf("Failed to empty repoDir indexDir: %v with error: %v", s.opts.repoDir, err)

Expand Down Expand Up @@ -247,7 +244,6 @@ func (s *indexServer) startIndexingApi() {

func emptyDirectory(dir string) error {
files, err := os.ReadDir(dir)

if err != nil {
return err
}
Expand Down
5 changes: 1 addition & 4 deletions cmd/zoekt-dynamic-indexserver/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
"time"
)

var (
cmdTimeout = 100 * time.Millisecond
)
var cmdTimeout = 100 * time.Millisecond

func captureOutput(f func()) string {
var buf bytes.Buffer
Expand Down Expand Up @@ -91,7 +89,6 @@ func TestIndexRepository(t *testing.T) {
}

_, err := indexRepository(opts, req)

if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/zoekt-repo-index/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ func getManifest(repo *git.Repository, branch, path string) (*manifest.Manifest,
// iterateManifest constructs a complete tree from the given Manifest.
func iterateManifest(mf *manifest.Manifest,
baseURL url.URL, revPrefix string,
cache *gitindex.RepoCache) (map[fileKey]gitindex.BlobLocation, map[string]plumbing.Hash, error) {
cache *gitindex.RepoCache,
) (map[fileKey]gitindex.BlobLocation, map[string]plumbing.Hash, error) {
allFiles := map[fileKey]gitindex.BlobLocation{}
allVersions := map[string]plumbing.Hash{}
for _, p := range mf.Project {
Expand Down
3 changes: 2 additions & 1 deletion cmd/zoekt-sourcegraph-indexserver/backoff.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/sourcegraph/log"
"time"

"github.com/sourcegraph/log"
)

type backoff struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/zoekt-sourcegraph-indexserver/backoff_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"github.com/sourcegraph/log/logtest"
"testing"
"time"

"github.com/sourcegraph/log/logtest"
)

func TestQueue_BackoffOnFail(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/zoekt-sourcegraph-indexserver/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var metricCleanupDuration = promauto.NewHistogram(prometheus.HistogramOpts{
func cleanup(indexDir string, repos []uint32, now time.Time, shardMerging bool) {
start := time.Now()
trashDir := filepath.Join(indexDir, ".trash")
if err := os.MkdirAll(trashDir, 0755); err != nil {
if err := os.MkdirAll(trashDir, 0o755); err != nil {
log.Printf("failed to create trash dir: %v", err)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/zoekt-sourcegraph-indexserver/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestCleanup(t *testing.T) {
func createTestShard(t *testing.T, repo string, id uint32, path string, optFns ...func(in *zoekt.Repository)) {
t.Helper()

if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
t.Fatal(err)
}
r := &zoekt.Repository{
Expand All @@ -178,7 +178,7 @@ func createTestShard(t *testing.T, repo string, id uint32, path string, optFns .
if err != nil {
t.Fatal(err)
}
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0600)
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o600)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/zoekt-sourcegraph-indexserver/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,16 @@ func gitIndex(c gitIndexConfig, o *indexArgs, sourcegraph Sourcegraph, l sglog.L
metricFetchDuration.WithLabelValues(success, name).Observe(fetchDuration.Seconds())
}()

var runFetch = func(branches []zoekt.RepositoryBranch) error {
runFetch := func(branches []zoekt.RepositoryBranch) error {
// We shallow fetch each commit specified in zoekt.Branches. This requires
// the server to have configured both uploadpack.allowAnySHA1InWant and
// uploadpack.allowFilter. (See gitservice.go in the Sourcegraph repository)
fetchArgs := []string{
"-C", gitDir,
"-c", "protocol.version=2",
"-c", "http.extraHeader=X-Sourcegraph-Actor-UID: internal",
"fetch", "--depth=1", o.CloneURL}
"fetch", "--depth=1", o.CloneURL,
}

var commits []string
for _, b := range branches {
Expand Down Expand Up @@ -359,7 +360,7 @@ func gitIndex(c gitIndexConfig, o *indexArgs, sourcegraph Sourcegraph, l sglog.L
return err
}

if err := os.WriteFile(documentsRankFile, b, 0600); err != nil {
if err := os.WriteFile(documentsRankFile, b, 0o600); err != nil {
return fmt.Errorf("failed to write %s to disk: %w", documentsRankFile, err)
}

Expand Down
6 changes: 0 additions & 6 deletions cmd/zoekt-sourcegraph-indexserver/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ func TestIterateIndexOptions_Fingerprint(t *testing.T) {
}
})
}

})

t.Run("REST", func(t *testing.T) {
Expand Down Expand Up @@ -321,13 +320,11 @@ func TestIterateIndexOptions_Fingerprint(t *testing.T) {
}
})
}

})
}

func TestGetIndexOptions(t *testing.T) {
t.Run("gRPC", func(t *testing.T) {

type testCase struct {
name string
response *proto.SearchConfigurationResponse
Expand Down Expand Up @@ -465,7 +462,6 @@ func TestGetIndexOptions(t *testing.T) {
// Mimic our fingerprint API, which doesn't return anything if the
// repo hasn't changed.
t.Run("unchanged", func(t *testing.T) {

called := false
mockClient := &mockGRPCClient{
mockSearchConfiguration: func(_ context.Context, _ *proto.SearchConfigurationRequest, _ ...grpc.CallOption) (*proto.SearchConfigurationResponse, error) {
Expand Down Expand Up @@ -506,7 +502,6 @@ func TestGetIndexOptions(t *testing.T) {
t.Fatalf("expected no options, got %v", gotAtLeastOneOption)
}
})

})
t.Run("REST", func(t *testing.T) {
var response []byte
Expand Down Expand Up @@ -834,7 +829,6 @@ func TestIndex(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {

var got []string
runCmd := func(c *exec.Cmd) error {
cmd := strings.Join(c.Args, " ")
Expand Down
8 changes: 3 additions & 5 deletions cmd/zoekt-sourcegraph-indexserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,6 @@ func (s *Server) handleDebugList(w http.ResponseWriter, r *http.Request) {
// trigger an initial merge run. In the steady-state, merges happen rarely, even
// on busy instances, and users can rely on automatic merging instead.
func (s *Server) handleDebugMerge(w http.ResponseWriter, _ *http.Request) {

// A merge operation can take very long, depending on the number merges and the
// target size of the compound shards. We run the merge in the background and
// return immediately to the user.
Expand Down Expand Up @@ -1027,7 +1026,7 @@ func setupTmpDir(logger sglog.Logger, main bool, index string) error {
}
}

if err := os.MkdirAll(tmpRoot, 0755); err != nil {
if err := os.MkdirAll(tmpRoot, 0o755); err != nil {
return err
}

Expand Down Expand Up @@ -1275,7 +1274,6 @@ func startServer(conf rootConfig) error {
go func() {
debug.Printf("serving HTTP on %s", conf.listen)
log.Fatal(http.ListenAndServe(conf.listen, mux))

}()

// Serve mux on a unix domain socket on a best-effort-basis so that
Expand Down Expand Up @@ -1303,7 +1301,7 @@ func startServer(conf rootConfig) error {
// it.
//
// See https://github.com/golang/go/issues/11822 for more context.
if err := os.Chmod(socket, 0777); err != nil {
if err := os.Chmod(socket, 0o777); err != nil {
return fmt.Errorf("failed to change permission of socket %s: %w", socket, err)
}
debug.Printf("serving HTTP on %s", socket)
Expand Down Expand Up @@ -1362,7 +1360,7 @@ func newServer(conf rootConfig) (*Server, error) {
}

if _, err := os.Stat(conf.index); err != nil {
if err := os.MkdirAll(conf.index, 0755); err != nil {
if err := os.MkdirAll(conf.index, 0o755); err != nil {
return nil, fmt.Errorf("MkdirAll %s: %v", conf.index, err)
}
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/zoekt-sourcegraph-indexserver/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func TestServer_parallelism(t *testing.T) {

func TestListRepoIDs(t *testing.T) {
t.Run("gRPC", func(t *testing.T) {

grpcClient := &mockGRPCClient{}

clientOptions := []SourcegraphClientOption{
Expand Down Expand Up @@ -247,7 +246,6 @@ func TestListRepoIDs_Error_REST(t *testing.T) {

msg := "deadbeaf deadbeaf"
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

// This is how Sourcegraph returns error messages to the caller.
http.Error(w, msg, http.StatusInternalServerError)
}))
Expand Down
1 change: 0 additions & 1 deletion cmd/zoekt-sourcegraph-indexserver/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func (s *Server) doMerge() {

// same as doMerge but with a configurable merge command.
func (s *Server) merge(mergeCmd func(args ...string) *exec.Cmd) {

// Guard against the user triggering competing merge jobs with the debug
// command.
if !mergeRunning.CompareAndSwap(false, true) {
Expand Down
2 changes: 0 additions & 2 deletions cmd/zoekt-sourcegraph-indexserver/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func TestCallMerge(t *testing.T) {
}

func TestMerge(t *testing.T) {

// A fixed set of shards gives us reliable shard sizes which makes it easy to
// define a cutoff with targetSizeBytes.
m := []string{
Expand Down Expand Up @@ -197,7 +196,6 @@ func TestMerge(t *testing.T) {
checkCount(dir, "*_v16.00000.zoekt", tc.wantSimple)
})
}

}

func copyTestShards(dstDir string, srcShards []string) ([]string, error) {
Expand Down
Loading

0 comments on commit b227501

Please sign in to comment.