aboutsummaryrefslogtreecommitdiff
path: root/repository/algorithm.go
blob: 1098f0b8eab75120878e0378a8d5d0e0935ba444 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}