

Tell HN: HN driven development: libgit2 Postgres back end arrives - andrewstuart

I wanted to store git repos in Postgres.<p>My request for help hit the HN front page and within 2 hours of asking  https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9833548 a complete (but untested) solution https:&#x2F;&#x2F;gist.github.com&#x2F;mhodgson&#x2F;d29bbd35e1a8db5e0800 was donated by an HN community member mhodgson.<p>So libgit2 now has a Postgres back end thanks to HN and HN user mhodgson!<p>Any C programmers with Postgres and&#x2F;or git knowledge, it would be awesome if you posted your comments on the freshly open sourced code<p>HN driven development has taken off!
======
_cbdev
FWIW I enjoyed the challenge of hacking up my own version of this. It's
admittedly not battle-tested, but hey ;)

[https://github.com/cbdevnet/libgit2-backends/blob/master/pos...](https://github.com/cbdevnet/libgit2-backends/blob/master/postgres/postgres.c)

~~~
andrewstuart
Awesome!

Incredible to get two implementations.

I really appreciate that you've made this happen.

Is this built from scratch or a port of one of the existing drivers? Did you
have a chance to have a look at the other implementation - what do you see as
the major differences?

Any thoughts of submitting to the libgit2 project?

~~~
_cbdev
I copied the prototypes and general structure of the driver from the existing
ones (mainly the sqlite driver), implementing the functionality with the
appropriate postgres API calls.

As for the implementation by mhodgson, one thing I noticed is that it uses the
slightly newer PQexecPrepared API, which only works from protocol version 3.0
and upwards (which was introduced with PostgreSQL 7.4, so not really a
problem). He also seems to use some more calls to the libgit2 API, mainly for
copying and creating buffers for SQL statements (which I did with static
allocation, at the expense of having hardcoded schema and table names).

All in all, mhodgson's implementation seems more feature-complete (and well-
tested) than mine, yet also considerably more complex.

As for submitting it, I'd like to have some confirmation that it works first
:) Unfortunately, I'm currently too busy to really set up some tests for it,
but once I have the time, I just might ;)

