Refactor git command stdio pipe (#36393)

And remove the incorrect `ensureValidGitRepository`
This commit is contained in:
wxiaoguang
2026-01-18 02:11:46 +08:00
committed by GitHub
parent 7a2aac406d
commit 149f7a6f1f
9 changed files with 210 additions and 122 deletions
+2 -13
View File
@@ -44,23 +44,12 @@ func (repo *Repository) GetRefCommitID(name string) (string, error) {
info, err := batch.QueryInfo(name)
if IsErrNotExist(err) {
return "", ErrNotExist{name, ""}
} else if err != nil {
return "", err
}
return info.ID, nil
}
// IsCommitExist returns true if given commit exists in current repository.
func (repo *Repository) IsCommitExist(name string) bool {
if err := ensureValidGitRepository(repo.Ctx, repo.Path); err != nil {
log.Error("IsCommitExist: %v", err)
return false
}
_, _, err := gitcmd.NewCommand("cat-file", "-e").
AddDynamicArguments(name).
WithDir(repo.Path).
RunStdString(repo.Ctx)
return err == nil
}
func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {