You're able to achieve that with git_odb_open
. It's part of the official libgit2 API.
Basically, git_odb_open
"[c]reate[s] a new object database and automatically add[s] the two default backends" (quote taken from here). If you take a look at the ligbit2 GitHub repository, you can find the GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
within odb.h
(in general, I suggest to check out all the odb functions). Anyhow, the comments below the function are extremely useful:
/**
* Add a custom backend to an existing Object DB
*
* The backends are checked in relative ordering, based on the
* value of the `priority` parameter.
*
* Read <odb_backends.h> for more information.
*
* @param odb database to add the backend to
* @param backend pointer to a git_odb_backend instance
* @param priority Value for ordering the backends queue
* @return 0 on success; error code otherwise
*/
Kinda unfortunate that those notes aren't included on the standard documentation. Anyway, here you can see the important @param
for a backend pointer to the instance itself. On a slight off-topic note, I'd suggest checking out the code of odb_backend.h
as well (fortunately, ligbit2 is very well documented).
By the way (for the sake of completeness), I should mention you also can plug a custom backend into an already existing odb via git_odb_add_backend
(obviously you got the pointer there as well), though it requires you to have an existing database to begin with . In case you're looking add an alternative to already-existing backends, i.e. in your case one one that doesn't compresses objects, you may go with git_odb_add_alternate
.
git config core.compression 0
?libgit2