diff --git a/commands/command_migrate.go b/commands/command_migrate.go index 53c44876..7e889d0b 100644 --- a/commands/command_migrate.go +++ b/commands/command_migrate.go @@ -10,7 +10,7 @@ import ( "github.com/git-lfs/git-lfs/git" "github.com/git-lfs/git-lfs/git/githistory" "github.com/git-lfs/git-lfs/tasklog" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" "github.com/spf13/cobra" ) diff --git a/commands/command_migrate_export.go b/commands/command_migrate_export.go index bc24a1a8..57bb3b27 100644 --- a/commands/command_migrate_export.go +++ b/commands/command_migrate_export.go @@ -12,7 +12,7 @@ import ( "github.com/git-lfs/git-lfs/lfs" "github.com/git-lfs/git-lfs/tasklog" "github.com/git-lfs/git-lfs/tools" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" "github.com/spf13/cobra" ) diff --git a/commands/command_migrate_import.go b/commands/command_migrate_import.go index e2bff9ed..81c0b0cd 100644 --- a/commands/command_migrate_import.go +++ b/commands/command_migrate_import.go @@ -17,7 +17,7 @@ import ( "github.com/git-lfs/git-lfs/lfs" "github.com/git-lfs/git-lfs/tasklog" "github.com/git-lfs/git-lfs/tools" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" "github.com/spf13/cobra" ) diff --git a/commands/command_migrate_info.go b/commands/command_migrate_info.go index 92fca52b..2a169014 100644 --- a/commands/command_migrate_info.go +++ b/commands/command_migrate_info.go @@ -13,7 +13,7 @@ import ( "github.com/git-lfs/git-lfs/tasklog" "github.com/git-lfs/git-lfs/tools" "github.com/git-lfs/git-lfs/tools/humanize" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" "github.com/spf13/cobra" ) diff --git a/git/git.go b/git/git.go index 3f1d927e..5b8d9b7f 100644 --- a/git/git.go +++ b/git/git.go @@ -26,7 +26,7 @@ import ( lfserrors "github.com/git-lfs/git-lfs/errors" "github.com/git-lfs/git-lfs/subprocess" "github.com/git-lfs/git-lfs/tools" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" "github.com/rubyist/tracerx" ) @@ -1427,6 +1427,21 @@ func IsWorkingCopyDirty() (bool, error) { } func ObjectDatabase(osEnv, gitEnv Environment, gitdir, tempdir string) (*gitobj.ObjectDatabase, error) { + var options []gitobj.Option alternates, _ := osEnv.Get("GIT_ALTERNATE_OBJECT_DIRECTORIES") - return gitobj.FromFilesystemWithAlternates(filepath.Join(gitdir, "objects"), tempdir, alternates) + if alternates != "" { + options = append(options, gitobj.Alternates(alternates)) + } + hashAlgo, _ := gitEnv.Get("extensions.objectformat") + if hashAlgo != "" { + options = append(options, gitobj.ObjectFormat(gitobj.ObjectFormatAlgorithm(hashAlgo))) + } + odb, err := gitobj.FromFilesystem(filepath.Join(gitdir, "objects"), tempdir, options...) + if err != nil { + return nil, err + } + if odb.Hasher() == nil { + return nil, fmt.Errorf("unsupported repository hash algorithm %q", hashAlgo) + } + return odb, nil } diff --git a/git/gitattr/tree.go b/git/gitattr/tree.go index 409b38a1..d54378fb 100644 --- a/git/gitattr/tree.go +++ b/git/gitattr/tree.go @@ -3,7 +3,7 @@ package gitattr import ( "strings" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" ) // Tree represents the .gitattributes file at one layer of the tree in a Git diff --git a/git/gitattr/tree_test.go b/git/gitattr/tree_test.go index 5aaba96b..d1d64d65 100644 --- a/git/gitattr/tree_test.go +++ b/git/gitattr/tree_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" "github.com/git-lfs/wildmatch" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/git/githistory/fixtures_test.go b/git/githistory/fixtures_test.go index 7b8a61b4..ce0de6c5 100644 --- a/git/githistory/fixtures_test.go +++ b/git/githistory/fixtures_test.go @@ -11,7 +11,7 @@ import ( "strings" "testing" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" "github.com/stretchr/testify/assert" ) diff --git a/git/githistory/ref_updater.go b/git/githistory/ref_updater.go index 4819318f..88cf103c 100644 --- a/git/githistory/ref_updater.go +++ b/git/githistory/ref_updater.go @@ -9,7 +9,7 @@ import ( "github.com/git-lfs/git-lfs/git" "github.com/git-lfs/git-lfs/tasklog" "github.com/git-lfs/git-lfs/tools" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" ) // refUpdater is a type responsible for moving references from one point in the diff --git a/git/githistory/rewriter.go b/git/githistory/rewriter.go index 9a636e50..d5dd8de2 100644 --- a/git/githistory/rewriter.go +++ b/git/githistory/rewriter.go @@ -12,7 +12,7 @@ import ( "github.com/git-lfs/git-lfs/filepathfilter" "github.com/git-lfs/git-lfs/git" "github.com/git-lfs/git-lfs/tasklog" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" ) // Rewriter allows rewriting topologically equivalent Git histories diff --git a/git/githistory/rewriter_test.go b/git/githistory/rewriter_test.go index 8c3d8933..829e5083 100644 --- a/git/githistory/rewriter_test.go +++ b/git/githistory/rewriter_test.go @@ -12,7 +12,7 @@ import ( "github.com/git-lfs/git-lfs/errors" "github.com/git-lfs/git-lfs/filepathfilter" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" "github.com/stretchr/testify/assert" ) diff --git a/git/object_scanner.go b/git/object_scanner.go index 6bcbd12c..aa9c35a5 100644 --- a/git/object_scanner.go +++ b/git/object_scanner.go @@ -5,8 +5,8 @@ import ( "fmt" "io" - "github.com/git-lfs/gitobj" - "github.com/git-lfs/gitobj/errors" + "github.com/git-lfs/gitobj/v2" + "github.com/git-lfs/gitobj/v2/errors" ) // object represents a generic Git object of any type. diff --git a/go.mod b/go.mod index e93eddcf..06952242 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/alexbrainman/sspi v0.0.0-20180125232955-4729b3d4d858 github.com/avast/retry-go v2.4.2+incompatible github.com/dpotapov/go-spnego v0.0.0-20190506202455-c2c609116ad0 - github.com/git-lfs/gitobj v1.4.1 + github.com/git-lfs/gitobj/v2 v2.0.0 github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18 github.com/git-lfs/go-ntlm v0.0.0-20190401175752-c5056e7fa066 github.com/git-lfs/wildmatch v1.0.4 diff --git a/go.sum b/go.sum index cbf6ad5f..b5a14e7a 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/dpotapov/go-spnego v0.0.0-20190506202455-c2c609116ad0 h1:Hhh7nu7CfFVl github.com/dpotapov/go-spnego v0.0.0-20190506202455-c2c609116ad0/go.mod h1:P4f4MSk7h52F2PK0lCapn5+fu47Uf8aRdxDSqgezxZE= github.com/git-lfs/gitobj v1.4.1 h1:6nH5d1QP7GJjZfBqaBXpS7mDzT4plXQLqUjPbcbtRpw= github.com/git-lfs/gitobj v1.4.1/go.mod h1:B+djgKTnUoJHbg4uDvnC/+6xPcfEJNFbZd/YunEJRtA= +github.com/git-lfs/gitobj/v2 v2.0.0 h1:2Nm6MQo6coYxv1yYptgBQfny9HFRLHHdbYetBDIkJyg= +github.com/git-lfs/gitobj/v2 v2.0.0/go.mod h1:q6aqxl6Uu3gWsip5GEKpw+7459F97er8COmU45ncAxw= github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18 h1:7Th0eBA4rT8WJNiM1vppjaIv9W5WJinhpbCJvRJxloI= github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18/go.mod h1:70O4NAtvWn1jW8V8V+OKrJJYcxDLTmIozfi2fmSz5SI= github.com/git-lfs/go-ntlm v0.0.0-20190401175752-c5056e7fa066 h1:f5UyyCnv3o2EHy+zsqOyYa8jB5bZR/N9ZEideqeDYag= diff --git a/lfs/gitscanner_pointerscanner_test.go b/lfs/gitscanner_pointerscanner_test.go index 776a51b1..3e62771b 100644 --- a/lfs/gitscanner_pointerscanner_test.go +++ b/lfs/gitscanner_pointerscanner_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/git-lfs/git-lfs/git" - "github.com/git-lfs/gitobj" + "github.com/git-lfs/gitobj/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/vendor/github.com/git-lfs/gitobj/.travis.yml b/vendor/github.com/git-lfs/gitobj/.travis.yml deleted file mode 100644 index 45e85810..00000000 --- a/vendor/github.com/git-lfs/gitobj/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: go -go: 1.11 -before_install: - - > - mkdir -p ~/src; - mv "$TRAVIS_BUILD_DIR" ~/src/gitobj; - export TRAVIS_BUILD_DIR=~/src/gitobj; -notifications: - email: false diff --git a/vendor/github.com/git-lfs/gitobj/LICENSE.md b/vendor/github.com/git-lfs/gitobj/v2/LICENSE.md similarity index 100% rename from vendor/github.com/git-lfs/gitobj/LICENSE.md rename to vendor/github.com/git-lfs/gitobj/v2/LICENSE.md diff --git a/vendor/github.com/git-lfs/gitobj/README.md b/vendor/github.com/git-lfs/gitobj/v2/README.md similarity index 100% rename from vendor/github.com/git-lfs/gitobj/README.md rename to vendor/github.com/git-lfs/gitobj/v2/README.md diff --git a/vendor/github.com/git-lfs/gitobj/backend.go b/vendor/github.com/git-lfs/gitobj/v2/backend.go similarity index 78% rename from vendor/github.com/git-lfs/gitobj/backend.go rename to vendor/github.com/git-lfs/gitobj/v2/backend.go index 9e64285d..4f96cfac 100644 --- a/vendor/github.com/git-lfs/gitobj/backend.go +++ b/vendor/github.com/git-lfs/gitobj/v2/backend.go @@ -2,6 +2,7 @@ package gitobj import ( "bufio" + "hash" "io" "os" "path" @@ -9,32 +10,28 @@ import ( "strconv" "strings" - "github.com/git-lfs/gitobj/pack" - "github.com/git-lfs/gitobj/storage" + "github.com/git-lfs/gitobj/v2/pack" + "github.com/git-lfs/gitobj/v2/storage" ) -// NewFilesystemBackend initializes a new filesystem-based backend. -func NewFilesystemBackend(root, tmp string) (storage.Backend, error) { - return NewFilesystemBackendWithAlternates(root, tmp, "") -} - -// NewFilesystemBackendWithAlternates initializes a new filesystem-based -// backend, optionally with additional alternates as specified in the +// NewFilesystemBackend initializes a new filesystem-based backend, +// optionally with additional alternates as specified in the // `alternates` variable. The syntax is that of the Git environment variable -// GIT_ALTERNATE_OBJECT_DIRECTORIES. -func NewFilesystemBackendWithAlternates(root, tmp, alternates string) (storage.Backend, error) { +// GIT_ALTERNATE_OBJECT_DIRECTORIES. The hash algorithm used is specified by +// the algo parameter. +func NewFilesystemBackend(root, tmp, alternates string, algo hash.Hash) (storage.Backend, error) { fsobj := newFileStorer(root, tmp) - packs, err := pack.NewStorage(root) + packs, err := pack.NewStorage(root, algo) if err != nil { return nil, err } - storage, err := findAllBackends(fsobj, packs, root) + storage, err := findAllBackends(fsobj, packs, root, algo) if err != nil { return nil, err } - storage, err = addAlternatesFromEnvironment(storage, alternates) + storage, err = addAlternatesFromEnvironment(storage, alternates, algo) if err != nil { return nil, err } @@ -45,7 +42,7 @@ func NewFilesystemBackendWithAlternates(root, tmp, alternates string) (storage.B }, nil } -func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root string) ([]storage.Storage, error) { +func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root string, algo hash.Hash) ([]storage.Storage, error) { storage := make([]storage.Storage, 2) storage[0] = mainLoose storage[1] = mainPacked @@ -61,7 +58,7 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin scanner := bufio.NewScanner(f) for scanner.Scan() { - storage, err = addAlternateDirectory(storage, scanner.Text()) + storage, err = addAlternateDirectory(storage, scanner.Text(), algo) if err != nil { return nil, err } @@ -74,9 +71,9 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin return storage, nil } -func addAlternateDirectory(s []storage.Storage, dir string) ([]storage.Storage, error) { +func addAlternateDirectory(s []storage.Storage, dir string, algo hash.Hash) ([]storage.Storage, error) { s = append(s, newFileStorer(dir, "")) - pack, err := pack.NewStorage(dir) + pack, err := pack.NewStorage(dir, algo) if err != nil { return s, err } @@ -84,14 +81,14 @@ func addAlternateDirectory(s []storage.Storage, dir string) ([]storage.Storage, return s, nil } -func addAlternatesFromEnvironment(s []storage.Storage, env string) ([]storage.Storage, error) { +func addAlternatesFromEnvironment(s []storage.Storage, env string, algo hash.Hash) ([]storage.Storage, error) { if len(env) == 0 { return s, nil } for _, dir := range splitAlternateString(env, alternatesSeparator) { var err error - s, err = addAlternateDirectory(s, dir) + s, err = addAlternateDirectory(s, dir, algo) if err != nil { return nil, err } diff --git a/vendor/github.com/git-lfs/gitobj/backend_nix.go b/vendor/github.com/git-lfs/gitobj/v2/backend_nix.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/backend_nix.go rename to vendor/github.com/git-lfs/gitobj/v2/backend_nix.go diff --git a/vendor/github.com/git-lfs/gitobj/backend_windows.go b/vendor/github.com/git-lfs/gitobj/v2/backend_windows.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/backend_windows.go rename to vendor/github.com/git-lfs/gitobj/v2/backend_windows.go diff --git a/vendor/github.com/git-lfs/gitobj/blob.go b/vendor/github.com/git-lfs/gitobj/v2/blob.go similarity index 97% rename from vendor/github.com/git-lfs/gitobj/blob.go rename to vendor/github.com/git-lfs/gitobj/v2/blob.go index d783843b..ae9c48da 100644 --- a/vendor/github.com/git-lfs/gitobj/blob.go +++ b/vendor/github.com/git-lfs/gitobj/v2/blob.go @@ -3,6 +3,7 @@ package gitobj import ( "bytes" "fmt" + "hash" "io" "os" ) @@ -75,7 +76,7 @@ func (b *Blob) Type() ObjectType { return BlobObjectType } // stream, which is always zero. // // If any errors are encountered while reading the blob, they will be returned. -func (b *Blob) Decode(r io.Reader, size int64) (n int, err error) { +func (b *Blob) Decode(hash hash.Hash, r io.Reader, size int64) (n int, err error) { b.Size = size b.Contents = io.LimitReader(r, size) diff --git a/vendor/github.com/git-lfs/gitobj/commit.go b/vendor/github.com/git-lfs/gitobj/v2/commit.go similarity index 97% rename from vendor/github.com/git-lfs/gitobj/commit.go rename to vendor/github.com/git-lfs/gitobj/v2/commit.go index c8556f04..daf3be58 100644 --- a/vendor/github.com/git-lfs/gitobj/commit.go +++ b/vendor/github.com/git-lfs/gitobj/v2/commit.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/hex" "fmt" + "hash" "io" "strings" "time" @@ -91,11 +92,12 @@ func (c *Commit) Type() ObjectType { return CommitObjectType } // // If any error was encountered along the way, that will be returned, along with // the number of bytes read up to that point. -func (c *Commit) Decode(from io.Reader, size int64) (n int, err error) { +func (c *Commit) Decode(hash hash.Hash, from io.Reader, size int64) (n int, err error) { var finishedHeaders bool var messageParts []string s := bufio.NewScanner(from) + s.Buffer(nil, 1024*1024) for s.Scan() { text := s.Text() n = n + len(text+"\n") @@ -169,7 +171,7 @@ func (c *Commit) Decode(from io.Reader, size int64) (n int, err error) { c.Message = strings.Join(messageParts, "\n") if err = s.Err(); err != nil { - return n, err + return n, fmt.Errorf("failed to parse commit buffer: %s", err) } return n, err } diff --git a/vendor/github.com/git-lfs/gitobj/errors.go b/vendor/github.com/git-lfs/gitobj/v2/errors.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/errors.go rename to vendor/github.com/git-lfs/gitobj/v2/errors.go diff --git a/vendor/github.com/git-lfs/gitobj/errors/errors.go b/vendor/github.com/git-lfs/gitobj/v2/errors/errors.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/errors/errors.go rename to vendor/github.com/git-lfs/gitobj/v2/errors/errors.go diff --git a/vendor/github.com/git-lfs/gitobj/file_storer.go b/vendor/github.com/git-lfs/gitobj/v2/file_storer.go similarity index 98% rename from vendor/github.com/git-lfs/gitobj/file_storer.go rename to vendor/github.com/git-lfs/gitobj/v2/file_storer.go index fb20e86b..bdb63b5b 100644 --- a/vendor/github.com/git-lfs/gitobj/file_storer.go +++ b/vendor/github.com/git-lfs/gitobj/v2/file_storer.go @@ -8,7 +8,7 @@ import ( "os" "path/filepath" - "github.com/git-lfs/gitobj/errors" + "github.com/git-lfs/gitobj/v2/errors" ) // fileStorer implements the storer interface by writing to the .git/objects diff --git a/vendor/github.com/git-lfs/gitobj/go.mod b/vendor/github.com/git-lfs/gitobj/v2/go.mod similarity index 81% rename from vendor/github.com/git-lfs/gitobj/go.mod rename to vendor/github.com/git-lfs/gitobj/v2/go.mod index 3a603be1..a1eb0bfe 100644 --- a/vendor/github.com/git-lfs/gitobj/go.mod +++ b/vendor/github.com/git-lfs/gitobj/v2/go.mod @@ -1,4 +1,4 @@ -module github.com/git-lfs/gitobj +module github.com/git-lfs/gitobj/v2 require ( github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/vendor/github.com/git-lfs/gitobj/go.sum b/vendor/github.com/git-lfs/gitobj/v2/go.sum similarity index 100% rename from vendor/github.com/git-lfs/gitobj/go.sum rename to vendor/github.com/git-lfs/gitobj/v2/go.sum diff --git a/vendor/github.com/git-lfs/gitobj/memory_storer.go b/vendor/github.com/git-lfs/gitobj/v2/memory_storer.go similarity index 98% rename from vendor/github.com/git-lfs/gitobj/memory_storer.go rename to vendor/github.com/git-lfs/gitobj/v2/memory_storer.go index 2359b92e..ba4ea5af 100644 --- a/vendor/github.com/git-lfs/gitobj/memory_storer.go +++ b/vendor/github.com/git-lfs/gitobj/v2/memory_storer.go @@ -6,7 +6,7 @@ import ( "io" "sync" - "github.com/git-lfs/gitobj/errors" + "github.com/git-lfs/gitobj/v2/errors" ) // memoryStorer is an implementation of the storer interface that holds data for diff --git a/vendor/github.com/git-lfs/gitobj/object.go b/vendor/github.com/git-lfs/gitobj/v2/object.go similarity index 93% rename from vendor/github.com/git-lfs/gitobj/object.go rename to vendor/github.com/git-lfs/gitobj/v2/object.go index 00b79dab..451c6956 100644 --- a/vendor/github.com/git-lfs/gitobj/object.go +++ b/vendor/github.com/git-lfs/gitobj/v2/object.go @@ -1,6 +1,9 @@ package gitobj -import "io" +import ( + "hash" + "io" +) // Object is an interface satisfied by any concrete type that represents a loose // Git object. @@ -29,7 +32,7 @@ type Object interface { // // If an(y) error was encountered, it should be returned immediately, // along with the number of bytes read up to that point. - Decode(from io.Reader, size int64) (n int, err error) + Decode(hash hash.Hash, from io.Reader, size int64) (n int, err error) // Type returns the ObjectType constant that represents an instance of // the implementing type. diff --git a/vendor/github.com/git-lfs/gitobj/object_db.go b/vendor/github.com/git-lfs/gitobj/v2/object_db.go similarity index 79% rename from vendor/github.com/git-lfs/gitobj/object_db.go rename to vendor/github.com/git-lfs/gitobj/v2/object_db.go index 89ce7e02..5eaa555d 100644 --- a/vendor/github.com/git-lfs/gitobj/object_db.go +++ b/vendor/github.com/git-lfs/gitobj/v2/object_db.go @@ -2,13 +2,16 @@ package gitobj import ( "bytes" + "crypto/sha1" + "crypto/sha256" "fmt" + "hash" "io" "io/ioutil" "os" "sync/atomic" - "github.com/git-lfs/gitobj/storage" + "github.com/git-lfs/gitobj/v2/storage" ) // ObjectDatabase enables the reading and writing of objects against a storage @@ -29,41 +32,80 @@ type ObjectDatabase struct { // temp directory, defaults to os.TempDir tmp string + + // objectFormat is the object format (hash algorithm) + objectFormat ObjectFormatAlgorithm +} + +type options struct { + alternates string + objectFormat ObjectFormatAlgorithm +} + +type Option func(*options) + +type ObjectFormatAlgorithm string + +const ( + ObjectFormatSHA1 = ObjectFormatAlgorithm("sha1") + ObjectFormatSHA256 = ObjectFormatAlgorithm("sha256") +) + +// Alternates is an Option to specify the string of alternate repositories that +// are searched for objects. The format is the same as for +// GIT_ALTERNATE_OBJECT_DIRECTORIES. +func Alternates(alternates string) Option { + return func(args *options) { + args.alternates = alternates + } +} + +// ObjectFormat is an Option to specify the hash algorithm (object format) in +// use in Git. If not specified, it defaults to ObjectFormatSHA1. +func ObjectFormat(algo ObjectFormatAlgorithm) Option { + return func(args *options) { + args.objectFormat = algo + } } // FromFilesystem constructs an *ObjectDatabase instance that is backed by a // directory on the filesystem. Specifically, this should point to: // // /absolute/repo/path/.git/objects -func FromFilesystem(root, tmp string) (*ObjectDatabase, error) { - return FromFilesystemWithAlternates(root, tmp, "") -} +func FromFilesystem(root, tmp string, setters ...Option) (*ObjectDatabase, error) { + args := &options{objectFormat: ObjectFormatSHA1} -// FromFilesystemWithAlternates constructs an *ObjectDatabase instance that is -// backed by a directory on the filesystem, optionally with one or more -// alternates. Specifically, this should point to: -// -// /absolute/repo/path/.git/objects -func FromFilesystemWithAlternates(root, tmp, alternates string) (*ObjectDatabase, error) { - b, err := NewFilesystemBackendWithAlternates(root, tmp, alternates) + for _, setter := range setters { + setter(args) + } + + b, err := NewFilesystemBackend(root, tmp, args.alternates, hasher(args.objectFormat)) if err != nil { return nil, err } - ro, rw := b.Storage() - return &ObjectDatabase{ - tmp: tmp, - ro: ro, - rw: rw, - }, nil + odb, err := FromBackend(b, setters...) + if err != nil { + return nil, err + } + odb.tmp = tmp + return odb, nil } -func FromBackend(b storage.Backend) (*ObjectDatabase, error) { +func FromBackend(b storage.Backend, setters ...Option) (*ObjectDatabase, error) { + args := &options{objectFormat: ObjectFormatSHA1} + + for _, setter := range setters { + setter(args) + } + ro, rw := b.Storage() - return &ObjectDatabase{ - ro: ro, - rw: rw, - }, nil + odb := &ObjectDatabase{ + ro: ro, + rw: rw, + objectFormat: args.objectFormat, + } + return odb, nil } // Close closes the *ObjectDatabase, freeing any open resources (namely: the @@ -227,6 +269,11 @@ func (o *ObjectDatabase) Root() (string, bool) { return "", false } +// Hasher returns a new hash instance suitable for this object database. +func (o *ObjectDatabase) Hasher() hash.Hash { + return hasher(o.objectFormat) +} + // encode encodes and saves an object to the storage backend and uses an // in-memory buffer to calculate the object's encoded body. func (d *ObjectDatabase) encode(object Object) (sha []byte, n int64, err error) { @@ -247,7 +294,7 @@ func (d *ObjectDatabase) encodeBuffer(object Object, buf io.ReadWriter) (sha []b } defer d.cleanup(tmp) - to := NewObjectWriter(tmp) + to := NewObjectWriter(tmp, d.Hasher()) if _, err = to.WriteHeader(object.Type(), int64(cn)); err != nil { return nil, 0, err } @@ -323,7 +370,7 @@ func (o *ObjectDatabase) decode(r *ObjectReader, into Object) error { return &UnexpectedObjectType{Got: typ, Wanted: into.Type()} } - if _, err = into.Decode(r, size); err != nil { + if _, err = into.Decode(o.Hasher(), r, size); err != nil { return err } @@ -337,3 +384,14 @@ func (o *ObjectDatabase) cleanup(f *os.File) { f.Close() os.Remove(f.Name()) } + +func hasher(algo ObjectFormatAlgorithm) hash.Hash { + switch algo { + case ObjectFormatSHA1: + return sha1.New() + case ObjectFormatSHA256: + return sha256.New() + default: + return nil + } +} diff --git a/vendor/github.com/git-lfs/gitobj/object_reader.go b/vendor/github.com/git-lfs/gitobj/v2/object_reader.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/object_reader.go rename to vendor/github.com/git-lfs/gitobj/v2/object_reader.go diff --git a/vendor/github.com/git-lfs/gitobj/object_type.go b/vendor/github.com/git-lfs/gitobj/v2/object_type.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/object_type.go rename to vendor/github.com/git-lfs/gitobj/v2/object_type.go diff --git a/vendor/github.com/git-lfs/gitobj/object_writer.go b/vendor/github.com/git-lfs/gitobj/v2/object_writer.go similarity index 88% rename from vendor/github.com/git-lfs/gitobj/object_writer.go rename to vendor/github.com/git-lfs/gitobj/v2/object_writer.go index 85074394..5fb33ab6 100644 --- a/vendor/github.com/git-lfs/gitobj/object_writer.go +++ b/vendor/github.com/git-lfs/gitobj/v2/object_writer.go @@ -2,7 +2,6 @@ package gitobj import ( "compress/zlib" - "crypto/sha1" "fmt" "hash" "io" @@ -50,18 +49,20 @@ func (n *nopCloser) Close() error { } // NewObjectWriter returns a new *ObjectWriter instance that drains incoming -// writes into the io.Writer given, "w". -func NewObjectWriter(w io.Writer) *ObjectWriter { - return NewObjectWriteCloser(&nopCloser{w}) +// writes into the io.Writer given, "w". "hash" is a hash instance from the +// ObjectDatabase'e Hash method. +func NewObjectWriter(w io.Writer, hash hash.Hash) *ObjectWriter { + return NewObjectWriteCloser(&nopCloser{w}, hash) } // NewObjectWriter returns a new *ObjectWriter instance that drains incoming -// writes into the io.Writer given, "w". +// writes into the io.Writer given, "w". "sum" is a hash instance from the +// ObjectDatabase'e Hash method. // // Upon closing, it calls the given Close() function of the io.WriteCloser. -func NewObjectWriteCloser(w io.WriteCloser) *ObjectWriter { +func NewObjectWriteCloser(w io.WriteCloser, sum hash.Hash) *ObjectWriter { zw := zlib.NewWriter(w) - sum := sha1.New() + sum.Reset() return &ObjectWriter{ w: io.MultiWriter(zw, sum), diff --git a/vendor/github.com/git-lfs/gitobj/pack/bounds.go b/vendor/github.com/git-lfs/gitobj/v2/pack/bounds.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/bounds.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/bounds.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/chain.go b/vendor/github.com/git-lfs/gitobj/v2/pack/chain.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/chain.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/chain.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/chain_base.go b/vendor/github.com/git-lfs/gitobj/v2/pack/chain_base.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/chain_base.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/chain_base.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/chain_delta.go b/vendor/github.com/git-lfs/gitobj/v2/pack/chain_delta.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/chain_delta.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/chain_delta.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/delayed_object.go b/vendor/github.com/git-lfs/gitobj/v2/pack/delayed_object.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/delayed_object.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/delayed_object.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/errors.go b/vendor/github.com/git-lfs/gitobj/v2/pack/errors.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/errors.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/errors.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/index.go b/vendor/github.com/git-lfs/gitobj/v2/pack/index.go similarity index 98% rename from vendor/github.com/git-lfs/gitobj/pack/index.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/index.go index 143d6ef2..2d046501 100644 --- a/vendor/github.com/git-lfs/gitobj/pack/index.go +++ b/vendor/github.com/git-lfs/gitobj/v2/pack/index.go @@ -2,10 +2,13 @@ package pack import ( "bytes" + "crypto/sha256" "fmt" "io" ) +const maxHashSize = sha256.Size + // Index stores information about the location of objects in a corresponding // packfile. type Index struct { diff --git a/vendor/github.com/git-lfs/gitobj/pack/index_decode.go b/vendor/github.com/git-lfs/gitobj/v2/pack/index_decode.go similarity index 82% rename from vendor/github.com/git-lfs/gitobj/pack/index_decode.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/index_decode.go index a2cf54ce..b0dc00d7 100644 --- a/vendor/github.com/git-lfs/gitobj/pack/index_decode.go +++ b/vendor/github.com/git-lfs/gitobj/v2/pack/index_decode.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "fmt" + "hash" "io" ) @@ -33,8 +34,6 @@ const ( // V2 header. indexOffsetV2Start = indexV2Width + indexFanoutWidth - // indexObjectNameWidth is the width of a SHA1 object name. - indexObjectNameWidth = 20 // indexObjectCRCWidth is the width of the CRC accompanying each object // in V2. indexObjectCRCWidth = 4 @@ -44,13 +43,6 @@ const ( // indexObjectLargeOffsetWidth is the width of the optional large offset // encoded into the small offset. indexObjectLargeOffsetWidth = 8 - - // indexObjectEntryV1Width is the width of one contiguous object entry - // in V1. - indexObjectEntryV1Width = indexObjectNameWidth + indexObjectSmallOffsetWidth - // indexObjectEntryV2Width is the width of one non-contiguous object - // entry in V2. - indexObjectEntryV2Width = indexObjectNameWidth + indexObjectCRCWidth + indexObjectSmallOffsetWidth ) var ( @@ -69,8 +61,8 @@ var ( // parse index entries. // // If there was an error parsing, it will be returned immediately. -func DecodeIndex(r io.ReaderAt) (*Index, error) { - version, err := decodeIndexHeader(r) +func DecodeIndex(r io.ReaderAt, hash hash.Hash) (*Index, error) { + version, err := decodeIndexHeader(r, hash) if err != nil { return nil, err } @@ -89,7 +81,7 @@ func DecodeIndex(r io.ReaderAt) (*Index, error) { } // decodeIndexHeader determines which version the index given by "r" is. -func decodeIndexHeader(r io.ReaderAt) (IndexVersion, error) { +func decodeIndexHeader(r io.ReaderAt, hash hash.Hash) (IndexVersion, error) { hdr := make([]byte, 4) if _, err := r.ReadAt(hdr, 0); err != nil { return nil, err @@ -104,13 +96,13 @@ func decodeIndexHeader(r io.ReaderAt) (IndexVersion, error) { version := binary.BigEndian.Uint32(vb) switch version { case 1: - return new(V1), nil + return &V1{hash: hash}, nil case 2: - return new(V2), nil + return &V2{hash: hash}, nil } return nil, &UnsupportedVersionErr{uint32(version)} } - return new(V1), nil + return &V1{hash: hash}, nil } // decodeIndexFanout decodes the fanout table given by "r" and beginning at the diff --git a/vendor/github.com/git-lfs/gitobj/pack/index_entry.go b/vendor/github.com/git-lfs/gitobj/v2/pack/index_entry.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/index_entry.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/index_entry.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/index_v1.go b/vendor/github.com/git-lfs/gitobj/v2/pack/index_v1.go similarity index 72% rename from vendor/github.com/git-lfs/gitobj/pack/index_v1.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/index_v1.go index c619f057..e7170cf6 100644 --- a/vendor/github.com/git-lfs/gitobj/pack/index_v1.go +++ b/vendor/github.com/git-lfs/gitobj/v2/pack/index_v1.go @@ -2,27 +2,33 @@ package pack import ( "encoding/binary" + "hash" ) // V1 implements IndexVersion for v1 packfiles. -type V1 struct{} +type V1 struct { + hash hash.Hash +} // Name implements IndexVersion.Name by returning the 20 byte SHA-1 object name // for the given entry at offset "at" in the v1 index file "idx". func (v *V1) Name(idx *Index, at int64) ([]byte, error) { - var sha [20]byte - if _, err := idx.readAt(sha[:], v1ShaOffset(at)); err != nil { + var sha [maxHashSize]byte + + hashlen := v.hash.Size() + + if _, err := idx.readAt(sha[:hashlen], v1ShaOffset(at, int64(hashlen))); err != nil { return nil, err } - return sha[:], nil + return sha[:hashlen], nil } // Entry implements IndexVersion.Entry for v1 packfiles by parsing and returning // the IndexEntry specified at the offset "at" in the given index file. func (v *V1) Entry(idx *Index, at int64) (*IndexEntry, error) { var offs [4]byte - if _, err := idx.readAt(offs[:], v1EntryOffset(at)); err != nil { + if _, err := idx.readAt(offs[:], v1EntryOffset(at, int64(v.hash.Size()))); err != nil { return nil, err } @@ -38,9 +44,9 @@ func (v *V1) Width() int64 { } // v1ShaOffset returns the location of the SHA1 of an object given at "at". -func v1ShaOffset(at int64) int64 { +func v1ShaOffset(at int64, hashlen int64) int64 { // Skip forward until the desired entry. - return v1EntryOffset(at) + + return v1EntryOffset(at, hashlen) + // Skip past the 4-byte object offset in the desired entry to // the SHA1. indexObjectSmallOffsetWidth @@ -48,9 +54,9 @@ func v1ShaOffset(at int64) int64 { // v1EntryOffset returns the location of the packfile offset for the object // given at "at". -func v1EntryOffset(at int64) int64 { +func v1EntryOffset(at int64, hashlen int64) int64 { // Skip the L1 fanout table return indexOffsetV1Start + // Skip the object entries before the one located at "at" - (indexObjectEntryV1Width * at) + ((hashlen + indexObjectSmallOffsetWidth) * at) } diff --git a/vendor/github.com/git-lfs/gitobj/pack/index_v2.go b/vendor/github.com/git-lfs/gitobj/v2/pack/index_v2.go similarity index 82% rename from vendor/github.com/git-lfs/gitobj/pack/index_v2.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/index_v2.go index 2ff196c1..85f37b4b 100644 --- a/vendor/github.com/git-lfs/gitobj/pack/index_v2.go +++ b/vendor/github.com/git-lfs/gitobj/v2/pack/index_v2.go @@ -2,27 +2,36 @@ package pack import ( "encoding/binary" + "hash" ) // V2 implements IndexVersion for v2 packfiles. -type V2 struct{} +type V2 struct { + hash hash.Hash +} // Name implements IndexVersion.Name by returning the 20 byte SHA-1 object name // for the given entry at offset "at" in the v2 index file "idx". func (v *V2) Name(idx *Index, at int64) ([]byte, error) { - var sha [20]byte - if _, err := idx.readAt(sha[:], v2ShaOffset(at)); err != nil { + var sha [maxHashSize]byte + + hashlen := v.hash.Size() + + if _, err := idx.readAt(sha[:hashlen], v2ShaOffset(at, int64(hashlen))); err != nil { return nil, err } - return sha[:], nil + return sha[:hashlen], nil } // Entry implements IndexVersion.Entry for v2 packfiles by parsing and returning // the IndexEntry specified at the offset "at" in the given index file. func (v *V2) Entry(idx *Index, at int64) (*IndexEntry, error) { var offs [4]byte - if _, err := idx.readAt(offs[:], v2SmallOffsetOffset(at, int64(idx.Count()))); err != nil { + + hashlen := v.hash.Size() + + if _, err := idx.readAt(offs[:], v2SmallOffsetOffset(at, int64(idx.Count()), int64(hashlen))); err != nil { return nil, err } @@ -33,7 +42,7 @@ func (v *V2) Entry(idx *Index, at int64) (*IndexEntry, error) { // // Mask away (offs&0x7fffffff) the MSB to use as an index to // find the offset of the 8-byte pack offset. - lo := v2LargeOffsetOffset(int64(loc&0x7fffffff), int64(idx.Count())) + lo := v2LargeOffsetOffset(int64(loc&0x7fffffff), int64(idx.Count()), int64(hashlen)) var offs [8]byte if _, err := idx.readAt(offs[:], lo); err != nil { @@ -52,20 +61,20 @@ func (v *V2) Width() int64 { } // v2ShaOffset returns the offset of a SHA1 given at "at" in the V2 index file. -func v2ShaOffset(at int64) int64 { +func v2ShaOffset(at int64, hashlen int64) int64 { // Skip the packfile index header and the L1 fanout table. return indexOffsetV2Start + // Skip until the desired name in the sorted names table. - (indexObjectNameWidth * at) + (hashlen * at) } // v2SmallOffsetOffset returns the offset of an object's small (4-byte) offset // given by "at". -func v2SmallOffsetOffset(at, total int64) int64 { +func v2SmallOffsetOffset(at, total, hashlen int64) int64 { // Skip the packfile index header and the L1 fanout table. return indexOffsetV2Start + // Skip the name table. - (indexObjectNameWidth * total) + + (hashlen * total) + // Skip the CRC table. (indexObjectCRCWidth * total) + // Skip until the desired index in the small offsets table. @@ -74,11 +83,11 @@ func v2SmallOffsetOffset(at, total int64) int64 { // v2LargeOffsetOffset returns the offset of an object's large (4-byte) offset, // given by the index "at". -func v2LargeOffsetOffset(at, total int64) int64 { +func v2LargeOffsetOffset(at, total, hashlen int64) int64 { // Skip the packfile index header and the L1 fanout table. return indexOffsetV2Start + // Skip the name table. - (indexObjectNameWidth * total) + + (hashlen * total) + // Skip the CRC table. (indexObjectCRCWidth * total) + // Skip the small offsets table. diff --git a/vendor/github.com/git-lfs/gitobj/pack/index_version.go b/vendor/github.com/git-lfs/gitobj/v2/pack/index_version.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/index_version.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/index_version.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/io.go b/vendor/github.com/git-lfs/gitobj/v2/pack/io.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/io.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/io.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/object.go b/vendor/github.com/git-lfs/gitobj/v2/pack/object.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/object.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/object.go diff --git a/vendor/github.com/git-lfs/gitobj/pack/packfile.go b/vendor/github.com/git-lfs/gitobj/v2/pack/packfile.go similarity index 93% rename from vendor/github.com/git-lfs/gitobj/pack/packfile.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/packfile.go index eb0cdbc1..f5612139 100644 --- a/vendor/github.com/git-lfs/gitobj/pack/packfile.go +++ b/vendor/github.com/git-lfs/gitobj/v2/pack/packfile.go @@ -3,6 +3,7 @@ package pack import ( "compress/zlib" "fmt" + "hash" "io" "io/ioutil" ) @@ -18,6 +19,9 @@ type Packfile struct { // objects in this packfile. idx *Index + // hash is the hash algorithm used in this pack. + hash hash.Hash + // r is an io.ReaderAt that allows read access to the packfile itself. r io.ReaderAt } @@ -181,11 +185,13 @@ func (p *Packfile) find(offset int64) (Chain, error) { func (p *Packfile) findBase(typ PackedObjectType, offset, objOffset int64) (Chain, int64, error) { var baseOffset int64 - // We assume that we have to read at least 20 bytes (the SHA-1 length in - // the case of a OBJ_REF_DELTA, or greater than the length of the base - // offset encoded in an OBJ_OFS_DELTA). - var sha [20]byte - if _, err := p.r.ReadAt(sha[:], offset); err != nil { + hashlen := p.hash.Size() + + // We assume that we have to read at least an object ID's worth (the + // hash length in the case of a OBJ_REF_DELTA, or greater than the + // length of the base offset encoded in an OBJ_OFS_DELTA). + var sha [32]byte + if _, err := p.r.ReadAt(sha[:hashlen], offset); err != nil { return nil, baseOffset, err } @@ -213,13 +219,13 @@ func (p *Packfile) findBase(typ PackedObjectType, offset, objOffset int64) (Chai // If the delta is an OBJ_REFS_DELTA, find the location of its // base by reading the SHA-1 name and looking it up in the // corresponding pack index file. - e, err := p.idx.Entry(sha[:]) + e, err := p.idx.Entry(sha[:hashlen]) if err != nil { return nil, baseOffset, err } baseOffset = int64(e.PackOffset) - offset += 20 + offset += int64(hashlen) default: // If we did not receive an OBJ_OFS_DELTA, or OBJ_REF_DELTA, the // type given is not a delta-fied type. Return an error. diff --git a/vendor/github.com/git-lfs/gitobj/pack/packfile_decode.go b/vendor/github.com/git-lfs/gitobj/v2/pack/packfile_decode.go similarity index 91% rename from vendor/github.com/git-lfs/gitobj/pack/packfile_decode.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/packfile_decode.go index ef7bf471..afac0e36 100644 --- a/vendor/github.com/git-lfs/gitobj/pack/packfile_decode.go +++ b/vendor/github.com/git-lfs/gitobj/v2/pack/packfile_decode.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "errors" + "hash" "io" ) @@ -22,7 +23,7 @@ var ( // // If the header is malformed, or otherwise cannot be read, an error will be // returned without a corresponding packfile. -func DecodePackfile(r io.ReaderAt) (*Packfile, error) { +func DecodePackfile(r io.ReaderAt, hash hash.Hash) (*Packfile, error) { header := make([]byte, 12) if _, err := r.ReadAt(header[:], 0); err != nil { return nil, err @@ -40,5 +41,6 @@ func DecodePackfile(r io.ReaderAt) (*Packfile, error) { Objects: objects, r: r, + hash: hash, }, nil } diff --git a/vendor/github.com/git-lfs/gitobj/pack/set.go b/vendor/github.com/git-lfs/gitobj/v2/pack/set.go similarity index 96% rename from vendor/github.com/git-lfs/gitobj/pack/set.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/set.go index 04eaff06..8fe4fe53 100644 --- a/vendor/github.com/git-lfs/gitobj/pack/set.go +++ b/vendor/github.com/git-lfs/gitobj/v2/pack/set.go @@ -2,13 +2,14 @@ package pack import ( "fmt" + "hash" "os" "path/filepath" "regexp" "sort" "strings" - "github.com/git-lfs/gitobj/errors" + "github.com/git-lfs/gitobj/v2/errors" ) // Set allows access of objects stored across a set of packfiles. @@ -38,7 +39,7 @@ var ( // containing them. If there was an error parsing the packfiles in that // directory, or the directory was otherwise unable to be observed, NewSet // returns that error. -func NewSet(db string) (*Set, error) { +func NewSet(db string, algo hash.Hash) (*Set, error) { pd := filepath.Join(db, "pack") paths, err := filepath.Glob(filepath.Join(escapeGlobPattern(pd), "*.pack")) @@ -75,12 +76,12 @@ func NewSet(db string) (*Set, error) { return nil, err } - pack, err := DecodePackfile(packf) + pack, err := DecodePackfile(packf, algo) if err != nil { return nil, err } - idx, err := DecodeIndex(idxf) + idx, err := DecodeIndex(idxf, algo) if err != nil { return nil, err } @@ -138,7 +139,7 @@ func NewSetPacks(packs ...*Packfile) *Set { } return &Set{ - m: m, + m: m, closeFn: func() error { for _, pack := range packs { if err := pack.Close(); err != nil { diff --git a/vendor/github.com/git-lfs/gitobj/pack/storage.go b/vendor/github.com/git-lfs/gitobj/v2/pack/storage.go similarity index 87% rename from vendor/github.com/git-lfs/gitobj/pack/storage.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/storage.go index 5736e74f..489ed134 100644 --- a/vendor/github.com/git-lfs/gitobj/pack/storage.go +++ b/vendor/github.com/git-lfs/gitobj/v2/pack/storage.go @@ -1,6 +1,7 @@ package pack import ( + "hash" "io" ) @@ -10,8 +11,8 @@ type Storage struct { } // NewStorage returns a new storage object based on a pack set. -func NewStorage(root string) (*Storage, error) { - packs, err := NewSet(root) +func NewStorage(root string, algo hash.Hash) (*Storage, error) { + packs, err := NewSet(root, algo) if err != nil { return nil, err } diff --git a/vendor/github.com/git-lfs/gitobj/pack/type.go b/vendor/github.com/git-lfs/gitobj/v2/pack/type.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/pack/type.go rename to vendor/github.com/git-lfs/gitobj/v2/pack/type.go diff --git a/vendor/github.com/git-lfs/gitobj/storage/backend.go b/vendor/github.com/git-lfs/gitobj/v2/storage/backend.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/storage/backend.go rename to vendor/github.com/git-lfs/gitobj/v2/storage/backend.go diff --git a/vendor/github.com/git-lfs/gitobj/storage/decompressing_readcloser.go b/vendor/github.com/git-lfs/gitobj/v2/storage/decompressing_readcloser.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/storage/decompressing_readcloser.go rename to vendor/github.com/git-lfs/gitobj/v2/storage/decompressing_readcloser.go diff --git a/vendor/github.com/git-lfs/gitobj/storage/multi_storage.go b/vendor/github.com/git-lfs/gitobj/v2/storage/multi_storage.go similarity index 96% rename from vendor/github.com/git-lfs/gitobj/storage/multi_storage.go rename to vendor/github.com/git-lfs/gitobj/v2/storage/multi_storage.go index aa7a2d3e..2d486523 100644 --- a/vendor/github.com/git-lfs/gitobj/storage/multi_storage.go +++ b/vendor/github.com/git-lfs/gitobj/v2/storage/multi_storage.go @@ -3,7 +3,7 @@ package storage import ( "io" - "github.com/git-lfs/gitobj/errors" + "github.com/git-lfs/gitobj/v2/errors" ) // Storage implements an interface for reading, but not writing, objects in an diff --git a/vendor/github.com/git-lfs/gitobj/storage/storage.go b/vendor/github.com/git-lfs/gitobj/v2/storage/storage.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/storage/storage.go rename to vendor/github.com/git-lfs/gitobj/v2/storage/storage.go diff --git a/vendor/github.com/git-lfs/gitobj/storer.go b/vendor/github.com/git-lfs/gitobj/v2/storer.go similarity index 100% rename from vendor/github.com/git-lfs/gitobj/storer.go rename to vendor/github.com/git-lfs/gitobj/v2/storer.go diff --git a/vendor/github.com/git-lfs/gitobj/tag.go b/vendor/github.com/git-lfs/gitobj/v2/tag.go similarity index 96% rename from vendor/github.com/git-lfs/gitobj/tag.go rename to vendor/github.com/git-lfs/gitobj/v2/tag.go index 65f17fb7..f82b6910 100644 --- a/vendor/github.com/git-lfs/gitobj/tag.go +++ b/vendor/github.com/git-lfs/gitobj/v2/tag.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/hex" "fmt" + "hash" "io" "strings" ) @@ -24,7 +25,7 @@ type Tag struct { // // If any error was encountered along the way it will be returned, and the // receiving *Tag is considered invalid. -func (t *Tag) Decode(r io.Reader, size int64) (int, error) { +func (t *Tag) Decode(hash hash.Hash, r io.Reader, size int64) (int, error) { scanner := bufio.NewScanner(io.LimitReader(r, size)) var ( diff --git a/vendor/github.com/git-lfs/gitobj/tree.go b/vendor/github.com/git-lfs/gitobj/v2/tree.go similarity index 96% rename from vendor/github.com/git-lfs/gitobj/tree.go rename to vendor/github.com/git-lfs/gitobj/v2/tree.go index 6ebcf123..070b1764 100644 --- a/vendor/github.com/git-lfs/gitobj/tree.go +++ b/vendor/github.com/git-lfs/gitobj/v2/tree.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "fmt" + "hash" "io" "sort" "strconv" @@ -27,7 +28,8 @@ func (t *Tree) Type() ObjectType { return TreeObjectType } // // If any error was encountered along the way, that will be returned, along with // the number of bytes read up to that point. -func (t *Tree) Decode(from io.Reader, size int64) (n int, err error) { +func (t *Tree) Decode(hash hash.Hash, from io.Reader, size int64) (n int, err error) { + hashlen := hash.Size() buf := bufio.NewReader(from) var entries []*TreeEntry @@ -51,15 +53,15 @@ func (t *Tree) Decode(from io.Reader, size int64) (n int, err error) { n += len(fname) fname = strings.TrimSuffix(fname, "\x00") - var sha [20]byte - if _, err = io.ReadFull(buf, sha[:]); err != nil { + var sha [32]byte + if _, err = io.ReadFull(buf, sha[:hashlen]); err != nil { return n, err } - n += 20 + n += hashlen entries = append(entries, &TreeEntry{ Name: fname, - Oid: sha[:], + Oid: sha[:hashlen], Filemode: int32(mode), }) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 902feac4..6da18183 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -8,11 +8,11 @@ github.com/avast/retry-go github.com/davecgh/go-spew/spew # github.com/dpotapov/go-spnego v0.0.0-20190506202455-c2c609116ad0 github.com/dpotapov/go-spnego -# github.com/git-lfs/gitobj v1.4.1 -github.com/git-lfs/gitobj -github.com/git-lfs/gitobj/errors -github.com/git-lfs/gitobj/pack -github.com/git-lfs/gitobj/storage +# github.com/git-lfs/gitobj/v2 v2.0.0 +github.com/git-lfs/gitobj/v2 +github.com/git-lfs/gitobj/v2/errors +github.com/git-lfs/gitobj/v2/pack +github.com/git-lfs/gitobj/v2/storage # github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18 github.com/git-lfs/go-netrc/netrc # github.com/git-lfs/go-ntlm v0.0.0-20190401175752-c5056e7fa066