tags:

views:

144

answers:

1

I have read in several places that it's possible to share the objects directory between multiple git repositories, e.g. with symbolic links. I would like to do this to share the object databases between several bare repositories in the same directory:

shared-objects-database/
foo.git/
  objects -> ../shared-objects-database
bar.git/
  objects -> ../shared-objects-database
baz.git/
  objects -> ../shared-objects-database

(I'm doing this because there are going to be lots of large blobs redundantly stored in each objects directory otherwise.)

My concern about this is that when using these repositories, git gc will be called automatically and cause objects which are unreachable from one repository to be pruned, making the other repositories incomplete. Is there any easy way of ensuring that this doesn't happen? For example, is there a config option that would force --no-prune to be the default for git gc, and, if so, would that be sufficient to use this setup without risking losing data?

At the moment, I've been using the objects/info/alternates mechanism to share objects between these repositories, but maintaining these pointers from each repository to all the others is a bit hacky.

(My other alternative is to just to have a single bare repository, with all the branches of foo.git, bar.git and baz.git named foo-master, foo-testing, bar-master, etc. However, that'd be a bit more work to manage, so if the symlinked objects directory can work safely, I'd rather do that.)

You might guess that this is one of those Using Git For What It Was Not Intended use cases, but I hope the question is clear and valid nonetheless ;)

+2  A: 

Why not just crank the gc.pruneExpire variable up to never? It's unlikely you'll ever have loose objects 1000 years old that you don't want deleted.

To make sure that the things which really should be pruned do get pruned, you can keep one repo which has all the others as remotes. git gc would be quite safe in that one, since it really knows what is unreachable.

Edit: Okay, I was a bit cavalier about the time limit; as is pointed out in the comments, 1000 years isn't gonna work too well, but the beginning of the epoch would, or never.

Jefromi
Thanks for your answer - in particular the suggestion about how to prune safely.
Mark Longair
Jefromi: perhaps you could update your answer with a couple of notes? I'm not 100% sure of this, but playing with the tests in git.git, I suspect that values over 39 years may not work, since they go back before the beginning of the epoch. However, since this commit: http://github.com/git/git/commit/cbf731ed4ec511f2c32598e03d7865f35881fea2 you can set gc.pruneExpire to "never" and that will work. (From "git tag --contains cbf731ed4ec511f2" it looks as if versions after (and including) v1.7.0.3 should be fine.)
Mark Longair