Skip to content

Commit 2985f22

Browse files
authored
Merge pull request #181 from ajnavarro/doc/improve-readme
Improve and update README
2 parents b7734fd + d5ac292 commit 2985f22

File tree

3 files changed

+68
-17
lines changed

3 files changed

+68
-17
lines changed

README.md

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# 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>
22

3-
<div style="text-align:center"><img src ="assets/tty.gif"/></div>
3+
Query git repositories with a MySQL interface.
44

55
## Installation
66

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.
98

109
## Usage
1110

@@ -24,7 +23,7 @@ Available commands:
2423
A MySQL client is needed to connect to the server. For example:
2524

2625
```bash
27-
$ mysql -u root -h 127.0.0.1
26+
$ mysql -q -u root -h 127.0.0.1
2827
MySQL [(none)]> SELECT hash, author_email, author_name FROM commits LIMIT 2;
2928
SELECT hash, author_email, author_name FROM commits LIMIT 2;
3029
+------------------------------------------+---------------------+-----------------------+
@@ -38,26 +37,78 @@ SELECT hash, author_email, author_name FROM commits LIMIT 2;
3837

3938
## Tables
4039

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+
4143
gitquery exposes the following tables:
4244

4345
| Name | Columns |
4446
|:------------:|:---------------------------------------------------------------------------------------------------:|
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 |
4952
| tree_entries | tree_hash, entry_hash, mode, name |
5053

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 |
5265

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+
```
5473

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+
```
61112

62113
## License
63114

assets/tty.gif

-1.3 MB
Binary file not shown.

internal/function/is_remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"gopkg.in/src-d/go-mysql-server.v0/sql/expression"
1010
)
1111

12-
// IsRemote checks the given string is a tag name.
12+
// IsRemote checks the given string is a remote reference.
1313
type IsRemote struct {
1414
expression.UnaryExpression
1515
}

0 commit comments

Comments
 (0)