aboutsummaryrefslogtreecommitdiff
path: root/object/store/packed/new.go
blob: 0668268e6f350054ffa1f12ec36944f9d5604aae (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
30
31
32
33
package packed

import (
	"fmt"
	"os"

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

// New creates a packed-object store rooted at an objects/pack directory.
//
// Labels: Deps-Borrowed.
func New(root *os.Root, algo objectid.Algorithm, opts Options) (*Store, error) {
	if algo.Size() == 0 {
		return nil, objectid.ErrInvalidAlgorithm
	}

	switch opts.RefreshPolicy {
	case RefreshPolicyOnMissing, RefreshPolicyNever:
	default:
		return nil, fmt.Errorf("objectstore/packed: invalid refresh policy %d", opts.RefreshPolicy)
	}

	return &Store{
		root:          root,
		algo:          algo,
		refreshPolicy: opts.RefreshPolicy,
		mruNodeByPack: make(map[string]*packCandidateNode),
		idxByPack:     make(map[string]*idxFile),
		packs:         make(map[string]*packFile),
		deltaCache:    newDeltaCache(defaultDeltaCacheMaxBytes),
	}, nil
}