This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -27,8 +27,10 @@ func NewMemoryRepository() (*Repository, error) {
27
27
}
28
28
29
29
// 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 )
32
34
if err != nil {
33
35
return nil , err
34
36
}
You can’t perform that action at this time.
0 commit comments