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
30
31
32
33
34
35
36
37
38
39
|
package repository
import (
"fmt"
"os"
"codeberg.org/lindenii/furgit/config"
"codeberg.org/lindenii/furgit/objectid"
)
func parseRepositoryConfig(root *os.Root) (*config.Config, error) {
configFile, err := root.Open("config")
if err != nil {
return nil, fmt.Errorf("repository: open config: %w", err)
}
defer func() { _ = configFile.Close() }()
cfg, err := config.ParseConfig(configFile)
if err != nil {
return nil, fmt.Errorf("repository: parse config: %w", err)
}
return cfg, nil
}
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
}
|