Skip to content

Commit 90055a4

Browse files
authored
Merge pull request #466 from jfontan/improvement/use-storer-options-partitions
Improvement/use storer options partitions
2 parents 0082a18 + 429c946 commit 90055a4

28 files changed

+661
-39
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[[constraint]]
1818
name = "gopkg.in/src-d/go-git.v4"
1919
source = "github.com/src-d/go-git"
20-
revision = "5cc316baa64287c7e56cb7372a5046c30fd955c1"
20+
revision = "d3cec13ac0b195bfb897ed038a08b5130ab9969e"
2121

2222
[[constraint]]
2323
name = "gopkg.in/src-d/go-git-fixtures.v3"

blobs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ func (i *blobRowIter) Close() error {
239239
i.iter.Close()
240240
}
241241

242+
i.repo.Close()
243+
242244
return nil
243245
}
244246

commit_blobs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,7 @@ func (i *commitBlobsRowIter) Close() error {
314314
return i.index.Close()
315315
}
316316

317+
i.repo.Close()
318+
317319
return nil
318320
}

commit_trees.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,7 @@ func (i *commitTreesRowIter) Close() error {
326326
return i.index.Close()
327327
}
328328

329+
i.repo.Close()
330+
329331
return nil
330332
}

commits.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ func (i *commitIter) Close() error {
193193
i.iter.Close()
194194
}
195195

196+
i.repo.Close()
197+
196198
return nil
197199
}
198200

files.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ func (i *filesRowIter) Close() error {
282282
i.commits.Close()
283283
}
284284

285+
i.repo.Close()
286+
285287
return nil
286288
}
287289

ref_commits.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
263263
if i.refs == nil {
264264
i.refs, err = i.repo.References()
265265
if err != nil {
266+
i.repo.Close()
267+
266268
if i.skipGitErrors {
267269
return nil, io.EOF
268270
}
@@ -275,6 +277,8 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
275277
if i.skipGitErrors {
276278
continue
277279
}
280+
281+
i.repo.Close()
278282
return nil, err
279283
}
280284
}
@@ -286,13 +290,15 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
286290
ref, err = i.refs.Next()
287291
if err != nil {
288292
if err == io.EOF {
293+
i.repo.Close()
289294
return nil, io.EOF
290295
}
291296

292297
if i.skipGitErrors {
293298
continue
294299
}
295300

301+
i.repo.Close()
296302
return nil, err
297303
}
298304

@@ -315,6 +321,7 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
315321
continue
316322
}
317323

324+
i.repo.Close()
318325
return nil, err
319326
}
320327

@@ -332,6 +339,7 @@ func (i *refCommitsRowIter) next() (sql.Row, error) {
332339
continue
333340
}
334341

342+
i.repo.Close()
335343
return nil, err
336344
}
337345

@@ -353,6 +361,8 @@ func (i *refCommitsRowIter) Close() error {
353361
return i.index.Close()
354362
}
355363

364+
i.repo.Close()
365+
356366
return nil
357367
}
358368

@@ -387,6 +397,7 @@ type stackFrame struct {
387397
func (i *indexedCommitIter) Next() (*object.Commit, int, error) {
388398
for {
389399
if len(i.stack) == 0 {
400+
i.repo.Close()
390401
return nil, -1, io.EOF
391402
}
392403

@@ -408,6 +419,7 @@ func (i *indexedCommitIter) Next() (*object.Commit, int, error) {
408419
continue
409420
}
410421

422+
i.repo.Close()
411423
return nil, -1, err
412424
}
413425

repository_pool.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,47 @@ func NewRepository(id string, repo *git.Repository) *Repository {
3535
}
3636
}
3737

38+
// Close closes all opened files in the repository.
39+
func (r *Repository) Close() {
40+
if r != nil && r.Repository != nil {
41+
f, ok := r.Storer.(*filesystem.Storage)
42+
if ok {
43+
// The only type of error returned is "file already closed" and
44+
// we don't want to do anything with it.
45+
f.Close()
46+
}
47+
}
48+
}
49+
3850
// NewRepositoryFromPath creates and initializes a new Repository structure
3951
// and initializes a go-git repository
4052
func NewRepositoryFromPath(id, path string) (*Repository, error) {
41-
repo, err := git.PlainOpen(path)
53+
op := filesystem.Options{
54+
ExclusiveAccess: true,
55+
KeepDescriptors: true,
56+
}
57+
58+
var wt billy.Filesystem
59+
fs := osfs.New(path)
60+
f, err := fs.Stat(git.GitDirName)
61+
if err != nil && !os.IsNotExist(err) {
62+
return nil, err
63+
}
64+
65+
if f != nil && f.IsDir() {
66+
wt = fs
67+
fs, err = fs.Chroot(git.GitDirName)
68+
if err != nil {
69+
return nil, err
70+
}
71+
}
72+
73+
sto, err := filesystem.NewStorageWithOptions(fs, op)
74+
if err != nil {
75+
return nil, err
76+
}
77+
78+
repo, err := git.Open(sto, wt)
4279
if err != nil {
4380
return nil, err
4481
}
@@ -63,7 +100,12 @@ func NewSivaRepositoryFromPath(id, path string) (*Repository, error) {
63100
return nil, err
64101
}
65102

66-
sto, err := filesystem.NewStorage(fs)
103+
op := filesystem.Options{
104+
ExclusiveAccess: true,
105+
KeepDescriptors: true,
106+
}
107+
108+
sto, err := filesystem.NewStorageWithOptions(fs, op)
67109
if err != nil {
68110
return nil, err
69111
}

squash.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,12 @@ func (i *squashRowIter) Next() (sql.Row, error) {
213213
row, err := i.iter.Next()
214214
if err != nil {
215215
if err == io.EOF {
216+
i.iter.Close()
216217
i.iter = nil
217218
continue
218219
}
219220

221+
i.iter.Close()
220222
return nil, err
221223
}
222224

0 commit comments

Comments
 (0)