aboutsummaryrefslogtreecommitdiff
path: root/format/pack/ingest/state.go
blob: 2263e8a15d45c513fb9549dea86e33856cc787d7 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package ingest

import (
	"io"
	"os"

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

const (
	defaultDeltaBaseCacheMaxBytes = 32 << 20
)

// ingestState holds mutable state for one Ingest call.
type ingestState struct {
	src         io.Reader
	destination *os.Root
	algo        objectid.Algorithm
	fixThin     bool
	writeRev    bool
	base        objectstore.Store

	packFile    *os.File
	packTmpName string
	idxFile     *os.File
	idxTmpName  string
	revFile     *os.File
	revTmpName  string

	stream *streamScanner

	records             []objectRecord
	ofsDeltas           []ofsDeltaRef
	refDeltas           []refDeltaRef
	unresolvedRefDeltas []int
	offsetToRecord      map[uint64]int
	objectToRecord      map[objectid.ObjectID]int

	baseCache *deltaBaseCache
	packHash  objectid.ObjectID

	objectCountHeader uint32
	thinFixed         bool
}

// newIngestState constructs one call-local ingest state.
func newIngestState(
	src io.Reader,
	destination *os.Root,
	algo objectid.Algorithm,
	fixThin bool,
	writeRev bool,
	base objectstore.Store,
) (*ingestState, error) {
	if algo.Size() == 0 {
		return nil, objectid.ErrInvalidAlgorithm
	}

	return &ingestState{
		src:            src,
		destination:    destination,
		algo:           algo,
		fixThin:        fixThin,
		writeRev:       writeRev,
		base:           base,
		offsetToRecord: make(map[uint64]int),
		objectToRecord: make(map[objectid.ObjectID]int),
		baseCache:      newDeltaBaseCache(defaultDeltaBaseCacheMaxBytes),
	}, nil
}