Refactor cat-file batch operations and support --batch-command approach (#35775)

Replace #34651 and address more problems including fix framework bugs and changing to QueryInfo and QueryContent calls.

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
wxiaoguang
2026-01-09 05:37:36 +08:00
committed by GitHub
parent ee9d8893a7
commit e226720cff
34 changed files with 832 additions and 812 deletions
+9 -15
View File
@@ -8,7 +8,6 @@ package git
import (
"bufio"
"bytes"
"context"
"io"
"strings"
@@ -18,24 +17,24 @@ import (
)
// IsObjectExist returns true if the given object exists in the repository.
// FIXME: this function doesn't seem right, it is only used by GarbageCollectLFSMetaObjectsForRepo
func (repo *Repository) IsObjectExist(name string) bool {
if name == "" {
return false
}
batch, cancel, err := repo.CatFileBatchCheck(repo.Ctx)
batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
log.Debug("Error writing to CatFileBatchCheck %v", err)
log.Debug("Error opening CatFileBatch %v", err)
return false
}
defer cancel()
_, err = batch.Writer().Write([]byte(name + "\n"))
info, err := batch.QueryInfo(name)
if err != nil {
log.Debug("Error writing to CatFileBatchCheck %v", err)
log.Debug("Error checking object info %v", err)
return false
}
sha, _, _, err := ReadBatchLine(batch.Reader())
return err == nil && bytes.HasPrefix(sha, []byte(strings.TrimSpace(name)))
return strings.HasPrefix(info.ID, name) // FIXME: this logic doesn't seem right, why "HasPrefix"
}
// IsReferenceExist returns true if given reference exists in the repository.
@@ -44,18 +43,13 @@ func (repo *Repository) IsReferenceExist(name string) bool {
return false
}
batch, cancel, err := repo.CatFileBatchCheck(repo.Ctx)
batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
log.Debug("Error writing to CatFileBatchCheck %v", err)
log.Error("Error opening CatFileBatch %v", err)
return false
}
defer cancel()
_, err = batch.Writer().Write([]byte(name + "\n"))
if err != nil {
log.Debug("Error writing to CatFileBatchCheck %v", err)
return false
}
_, _, _, err = ReadBatchLine(batch.Reader())
_, err = batch.QueryInfo(name)
return err == nil
}