aboutsummaryrefslogtreecommitdiff
path: root/object/storer/packed/new.go
blob: cbfc9383be517570cc95a89725030beeb5bf221b (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
package packed

import (
	"fmt"
	"os"

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

// New creates a packed-object store rooted at an objects/pack directory.
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("objectstorer/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
}