gitquery

package module
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2018 License: MIT Imports: 23 Imported by: 5

README

GitQuery Build Status codecov GoDoc

Query git repositories with a MySQL interface.

Installation

Check the Releases page to download the gitquery binary.

Usage

Usage:
  gitquery [OPTIONS] <server | version>

Help Options:
  -h, --help  Show this help message

Available commands:
  server   Start SQL server.
  version  Show the version information.

A MySQL client is needed to connect to the server. For example:

$ mysql -q -u root -h 127.0.0.1
MySQL [(none)]> SELECT hash, author_email, author_name FROM commits LIMIT 2;
SELECT hash, author_email, author_name FROM commits LIMIT 2;
+------------------------------------------+---------------------+-----------------------+
| hash                                     | author_email        | author_name           |
+------------------------------------------+---------------------+-----------------------+
| 003dc36e0067b25333cb5d3a5ccc31fd028a1c83 | user1@test.io       | Santiago M. Mola      |
| 01ace9e4d144aaeb50eb630fed993375609bcf55 | user2@test.io       | Antonio Navarro Perez |
+------------------------------------------+---------------------+-----------------------+
2 rows in set (0.01 sec)

Tables

You can execute the SHOW TABLES statement to get a list of the available tables. To get all the columns and types of a specific table, you can write DESCRIBE TABLE [tablename].

gitquery exposes the following tables:

Name Columns
repositories id
remotes repository_id, name, push_url,fetch_url,push_refspec,fetch_refspec
commits hash, author_name, author_email, author_when, comitter_name, comitter_email, comitter_when, message, tree_hash
blobs hash, size, content
refs repository_id, name, hash
tree_entries tree_hash, entry_hash, mode, name

Functions

To make some common tasks easier for the user, there are some functions to interact with the previous mentioned tables:

Name Description
commit_has_blob(commit_hash,blob_hash)bool get if the specified commit contains the specified blob
commit_has_tree(commit_hash,tree_hash)bool get if the specified commit contains the specified tree
history_idx(start_hash, target_hash)int get the index of a commit in the history of another commit
is_remote(reference_name)bool check if the given reference name is from a remote one
is_tag(reference_name)bool check if the given reference name is a tag

Examples

Get all the HEAD references from all the repositories
SELECT * FROM refs WHERE name = 'HEAD'

Commits that appears in more than one reference
SELECT * FROM (
				SELECT COUNT(c.hash) AS num, c.hash
				FROM refs r
				INNER JOIN commits c
					ON history_idx(r.hash, c.hash) >= 0
				GROUP BY c.hash
			) t WHERE num > 1
Get the number of blobs per HEAD commit
SELECT COUNT(c.hash), c.hash
			FROM refs r
			INNER JOIN commits c
				ON r.name = 'HEAD' AND history_idx(r.hash, c.hash) >= 0
			INNER JOIN blobs b
				ON commit_has_blob(c.hash, b.hash)
			GROUP BY c.hash
Get commits per commiter, per month in 2015
SELECT COUNT(*) as num_commits, month, repo_id, committer_email
			FROM (
				SELECT
					MONTH(committer_when) as month,
					r.id as repo_id,
					committer_email
				FROM repositories r
				INNER JOIN refs ON refs.repository_id = r.id AND refs.name = 'HEAD'
				INNER JOIN commits c ON YEAR(committer_when) = 2015 AND history_idx(refs.hash, c.hash) >= 0
			) as t
			GROUP BY committer_email, month, repo_id

License

gitquery is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidGitQuerySession = errors.NewKind("expecting gitquery session, but received: %T")

ErrInvalidGitQuerySession is returned when some node expected a GitQuery session but received something else.

Functions

func NewDatabase added in v0.6.0

func NewDatabase(name string, pool *RepositoryPool) sql.Database

NewDatabase creates a new Database structure and initializes its tables with the given pool

func NewRowRepoIter added in v0.10.0

func NewRowRepoIter(
	pool *RepositoryPool,
	iter RowRepoIter,
) (*rowRepoIter, error)

NewRowRepoIter initializes a new repository iterator.

* pool: is a RepositoryPool we want to iterate * iter: specific RowRepoIter interface

  • NewIterator: called when a new repository is about to be iterated, returns a new RowRepoIter
  • Next: called for each row
  • Close: called when a repository finished iterating

func NewSessionBuilder added in v0.10.0

func NewSessionBuilder(pool *RepositoryPool) server.SessionBuilder

NewSessionBuilder creates a SessionBuilder with the given Repository Pool.

Types

type Database added in v0.6.0

type Database struct {
	// contains filtered or unexported fields
}

Database holds all git repository tables

func (*Database) Name added in v0.6.0

func (d *Database) Name() string

Name returns the name of the database

func (*Database) Tables added in v0.6.0

func (d *Database) Tables() map[string]sql.Table

Tables returns a map with all initialized tables

type Repository added in v0.10.0

type Repository struct {
	ID   string
	Repo *git.Repository
}

Repository struct holds an initialized repository and its ID

func NewRepository added in v0.10.0

func NewRepository(id string, repo *git.Repository) Repository

NewRepository creates and initializes a new Repository structure

func NewRepositoryFromPath added in v0.10.0

func NewRepositoryFromPath(id, path string) (Repository, error)

NewRepositoryFromPath creates and initializes a new Repository structure and initializes a go-git repository

type RepositoryIter added in v0.10.0

type RepositoryIter struct {
	// contains filtered or unexported fields
}

RepositoryIter iterates over all repositories in the pool

func (*RepositoryIter) Close added in v0.10.0

func (i *RepositoryIter) Close() error

Close finished iterator. It's no-op.

func (*RepositoryIter) Next added in v0.10.0

func (i *RepositoryIter) Next() (*Repository, error)

Next retrieves the next Repository. It returns io.EOF as error when there are no more Repositories to retrieve.

type RepositoryPool added in v0.10.0

type RepositoryPool struct {
	// contains filtered or unexported fields
}

RepositoryPool holds a pool git repository paths and functionality to open and iterate them.

func NewRepositoryPool added in v0.10.0

func NewRepositoryPool() RepositoryPool

NewRepositoryPool initializes a new RepositoryPool

func (*RepositoryPool) Add added in v0.10.0

func (p *RepositoryPool) Add(id, path string)

Add inserts a new repository in the pool

func (*RepositoryPool) AddDir added in v0.10.0

func (p *RepositoryPool) AddDir(path string) error

AddDir adds all direct subdirectories from path as repos

func (*RepositoryPool) AddGit added in v0.10.0

func (p *RepositoryPool) AddGit(path string) (string, error)

AddGit checks if a git repository can be opened and adds it to the pool. It also sets its path as ID.

func (*RepositoryPool) GetPos added in v0.10.0

func (p *RepositoryPool) GetPos(pos int) (*Repository, error)

GetPos retrieves a repository at a given position. If the position is out of bounds it returns io.EOF

func (*RepositoryPool) RepoIter added in v0.10.0

func (p *RepositoryPool) RepoIter() (*RepositoryIter, error)

RepoIter creates a new Repository iterator

type RowRepoIter added in v0.10.0

type RowRepoIter interface {
	NewIterator(*Repository) (RowRepoIter, error)
	Next() (sql.Row, error)
	Close() error
}

RowRepoIter is the interface needed by each iterator implementation

type Session added in v0.10.0

type Session struct {
	sql.Session
	Pool *RepositoryPool
}

Session is the custom implementation of a gitquery session.

func NewSession added in v0.10.0

func NewSession(ctx context.Context, pool *RepositoryPool) *Session

NewSession creates a new Session.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL