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

Commit 1eb3939

Browse files
Serabemcuadros
authored andcommitted
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
1 parent c9353b2 commit 1eb3939

File tree

18 files changed

+46
-1183
lines changed

18 files changed

+46
-1183
lines changed

fixtures/fixtures.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"os"
88
"path/filepath"
99

10-
"github.com/alcortesm/tgz"
11-
1210
"gopkg.in/check.v1"
1311
"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"
12+
13+
"github.com/alcortesm/tgz"
14+
"srcd.works/go-billy.v1"
15+
osfs "srcd.works/go-billy.v1/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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ 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-
fs "gopkg.in/src-d/go-git.v4/utils/fs/memory"
13+
14+
fs "srcd.works/go-billy.v1/memory"
1415

1516
. "gopkg.in/check.v1"
1617
)

remote_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ 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-
osfs "gopkg.in/src-d/go-git.v4/utils/fs/os"
14+
15+
osfs "srcd.works/go-billy.v1/os"
1516

1617
. "gopkg.in/check.v1"
1718
)

repository.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ 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-
osfs "gopkg.in/src-d/go-git.v4/utils/fs/os"
14+
15+
osfs "srcd.works/go-billy.v1/os"
1516
)
1617

1718
var (

storage/filesystem/config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ 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+
10+
"srcd.works/go-billy.v1/os"
1011

1112
. "gopkg.in/check.v1"
1213
)

storage/filesystem/internal/dotgit/dotgit.go

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

1212
"gopkg.in/src-d/go-git.v4/plumbing"
13-
"gopkg.in/src-d/go-git.v4/utils/fs"
13+
14+
"srcd.works/go-billy.v1"
1415
)
1516

1617
const (
@@ -51,33 +52,33 @@ var (
5152
// The DotGit type represents a local git repository on disk. This
5253
// type is not zero-value-safe, use the New function to initialize it.
5354
type DotGit struct {
54-
fs fs.Filesystem
55+
fs billy.Filesystem
5556
}
5657

5758
// New returns a DotGit value ready to be used. The path argument must
5859
// be the absolute path of a git repository directory (e.g.
5960
// "/foo/bar/.git").
60-
func New(fs fs.Filesystem) *DotGit {
61+
func New(fs billy.Filesystem) *DotGit {
6162
return &DotGit{fs: fs}
6263
}
6364

6465
// ConfigWriter returns a file pointer for write to the config file
65-
func (d *DotGit) ConfigWriter() (fs.File, error) {
66+
func (d *DotGit) ConfigWriter() (billy.File, error) {
6667
return d.fs.Create(configPath)
6768
}
6869

6970
// Config returns a file pointer for read to the config file
70-
func (d *DotGit) Config() (fs.File, error) {
71+
func (d *DotGit) Config() (billy.File, error) {
7172
return d.fs.Open(configPath)
7273
}
7374

7475
// ShallowWriter returns a file pointer for write to the shallow file
75-
func (d *DotGit) ShallowWriter() (fs.File, error) {
76+
func (d *DotGit) ShallowWriter() (billy.File, error) {
7677
return d.fs.Create(shallowPath)
7778
}
7879

7980
// Shallow returns a file pointer for read to the shallow file
80-
func (d *DotGit) Shallow() (fs.File, error) {
81+
func (d *DotGit) Shallow() (billy.File, error) {
8182
f, err := d.fs.Open(shallowPath)
8283
if err != nil {
8384
if os.IsNotExist(err) {
@@ -124,7 +125,7 @@ func (d *DotGit) ObjectPacks() ([]plumbing.Hash, error) {
124125
}
125126

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

130131
pack, err := d.fs.Open(file)
@@ -140,7 +141,7 @@ func (d *DotGit) ObjectPack(hash plumbing.Hash) (fs.File, error) {
140141
}
141142

142143
// ObjectPackIdx returns a fs.File of the index file for a given packfile
143-
func (d *DotGit) ObjectPackIdx(hash plumbing.Hash) (fs.File, error) {
144+
func (d *DotGit) ObjectPackIdx(hash plumbing.Hash) (billy.File, error) {
144145
file := d.fs.Join(objectsPath, packPath, fmt.Sprintf("pack-%s.idx", hash.String()))
145146
idx, err := d.fs.Open(file)
146147
if err != nil {
@@ -190,7 +191,7 @@ func (d *DotGit) Objects() ([]plumbing.Hash, error) {
190191
}
191192

192193
// Object return a fs.File poiting the object file, if exists
193-
func (d *DotGit) Object(h plumbing.Hash) (fs.File, error) {
194+
func (d *DotGit) Object(h plumbing.Hash) (billy.File, error) {
194195
hash := h.String()
195196
file := d.fs.Join(objectsPath, hash[0:2], hash[2:40])
196197

storage/filesystem/internal/dotgit/dotgit_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ 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+
13+
osfs "srcd.works/go-billy.v1/os"
1314

1415
. "gopkg.in/check.v1"
1516
)

storage/filesystem/internal/dotgit/writers.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ 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+
13+
"srcd.works/go-billy.v1"
1314
)
1415

1516
// PackWriter is a io.Writer that generates the packfile index simultaneously,
@@ -21,15 +22,15 @@ import (
2122
type PackWriter struct {
2223
Notify func(h plumbing.Hash, i idxfile.Idxfile)
2324

24-
fs fs.Filesystem
25-
fr, fw fs.File
25+
fs billy.Filesystem
26+
fr, fw billy.File
2627
synced *syncedReader
2728
checksum plumbing.Hash
2829
index idxfile.Idxfile
2930
result chan error
3031
}
3132

32-
func newPackWrite(fs fs.Filesystem) (*PackWriter, error) {
33+
func newPackWrite(fs billy.Filesystem) (*PackWriter, error) {
3334
fw, err := fs.TempFile(fs.Join(objectsPath, packPath), "tmp_pack_")
3435
if err != nil {
3536
return nil, err
@@ -248,11 +249,11 @@ func (s *syncedReader) Close() error {
248249

249250
type ObjectWriter struct {
250251
objfile.Writer
251-
fs fs.Filesystem
252-
f fs.File
252+
fs billy.Filesystem
253+
f billy.File
253254
}
254255

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

storage/filesystem/internal/dotgit/writers_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ 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+
13+
osfs "srcd.works/go-billy.v1/os"
1314

1415
. "gopkg.in/check.v1"
1516
)

storage/filesystem/object.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ 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+
15+
"srcd.works/go-billy.v1"
1516
)
1617

1718
type ObjectStorage struct {
@@ -261,7 +262,7 @@ func (i index) Decode(r io.Reader) error {
261262
}
262263

263264
type packfileIter struct {
264-
f fs.File
265+
f billy.File
265266
d *packfile.Decoder
266267
t plumbing.ObjectType
267268

@@ -270,7 +271,7 @@ type packfileIter struct {
270271
total uint32
271272
}
272273

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

0 commit comments

Comments
 (0)