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

Configure Feed

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

zoekt-mirror-gerrit: add an option to fetch meta/config branch (#774)

+37
+4
cmd/zoekt-indexserver/config.go
··· 50 50 ExcludeTopics []string 51 51 Active bool 52 52 NoArchived bool 53 + GerritFetchMetaConfig bool 53 54 } 54 55 55 56 func randomize(entries []ConfigEntry) []ConfigEntry { ··· 258 259 } 259 260 if c.Active { 260 261 cmd.Args = append(cmd.Args, "-active") 262 + } 263 + if c.GerritFetchMetaConfig { 264 + cmd.Args = append(cmd.Args, "-fetch-meta-config") 261 265 } 262 266 cmd.Args = append(cmd.Args, c.GerritApiURL) 263 267 } else {
+33
cmd/zoekt-mirror-gerrit/main.go
··· 31 31 "strings" 32 32 33 33 gerrit "github.com/andygrunwald/go-gerrit" 34 + git "github.com/go-git/go-git/v5" 35 + "github.com/go-git/go-git/v5/config" 34 36 "github.com/sourcegraph/zoekt/gitindex" 35 37 ) 36 38 ··· 92 94 repoNameFormat := flag.String("repo-name-format", qualifiedRepoNameFormat, fmt.Sprintf("the format of the local repo name in zoekt (valid values: %s)", strings.Join(validRepoNameFormat, ", "))) 93 95 excludePattern := flag.String("exclude", "", "don't mirror repos whose names match this regexp.") 94 96 deleteRepos := flag.Bool("delete", false, "delete missing repos") 97 + fetchMetaConfig := flag.Bool("fetch-meta-config", false, "fetch gerrit meta/config branch") 95 98 httpCrendentialsPath := flag.String("http-credentials", "", "path to a file containing http credentials stored like 'user:password'.") 96 99 active := flag.Bool("active", false, "mirror only active projects") 97 100 flag.Parse() ··· 216 219 } else { 217 220 fmt.Println(dest) 218 221 } 222 + if *fetchMetaConfig { 223 + if err := addMetaConfigFetch(filepath.Join(*dest, name+".git")); err != nil { 224 + log.Fatalf("addMetaConfigFetch: %v", err) 225 + } 226 + } 219 227 } 220 228 if *deleteRepos { 221 229 if err := deleteStaleRepos(*dest, filter, projects, projectURL); err != nil { ··· 263 271 username := user.Username() 264 272 return strings.Replace(u, fmt.Sprintf("://%s@", username), fmt.Sprintf("://%s:%s@", username, password), 1) 265 273 } 274 + 275 + func addMetaConfigFetch(repoDir string) error { 276 + repo, err := git.PlainOpen(repoDir) 277 + if err != nil { 278 + return err 279 + } 280 + 281 + cfg, err := repo.Config() 282 + if err != nil { 283 + return err 284 + } 285 + 286 + rm := cfg.Remotes["origin"] 287 + if rm != nil { 288 + configRefSpec := config.RefSpec("+refs/meta/config:refs/heads/meta/config") 289 + if !slices.Contains(rm.Fetch, configRefSpec) { 290 + rm.Fetch = append(rm.Fetch, configRefSpec) 291 + } 292 + } 293 + if err := repo.Storer.SetConfig(cfg); err != nil { 294 + return err 295 + } 296 + 297 + return nil 298 + }