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

Configure Feed

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

Make IndexGitRepo signal whether there were changes (#781)

As described, we'd like this information to be externally available to
drive metrics for incremental indexing.

Closes #780.

author
Ian Kerins
committer
GitHub
date (May 29, 2024, 9:09 AM -0700) commit f9834a41 parent 640102a4
+30 -26
+1 -1
cmd/zoekt-git-index/main.go
··· 122 122 DeltaShardNumberFallbackThreshold: *deltaShardNumberFallbackThreshold, 123 123 } 124 124 125 - if err := gitindex.IndexGitRepo(gitOpts); err != nil { 125 + if _, err := gitindex.IndexGitRepo(gitOpts); err != nil { 126 126 log.Printf("indexGitRepo(%s, delta=%t): %v", dir, gitOpts.BuildOptions.IsDelta, err) 127 127 exitStatus = 1 128 128 }
+1 -1
gitindex/ignore_test.go
··· 73 73 Submodules: true, 74 74 Incremental: true, 75 75 } 76 - if err := IndexGitRepo(opts); err != nil { 76 + if _, err := IndexGitRepo(opts); err != nil { 77 77 t.Fatalf("IndexGitRepo: %v", err) 78 78 } 79 79
+18 -14
gitindex/index.go
··· 388 388 } 389 389 390 390 // IndexGitRepo indexes the git repository as specified by the options. 391 - func IndexGitRepo(opts Options) error { 391 + // The returned bool indicates whether the index was updated as a result. This 392 + // can be informative if doing incremental indexing. 393 + func IndexGitRepo(opts Options) (bool, error) { 392 394 return indexGitRepo(opts, gitIndexConfig{}) 393 395 } 394 396 395 397 // indexGitRepo indexes the git repository as specified by the options and the provided gitIndexConfig. 396 - func indexGitRepo(opts Options, config gitIndexConfig) error { 398 + // The returned bool indicates whether the index was updated as a result. This 399 + // can be informative if doing incremental indexing. 400 + func indexGitRepo(opts Options, config gitIndexConfig) (bool, error) { 397 401 prepareDeltaBuild := prepareDeltaBuild 398 402 if config.prepareDeltaBuild != nil { 399 403 prepareDeltaBuild = config.prepareDeltaBuild ··· 407 411 // Set max thresholds, since we use them in this function. 408 412 opts.BuildOptions.SetDefaults() 409 413 if opts.RepoDir == "" { 410 - return fmt.Errorf("gitindex: must set RepoDir") 414 + return false, fmt.Errorf("gitindex: must set RepoDir") 411 415 } 412 416 413 417 opts.BuildOptions.RepositoryDescription.Source = opts.RepoDir 414 418 repo, err := git.PlainOpen(opts.RepoDir) 415 419 if err != nil { 416 - return fmt.Errorf("git.PlainOpen: %w", err) 420 + return false, fmt.Errorf("git.PlainOpen: %w", err) 417 421 } 418 422 419 423 if err := setTemplatesFromConfig(&opts.BuildOptions.RepositoryDescription, opts.RepoDir); err != nil { ··· 422 426 423 427 branches, err := expandBranches(repo, opts.Branches, opts.BranchPrefix) 424 428 if err != nil { 425 - return fmt.Errorf("expandBranches: %w", err) 429 + return false, fmt.Errorf("expandBranches: %w", err) 426 430 } 427 431 for _, b := range branches { 428 432 commit, err := getCommit(repo, opts.BranchPrefix, b) ··· 431 435 continue 432 436 } 433 437 434 - return fmt.Errorf("getCommit(%q, %q): %w", opts.BranchPrefix, b, err) 438 + return false, fmt.Errorf("getCommit(%q, %q): %w", opts.BranchPrefix, b, err) 435 439 } 436 440 437 441 opts.BuildOptions.RepositoryDescription.Branches = append(opts.BuildOptions.RepositoryDescription.Branches, zoekt.RepositoryBranch{ ··· 445 449 } 446 450 447 451 if opts.Incremental && opts.BuildOptions.IncrementalSkipIndexing() { 448 - return nil 452 + return false, nil 449 453 } 450 454 451 455 // branch => (path, sha1) => repo. ··· 474 478 if !opts.BuildOptions.IsDelta { 475 479 repos, branchMap, branchVersions, err = prepareNormalBuild(opts, repo) 476 480 if err != nil { 477 - return fmt.Errorf("preparing normal build: %w", err) 481 + return false, fmt.Errorf("preparing normal build: %w", err) 478 482 } 479 483 } 480 484 ··· 507 511 508 512 builder, err := build.NewBuilder(opts.BuildOptions) 509 513 if err != nil { 510 - return fmt.Errorf("build.NewBuilder: %w", err) 514 + return false, fmt.Errorf("build.NewBuilder: %w", err) 511 515 } 512 516 513 517 var ranks repoPathRanks ··· 515 519 if opts.BuildOptions.DocumentRanksPath != "" { 516 520 data, err := os.ReadFile(opts.BuildOptions.DocumentRanksPath) 517 521 if err != nil { 518 - return err 522 + return false, err 519 523 } 520 524 521 525 err = json.Unmarshal(data, &ranks) 522 526 if err != nil { 523 - return err 527 + return false, err 524 528 } 525 529 526 530 // Compute the mean rank for this repository. Note: we overwrite the rank ··· 564 568 for _, key := range keys { 565 569 doc, err := createDocument(key, repos, branchMap, ranks, opts.BuildOptions) 566 570 if err != nil { 567 - return err 571 + return false, err 568 572 } 569 573 570 574 if err := builder.Add(doc); err != nil { 571 - return fmt.Errorf("error adding document with name %s: %w", key.FullPath(), err) 575 + return false, fmt.Errorf("error adding document with name %s: %w", key.FullPath(), err) 572 576 } 573 577 } 574 578 } 575 579 576 - return builder.Finish() 580 + return true, builder.Finish() 577 581 } 578 582 579 583 type repoPathRanks struct {
+2 -2
gitindex/index_test.go
··· 56 56 }, 57 57 } 58 58 59 - if err := IndexGitRepo(opts); err != nil { 59 + if _, err := IndexGitRepo(opts); err != nil { 60 60 t.Fatalf("IndexGitRepo: %v", err) 61 61 } 62 62 } ··· 619 619 } 620 620 621 621 // run test 622 - err := indexGitRepo(options, gitIndexConfig{ 622 + _, err := indexGitRepo(options, gitIndexConfig{ 623 623 prepareDeltaBuild: prepareDeltaSpy, 624 624 prepareNormalBuild: prepareNormalSpy, 625 625 })
+8 -8
gitindex/tree_test.go
··· 213 213 Incremental: true, 214 214 RepoCacheDir: dir, 215 215 } 216 - if err := IndexGitRepo(opts); err != nil { 216 + if _, err := IndexGitRepo(opts); err != nil { 217 217 t.Fatalf("IndexGitRepo: %v", err) 218 218 } 219 219 ··· 317 317 Incremental: true, 318 318 RepoCacheDir: dir, 319 319 } 320 - if err := IndexGitRepo(opts); err != nil { 320 + if _, err := IndexGitRepo(opts); err != nil { 321 321 t.Fatalf("IndexGitRepo: %v", err) 322 322 } 323 323 ··· 375 375 Incremental: true, 376 376 RepoCacheDir: dir, 377 377 } 378 - if err := IndexGitRepo(opts); err == nil { 378 + if _, err := IndexGitRepo(opts); err == nil { 379 379 t.Fatalf("IndexGitRepo(nonexist) succeeded") 380 380 } 381 381 opts.AllowMissingBranch = true 382 - if err := IndexGitRepo(opts); err != nil { 382 + if _, err := IndexGitRepo(opts); err != nil { 383 383 t.Fatalf("IndexGitRepo(nonexist, allow): %v", err) 384 384 } 385 385 } ··· 444 444 Submodules: true, 445 445 Incremental: true, 446 446 } 447 - if err := IndexGitRepo(opts); err != nil { 447 + if _, err := IndexGitRepo(opts); err != nil { 448 448 t.Fatalf("IndexGitRepo: %v", err) 449 449 } 450 450 ··· 492 492 Branches: []string{"master"}, 493 493 Submodules: false, 494 494 } 495 - if err := IndexGitRepo(opts); err != nil { 495 + if _, err := IndexGitRepo(opts); err != nil { 496 496 t.Fatalf("IndexGitRepo: %v", err) 497 497 } 498 498 } ··· 523 523 Incremental: false, 524 524 AllowMissingBranch: false, 525 525 } 526 - if err := IndexGitRepo(opts); err != nil { 526 + if _, err := IndexGitRepo(opts); err != nil { 527 527 t.Fatalf("IndexGitRepo: %v", err) 528 528 } 529 529 ··· 573 573 BranchPrefix: "refs/heads", 574 574 Branches: []string{"branchdir/a", "branchdir/b"}, 575 575 } 576 - if err := IndexGitRepo(opts); err != nil { 576 + if _, err := IndexGitRepo(opts); err != nil { 577 577 t.Fatalf("IndexGitRepo: %v", err) 578 578 } 579 579