Skip to content

Commit c429264

Browse files
committed
libgit2: use set_ob() instead of wrap_odb() for a custom backend
The purpose of git_repository_warp_odb() is not to use a repository with a custom odb backend, but to access an odb via functions which want a repository object. A repository build this way has no path, no refs db, no configuration, no worktree, etc. It is useless unless you're e.g. trying to extract information out of a packfile via git_object_lookup() and friends. In order to have an otherwise "normal" repository but use a custom backend for the objects, you need to open/init the repository as you usually do and then set the custom odb.
1 parent ec535c1 commit c429264

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

book/B-embedding-git/sections/libgit2.asc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,25 @@ Here's how a custom backend for the object database is set up:
124124
git_odb *odb;
125125
int error = git_odb_new(&odb); // <1>
126126
127-
git_repository *repo;
128-
error = git_repository_wrap_odb(&repo, odb); // <2>
129-
130127
git_odb_backend *my_backend;
131-
error = git_odb_backend_mine(&my_backend, /*…*/); // <3>
128+
error = git_odb_backend_mine(&my_backend, /*…*/); // <2>
132129
133-
error = git_odb_add_backendodb, my_backend, 1); // <4>
130+
error = git_odb_add_backendodb, my_backend, 1); // <3>
131+
132+
git_repository *repo;
133+
error = git_repository_open(&repo, "some-path");
134+
error = git_repository_set_odb(odb); // <4>
134135
----
135136

136137
_(Note that errors are captured, but not handled. We hope your code is better than ours.)_
137138

138-
<1> Initialize an empty object database (ODB) ``frontend,'' which will act as a handle to the real ODB.
139-
<2> Construct a `git_repository` around the empty ODB.
140-
<3> Initialize a custom ODB backend.
141-
<4> Set the repository to use the custom backend for its ODB.
139+
<1> Initialize an empty object database (ODB) ``frontend,'' which will act as a container for the ``backends'' which are the ones doing the real work.
140+
<2> Initialize a custom ODB backend.
141+
<3> Open a repository
142+
<4> Set the repository to use our ODB to look up objects.
142143

143144
But what is this `git_odb_backend_mine` thing?
144-
Well, that's your own ODB implementation, and you can do whatever you want in there, so long as you fill in the `git_odb_backend` structure properly.
145+
Well, that's the constructor for your own ODB implementation, and you can do whatever you want in there, so long as you fill in the `git_odb_backend` structure properly.
145146
Here's what it _could_ look like:
146147

147148
[source,c]

0 commit comments

Comments
 (0)