Skip to content

Commit

Permalink
Remove branchMap in prepareNormalBuild (#838)
Browse files Browse the repository at this point in the history
This PR refactors the "build preparation" code to remove `branchMap`, in favor of storing everything in a single map. The main motivation is just to make the code clearer.

Specific changes:
* Store branches in the same map as blob locations, remove `branchMap`
* Introduce new struct `BlobIndexInfo` to hold the old location information, plus branches
* Rename `BlobLocation` -> `BlobRepo`
  • Loading branch information
jtibshirani authored Sep 30, 2024
1 parent 64f1ad8 commit 282a251
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 98 deletions.
12 changes: 6 additions & 6 deletions cmd/zoekt-repo-index/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func main() {
}
}

perBranch := map[string]map[fileKey]gitindex.BlobLocation{}
perBranch := map[string]map[fileKey]gitindex.BlobRepo{}
opts.SubRepositories = map[string]*zoekt.Repository{}

// branch => repo => version
Expand All @@ -193,7 +193,7 @@ func main() {
}

perBranch[br.branch] = files
for key, loc := range files {
for key, repo := range files {
_, ok := opts.SubRepositories[key.SubRepoPath]
if ok {
// This can be incorrect: if the layout of manifests
Expand All @@ -204,8 +204,8 @@ func main() {
}

desc := &zoekt.Repository{}
if err := gitindex.SetTemplatesFromOrigin(desc, loc.URL); err != nil {
log.Fatalf("SetTemplatesFromOrigin(%s): %v", loc.URL, err)
if err := gitindex.SetTemplatesFromOrigin(desc, repo.URL); err != nil {
log.Fatalf("SetTemplatesFromOrigin(%s): %v", repo.URL, err)
}

opts.SubRepositories[key.SubRepoPath] = desc
Expand Down Expand Up @@ -325,8 +325,8 @@ func getManifest(repo *git.Repository, branch, path string) (*manifest.Manifest,
func iterateManifest(mf *manifest.Manifest,
baseURL url.URL, revPrefix string,
cache *gitindex.RepoCache,
) (map[fileKey]gitindex.BlobLocation, map[string]plumbing.Hash, error) {
allFiles := map[fileKey]gitindex.BlobLocation{}
) (map[fileKey]gitindex.BlobRepo, map[string]plumbing.Hash, error) {
allFiles := map[fileKey]gitindex.BlobRepo{}
allVersions := map[string]plumbing.Hash{}
for _, p := range mf.Project {
rev := mf.ProjectRevision(&p)
Expand Down
Loading

0 comments on commit 282a251

Please sign in to comment.