|
|
|
|
@ -7,8 +7,6 @@ package git
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"path"
|
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
|
|
@ -124,48 +122,25 @@ func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string,
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
batchStdinWriter, batchReader, cancel, err := commit.repo.CatFileBatch(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
commitsMap := map[string]*Commit{}
|
|
|
|
|
commitsMap[commit.ID.String()] = commit
|
|
|
|
|
|
|
|
|
|
commitCommits := map[string]*Commit{}
|
|
|
|
|
for path, commitID := range revs {
|
|
|
|
|
c, ok := commitsMap[commitID]
|
|
|
|
|
if ok {
|
|
|
|
|
commitCommits[path] = c
|
|
|
|
|
if len(commitID) == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(commitID) == 0 {
|
|
|
|
|
c, ok := commitsMap[commitID]
|
|
|
|
|
if ok {
|
|
|
|
|
commitCommits[path] = c
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := batchStdinWriter.Write([]byte(commitID + "\n"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
_, typ, size, err := ReadBatchLine(batchReader)
|
|
|
|
|
c, err := commit.repo.GetCommit(commitID) // Ensure the commit exists in the repository
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if typ != "commit" {
|
|
|
|
|
if err := DiscardFull(batchReader, size+1); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return nil, fmt.Errorf("unexpected type: %s for commit id: %s", typ, commitID)
|
|
|
|
|
}
|
|
|
|
|
c, err = CommitFromReader(commit.repo, MustIDFromString(commitID), io.LimitReader(batchReader, size))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if _, err := batchReader.Discard(1); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
commitCommits[path] = c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|