aboutsummaryrefslogtreecommitdiff
path: root/objectstore/packed/store.go
blob: 000e04f24d49712f64bdd36c682a6d0a4c808434 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Package packed provides packfile reading and associated indexes.
package packed

import (
	"os"
	"sync"

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

// Store reads Git objects from pack/index files under an objects/pack root.
//
// Store owns root and closes it in Close.
type Store struct {
	// root is the objects/pack capability used for all file access.
	root *os.Root
	// algo is the expected object ID algorithm for lookups.
	algo objectid.Algorithm

	// discoverOnce guards one-time pack candidate discovery.
	discoverOnce sync.Once
	// discoverErr stores candidate discovery failures.
	discoverErr error
	// candidateHead is the first candidate in lookup priority order.
	candidateHead *packCandidateNode
	// candidateTail is the last candidate in lookup priority order.
	candidateTail *packCandidateNode
	// candidateByPack maps pack basename to discovered candidate.
	candidateByPack map[string]packCandidate
	// candidateNodeByPack maps pack basename to linked-list node.
	candidateNodeByPack map[string]*packCandidateNode
	// idxByPack caches opened and parsed indexes by pack basename.
	idxByPack map[string]*idxFile

	// stateMu guards pack cache and close state.
	stateMu sync.RWMutex
	// candidatesMu guards discovered candidates and MRU order.
	candidatesMu sync.RWMutex
	// idxMu guards parsed index cache.
	idxMu sync.RWMutex
	// cacheMu guards delta cache operations.
	cacheMu sync.RWMutex
	// packs caches opened .pack handles by basename.
	packs map[string]*packFile
	// deltaCache caches resolved base objects by pack location.
	deltaCache *deltaCache
	// closed reports whether Close has been called.
	closed bool
}

var _ objectstore.Store = (*Store)(nil)