Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 5268cca

Browse files
committed
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
1 parent cb30e88 commit 5268cca

File tree

20 files changed

+34
-1182
lines changed

20 files changed

+34
-1182
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ import (
134134
"io"
135135

136136
"gopkg.in/src-d/go-git.v4"
137-
"gopkg.in/src-d/go-git.v4/utils/fs"
137+
"srcd.works/go-billy.v0/os"
138138
)
139139

140140
func main() {
141-
fs := fs.NewOS() // a simple proxy for the local host filesystem
141+
fs := os.NewOS() // a simple proxy for the local host filesystem
142142
path := "/tmp/go-git/.git"
143143

144144
repo, err := git.NewRepositoryFromFS(fs, path)

examples/fs_implementation/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
1818
"gopkg.in/src-d/go-git.v4"
1919
"gopkg.in/src-d/go-git.v4/storage/filesystem"
20-
"gopkg.in/src-d/go-git.v4/utils/fs"
20+
"srcd.works/go-billy.v0"
2121
)
2222
2323
func main() {

fixtures/fixtures.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
"gopkg.in/check.v1"
1313
"gopkg.in/src-d/go-git.v4/plumbing"
14-
"gopkg.in/src-d/go-git.v4/utils/fs"
15-
osfs "gopkg.in/src-d/go-git.v4/utils/fs/os"
14+
"srcd.works/go-billy.v0"
15+
osfs "srcd.works/go-billy.v0/os"
1616
)
1717

