Debian Codegraph @

_examples/storage/README.md

raw
1 # go-git + aerospike: a git repository backed by a database
2
3 <img src="https://upload.wikimedia.org/wikipedia/en/2/2b/Aerospike_logo.png" align="right"/> This is an example of a [go-git](https://github.com/src-d/go-git) repository backed by [Aerospike](http://www.aerospike.com/).
4
5
6
7
8 ### and what this means ...
9 *git* has a very well defined storage system, the `.git` directory, present on any repository. This is the place where `git` stores all the [`objects`](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects), [`references`](https://git-scm.com/book/es/v2/Git-Internals-Git-References) and [`configuration`](https://git-scm.com/docs/git-config#_configuration_file). This information is stored in plain files.
10
11 Our original **go-git** version was designed to work in memory, some time after we added support to read the `.git`, and now we have added support for fully customized [storages](https://godoc.org/gopkg.in/src-d/go-git.v4/storage#Storer).
12
13 This means that the internal database of any repository can be saved and accessed on any support, databases, distributed filesystems, etc. This functionality is pretty similar to the [libgit2 backends](http://blog.deveo.com/your-git-repository-in-a-database-pluggable-backends-in-libgit2/)
14
15
16 Installation
17 ------------
18
19 What do you need? You need an *aerospike* server. The easiest way to get one for testing is running the official **docker** container provided by Aerospike:
20
21 ```
22 docker run -d -p 3000:3000 --name aerospike aerospike/aerospike-server
23 ```
24
25 Now, we need the sample code.
26
27 ```
28 go get -u github.com/mcuadros/go-git-aerospike/...
29 ```
30
31 Running this command will make the binary `go-git-aerospike`. if you have `GOPATH` on your `PATH`, you are ready to go. If not, this is a great moment.
32
33 Usage
34 -----
35
36 ### Cloning the repository into the database
37
38 Running the command `go-git-aerospike` with the `clone` option followed by the URL of a git repository clones the repository into the database, storing all the git objects in it:
39
40 ```sh
41 go-git-aerospike clone https://github.com/src-d/flamingo.git
42 ```
43
44 The repository is stored in the aerospike database. This means that all the internal objects like commits, trees, blobs and tags are `records` in different `sets` in the `test` namespace:
45
46 ```sql
47 aql> SELECT hash, type, url FROM test.commit
48 ```
49
50 ```
51 +--------------------------------------------+----------+-------+-----------------------------------+
52 | hash | type | blob | url |
53 +--------------------------------------------+----------+-------+-----------------------------------+
54 | "c94450c805876e49b38d2ff1103b8c09cdd2aef4" | "commit" | 00 00 | ...github.com/src-d/flamingo.git" |
55 | "7f71640877608ee9cfe584fac216f03f9aebb523" | "commit" | 00 00 | ...github.com/src-d/flamingo.git" |
56 | "255f097450dd91812c4eb7b9e0d3a4f034f2acaf" | "commit" | 00 00 | ...github.com/src-d/flamingo.git" |
57 +--------------------------------------------+----------+-------+-----------------------------------+
58 102 rows in set (0.071 secs)
59 ```
60
61 And also the references and the configuration (remotes) are stored in it.
62
63 ```sql
64 aql> SELECT name, target, url FROM test.reference
65 ```
66 ```
67 +------------------------------+--------------------------------------------+-----------------------+
68 | name | target | url |
69 +------------------------------+--------------------------------------------+-----------------------+
70 | "HEAD" | "ref: refs/heads/master" | ...rc-d/flamingo.git" |
71 | "refs/heads/master" | "ed3e1aa2e46584cb803ed356cb5d8855f6d05660" | ...rc-d/flamingo.git" |
72 | "refs/remotes/origin/master" | "ed3e1aa2e46584cb803ed356cb5d8855f6d05660" | ...rc-d/flamingo.git" |
73 +------------------------------+--------------------------------------------+-----------------------+
74 3 rows in set (0.046 secs)
75 ```
76
77 ### Reading the repository
78
79 Running the `log` command, a `git log --online` like result is printed:
80
81 ```sh
82 go-git-aerospike log https://github.com/src-d/flamingo.git
83 ```
84
85 The URL of the repository is the way we identify the objects in the `set`s, since we can clone several repositories to the same database.
86
87 ```
88 ed3e1aa ID is also allowed in SendFormTo and SayTo
89 2031f3e Handle close of message channel in WaitForMessage
90 e784495 Add SendFormTo and SayTo
91 447748a Make text in attachments accept markdown
92 595b4e7 Form author name and author icon and text groupfield
93 0f2e315 Test for InvokeAction
94 0dc7c9a Handle closing of channel
95 b3f167b Implement InvokeAction
96 ```
97
98 The process has read all the commits and all the needed objects from the aerospike sets.
99
100 ### Playing with the database
101
102 If you want to explore the database, you can execute the `aql` tool and run some queries:
103
104 ```sh
105 docker run -it aerospike/aerospike-tools aql -h 172.17.0.1
106 aql> SELECT * FROM test;
107 ```