@ -339,8 +339,7 @@ func (t *TemporaryUploadRepository) Push(doer *user_model.User, commitHash, bran
func ( t * TemporaryUploadRepository ) DiffIndex ( ) ( * gitdiff . Diff , error ) {
func ( t * TemporaryUploadRepository ) DiffIndex ( ) ( * gitdiff . Diff , error ) {
stdoutReader , stdoutWriter , err := os . Pipe ( )
stdoutReader , stdoutWriter , err := os . Pipe ( )
if err != nil {
if err != nil {
log . Error ( "Unable to open stdout pipe: %v" , err )
return nil , fmt . Errorf ( "unable to open stdout pipe: %w" , err )
return nil , fmt . Errorf ( "Unable to open stdout pipe: %w" , err )
}
}
defer func ( ) {
defer func ( ) {
_ = stdoutReader . Close ( )
_ = stdoutReader . Close ( )
@ -348,9 +347,7 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) {
} ( )
} ( )
stderr := new ( bytes . Buffer )
stderr := new ( bytes . Buffer )
var diff * gitdiff . Diff
var diff * gitdiff . Diff
var finalErr error
err = git . NewCommand ( t . ctx , "diff-index" , "--src-prefix=\\a/" , "--dst-prefix=\\b/" , "--cached" , "-p" , "HEAD" ) .
if err := git . NewCommand ( t . ctx , "diff-index" , "--src-prefix=\\a/" , "--dst-prefix=\\b/" , "--cached" , "-p" , "HEAD" ) .
Run ( & git . RunOpts {
Run ( & git . RunOpts {
Timeout : 30 * time . Second ,
Timeout : 30 * time . Second ,
Dir : t . basePath ,
Dir : t . basePath ,
@ -359,27 +356,19 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) {
PipelineFunc : func ( ctx context . Context , cancel context . CancelFunc ) error {
PipelineFunc : func ( ctx context . Context , cancel context . CancelFunc ) error {
_ = stdoutWriter . Close ( )
_ = stdoutWriter . Close ( )
defer cancel ( )
defer cancel ( )
diff , finalErr = gitdiff . ParsePatch ( t . ctx , setting . Git . MaxGitDiffLines , setting . Git . MaxGitDiffLineCharacters , setting . Git . MaxGitDiffFiles , stdoutReader , "" )
var diffErr error
if finalErr != nil {
diff , diffErr = gitdiff . ParsePatch ( t . ctx , setting . Git . MaxGitDiffLines , setting . Git . MaxGitDiffLineCharacters , setting . Git . MaxGitDiffFiles , stdoutReader , "" )
log . Error ( "ParsePatch: %v" , finalErr )
cancel ( )
}
_ = stdoutReader . Close ( )
_ = stdoutReader . Close ( )
return finalErr
if diffErr != nil {
} ,
// if the diffErr is not nil, it will be returned as the error of "Run()"
} ) ; err != nil {
return fmt . Errorf ( "ParsePatch: %w" , diffErr )
if finalErr != nil {
log . Error ( "Unable to ParsePatch in temporary repo %s (%s). Error: %v" , t . repo . FullName ( ) , t . basePath , finalErr )
return nil , finalErr
}
// If the process exited early, don't error
if err != context . Canceled {
log . Error ( "Unable to run diff-index pipeline in temporary repo %s (%s). Error: %v\nStderr: %s" ,
t . repo . FullName ( ) , t . basePath , err , stderr )
return nil , fmt . Errorf ( "Unable to run diff-index pipeline in temporary repo %s. Error: %w\nStderr: %s" ,
t . repo . FullName ( ) , err , stderr )
}
}
return nil
} ,
} )
if err != nil && ! git . IsErrCanceledOrKilled ( err ) {
log . Error ( "Unable to diff-index in temporary repo %s (%s). Error: %v\nStderr: %s" , t . repo . FullName ( ) , t . basePath , err , stderr )
return nil , fmt . Errorf ( "unable to run diff-index pipeline in temporary repo: %w" , err )
}
}
diff . NumFiles , diff . TotalAddition , diff . TotalDeletion , err = git . GetDiffShortStat ( t . ctx , t . basePath , git . TrustedCmdArgs { "--cached" } , "HEAD" )
diff . NumFiles , diff . TotalAddition , diff . TotalDeletion , err = git . GetDiffShortStat ( t . ctx , t . basePath , git . TrustedCmdArgs { "--cached" } , "HEAD" )