Skip to content

Commit

Permalink
Merge branch 'main' into index-gerrit
Browse files Browse the repository at this point in the history
  • Loading branch information
keegancsmith authored May 3, 2024
2 parents e382642 + 69068bf commit 54e16d8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build/scoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func TestBM25(t *testing.T) {
query: &query.Substring{Pattern: "example"},
content: exampleJava,
language: "Java",
// keyword-score:1.63 (sum-tf: 6.00, length-ratio: 2.00)
wantScore: 1.63,
// keyword-score:1.69 (sum-tf: 7.00, length-ratio: 2.00)
wantScore: 1.69,
}, {
// Matches only on content
fileName: "example.java",
Expand Down
6 changes: 5 additions & 1 deletion cmd/zoekt-indexserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type ConfigEntry struct {
ExcludeTopics []string
Active bool
NoArchived bool
GerritRepoNameFormat string
GerritFetchMetaConfig bool
GerritRepoNameFormat string
}

func randomize(entries []ConfigEntry) []ConfigEntry {
Expand Down Expand Up @@ -260,6 +261,9 @@ func executeMirror(cfg []ConfigEntry, repoDir string, pendingRepos chan<- string
if c.Active {
cmd.Args = append(cmd.Args, "-active")
}
if c.GerritFetchMetaConfig {
cmd.Args = append(cmd.Args, "-fetch-meta-config")
}
if c.GerritRepoNameFormat != "" {
cmd.Args = append(cmd.Args, "-repo-name-format", c.GerritRepoNameFormat)
}
Expand Down
33 changes: 33 additions & 0 deletions cmd/zoekt-mirror-gerrit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"strings"

gerrit "github.com/andygrunwald/go-gerrit"
git "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/sourcegraph/zoekt/gitindex"
)

Expand Down Expand Up @@ -92,6 +94,7 @@ func main() {
repoNameFormat := flag.String("repo-name-format", qualifiedRepoNameFormat, fmt.Sprintf("the format of the local repo name in zoekt (valid values: %s)", strings.Join(validRepoNameFormat, ", ")))
excludePattern := flag.String("exclude", "", "don't mirror repos whose names match this regexp.")
deleteRepos := flag.Bool("delete", false, "delete missing repos")
fetchMetaConfig := flag.Bool("fetch-meta-config", false, "fetch gerrit meta/config branch")
httpCrendentialsPath := flag.String("http-credentials", "", "path to a file containing http credentials stored like 'user:password'.")
active := flag.Bool("active", false, "mirror only active projects")
flag.Parse()
Expand Down Expand Up @@ -216,6 +219,11 @@ func main() {
} else {
fmt.Println(dest)
}
if *fetchMetaConfig {
if err := addMetaConfigFetch(filepath.Join(*dest, name+".git")); err != nil {
log.Fatalf("addMetaConfigFetch: %v", err)
}
}
}
if *deleteRepos {
if err := deleteStaleRepos(*dest, filter, projects, projectURL); err != nil {
Expand Down Expand Up @@ -263,3 +271,28 @@ func addPassword(u string, user *url.Userinfo) string {
username := user.Username()
return strings.Replace(u, fmt.Sprintf("://%s@", username), fmt.Sprintf("://%s:%s@", username, password), 1)
}

func addMetaConfigFetch(repoDir string) error {
repo, err := git.PlainOpen(repoDir)
if err != nil {
return err
}

cfg, err := repo.Config()
if err != nil {
return err
}

rm := cfg.Remotes["origin"]
if rm != nil {
configRefSpec := config.RefSpec("+refs/meta/config:refs/heads/meta/config")
if !slices.Contains(rm.Fetch, configRefSpec) {
rm.Fetch = append(rm.Fetch, configRefSpec)
}
}
if err := repo.Storer.SetConfig(cfg); err != nil {
return err
}

return nil
}
4 changes: 2 additions & 2 deletions contentprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (p *contentProvider) findOffset(filename bool, r uint32) uint32 {
// returned by the API it needs to be copied.
func (p *contentProvider) fillMatches(ms []*candidateMatch, numContextLines int, language string, debug bool) []LineMatch {
var filenameMatches []*candidateMatch
contentMatches := ms[:0]
contentMatches := make([]*candidateMatch, 0, len(ms))

for _, m := range ms {
if m.fileName {
Expand Down Expand Up @@ -194,7 +194,7 @@ func (p *contentProvider) fillMatches(ms []*candidateMatch, numContextLines int,
// returned by the API it needs to be copied.
func (p *contentProvider) fillChunkMatches(ms []*candidateMatch, numContextLines int, language string, debug bool) []ChunkMatch {
var filenameMatches []*candidateMatch
contentMatches := ms[:0]
contentMatches := make([]*candidateMatch, 0, len(ms))

for _, m := range ms {
if m.fileName {
Expand Down

0 comments on commit 54e16d8

Please sign in to comment.