aboutsummaryrefslogtreecommitdiff
path: root/refstore/files/new.go
blob: bca3a4916368d1559c79e95a2e5dd0815e462b44 (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 files

import (
	"math/rand"
	"os"
	"time"

	objectid "codeberg.org/lindenii/furgit/object/id"
)

// New creates one files ref store rooted at one repository gitdir.
func New(root *os.Root, algo objectid.Algorithm, packedRefsTimeout time.Duration) (*Store, error) {
	if algo.Size() == 0 {
		return nil, objectid.ErrInvalidAlgorithm
	}

	commonRoot, err := openCommonRoot(root)
	if err != nil {
		return nil, err
	}

	return &Store{
		gitRoot:           root,
		commonRoot:        commonRoot,
		algo:              algo,
		lockRand:          rand.New(rand.NewSource(time.Now().UnixNano())), //nolint:gosec
		packedRefsTimeout: packedRefsTimeout,
	}, nil
}