aboutsummaryrefslogtreecommitdiff
path: root/repository/open.go
blob: f1bff5da5e67d65d78b2efdb299785c6c65025c9 (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
package repository

import "os"

// Open opens a repository and wires object/ref stores from its on-disk format.
//
// Open borrows root during construction and does not close it.
func Open(root *os.Root) (repo *Repository, err error) {
	repo = &Repository{}

	defer func() {
		if err != nil {
			_ = repo.Close()
		}
	}()

	cfg, err := parseRepositoryConfig(root)
	if err != nil {
		return nil, err
	}

	repo.config = cfg

	algo, err := detectObjectAlgorithm(cfg)
	if err != nil {
		return nil, err
	}

	repo.algo = algo

	objects, objectsLooseForWritingOnly, err := openObjectStore(root, algo)
	if err != nil {
		return nil, err
	}

	repo.objects = objects
	repo.objectsLooseForWritingOnly = objectsLooseForWritingOnly

	refs, err := openRefStore(root, algo, detectPackedRefsTimeout(cfg))
	if err != nil {
		return nil, err
	}

	repo.refs = refs

	return repo, nil
}