Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree_entry: fix CommitsInfo messed up with entries have the same SHA1 #59

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions tree_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (es Entries) Sort() {
// EntryCommitInfo contains a tree entry with its commit information.
type EntryCommitInfo struct {
Entry *TreeEntry
Index int
Commit *Commit
Submodule *Submodule
}
Expand Down Expand Up @@ -212,7 +213,7 @@ func (es Entries) CommitsInfo(commit *Commit, opts ...CommitsInfoOptions) ([]*En
// Block until there is an empty slot to control the maximum concurrency
bucket <- struct{}{}

go func(e *TreeEntry) {
go func(e *TreeEntry, i int) {
defer func() {
wg.Done()
<-bucket
Expand All @@ -225,6 +226,7 @@ func (es Entries) CommitsInfo(commit *Commit, opts ...CommitsInfoOptions) ([]*En

info := &EntryCommitInfo{
Entry: e,
Index: i,
}
epath := path.Join(opt.Path, e.Name())

Expand All @@ -248,7 +250,7 @@ func (es Entries) CommitsInfo(commit *Commit, opts ...CommitsInfoOptions) ([]*En
}

results <- info
}(e)
}(e, i)
}
}()

Expand All @@ -258,14 +260,10 @@ func (es Entries) CommitsInfo(commit *Commit, opts ...CommitsInfoOptions) ([]*En
}

close(results)
infos := make(map[[20]byte]*EntryCommitInfo, len(es))
for info := range results {
infos[info.Entry.id.bytes] = info
}

commitsInfo := make([]*EntryCommitInfo, len(es))
for i, e := range es {
commitsInfo[i] = infos[e.id.bytes]
for info := range results {
commitsInfo[info.Index] = info
}
return commitsInfo, nil
}