mirror of
https://github.com/harness/drone.git
synced 2025-05-03 21:29:42 +08:00
Add alternateObjectDirs param to get blob related funcs (#1157)
This commit is contained in:
parent
4f6227bf1a
commit
9a1e656be1
@ -37,10 +37,11 @@ type BlobReader struct {
|
||||
func (g *Git) GetBlob(
|
||||
ctx context.Context,
|
||||
repoPath string,
|
||||
alternateObjectDirs []string,
|
||||
sha sha.SHA,
|
||||
sizeLimit int64,
|
||||
) (*BlobReader, error) {
|
||||
stdIn, stdOut, cancel := CatFileBatch(ctx, repoPath)
|
||||
stdIn, stdOut, cancel := CatFileBatch(ctx, repoPath, alternateObjectDirs)
|
||||
line := sha.String() + "\n"
|
||||
_, err := stdIn.Write([]byte(line))
|
||||
if err != nil {
|
||||
|
@ -41,6 +41,7 @@ type WriteCloserError interface {
|
||||
func CatFileBatch(
|
||||
ctx context.Context,
|
||||
repoPath string,
|
||||
alternateObjectDirs []string,
|
||||
flags ...command.CmdOptionFunc,
|
||||
) (WriteCloserError, *bufio.Reader, func()) {
|
||||
const bufferSize = 32 * 1024
|
||||
@ -67,6 +68,7 @@ func CatFileBatch(
|
||||
stderr := bytes.Buffer{}
|
||||
cmd := command.New("cat-file",
|
||||
command.WithFlag("--batch"),
|
||||
command.WithAlternateObjectDirs(alternateObjectDirs...),
|
||||
)
|
||||
cmd.Add(flags...)
|
||||
err := cmd.Run(ctx,
|
||||
|
@ -758,7 +758,7 @@ func GetCommit(
|
||||
repoPath string,
|
||||
rev string,
|
||||
) (*Commit, error) {
|
||||
wr, rd, cancel := CatFileBatch(ctx, repoPath)
|
||||
wr, rd, cancel := CatFileBatch(ctx, repoPath, nil)
|
||||
defer cancel()
|
||||
|
||||
_, _ = wr.Write([]byte(rev + "\n"))
|
||||
|
@ -40,7 +40,7 @@ func (g *Git) MatchFiles(
|
||||
return nil, fmt.Errorf("failed to list files in match files: %w", err)
|
||||
}
|
||||
|
||||
catFileWriter, catFileReader, catFileStop := CatFileBatch(ctx, repoPath)
|
||||
catFileWriter, catFileReader, catFileStop := CatFileBatch(ctx, repoPath, nil)
|
||||
defer catFileStop()
|
||||
|
||||
var files []FileContent
|
||||
|
@ -50,7 +50,7 @@ func (g *Git) GetSubmodule(
|
||||
ref, commit)
|
||||
}
|
||||
|
||||
reader, err := g.GetBlob(ctx, repoPath, node.SHA, 0)
|
||||
reader, err := g.GetBlob(ctx, repoPath, nil, node.SHA, 0)
|
||||
if err != nil {
|
||||
return nil, processGitErrorf(err, "error reading commit for ref '%s'", ref)
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func getAnnotatedTags(
|
||||
return nil, ErrRepositoryPathEmpty
|
||||
}
|
||||
// The tag is an annotated tag with a message.
|
||||
writer, reader, cancel := CatFileBatch(ctx, repoPath)
|
||||
writer, reader, cancel := CatFileBatch(ctx, repoPath, nil)
|
||||
defer func() {
|
||||
cancel()
|
||||
_ = writer.Close()
|
||||
|
@ -45,7 +45,13 @@ func (s *Service) GetBlob(ctx context.Context, params *GetBlobParams) (*GetBlobO
|
||||
repoPath := getFullPathForRepo(s.reposRoot, params.RepoUID)
|
||||
|
||||
// TODO: do we need to validate request for nil?
|
||||
reader, err := s.git.GetBlob(ctx, repoPath, sha.Must(params.SHA), params.SizeLimit)
|
||||
reader, err := s.git.GetBlob(
|
||||
ctx,
|
||||
repoPath,
|
||||
params.AlternateObjectDirs,
|
||||
sha.Must(params.SHA),
|
||||
params.SizeLimit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user