@@ -9,7 +9,7 @@ use std::mem::ManuallyDrop;
99use std:: ptr:: NonNull ;
1010use std:: { ptr, slice} ;
1111
12- /// A custom implementation of an [`Odb`] backend.
12+ /// A custom implementation of an [`Odb`](crate::Odb) backend.
1313///
1414/// Most of the default implementations of this trait's methods panic when called as they are
1515/// intended to be overridden.
@@ -273,11 +273,33 @@ pub trait OdbBackend {
273273 unimplemented ! ( "OdbBackend::freshen" )
274274 }
275275
276+ /// Creates a `multi-pack-index` file containing an index of all objects across all `.pack`
277+ /// files.
278+ ///
279+ /// Corresponds to the `writemidx` function of [`git_odb_backend`].
280+ /// Requires that [`SupportedOperations::WRITE_MULTIPACK_INDEX`] is present in the value returned from
281+ /// [`supported_operations`] to expose it to libgit2.
282+ ///
283+ /// The default implementation of this method panics.
284+ ///
285+ /// # Implementation notes
286+ ///
287+ /// TODO: Implementation notes for `write_multipack_index`
288+ ///
289+ /// # Errors
290+ ///
291+ /// See [`OdbBackend`].
292+ ///
293+ /// [`git_odb_backend`]: raw::git_odb_backend
294+ /// [`supported_operations`]: Self::supported_operations
295+ fn write_multipack_index ( & mut self , ctx : & OdbBackendContext ) -> Result < ( ) , Error > {
296+ unimplemented ! ( "OdbBackend::write_multipack_index" )
297+ }
298+
276299 // TODO: fn writestream()
277300 // TODO: fn readstream()
278301 // TODO: fn foreach()
279302 // TODO: fn writepack()
280- // TODO: fn writemidx()
281303}
282304
283305bitflags ! {
@@ -305,10 +327,10 @@ bitflags! {
305327 const REFRESH = 1 << 7 ;
306328 /// The backend supports the [`OdbBackend::foreach`] method.
307329 const FOREACH = 1 << 8 ;
308- /// The backend supports the [`OdbBackend::writepack `] method.
309- const WRITEPACK = 1 << 9 ;
310- /// The backend supports the [`OdbBackend::writemidx `] method.
311- const WRITEMIDX = 1 << 10 ;
330+ /// The backend supports the [`OdbBackend::write_pack `] method.
331+ const WRITE_PACK = 1 << 9 ;
332+ /// The backend supports the [`OdbBackend::write_multipack_index `] method.
333+ const WRITE_MULTIPACK_INDEX = 1 << 10 ;
312334 /// The backend supports the [`OdbBackend::freshen`] method.
313335 const FRESHEN = 1 << 11 ;
314336 }
@@ -469,6 +491,7 @@ impl<'a, B: OdbBackend> CustomOdbBackend<'a, B> {
469491 op_if ! ( exists if EXISTS ) ;
470492 op_if ! ( exists_prefix if EXISTS_PREFIX ) ;
471493 op_if ! ( refresh if REFRESH ) ;
494+ op_if ! ( writemidx if WRITE_MULTIPACK_INDEX ) ;
472495 op_if ! ( freshen if FRESHEN ) ;
473496
474497 backend. free = Some ( Backend :: < B > :: free) ;
@@ -648,6 +671,15 @@ impl<B: OdbBackend> Backend<B> {
648671 raw:: GIT_OK
649672 }
650673
674+ extern "C" fn writemidx ( backend_ptr : * mut raw:: git_odb_backend ) -> libc:: c_int {
675+ let backend = unsafe { backend_ptr. cast :: < Self > ( ) . as_mut ( ) . unwrap ( ) } ;
676+ let context = OdbBackendContext { backend_ptr } ;
677+ if let Err ( e) = backend. inner . write_multipack_index ( & context) {
678+ return unsafe { e. raw_set_git_error ( ) } ;
679+ }
680+ raw:: GIT_OK
681+ }
682+
651683 extern "C" fn freshen (
652684 backend_ptr : * mut raw:: git_odb_backend ,
653685 oid_ptr : * const raw:: git_oid ,
0 commit comments