Abstract hash function usage (#28138)

Refactor Hash interfaces and centralize hash function. This will allow
easier introduction of different hash function later on.

This forms the "no-op" part of the SHA256 enablement patch.
This commit is contained in:
Adam Majer 2023-12-13 21:02:00 +00:00 committed by GitHub
parent 064f05204c
commit cbf923e87b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
122 changed files with 947 additions and 594 deletions

View file

@ -9,7 +9,7 @@ import (
"io"
)
func (repo *Repository) getTree(id SHA1) (*Tree, error) {
func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
wr, rd, cancel := repo.CatFileBatch(repo.Ctx)
defer cancel()
@ -28,7 +28,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
if err != nil {
return nil, err
}
tag, err := parseTagData(data)
tag, err := parseTagData(id.Type(), data)
if err != nil {
return nil, err
}
@ -51,7 +51,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
case "tree":
tree := NewTree(repo, id)
tree.ResolvedID = id
tree.entries, err = catBatchParseTreeEntries(tree, rd, size)
tree.entries, err = catBatchParseTreeEntries(repo.objectFormat, tree, rd, size)
if err != nil {
return nil, err
}
@ -66,7 +66,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
// GetTree find the tree object in the repository.
func (repo *Repository) GetTree(idStr string) (*Tree, error) {
if len(idStr) != SHAFullLength {
if len(idStr) != repo.objectFormat.FullLength() {
res, err := repo.GetRefCommitID(idStr)
if err != nil {
return nil, err
@ -75,7 +75,7 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) {
idStr = res
}
}
id, err := NewIDFromString(idStr)
id, err := repo.objectFormat.NewIDFromString(idStr)
if err != nil {
return nil, err
}