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

Configure Feed

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

gitindex: respect flag -submodule (#208)

With this change we don't set `RepoCache` if `-submodule=false`;

It turns out that we didn't respect the submodule flag, IE submodules was enabled by default.
This caused issues, e.g. if a repository had an invalid .gitmodules file.

I also wrapped some of the high-level calls that gitindex does to generate better error
messages and speed-up future debugging.

+22 -14
+12 -8
gitindex/index.go
··· 360 360 opts.BuildOptions.RepositoryDescription.Source = opts.RepoDir 361 361 repo, err := git.PlainOpen(opts.RepoDir) 362 362 if err != nil { 363 - return err 363 + return fmt.Errorf("git.PlainOpen: %w", err) 364 364 } 365 365 366 366 if err := setTemplatesFromConfig(&opts.BuildOptions.RepositoryDescription, opts.RepoDir); err != nil { 367 367 log.Printf("setTemplatesFromConfig(%s): %s", opts.RepoDir, err) 368 368 } 369 369 370 - repoCache := NewRepoCache(opts.RepoCacheDir) 370 + var repoCache *RepoCache 371 + if opts.Submodules { 372 + repoCache = NewRepoCache(opts.RepoCacheDir) 373 + } 371 374 372 375 // branch => (path, sha1) => repo. 373 376 repos := map[fileKey]BlobLocation{} ··· 380 383 381 384 branches, err := expandBranches(repo, opts.Branches, opts.BranchPrefix) 382 385 if err != nil { 383 - return err 386 + return fmt.Errorf("expandBranches: %w", err) 384 387 } 385 388 for _, b := range branches { 386 389 commit, err := getCommit(repo, opts.BranchPrefix, b) ··· 389 392 continue 390 393 } 391 394 392 - return err 395 + return fmt.Errorf("getCommit: %w", err) 393 396 } 394 397 395 398 opts.BuildOptions.RepositoryDescription.Branches = append(opts.BuildOptions.RepositoryDescription.Branches, zoekt.RepositoryBranch{ ··· 403 406 404 407 tree, err := commit.Tree() 405 408 if err != nil { 409 + return fmt.Errorf("commit.Tree: %w", err) 406 410 return err 407 411 } 408 412 409 413 ig, err := newIgnoreMatcher(tree) 410 414 if err != nil { 411 - return err 415 + return fmt.Errorf("newIgnoreMatcher: %w", err) 412 416 } 413 417 414 418 files, subVersions, err := TreeToFiles(repo, tree, opts.BuildOptions.RepositoryDescription.URL, repoCache) 415 419 if err != nil { 416 - return err 420 + return fmt.Errorf("TreeToFiles: %w", err) 417 421 } 418 422 for k, v := range files { 419 423 if ig.Match(k.Path) { ··· 458 462 459 463 builder, err := build.NewBuilder(opts.BuildOptions) 460 464 if err != nil { 461 - return err 465 + return fmt.Errorf("build.NewBuilder: %w", err) 462 466 } 463 467 defer builder.Finish() 464 468 ··· 505 509 Content: contents, 506 510 Branches: brs, 507 511 }); err != nil { 508 - return err 512 + return fmt.Errorf("error adding document with name %s: %w", key.FullPath(), err) 509 513 } 510 514 } 511 515 }
+3 -2
gitindex/submodule.go
··· 16 16 17 17 import ( 18 18 "bytes" 19 + "fmt" 19 20 "io" 20 21 21 22 "github.com/go-git/go-git/v5/plumbing/format/config" ··· 37 38 // https://stackoverflow.com/a/21375405 38 39 r, _, err := buf.ReadRune() 39 40 if err != nil && err != io.EOF { 40 - return nil, err 41 + return nil, fmt.Errorf("buf.ReadRune: %w", err) 41 42 } 42 43 if r != '\uFEFF' { 43 44 buf.UnreadRune() ··· 46 47 cfg := &config.Config{} 47 48 48 49 if err := dec.Decode(cfg); err != nil { 49 - return nil, err 50 + return nil, fmt.Errorf("error decoding content %s: %w", string(content), err) 50 51 } 51 52 52 53 result := map[string]*SubmoduleEntry{}
+7 -4
gitindex/tree.go
··· 73 73 74 74 // parseModuleMap initializes rw.submodules. 75 75 func (rw *repoWalker) parseModuleMap(t *object.Tree) error { 76 + if rw.repoCache == nil { 77 + return nil 78 + } 76 79 modEntry, _ := t.File(".gitmodules") 77 80 if modEntry != nil { 78 81 c, err := blobContents(&modEntry.Blob) 79 82 if err != nil { 80 - return err 83 + return fmt.Errorf("blobContents: %w", err) 81 84 } 82 85 mods, err := ParseGitModules(c) 83 86 if err != nil { 84 - return err 87 + return fmt.Errorf("ParseGitModules: %w", err) 85 88 } 86 89 rw.submodules = map[string]*SubmoduleEntry{} 87 90 for _, entry := range mods { ··· 99 102 rw := newRepoWalker(r, repoURL, repoCache) 100 103 101 104 if err := rw.parseModuleMap(t); err != nil { 102 - return nil, nil, err 105 + return nil, nil, fmt.Errorf("parseModuleMap: %w", err) 103 106 } 104 107 105 108 tw := object.NewTreeWalker(t, true, make(map[plumbing.Hash]bool)) ··· 110 113 break 111 114 } 112 115 if err := rw.handleEntry(name, &entry); err != nil { 113 - return nil, nil, err 116 + return nil, nil, fmt.Errorf("handleEntry: %w", err) 114 117 } 115 118 } 116 119 return rw.tree, rw.subRepoVersions, nil