
A Git query language - bryanrasmussen
https://github.com/cloudson/gitql
======
Erwin
This might benefit from SQLite's Virtual tables:
[https://sqlite.org/vtab.html](https://sqlite.org/vtab.html)

With Virtual Tables you can expose any data source as a SQLite table -- then
you can use every SQL feature that sqlite offers. You can just tell sqlite how
to iterate through your data with a few functions, with an option to push down
filtering information for efficiency.

You can also create your own aggregates, functions etc.

Here's an article where the author exposes redis as a table within sqlite:
[http://charlesleifer.com/blog/extending-sqlite-with-
python/](http://charlesleifer.com/blog/extending-sqlite-with-python/)

~~~
erydo
My thoughts went straight to PostgreSQL Foreign Data Wrappers. Something like
that would be really helpful!

~~~
andrewstuart2
Wouldn't that require a running Postgres server, though? Seems a bit heavy for
ad hoc queries.

For something like a GitLab server, though, that would be amazing.

~~~
oneweekwonder
According to the Ubuntu Dependencies[0] it already uses Postgres, it also
needs Redis, so with gitlab we are a bit pass the heavy bit.

[0]:
[http://packages.ubuntu.com/xenial/gitlab](http://packages.ubuntu.com/xenial/gitlab)

------
masklinn
Mercurial has a somewhat similar concept predating this (added circa 2010):
revision sets
([https://www.selenic.com/mercurial/hg.1.html#revsets](https://www.selenic.com/mercurial/hg.1.html#revsets))
(for selection, and templates for selection but git has that built-in, kind-
of, via log --format)

~~~
jordigh
Mercurial's are completely general, though. Any Mercurial command that can
accept a revision as an argument can also accept a revset expression. And
templating isn't just for log, but for many other commands, such as grep or
annotate (blame), and it's the same templating language for all of them. I
also find hg templates a bit easier to read, because they're
Djangoish/Jinjaish instead of being printf-ish like git's. Plus, you can save
and compose Mercurial templates and revsets.

I was actually hoping that gitql had finally gotten inspiration from Mercurial
and git would grow a general purpose query language, but it's read-only. :-(

~~~
aardvark179
Revsets are a wonderful feature, and it's something I wish git had. Just being
able to say I want to see what has changed between this branch head and its
latest common ancestor with trunk is an incredibly simple and useful thing to
be able to do.

~~~
trolor
Complete guess based on [1], but wouldn't

    
    
      git diff HEAD $(git merge-base HEAD master)
    

work?

[1]: [https://stackoverflow.com/questions/1549146/find-common-
ance...](https://stackoverflow.com/questions/1549146/find-common-ancestor-of-
two-branches)

~~~
jordigh
This requires using bash. I find it kind of cheating that git ships bash on
Windows so that Windows users can rely on bash for composing git commands. I'm
not sure if Windows users are generally that happy about typing bash commands,
but I guess nobody really cares what you have to type in as long as it's high
in the Google hits for whatever operation you want to perform.

Mercurial's API (i.e. the CLI) makes a point of being usable with powershell
and cmd.exe, which I think some Windows users appreciate.

~~~
dsp1234
Another way to look at this is that hg needed to bake this into their core,
whereas git didn't need to. There is a non-zero cost to all additional code,
so leaning on the shell to do work is generally a smart move.

------
koolba
This is pretty cool. Looks like it's local to the current repo which makes
sense for most usage. Having something like this across a swathe of repos
would be useful in different ways (ex: " _What has Bob committed over all the
repos for our projects that involves the string 'billing'?_".

Minor off topic rant about the animated example: _Who doesn 't put a space at
the end of their prompt after the $?! Ugh!_

~~~
icefox
Git map would work for many cases

[https://github.com/icefox/git-map](https://github.com/icefox/git-map)

    
    
      Git map ql ...

~~~
koolba
Nice. I can see a need for this as a lot of my projects are structured like
that (multiple sibling repos). Running 'git map log --grep ...' seems
particularly useful.

Quick eyeballing of the source, it does not handle whitespace in directory
names properly. The for loop would treat them as separate, invalid, entries.

Of course I'd also fire someone on the spot that commits a project directory
with whitespace in it...

~~~
icefox
Good point, switched it to a while loop.

------
c8g
active gitql [https://github.com/gitql/gitql](https://github.com/gitql/gitql)

~~~
somebehemoth
Thank you for sharing this. I was interested to know if this was a fork of
gitql by cloudson. It is not. The following issue clarifies the relationship:

[https://github.com/gitql/gitql/issues/83](https://github.com/gitql/gitql/issues/83)

"The relation is its purpose: SQL + Git, written in Go. There is no relation
other than that."

I thought this might help anyone else who was similarly interested.

------
taspeotis

        A Git query language (github.com)
        10 points by bryanrasmussen 1 hour ago
    

This ought to have (2014) in the title: Latest commit 49c1c17 on 22 Jun 2014.

~~~
patkai
That makes it even more interesting, I mean the fact that this or something
similar didn't get traction. I often have an idea of what I would like to know
about my repo, but don't want to start hacking the answer together.

~~~
OJFord
[https://github.com/gitql/gitql](https://github.com/gitql/gitql) (last commit
12 days ago)

~~~
palunon
Not the same project (look at the number of commits, and the top issue).

~~~
OJFord
I was responding to:

> _interesting, I mean the fact that this _or something similar_ didn 't get
> traction_

I think you'll agree this is something very similar and that has traction.

------
Tarean
Very cool. I always wanted to play around with a git provider for powershell.
Powershell's syntax is great for queries and you could use everything that
works on the normal file system with anything that has the abstractions
implemented.

The syntax seems close enough that this could just replace it, though:

    
    
        ls commits | where date < (get-date).AddDays(-4) | where message -like *foo* | select autor, message, date  -First 3 | ft

~~~
chadgeidel
I'm no powershell guru, but I'm using posh-git [1]. Is it possible to chain
commands using that tool?

[https://github.com/dahlbyk/posh-git](https://github.com/dahlbyk/posh-git)

------
odammit
Oh I love that the example gif includes:

    
    
      select author, message 
      from commits 
      where 'Fuck' in message
    

I'm pretty sure that query's results would fill my screen buffer.

~~~
jordigh
Just for comparison, in Mercurial you would do

    
    
       hg log --template "{author}, {desc}\n" --rev "desc('fuck')"

~~~
odammit
"Fuck" is right up there with "ch-ch-changes" in my git word cloud.

~~~
joslin01
Why?

------
andrewchambers
I don't see the point in wrapping the data in all that ascii art noise, will
make it harder to script with.

------
guard-of-terra
But why does it have to look like SQL (and not like xpath or jquery)?

Not many people enjoy writing SQL statements on the command line. It's
verbose, the order of things is arbitrary...

~~~
mwfunk
I would assume that the whole point of the project is to be able to do SQLish
queries on a git repo, and that it was written by and for people who are
familiar with SQL and have a preference for it over other query languages. And
they probably do enjoy writing SQL statements on the command line, however
uncommon that may or may not be.

~~~
guard-of-terra
Seems to be very narrow group. How is this relevant to HN? Flagged the story.

~~~
jsmeaton
You flagged the story because you don't like SQL on the CLI? Come on. Whether
or not you enjoy writing SQL on the CLI, SQL is a fine language for querying
data, and is probably more common than xpath. JQuery seems like a strange
choice too.

~~~
guard-of-terra
I just fail to praise the attitude. "Let's faithfully reproduce the looks of
30 y.o. technology, pseudographic tables included, with make-believe over
git".

------
oneeyedpigeon
Imagine if we could just have this automatically for every program that
generated text output. It doesn't seem beyond the realms of possibility that
every tool could either a) structure its text output in a way that can
guarantee simple command-piping to a general purpose query-language processing
tool or b) in the presence of a "\--output-json" flag, produce json which can
then easily be queried.

~~~
junke
Or you could have a single address space
([https://en.wikipedia.org/wiki/Single_address_space_operating...](https://en.wikipedia.org/wiki/Single_address_space_operating_system)),
and share objects directly.

~~~
amelius
Sounds like a security nightmare.

~~~
junke
But is it really? Couldn't there be a way to isolate things at the system
level?

------
0x54MUR41
Wow. It's awesome. I have never been seen project like this before. It seems
very useful. Anyway, I think it would be better if they demonstrate the
example of usage using asciinema [1].

[1]: [https://asciinema.org](https://asciinema.org)

------
seliopou
This can easily be accomplished using `git log`, `head`, and `grep`:

    
    
      git log --pretty="format:%an, %s, %ad" --after="2014-04-10" | grep "Fuck" | head -3

------
georgewfraser
If you actually want to query git data in production, it's really a better
idea to copy all the data into a real SQL data warehouse. If you're using
github, my company (Fivetran.com) has a connector that pulls from their API.

------
ecesena
It would be nice to see a plugin for presto

------
ujjwal_wadhawan
support for "SELECT DISTINCT" would be great !

------
rodorgas
That's a great idea!

