@ -9,6 +9,7 @@ package git
import (
"bufio"
"bytes"
"context"
"fmt"
"io"
"math"
@ -18,7 +19,7 @@ import (
)
// GetCommitsInfo gets information of all commits that are corresponding to these entries
func ( tes Entries ) GetCommitsInfo ( c ommit * Commit , treePath string , cache * LastCommitCache ) ( [ ] CommitInfo , * Commit , error ) {
func ( tes Entries ) GetCommitsInfo ( c tx context . Context , c ommit * Commit , treePath string , cache * LastCommitCache ) ( [ ] CommitInfo , * Commit , error ) {
entryPaths := make ( [ ] string , len ( tes ) + 1 )
// Get the commit for the treePath itself
entryPaths [ 0 ] = ""
@ -31,13 +32,13 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache *LastCo
var revs map [ string ] * Commit
if cache != nil {
var unHitPaths [ ] string
revs , unHitPaths , err = getLastCommitForPathsByCache ( c ommit. ID . String ( ) , treePath , entryPaths , cache )
revs , unHitPaths , err = getLastCommitForPathsByCache ( c tx, c ommit. ID . String ( ) , treePath , entryPaths , cache )
if err != nil {
return nil , nil , err
}
if len ( unHitPaths ) > 0 {
sort . Strings ( unHitPaths )
commits , err := GetLastCommitForPaths ( c ommit, treePath , unHitPaths )
commits , err := GetLastCommitForPaths ( c tx, c ommit, treePath , unHitPaths )
if err != nil {
return nil , nil , err
}
@ -53,7 +54,7 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache *LastCo
sort . Strings ( entryPaths )
revs = map [ string ] * Commit { }
var foundCommits [ ] * Commit
foundCommits , err = GetLastCommitForPaths ( c ommit, treePath , entryPaths )
foundCommits , err = GetLastCommitForPaths ( c tx, c ommit, treePath , entryPaths )
for i , found := range foundCommits {
revs [ entryPaths [ i ] ] = found
}
@ -101,7 +102,7 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache *LastCo
return commitsInfo , treeCommit , nil
}
func getLastCommitForPathsByCache ( c ommitID, treePath string , paths [ ] string , cache * LastCommitCache ) ( map [ string ] * Commit , [ ] string , error ) {
func getLastCommitForPathsByCache ( c tx context . Context , c ommitID, treePath string , paths [ ] string , cache * LastCommitCache ) ( map [ string ] * Commit , [ ] string , error ) {
wr , rd , cancel := cache . repo . CatFileBatch ( )
defer cancel ( )
@ -124,7 +125,7 @@ func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cac
}
// GetLastCommitForPaths returns last commit information
func GetLastCommitForPaths ( c ommit * Commit , treePath string , paths [ ] string ) ( [ ] * Commit , error ) {
func GetLastCommitForPaths ( c tx context . Context , c ommit * Commit , treePath string , paths [ ] string ) ( [ ] * Commit , error ) {
// We read backwards from the commit to obtain all of the commits
// We'll do this by using rev-list to provide us with parent commits in order
@ -136,7 +137,7 @@ func GetLastCommitForPaths(commit *Commit, treePath string, paths []string) ([]*
go func ( ) {
stderr := strings . Builder { }
err := NewCommand ( "rev-list" , "--format=%T" , commit . ID . String ( ) ) . RunInDirPipeline( commit . repo . Path , revListWriter , & stderr )
err := NewCommand ( "rev-list" , "--format=%T" , commit . ID . String ( ) ) . SetParentContext( ctx ) . RunInDirPipeline( commit . repo . Path , revListWriter , & stderr )
if err != nil {
_ = revListWriter . CloseWithError ( ConcatenateError ( err , ( & stderr ) . String ( ) ) )
} else {
@ -202,6 +203,11 @@ revListLoop:
treeReadingLoop :
for {
select {
case <- ctx . Done ( ) :
return nil , ctx . Err ( )
default :
}
_ , _ , size , err := ReadBatchLine ( batchReader )
if err != nil {
return nil , err
@ -321,6 +327,9 @@ revListLoop:
}
}
}
if scan . Err ( ) != nil {
return nil , scan . Err ( )
}
commitsMap := make ( map [ string ] * Commit , len ( commits ) )
commitsMap [ commit . ID . String ( ) ] = commit