1818
var RootFolder = ""
@@ -182,7 +182,7 @@ func (f *Fixture) Idx() *os.File {
182182

183183
// DotGit creates a new temporary directory and unpacks the repository .git
184184
// directory into it. Multiple calls to DotGit returns different directories.
185-
func (f *Fixture) DotGit() fs.Filesystem {
185+
func (f *Fixture) DotGit() billy.Filesystem {
186186
fn := filepath.Join(RootFolder, DataFolder, fmt.Sprintf("git-%s.tgz", f.DotGitHash))
187187
path, err := tgz.Extract(fn)
188188
if err != nil {
@@ -193,7 +193,7 @@ func (f *Fixture) DotGit() fs.Filesystem {
193193
return osfs.New(path)
194194
}
195195

196-
func (f *Fixture) Worktree() fs.Filesystem {
196+
func (f *Fixture) Worktree() billy.Filesystem {
197197
fn := filepath.Join(RootFolder, DataFolder, fmt.Sprintf("git-%s.tgz", f.DotGitHash))
198198
git, err := tgz.Extract(fn)
199199
if err != nil {

plumbing/format/packfile/decoder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"gopkg.in/src-d/go-git.v4/plumbing/storer"
1212
"gopkg.in/src-d/go-git.v4/storage/filesystem"
1313
"gopkg.in/src-d/go-git.v4/storage/memory"
14-
fs "gopkg.in/src-d/go-git.v4/utils/fs/memory"
14+
fs "srcd.works/go-billy.v0/memory"
1515

1616
. "gopkg.in/check.v1"
1717
)

remote_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
githttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
1919
"gopkg.in/src-d/go-git.v4/storage/filesystem"
2020
"gopkg.in/src-d/go-git.v4/storage/memory"
21-
osfs "gopkg.in/src-d/go-git.v4/utils/fs/os"
21+
osfs "srcd.works/go-billy.v0/os"
2222

2323
. "gopkg.in/check.v1"
2424
)

repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"gopkg.in/src-d/go-git.v4/plumbing/storer"
1111
"gopkg.in/src-d/go-git.v4/storage/filesystem"
1212
"gopkg.in/src-d/go-git.v4/storage/memory"
13-
osfs "gopkg.in/src-d/go-git.v4/utils/fs/os"
13+
osfs "srcd.works/go-billy.v0/os"
1414
)
1515

1616
var (

storage/filesystem/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"gopkg.in/src-d/go-git.v4/fixtures"
88
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
9-
"gopkg.in/src-d/go-git.v4/utils/fs/os"
9+
"srcd.works/go-billy.v0/os"
1010

1111
. "gopkg.in/check.v1"
1212
)

storage/filesystem/internal/dotgit/dotgit.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111

1212
"gopkg.in/src-d/go-git.v4/plumbing"
13-
"gopkg.in/src-d/go-git.v4/utils/fs"
13+
"srcd.works/go-billy.v0"
1414
)
1515

1616
const (
@@ -50,22 +50,22 @@ var (
5050
// The DotGit type represents a local git repository on disk. This
5151
// type is not zero-value-safe, use the New function to initialize it.
5252
type DotGit struct {
53-
fs fs.Filesystem
53+
fs billy.Filesystem
5454
}
5555

5656
// New returns a DotGit value ready to be used. The path argument must
5757
// be the absolute path of a git repository directory (e.g.
5858
// "/foo/bar/.git").
59-
func New(fs fs.Filesystem) *DotGit {
59+
func New(fs billy.Filesystem) *DotGit {
6060
return &DotGit{fs: fs}
6161
}
6262

63-
func (d *DotGit) ConfigWriter() (fs.File, error) {
63+
func (d *DotGit) ConfigWriter() (billy.File, error) {
6464
return d.fs.Create(configPath)
6565
}
6666

6767
// Config returns the path of the config file
68-
func (d *DotGit) Config() (fs.File, error) {
68+
func (d *DotGit) Config() (billy.File, error) {
6969
return d.fs.Open(configPath)
7070
}
7171

@@ -103,7 +103,7 @@ func (d *DotGit) ObjectPacks() ([]plumbing.Hash, error) {
103103
}
104104

105105
// ObjectPack returns a fs.File of the given packfile
106-
func (d *DotGit) ObjectPack(hash plumbing.Hash) (fs.File, error) {
106+
func (d *DotGit) ObjectPack(hash plumbing.Hash) (billy.File, error) {
107107
file := d.fs.Join(objectsPath, packPath, fmt.Sprintf("pack-%s.pack", hash.String()))
108108

109109
pack, err := d.fs.Open(file)
@@ -119,7 +119,7 @@ func (d *DotGit) ObjectPack(hash plumbing.Hash) (fs.File, error) {
119119
}
120120

121121
// ObjectPackIdx returns a fs.File of the index file for a given packfile
122-
func (d *DotGit) ObjectPackIdx(hash plumbing.Hash) (fs.File, error) {
122+
func (d *DotGit) ObjectPackIdx(hash plumbing.Hash) (billy.File, error) {
123123
file := d.fs.Join(objectsPath, packPath, fmt.Sprintf("pack-%s.idx", hash.String()))
124124
idx, err := d.fs.Open(file)
125125
if err != nil {
@@ -169,7 +169,7 @@ func (d *DotGit) Objects() ([]plumbing.Hash, error) {
169169
}
170170

171171
// Object return a fs.File poiting the object file, if exists
172-
func (d *DotGit) Object(h plumbing.Hash) (fs.File, error) {
172+
func (d *DotGit) Object(h plumbing.Hash) (billy.File, error) {
173173
hash := h.String()
174174
file := d.fs.Join(objectsPath, hash[0:2], hash[2:40])
175175

storage/filesystem/internal/dotgit/dotgit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"gopkg.in/src-d/go-git.v4/fixtures"
1111
"gopkg.in/src-d/go-git.v4/plumbing"
12-
osfs "gopkg.in/src-d/go-git.v4/utils/fs/os"
12+
osfs "srcd.works/go-billy.v0/os"
1313

1414
. "gopkg.in/check.v1"
1515
)

storage/filesystem/internal/dotgit/writers.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"gopkg.in/src-d/go-git.v4/plumbing/format/idxfile"
1010
"gopkg.in/src-d/go-git.v4/plumbing/format/objfile"
1111
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
12-
"gopkg.in/src-d/go-git.v4/utils/fs"
12+
"srcd.works/go-billy.v0"
1313
)
1414

1515
// PackWriter is a io.Writer that generates the packfile index simultaneously,
@@ -21,15 +21,15 @@ import (
2121
type PackWriter struct {
2222
Notify func(h plumbing.Hash, i idxfile.Idxfile)
2323

24-
fs fs.Filesystem
25-
fr, fw fs.File
24+
fs billy.Filesystem
25+
fr, fw billy.File
2626
synced *syncedReader
2727
checksum plumbing.Hash
2828
index idxfile.Idxfile
2929
result chan error
3030
}
3131

32-
func newPackWrite(fs fs.Filesystem) (*PackWriter, error) {
32+
func newPackWrite(fs billy.Filesystem) (*PackWriter, error) {
3333
fw, err := fs.TempFile(fs.Join(objectsPath, packPath), "tmp_pack_")
3434
if err != nil {
3535
return nil, err
@@ -248,11 +248,11 @@ func (s *syncedReader) Close() error {
248248

249249
type ObjectWriter struct {
250250
objfile.Writer
251-
fs fs.Filesystem
252-
f fs.File
251+
fs billy.Filesystem
252+
f billy.File
253253
}
254254

255-
func newObjectWriter(fs fs.Filesystem) (*ObjectWriter, error) {
255+
func newObjectWriter(fs billy.Filesystem) (*ObjectWriter, error) {
256256
f, err := fs.TempFile(fs.Join(objectsPath, packPath), "tmp_obj_")
257257
if err != nil {
258258
return nil, err

storage/filesystem/internal/dotgit/writers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strconv"
1010

1111
"gopkg.in/src-d/go-git.v4/fixtures"
12-
osfs "gopkg.in/src-d/go-git.v4/utils/fs/os"
12+
osfs "srcd.works/go-billy.v0/os"
1313

1414
. "gopkg.in/check.v1"
1515
)

storage/filesystem/object.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"gopkg.in/src-d/go-git.v4/plumbing/storer"
1212
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
1313
"gopkg.in/src-d/go-git.v4/storage/memory"
14-
"gopkg.in/src-d/go-git.v4/utils/fs"
14+
"srcd.works/go-billy.v0"
1515
)
1616

1717
type ObjectStorage struct {
@@ -261,7 +261,7 @@ func (i index) Decode(r io.Reader) error {
261261
}
262262

263263
type packfileIter struct {
264-
f fs.File
264+
f billy.File
265265
d *packfile.Decoder
266266
t plumbing.ObjectType
267267

@@ -270,7 +270,7 @@ type packfileIter struct {
270270
total uint32
271271
}
272272

273-
func newPackfileIter(f fs.File, t plumbing.ObjectType, seen map[plumbing.Hash]bool) (storer.ObjectIter, error) {
273+
func newPackfileIter(f billy.File, t plumbing.ObjectType, seen map[plumbing.Hash]bool) (storer.ObjectIter, error) {
274274
s := packfile.NewScanner(f)
275275
_, total, err := s.Header()
276276
if err != nil {

storage/filesystem/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package filesystem
33

44
import (
55
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
6-
"gopkg.in/src-d/go-git.v4/utils/fs"
6+
"srcd.works/go-billy.v0"
77
)
88

99
// Storage is an implementation of git.Storer that stores data on disk in the
@@ -16,7 +16,7 @@ type Storage struct {
1616
}
1717

1818
// NewStorage returns a new Storage backed by a given `fs.Filesystem`
19-
func NewStorage(fs fs.Filesystem) (*Storage, error) {
19+
func NewStorage(fs billy.Filesystem) (*Storage, error) {
2020
dir := dotgit.New(fs)
2121
o, err := newObjectStorage(dir)
2222
if err != nil {

storage/filesystem/storage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55

66
"gopkg.in/src-d/go-git.v4/storage/test"
7-
"gopkg.in/src-d/go-git.v4/utils/fs/os"
7+
"srcd.works/go-billy.v0/os"
88

99
. "gopkg.in/check.v1"
1010
)

utils/fs/fs.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)