From 1eb39394cdf09b26eb2f5c98225fb2912980e61f Mon Sep 17 00:00:00 2001 From: Sergio Arbeo Date: Mon, 19 Dec 2016 10:42:14 +0100 Subject: Extract billy (#173) * Extract billy Billy is a new library directly extracted from go-git. It abstract several storages systems in a filesystem interface. More in github.com/src-d/billy * Fix grouping in imports block * Update billy to v1 * Re-remove fs_implementation example --- storage/filesystem/internal/dotgit/dotgit.go | 21 +++++++++++---------- storage/filesystem/internal/dotgit/dotgit_test.go | 3 ++- storage/filesystem/internal/dotgit/writers.go | 15 ++++++++------- storage/filesystem/internal/dotgit/writers_test.go | 3 ++- 4 files changed, 23 insertions(+), 19 deletions(-) (limited to 'storage/filesystem/internal/dotgit') diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go index 3405908..f9763d1 100644 --- a/storage/filesystem/internal/dotgit/dotgit.go +++ b/storage/filesystem/internal/dotgit/dotgit.go @@ -10,7 +10,8 @@ import ( "strings" "gopkg.in/src-d/go-git.v4/plumbing" - "gopkg.in/src-d/go-git.v4/utils/fs" + + "srcd.works/go-billy.v1" ) const ( @@ -51,33 +52,33 @@ var ( // The DotGit type represents a local git repository on disk. This // type is not zero-value-safe, use the New function to initialize it. type DotGit struct { - fs fs.Filesystem + fs billy.Filesystem } // New returns a DotGit value ready to be used. The path argument must // be the absolute path of a git repository directory (e.g. // "/foo/bar/.git"). -func New(fs fs.Filesystem) *DotGit { +func New(fs billy.Filesystem) *DotGit { return &DotGit{fs: fs} } // ConfigWriter returns a file pointer for write to the config file -func (d *DotGit) ConfigWriter() (fs.File, error) { +func (d *DotGit) ConfigWriter() (billy.File, error) { return d.fs.Create(configPath) } // Config returns a file pointer for read to the config file -func (d *DotGit) Config() (fs.File, error) { +func (d *DotGit) Config() (billy.File, error) { return d.fs.Open(configPath) } // ShallowWriter returns a file pointer for write to the shallow file -func (d *DotGit) ShallowWriter() (fs.File, error) { +func (d *DotGit) ShallowWriter() (billy.File, error) { return d.fs.Create(shallowPath) } // Shallow returns a file pointer for read to the shallow file -func (d *DotGit) Shallow() (fs.File, error) { +func (d *DotGit) Shallow() (billy.File, error) { f, err := d.fs.Open(shallowPath) if err != nil { if os.IsNotExist(err) { @@ -124,7 +125,7 @@ func (d *DotGit) ObjectPacks() ([]plumbing.Hash, error) { } // ObjectPack returns a fs.File of the given packfile -func (d *DotGit) ObjectPack(hash plumbing.Hash) (fs.File, error) { +func (d *DotGit) ObjectPack(hash plumbing.Hash) (billy.File, error) { file := d.fs.Join(objectsPath, packPath, fmt.Sprintf("pack-%s.pack", hash.String())) pack, err := d.fs.Open(file) @@ -140,7 +141,7 @@ func (d *DotGit) ObjectPack(hash plumbing.Hash) (fs.File, error) { } // ObjectPackIdx returns a fs.File of the index file for a given packfile -func (d *DotGit) ObjectPackIdx(hash plumbing.Hash) (fs.File, error) { +func (d *DotGit) ObjectPackIdx(hash plumbing.Hash) (billy.File, error) { file := d.fs.Join(objectsPath, packPath, fmt.Sprintf("pack-%s.idx", hash.String())) idx, err := d.fs.Open(file) if err != nil { @@ -190,7 +191,7 @@ func (d *DotGit) Objects() ([]plumbing.Hash, error) { } // Object return a fs.File poiting the object file, if exists -func (d *DotGit) Object(h plumbing.Hash) (fs.File, error) { +func (d *DotGit) Object(h plumbing.Hash) (billy.File, error) { hash := h.String() file := d.fs.Join(objectsPath, hash[0:2], hash[2:40]) diff --git a/storage/filesystem/internal/dotgit/dotgit_test.go b/storage/filesystem/internal/dotgit/dotgit_test.go index b645a85..48f02f0 100644 --- a/storage/filesystem/internal/dotgit/dotgit_test.go +++ b/storage/filesystem/internal/dotgit/dotgit_test.go @@ -9,7 +9,8 @@ import ( "gopkg.in/src-d/go-git.v4/fixtures" "gopkg.in/src-d/go-git.v4/plumbing" - osfs "gopkg.in/src-d/go-git.v4/utils/fs/os" + + osfs "srcd.works/go-billy.v1/os" . "gopkg.in/check.v1" ) diff --git a/storage/filesystem/internal/dotgit/writers.go b/storage/filesystem/internal/dotgit/writers.go index 8e22a39..1cd893d 100644 --- a/storage/filesystem/internal/dotgit/writers.go +++ b/storage/filesystem/internal/dotgit/writers.go @@ -9,7 +9,8 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing/format/idxfile" "gopkg.in/src-d/go-git.v4/plumbing/format/objfile" "gopkg.in/src-d/go-git.v4/plumbing/format/packfile" - "gopkg.in/src-d/go-git.v4/utils/fs" + + "srcd.works/go-billy.v1" ) // PackWriter is a io.Writer that generates the packfile index simultaneously, @@ -21,15 +22,15 @@ import ( type PackWriter struct { Notify func(h plumbing.Hash, i idxfile.Idxfile) - fs fs.Filesystem - fr, fw fs.File + fs billy.Filesystem + fr, fw billy.File synced *syncedReader checksum plumbing.Hash index idxfile.Idxfile result chan error } -func newPackWrite(fs fs.Filesystem) (*PackWriter, error) { +func newPackWrite(fs billy.Filesystem) (*PackWriter, error) { fw, err := fs.TempFile(fs.Join(objectsPath, packPath), "tmp_pack_") if err != nil { return nil, err @@ -248,11 +249,11 @@ func (s *syncedReader) Close() error { type ObjectWriter struct { objfile.Writer - fs fs.Filesystem - f fs.File + fs billy.Filesystem + f billy.File } -func newObjectWriter(fs fs.Filesystem) (*ObjectWriter, error) { +func newObjectWriter(fs billy.Filesystem) (*ObjectWriter, error) { f, err := fs.TempFile(fs.Join(objectsPath, packPath), "tmp_obj_") if err != nil { return nil, err diff --git a/storage/filesystem/internal/dotgit/writers_test.go b/storage/filesystem/internal/dotgit/writers_test.go index c66613a..c546a3a 100644 --- a/storage/filesystem/internal/dotgit/writers_test.go +++ b/storage/filesystem/internal/dotgit/writers_test.go @@ -9,7 +9,8 @@ import ( "strconv" "gopkg.in/src-d/go-git.v4/fixtures" - osfs "gopkg.in/src-d/go-git.v4/utils/fs/os" + + osfs "srcd.works/go-billy.v1/os" . "gopkg.in/check.v1" ) -- cgit