1
1
# GitQuery <a href =" https://travis-ci.org/src-d/gitquery " ><img alt =" Build Status " src =" https://travis-ci.org/src-d/gitquery.svg?branch=master " /></a > <a href =" https://codecov.io/gh/src-d/gitquery " ><img alt =" codecov " src =" https://codecov.io/gh/src-d/gitquery/branch/master/graph/badge.svg " /></a > <a href =" https://godoc.org/gopkg.in/src-d/gitquery.v0 " ><img alt =" GoDoc " src =" https://godoc.org/gopkg.in/src-d/gitquery.v0?status.svg " /></a >
2
2
3
- < div style = " text-align : center " >< img src = " assets/tty.gif " /></ div >
3
+ See a set of repositories as a standard database.
4
4
5
5
## Installation
6
6
7
- Check the [ Releases] ( https://github.com/src-d/gitquery/releases ) page to download
8
- the gitquery binary.
7
+ Check the [ Releases] ( https://github.com/src-d/gitquery/releases ) page to download the gitquery binary.
9
8
10
9
## Usage
11
10
@@ -24,7 +23,7 @@ Available commands:
24
23
A MySQL client is needed to connect to the server. For example:
25
24
26
25
``` bash
27
- $ mysql -u root -h 127.0.0.1
26
+ $ mysql -q - u root -h 127.0.0.1
28
27
MySQL [(none)]> SELECT hash, author_email, author_name FROM commits LIMIT 2;
29
28
SELECT hash, author_email, author_name FROM commits LIMIT 2;
30
29
+------------------------------------------+---------------------+-----------------------+
@@ -38,26 +37,79 @@ SELECT hash, author_email, author_name FROM commits LIMIT 2;
38
37
39
38
## Tables
40
39
40
+ You can execute the ` SHOW TABLES ` statement to get a list of the available tables.
41
+ To get all the columns and types of a specific table, you can write ` DESCRIBE TABLE [tablename] ` .
42
+
41
43
gitquery exposes the following tables:
42
44
43
45
| Name | Columns |
44
46
| :------------:| :---------------------------------------------------------------------------------------------------:|
45
- | commits | hash, author_name, author_email, author_time, comitter_name, comitter_email, comitter_time, message |
46
- | blobs | hash, size |
47
- | refs | name, type, hash, target, is_branch, is_note, is_remote, is_tag |
48
- | tags | hash, name, tagger_email, tagger_name, tagger_when, message, target |
47
+ | repositories | id |
48
+ | remotes | repository_id, name, push_url,fetch_url,push_refspec,fetch_refspec |
49
+ | commits | hash, author_name, author_email, author_when, comitter_name, comitter_email, comitter_when, message, tree_hash |
50
+ | blobs | hash, size, content |
51
+ | refs | repository_id, name, hash |
49
52
| tree_entries | tree_hash, entry_hash, mode, name |
50
53
51
- ## SQL syntax
54
+ ## Functions
55
+
56
+ To make some common tasks easier for the user, there are some functions to interact with the previous mentioned tables:
57
+
58
+ | Name | Description |
59
+ | :------------:| :---------------------------------------------------------------------------------------------------:|
60
+ | commit_has_blob(commit_hash,blob_hash)bool| get if the specified commit contains the specified blob |
61
+ | history_idx(start_hash, target_hash)int| get the index of a commit in the history of another commit |
62
+ | is_remote(reference_name)bool| check if the given reference name is from a remote one |
63
+ | is_tag(reference_name)bool| check if the given reference name is a tag |
52
64
53
- We are continuously adding more functionality to gitquery. We support a subset of the SQL standard, currently including:
65
+ ## Examples
66
+
67
+ ### Get all the HEAD references from all the repositories
68
+ ``` sql
69
+ SELECT * FROM refs WHERE name = ' HEAD'
70
+
71
+ ```
54
72
55
- | | Supported |
56
- | :----------------------:| :---------------------------------------------------------------------------------:|
57
- | Comparison expressions | !=, ==, >, <, >=,<= |
58
- | Grouping expressions | COUNT, FIRST |
59
- | Standard expressions | ALIAS, LITERAL, STAR (* ) |
60
- | Statements | CROSS JOIN, DESCRIBE, FILTER (WHERE), GROUP BY, LIMIT, SELECT, SHOW TABLES, SORT |
73
+ ### Commits that appears in more than one reference
74
+
75
+ ``` sql
76
+ SELECT * FROM (
77
+ SELECT COUNT (c .hash ) AS num, c .hash
78
+ FROM refs r
79
+ INNER JOIN commits c
80
+ ON history_idx(r .hash , c .hash ) >= 0
81
+ GROUP BY c .hash
82
+ ) t WHERE num > 1
83
+ ```
84
+
85
+ ### Get the number of blobs per HEAD commit
86
+ ``` sql
87
+ SELECT COUNT (c .hash ), c .hash
88
+ FROM refs r
89
+ INNER JOIN commits c
90
+ ON history_idx(r .hash , c .hash ) >= 0
91
+ INNER JOIN blobs b
92
+ ON commit_has_blob(c .hash , b .hash )
93
+ WHERE r .name = ' HEAD'
94
+ GROUP BY c .hash
95
+ ```
96
+
97
+ ### Get commits per commiter, per month in 2015
98
+
99
+ ``` sql
100
+ SELECT COUNT (* ) as num_commits, month, repo_id, committer_email
101
+ FROM (
102
+ SELECT
103
+ MONTH(committer_when) as month,
104
+ r .id as repo_id,
105
+ committer_email
106
+ FROM repositories r
107
+ INNER JOIN refs ON refs .repository_id = r .id AND refs .name = ' HEAD'
108
+ INNER JOIN commits c ON history_idx(refs .hash , c .hash ) >= 0
109
+ WHERE YEAR(committer_when) = 2015
110
+ ) as t
111
+ GROUP BY committer_email, month, repo_id
112
+ ```
61
113
62
114
## License
63
115
0 commit comments