ref: 3ce59c3248dec0eb0f918c42f37f53bc2ac20425
dir: /repository/algorithm.go/
package repository
import (
"fmt"
"codeberg.org/lindenii/furgit/config"
objectid "codeberg.org/lindenii/furgit/object/id"
)
// detectObjectAlgorithm uses a repository's configuration to detect
// the expected Object ID hashing algorithm.
func detectObjectAlgorithm(cfg *config.Config) (objectid.Algorithm, error) {
algoName := cfg.Lookup("extensions", "", "objectformat").Value
if algoName == "" {
algoName = objectid.AlgorithmSHA1.String()
}
algo, ok := objectid.ParseAlgorithm(algoName)
if !ok {
return objectid.AlgorithmUnknown, fmt.Errorf("repository: unsupported object format %q", algoName)
}
return algo, nil
}
// Algorithm returns the repository object ID algorithm.
func (repo *Repository) Algorithm() objectid.Algorithm {
return repo.algo
}