aboutsummaryrefslogtreecommitdiffstats
path: root/examples/storage
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-01-30 16:24:07 +0100
committerGitHub <noreply@github.com>2017-01-30 16:24:07 +0100
commita24e40af0aa2d9d512051269993a1b08c0496d12 (patch)
tree65936a6a365263c93e4b57c3b67aad6a13489e68 /examples/storage
parenta48bc6e17ef6298f93ec21cdf1a5e387640673b6 (diff)
parent35378e7db9288e8244f2634a1b47981606731cef (diff)
downloadgo-git-a24e40af0aa2d9d512051269993a1b08c0496d12.tar.gz
Merge pull request #229 from mcuadros/worktree
Worktree and new Repository Contructors
Diffstat (limited to 'examples/storage')
-rw-r--r--examples/storage/aerospike/storage.go41
-rw-r--r--examples/storage/main.go21
2 files changed, 51 insertions, 11 deletions
diff --git a/examples/storage/aerospike/storage.go b/examples/storage/aerospike/storage.go
index 3ce5f5b..712c329 100644
--- a/examples/storage/aerospike/storage.go
+++ b/examples/storage/aerospike/storage.go
@@ -8,6 +8,7 @@ import (
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/format/index"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
driver "github.com/aerospike/aerospike-client-go"
@@ -248,6 +249,44 @@ func (s *Storage) buildConfigKey() (*driver.Key, error) {
return driver.NewKey(s.ns, configSet, fmt.Sprintf("%s|config", s.url))
}
+func (s *Storage) Index() (*index.Index, error) {
+ key, err := s.buildIndexKey()
+ if err != nil {
+ return nil, err
+ }
+
+ rec, err := s.client.Get(nil, key)
+ if err != nil {
+ return nil, err
+ }
+
+ idx := &index.Index{}
+ return idx, json.Unmarshal(rec.Bins["blob"].([]byte), idx)
+}
+
+func (s *Storage) SetIndex(idx *index.Index) error {
+ key, err := s.buildIndexKey()
+ if err != nil {
+ return err
+ }
+
+ json, err := json.Marshal(idx)
+ if err != nil {
+ return err
+ }
+
+ bins := driver.BinMap{
+ urlField: s.url,
+ "blob": json,
+ }
+
+ return s.client.Put(nil, key, bins)
+}
+
+func (s *Storage) buildIndexKey() (*driver.Key, error) {
+ return driver.NewKey(s.ns, configSet, fmt.Sprintf("%s|index", s.url))
+}
+
func (s *Storage) Shallow() ([]plumbing.Hash, error) {
key, err := s.buildShallowKey()
if err != nil {
@@ -283,7 +322,7 @@ func (s *Storage) SetShallow(hash []plumbing.Hash) error {
}
func (s *Storage) buildShallowKey() (*driver.Key, error) {
- return driver.NewKey(s.ns, configSet, fmt.Sprintf("%s|config", s.url))
+ return driver.NewKey(s.ns, configSet, fmt.Sprintf("%s|shallow", s.url))
}
func createIndexes(c *driver.Client, ns string) error {
diff --git a/examples/storage/main.go b/examples/storage/main.go
index b047e43..05752a1 100644
--- a/examples/storage/main.go
+++ b/examples/storage/main.go
@@ -26,30 +26,31 @@ func main() {
s, err := aerospike.NewStorage(client, "test", url)
CheckIfError(err)
- // A new repository instance using as storage the custom implementation
- r, err := git.NewRepository(s)
- CheckIfError(err)
-
switch action {
case "clone":
- clone(r, url)
+ clone(s, url)
case "log":
- log(r)
+ log(s)
default:
panic("unknown option")
}
}
-func clone(r *git.Repository, url string) {
+func clone(s git.Storer, url string) {
// Clone the given repository, all the objects, references and
- // configuration sush as remotes, are save into the Aerospike database.
+ // configuration sush as remotes, are save into the Aerospike database
+ // using the custom storer
Info("git clone %s", url)
- err := r.Clone(&git.CloneOptions{URL: url})
+ _, err := git.Clone(s, nil, &git.CloneOptions{URL: url})
CheckIfError(err)
}
-func log(r *git.Repository) {
+func log(s git.Storer) {
+ // We open the repository using as storer the custom implementation
+ r, err := git.Open(s, nil)
+ CheckIfError(err)
+
// Prints the history of the repository starting in the current HEAD, the
// objects are retrieved from Aerospike database.
Info("git log --oneline")