Have you tried https://github.com/davidbalbert/libgit2-postgresql? I know nothing about libgit2, but came across this repo while looking it up. If it's got some issues it's a great place to start from, since it also gives you somebody who could code review and you don't need to start completely from scratch.
This project uses PQescapeLiteral() and asprintf() to build queries. I'd recommend prepared statements over this approach (which is how the MySQL backend builds queries).
It doesn't implement anything but write() and free() yet, so it's not actually functional.
Unfortunately I believe this would clobber the library license (GPLv3 on this Postgres plugin vs GPLv2 with a linking exception for libgit). With this in mind I'd probably just recommend a rewrite. It's not that much code.