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

Commit 890a0e3

Browse files
committed
NewFilesystemRepository and example
1 parent f1a93f9 commit 890a0e3

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

examples/open/main.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
8+
"gopkg.in/src-d/go-git.v4"
9+
)
10+
11+
func main() {
12+
path, _ := filepath.Abs(os.Args[1])
13+
fmt.Printf("Opening repository %q ...\n", path)
14+
15+
r, err := git.NewFilesystemRepository(path)
16+
if err != nil {
17+
panic(err)
18+
}
19+
20+
iter, err := r.Commits()
21+
if err != nil {
22+
panic(err)
23+
}
24+
25+
defer iter.Close()
26+
27+
var count = 0
28+
err = iter.ForEach(func(commit *git.Commit) error {
29+
count++
30+
fmt.Println(commit)
31+
32+
return nil
33+
})
34+
35+
if err != nil {
36+
panic(err)
37+
}
38+
39+
fmt.Println("total commits:", count)
40+
}

repository.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ func NewMemoryRepository() (*Repository, error) {
2727
}
2828

2929
// NewFilesystemRepository creates a new repository, backed by a filesystem.Storage
30-
func NewFilesystemRepository(fs fs.FS, path string) (*Repository, error) {
31-
s, err := filesystem.NewStorage(fs, path)
30+
// based on a fs.OS, if you want to use a custom one you need to use the function
31+
// NewRepository and build you filesystem.Storage
32+
func NewFilesystemRepository(path string) (*Repository, error) {
33+
s, err := filesystem.NewStorage(fs.NewOS(), path)
3234
if err != nil {
3335
return nil, err
3436
}

0 commit comments

Comments
 (0)