@@ -30,8 +30,8 @@ struct git_odb_backend {
3030
3131 /* read and read_prefix each return to libgit2 a buffer which
3232 * will be freed later. The buffer should be allocated using
33- * the function git_odb_backend_malloc to ensure that it can
34- * be safely freed later. */
33+ * the function git_odb_backend_data_alloc to ensure that libgit2
34+ * can safely free it later. */
3535 int GIT_CALLBACK (read )(
3636 void * * , size_t * , git_object_t * , git_odb_backend * , const git_oid * );
3737
@@ -117,8 +117,52 @@ GIT_EXTERN(int) git_odb_init_backend(
117117 git_odb_backend * backend ,
118118 unsigned int version );
119119
120+ /**
121+ * Allocate data for an ODB object. Custom ODB backends may use this
122+ * to provide data back to the ODB from their read function. This
123+ * memory should not be freed once it is returned to libgit2. If a
124+ * custom ODB uses this function but encounters an error and does not
125+ * return this data to libgit2, then they should use the corresponding
126+ * git_odb_backend_data_free function.
127+ *
128+ * @param backend the ODB backend that is allocating this memory
129+ * @param len the number of bytes to allocate
130+ * @return the allocated buffer on success or NULL if out of memory
131+ */
132+ GIT_EXTERN (void * ) git_odb_backend_data_alloc (git_odb_backend * backend , size_t len );
133+
134+ /**
135+ * Frees custom allocated ODB data. This should only be called when
136+ * memory allocated using git_odb_backend_data_alloc is not returned
137+ * to libgit2 because the backend encountered an error in the read
138+ * function after allocation and did not return this data to libgit2.
139+ *
140+ * @param backend the ODB backend that is freeing this memory
141+ * @param data the buffer to free
142+ */
143+ GIT_EXTERN (void ) git_odb_backend_data_free (git_odb_backend * backend , void * data );
144+
145+
146+ /*
147+ * Users can avoid deprecated functions by defining `GIT_DEPRECATE_HARD`.
148+ */
149+ #ifndef GIT_DEPRECATE_HARD
150+
151+ /**
152+ * Allocate memory for an ODB object from a custom backend. This is
153+ * an alias of `git_odb_backend_data_alloc` and is preserved for
154+ * backward compatibility.
155+ *
156+ * This function is deprecated, but there is no plan to remove this
157+ * function at this time.
158+ *
159+ * @deprecated git_odb_backend_data_alloc
160+ * @see git_odb_backend_data_alloc
161+ */
120162GIT_EXTERN (void * ) git_odb_backend_malloc (git_odb_backend * backend , size_t len );
121163
164+ #endif
165+
122166GIT_END_DECL
123167
124168#endif
0 commit comments