Skip to content

Commit 80e88dd

Browse files
committed
backend: pass hash to the file system backend
In order to read packs and indices, we need to know the hash algorithm in use, since the length of the hash will differ. Pass the hash algorithm to the file system backend instantiation function. Since we're moving to a new major version and can break compatibility, let's also just turn the two constructors into one that takes all of the required arguments. If the user does not want alternates, they can pass an empty string and we'll do the right thing.
1 parent d316817 commit 80e88dd

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

backend.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gitobj
22

33
import (
44
"bufio"
5+
"hash"
56
"io"
67
"os"
78
"path"
@@ -13,16 +14,12 @@ import (
1314
"github.com/git-lfs/gitobj/v2/storage"
1415
)
1516

16-
// NewFilesystemBackend initializes a new filesystem-based backend.
17-
func NewFilesystemBackend(root, tmp string) (storage.Backend, error) {
18-
return NewFilesystemBackendWithAlternates(root, tmp, "")
19-
}
20-
21-
// NewFilesystemBackendWithAlternates initializes a new filesystem-based
22-
// backend, optionally with additional alternates as specified in the
17+
// NewFilesystemBackend initializes a new filesystem-based backend,
18+
// optionally with additional alternates as specified in the
2319
// `alternates` variable. The syntax is that of the Git environment variable
24-
// GIT_ALTERNATE_OBJECT_DIRECTORIES.
25-
func NewFilesystemBackendWithAlternates(root, tmp, alternates string) (storage.Backend, error) {
20+
// GIT_ALTERNATE_OBJECT_DIRECTORIES. The hash algorithm used is specified by
21+
// the algo parameter.
22+
func NewFilesystemBackend(root, tmp, alternates string, algo hash.Hash) (storage.Backend, error) {
2623
fsobj := newFileStorer(root, tmp)
2724
packs, err := pack.NewStorage(root)
2825
if err != nil {

object_db.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func FromFilesystem(root, tmp string, setters ...Option) (*ObjectDatabase, error
7979
setter(args)
8080
}
8181

82-
b, err := NewFilesystemBackendWithAlternates(root, tmp, args.alternates)
82+
b, err := NewFilesystemBackend(root, tmp, args.alternates, hasher(args.objectFormat))
8383
if err != nil {
8484
return nil, err
8585
}

0 commit comments

Comments
 (0)