aboutsummaryrefslogtreecommitdiff
path: root/network/receivepack/options.go
blob: ca13c623513e6b2b351e3b26befc44c54269ce0c (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
72
package receivepack

import (
	"os"

	commitgraphread "codeberg.org/lindenii/furgit/format/commitgraph/read"
	objectid "codeberg.org/lindenii/furgit/object/id"
	objectstore "codeberg.org/lindenii/furgit/object/store"
	refstore "codeberg.org/lindenii/furgit/ref/store"
)

// Options configures one receive-pack invocation.
//
// ReceivePack borrows all configured dependencies.
//
// Refs and ExistingObjects are required and must be non-nil.
// ObjectsRoot is required if the invocation may need to ingest or promote a
// pack.
type Options struct {
	// GitProtocol is the raw Git protocol version string from the transport,
	// such as "version=1".
	GitProtocol string
	// Algorithm is the repository object ID algorithm used by the push session.
	Algorithm objectid.Algorithm
	// Refs is the reference store visible to the push.
	Refs refstore.ReadWriteStore
	// ExistingObjects is the object store visible to the push before any newly
	// uploaded quarantined objects are promoted.
	ExistingObjects objectstore.ReadingStore
	// CommitGraph is an optional commit-graph snapshot corresponding to
	// ExistingObjects.
	CommitGraph *commitgraphread.Reader
	// ObjectsRoot is the permanent object storage root beneath which per-push
	// quarantine directories are derived.
	ObjectsRoot *os.Root
	// PromotedObjectPermissions, when non-nil, is applied to objects and
	// directories moved from quarantine into the permanent object store.
	PromotedObjectPermissions *PromotedObjectPermissions
	// Hook, when non-nil, runs after pack ingestion into quarantine and before
	// quarantine promotion or ref updates. Hook is borrowed for the duration of
	// ReceivePack.
	Hook Hook
	// Agent is the receive-pack agent string advertised via capability.
	//
	// When empty, ReceivePack derives one from build info and falls back to
	// "furgit".
	Agent string
	// SessionID is the advertised receive-pack session-id capability value.
	//
	// When empty, ReceivePack generates one random value per invocation.
	SessionID string
	// PushCertNonce is the advertised push-cert nonce capability value.
	//
	// When empty, ReceivePack generates one random value per invocation.
	PushCertNonce string
}

func validateOptions(opts Options) error {
	if opts.Algorithm == 0 {
		return ErrMissingAlgorithm
	}

	if opts.Refs == nil {
		return ErrMissingRefs
	}

	if opts.ExistingObjects == nil {
		return ErrMissingObjects
	}

	return nil
}