Skip to content

Commit dc977b2

Browse files
committed
pack: pass hash algorithm down into pack instantiation
When we instantiate a new pack or set of packs, pass the hash algorithm into these functions.
1 parent 67aa047 commit dc977b2

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

backend.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ import (
2121
// the algo parameter.
2222
func NewFilesystemBackend(root, tmp, alternates string, algo hash.Hash) (storage.Backend, error) {
2323
fsobj := newFileStorer(root, tmp)
24-
packs, err := pack.NewStorage(root)
24+
packs, err := pack.NewStorage(root, algo)
2525
if err != nil {
2626
return nil, err
2727
}
2828

29-
storage, err := findAllBackends(fsobj, packs, root)
29+
storage, err := findAllBackends(fsobj, packs, root, algo)
3030
if err != nil {
3131
return nil, err
3232
}
3333

34-
storage, err = addAlternatesFromEnvironment(storage, alternates)
34+
storage, err = addAlternatesFromEnvironment(storage, alternates, algo)
3535
if err != nil {
3636
return nil, err
3737
}
@@ -42,7 +42,7 @@ func NewFilesystemBackend(root, tmp, alternates string, algo hash.Hash) (storage
4242
}, nil
4343
}
4444

45-
func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root string) ([]storage.Storage, error) {
45+
func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root string, algo hash.Hash) ([]storage.Storage, error) {
4646
storage := make([]storage.Storage, 2)
4747
storage[0] = mainLoose
4848
storage[1] = mainPacked
@@ -58,7 +58,7 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin
5858

5959
scanner := bufio.NewScanner(f)
6060
for scanner.Scan() {
61-
storage, err = addAlternateDirectory(storage, scanner.Text())
61+
storage, err = addAlternateDirectory(storage, scanner.Text(), algo)
6262
if err != nil {
6363
return nil, err
6464
}
@@ -71,24 +71,24 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin
7171
return storage, nil
7272
}
7373

74-
func addAlternateDirectory(s []storage.Storage, dir string) ([]storage.Storage, error) {
74+
func addAlternateDirectory(s []storage.Storage, dir string, algo hash.Hash) ([]storage.Storage, error) {
7575
s = append(s, newFileStorer(dir, ""))
76-
pack, err := pack.NewStorage(dir)
76+
pack, err := pack.NewStorage(dir, algo)
7777
if err != nil {
7878
return s, err
7979
}
8080
s = append(s, pack)
8181
return s, nil
8282
}
8383

84-
func addAlternatesFromEnvironment(s []storage.Storage, env string) ([]storage.Storage, error) {
84+
func addAlternatesFromEnvironment(s []storage.Storage, env string, algo hash.Hash) ([]storage.Storage, error) {
8585
if len(env) == 0 {
8686
return s, nil
8787
}
8888

8989
for _, dir := range splitAlternateString(env, alternatesSeparator) {
9090
var err error
91-
s, err = addAlternateDirectory(s, dir)
91+
s, err = addAlternateDirectory(s, dir, algo)
9292
if err != nil {
9393
return nil, err
9494
}

pack/set.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pack
22

33
import (
44
"fmt"
5+
"hash"
56
"os"
67
"path/filepath"
78
"regexp"
@@ -38,7 +39,7 @@ var (
3839
// containing them. If there was an error parsing the packfiles in that
3940
// directory, or the directory was otherwise unable to be observed, NewSet
4041
// returns that error.
41-
func NewSet(db string) (*Set, error) {
42+
func NewSet(db string, algo hash.Hash) (*Set, error) {
4243
pd := filepath.Join(db, "pack")
4344

4445
paths, err := filepath.Glob(filepath.Join(escapeGlobPattern(pd), "*.pack"))

pack/storage.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pack
22

33
import (
4+
"hash"
45
"io"
56
)
67

@@ -10,8 +11,8 @@ type Storage struct {
1011
}
1112

1213
// NewStorage returns a new storage object based on a pack set.
13-
func NewStorage(root string) (*Storage, error) {
14-
packs, err := NewSet(root)
14+
func NewStorage(root string, algo hash.Hash) (*Storage, error) {
15+
packs, err := NewSet(root, algo)
1516
if err != nil {
1617
return nil, err
1718
}

0 commit comments

Comments
 (0)