If you're interested in building this kind of thing, JGit might be a good starting point, as it offers the right amount of flexibility [1] to be able to pull this off and stay sane in the process [2].
[2]: If programming Java allows you to do this, of course. I'm not too deep into the JVM ecosystem, so I don't know if you could just use a language that compiles to JVM bytecode.
[1]: A good example would be http://git.eclipse.org/c/jgit/jgit.git/tree/org.eclipse.jgit... (Git over Amazon S3)
[2]: If programming Java allows you to do this, of course. I'm not too deep into the JVM ecosystem, so I don't know if you could just use a language that compiles to JVM bytecode.