Add alternateObjectDirs param to get blob related funcs (#1157)

This commit is contained in:
Darko Draskovic 2024-03-28 02:02:06 +00:00 committed by Harness
parent 4f6227bf1a
commit 9a1e656be1
7 changed files with 15 additions and 6 deletions

View File

@ -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 {

View File

@ -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,

View File

@ -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"))

View File

@ -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

View File

@ -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)
}

View File

@ -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()

View File

@ -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
}