mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git commands run within the request context. This now means that the if there is a git repo already open in the context it will be used instead of reopening it. Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
		@@ -7,6 +7,7 @@ package pull
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bufio"
 | 
			
		||||
	"context"
 | 
			
		||||
	"io"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"sync"
 | 
			
		||||
@@ -18,7 +19,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// LFSPush pushes lfs objects referred to in new commits in the head repository from the base repository
 | 
			
		||||
func LFSPush(tmpBasePath, mergeHeadSHA, mergeBaseSHA string, pr *models.PullRequest) error {
 | 
			
		||||
func LFSPush(ctx context.Context, tmpBasePath, mergeHeadSHA, mergeBaseSHA string, pr *models.PullRequest) error {
 | 
			
		||||
	// Now we have to implement git lfs push
 | 
			
		||||
	// git rev-list --objects --filter=blob:limit=1k HEAD --not base
 | 
			
		||||
	// pass blob shas in to git cat-file --batch-check (possibly unnecessary)
 | 
			
		||||
@@ -41,19 +42,19 @@ func LFSPush(tmpBasePath, mergeHeadSHA, mergeBaseSHA string, pr *models.PullRequ
 | 
			
		||||
	go createLFSMetaObjectsFromCatFileBatch(catFileBatchReader, &wg, pr)
 | 
			
		||||
 | 
			
		||||
	// 5. Take the shas of the blobs and batch read them
 | 
			
		||||
	go pipeline.CatFileBatch(shasToBatchReader, catFileBatchWriter, &wg, tmpBasePath)
 | 
			
		||||
	go pipeline.CatFileBatch(ctx, shasToBatchReader, catFileBatchWriter, &wg, tmpBasePath)
 | 
			
		||||
 | 
			
		||||
	// 4. From the provided objects restrict to blobs <=1k
 | 
			
		||||
	go pipeline.BlobsLessThan1024FromCatFileBatchCheck(catFileCheckReader, shasToBatchWriter, &wg)
 | 
			
		||||
 | 
			
		||||
	// 3. Run batch-check on the objects retrieved from rev-list
 | 
			
		||||
	go pipeline.CatFileBatchCheck(shasToCheckReader, catFileCheckWriter, &wg, tmpBasePath)
 | 
			
		||||
	go pipeline.CatFileBatchCheck(ctx, shasToCheckReader, catFileCheckWriter, &wg, tmpBasePath)
 | 
			
		||||
 | 
			
		||||
	// 2. Check each object retrieved rejecting those without names as they will be commits or trees
 | 
			
		||||
	go pipeline.BlobsFromRevListObjects(revListReader, shasToCheckWriter, &wg)
 | 
			
		||||
 | 
			
		||||
	// 1. Run rev-list objects from mergeHead to mergeBase
 | 
			
		||||
	go pipeline.RevListObjects(revListWriter, &wg, tmpBasePath, mergeHeadSHA, mergeBaseSHA, errChan)
 | 
			
		||||
	go pipeline.RevListObjects(ctx, revListWriter, &wg, tmpBasePath, mergeHeadSHA, mergeBaseSHA, errChan)
 | 
			
		||||
 | 
			
		||||
	wg.Wait()
 | 
			
		||||
	select {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user