Skip to content

Commit c523924

Browse files
authored
tree_entry: fix CommitsInfo messed up with entries have the same SHA1 (#59)
1 parent cf0a6d7 commit c523924

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

tree_entry.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func (es Entries) Sort() {
146146
// EntryCommitInfo contains a tree entry with its commit information.
147147
type EntryCommitInfo struct {
148148
Entry *TreeEntry
149+
Index int
149150
Commit *Commit
150151
Submodule *Submodule
151152
}
@@ -212,7 +213,7 @@ func (es Entries) CommitsInfo(commit *Commit, opts ...CommitsInfoOptions) ([]*En
212213
// Block until there is an empty slot to control the maximum concurrency
213214
bucket <- struct{}{}
214215

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

226227
info := &EntryCommitInfo{
227228
Entry: e,
229+
Index: i,
228230
}
229231
epath := path.Join(opt.Path, e.Name())
230232

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

250252
results <- info
251-
}(e)
253+
}(e, i)
252254
}
253255
}()
254256

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

260262
close(results)
261-
infos := make(map[[20]byte]*EntryCommitInfo, len(es))
262-
for info := range results {
263-
infos[info.Entry.id.bytes] = info
264-
}
265263

266264
commitsInfo := make([]*EntryCommitInfo, len(es))
267-
for i, e := range es {
268-
commitsInfo[i] = infos[e.id.bytes]
265+
for info := range results {
266+
commitsInfo[info.Index] = info
269267
}
270268
return commitsInfo, nil
271269
}

0 commit comments

Comments
 (0)