diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-15 23:33:47 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-15 23:33:47 +0200 |
commit | f7ec0637a509b063831d0f57e13840aff9a6d748 (patch) | |
tree | 66244f62a8b44b4be5930989467bd6f6c62c9a0a | |
parent | 6b9a59be60de5b66aee14e9160ace80734008eca (diff) | |
download | go-git-f7ec0637a509b063831d0f57e13840aff9a6d748.tar.gz |
NewFilesystemRepository and example
-rw-r--r-- | examples/open/main.go | 40 | ||||
-rw-r--r-- | repository.go | 6 |
2 files changed, 44 insertions, 2 deletions
diff --git a/examples/open/main.go b/examples/open/main.go new file mode 100644 index 0000000..fa11844 --- /dev/null +++ b/examples/open/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + + "gopkg.in/src-d/go-git.v4" +) + +func main() { + path, _ := filepath.Abs(os.Args[1]) + fmt.Printf("Opening repository %q ...\n", path) + + r, err := git.NewFilesystemRepository(path) + if err != nil { + panic(err) + } + + iter, err := r.Commits() + if err != nil { + panic(err) + } + + defer iter.Close() + + var count = 0 + err = iter.ForEach(func(commit *git.Commit) error { + count++ + fmt.Println(commit) + + return nil + }) + + if err != nil { + panic(err) + } + + fmt.Println("total commits:", count) +} diff --git a/repository.go b/repository.go index 170a1b4..676c7b8 100644 --- a/repository.go +++ b/repository.go @@ -27,8 +27,10 @@ func NewMemoryRepository() (*Repository, error) { } // NewFilesystemRepository creates a new repository, backed by a filesystem.Storage -func NewFilesystemRepository(fs fs.FS, path string) (*Repository, error) { - s, err := filesystem.NewStorage(fs, path) +// based on a fs.OS, if you want to use a custom one you need to use the function +// NewRepository and build you filesystem.Storage +func NewFilesystemRepository(path string) (*Repository, error) { + s, err := filesystem.NewStorage(fs.NewOS(), path) if err != nil { return nil, err } |