shithub: furgit

ref: c3731c4eff12cc9e6636f89128948d86596ad860
dir: /objectstore/packed/new.go/

View raw version
package packed

import (
	"fmt"
	"os"

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

// 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("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
}