Skip to content

Commit b02a56a

Browse files
committed
Merge pull request #108 from carlosmn/libgit2-corrections
Libgit2 corrections
2 parents c9bac1d + 8d8b048 commit b02a56a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const git_oid *tree_id = git_commit_tree_id(commit);
2727
2828
// Cleanup
2929
git_commit_free(commit);
30-
git_object_free(head_commit);
3130
git_repository_free(repo);
3231
-----
3332

@@ -125,24 +124,25 @@ Here's how a custom backend for the object database is set up:
125124
git_odb *odb;
126125
int error = git_odb_new(&odb); // <1>
127126
128-
git_repository *repo;
129-
error = git_repository_wrap_odb(&repo, odb); // <2>
130-
131127
git_odb_backend *my_backend;
132-
error = git_odb_backend_mine(&my_backend, /*…*/); // <3>
128+
error = git_odb_backend_mine(&my_backend, /*…*/); // <2>
133129
134-
error = git_odb_add_backendodb, my_backend, 1); // <4>
130+
error = git_odb_add_backend(odb, 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>
135135
----
136136

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

139-
<1> Initialize an empty object database (ODB) ``frontend,'' which will act as a handle to the real ODB.
140-
<2> Construct a `git_repository` around the empty ODB.
141-
<3> Initialize a custom ODB backend.
142-
<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> Add the backend to the frontend.
142+
<4> Open a repository, and set it to use our ODB to look up objects.
143143

144144
But what is this `git_odb_backend_mine` thing?
145-
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.
146146
Here's what it _could_ look like:
147147

148148
[source,c]

0 commit comments

Comments
 (0)