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
+ Query git repositories with a MySQL interface.
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,78 @@ 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
+ | commit_has_tree(commit_hash,tree_hash)bool| get if the specified commit contains the specified tree |
62
+ | history_idx(start_hash, target_hash)int| get the index of a commit in the history of another commit |
63
+ | is_remote(reference_name)bool| check if the given reference name is from a remote one |
64
+ | is_tag(reference_name)bool| check if the given reference name is a tag |
52
65
53
- We are continuously adding more functionality to gitquery. We support a subset of the SQL standard, currently including:
66
+ ## Examples
67
+
68
+ ### Get all the HEAD references from all the repositories
69
+ ``` sql
70
+ SELECT * FROM refs WHERE name = ' HEAD'
71
+
72
+ ```
54
73
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 |
74
+ ### Commits that appears in more than one reference
75
+
76
+ ``` sql
77
+ SELECT * FROM (
78
+ SELECT COUNT (c .hash ) AS num, c .hash
79
+ FROM refs r
80
+ INNER JOIN commits c
81
+ ON history_idx(r .hash , c .hash ) >= 0
82
+ GROUP BY c .hash
83
+ ) t WHERE num > 1
84
+ ```
85
+
86
+ ### Get the number of blobs per HEAD commit
87
+ ``` sql
88
+ SELECT COUNT (c .hash ), c .hash
89
+ FROM refs r
90
+ INNER JOIN commits c
91
+ ON r .name = ' HEAD' AND history_idx(r .hash , c .hash ) >= 0
92
+ INNER JOIN blobs b
93
+ ON commit_has_blob(c .hash , b .hash )
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 YEAR(committer_when) = 2015 AND history_idx(refs .hash , c .hash ) >= 0
109
+ ) as t
110
+ GROUP BY committer_email, month, repo_id
111
+ ```
61
112
62
113
## License
63
114
0 commit comments