aboutsummaryrefslogtreecommitdiffstats
path: root/examples/object_storage/main.go
blob: 5cba6e6977d063d2ebe2909f878493979e5a55ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main

import (
	"fmt"
	"io"
	"os"
	"time"

	"github.com/aerospike/aerospike-client-go"

	"gopkg.in/src-d/go-git.v3"
)

func main() {
	url := os.Args[2]
	r, err := git.NewRepository(url, nil)
	if err != nil {
		panic(err)
	}

	client, err := aerospike.NewClient("127.0.0.1", 3000)
	if err != nil {
		panic(err)
	}

	r.Storage = NewAerospikeObjectStorage(url, client)

	switch os.Args[1] {
	case "pull":
		pull(r)
	case "list":
		list(r)
	default:
		panic("unknown option")
	}
}

func pull(r *git.Repository) {
	fmt.Printf("Retrieving %q ...\n", os.Args[2])
	start := time.Now()

	if err := r.PullDefault(); err != nil {
		panic(err)
	}

	fmt.Printf("Time elapsed %s\n", time.Since(start))
}

func list(r *git.Repository) {
	fmt.Printf("Listing commits from %q ...\n", os.Args[1])

	iter, err := r.Commits()
	if err != nil {
		panic(err)
	}
	defer iter.Close()

	var count int
	for {
		//the commits are not shorted in any special order
		commit, err := iter.Next()
		if err != nil {
			if err == io.EOF {
				break
			}

			panic(err)
		}

		count++
		fmt.Println(commit)
	}

	fmt.Printf("Total number of commits %d\n", count)
}