@@ -9,7 +9,7 @@ use std::mem::ManuallyDrop;
9
9
use std:: ptr:: NonNull ;
10
10
use std:: { ptr, slice} ;
11
11
12
- /// A custom implementation of an [`Odb`] backend.
12
+ /// A custom implementation of an [`Odb`](crate::Odb) backend.
13
13
///
14
14
/// Most of the default implementations of this trait's methods panic when called as they are
15
15
/// intended to be overridden.
@@ -273,11 +273,33 @@ pub trait OdbBackend {
273
273
unimplemented ! ( "OdbBackend::freshen" )
274
274
}
275
275
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
+
276
299
// TODO: fn writestream()
277
300
// TODO: fn readstream()
278
301
// TODO: fn foreach()
279
302
// TODO: fn writepack()
280
- // TODO: fn writemidx()
281
303
}
282
304
283
305
bitflags ! {
@@ -305,10 +327,10 @@ bitflags! {
305
327
const REFRESH = 1 << 7 ;
306
328
/// The backend supports the [`OdbBackend::foreach`] method.
307
329
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 ;
312
334
/// The backend supports the [`OdbBackend::freshen`] method.
313
335
const FRESHEN = 1 << 11 ;
314
336
}
@@ -469,6 +491,7 @@ impl<'a, B: OdbBackend> CustomOdbBackend<'a, B> {
469
491
op_if ! ( exists if EXISTS ) ;
470
492
op_if ! ( exists_prefix if EXISTS_PREFIX ) ;
471
493
op_if ! ( refresh if REFRESH ) ;
494
+ op_if ! ( writemidx if WRITE_MULTIPACK_INDEX ) ;
472
495
op_if ! ( freshen if FRESHEN ) ;
473
496
474
497
backend. free = Some ( Backend :: < B > :: free) ;
@@ -648,6 +671,15 @@ impl<B: OdbBackend> Backend<B> {
648
671
raw:: GIT_OK
649
672
}
650
673
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
+
651
683
extern "C" fn freshen (
652
684
backend_ptr : * mut raw:: git_odb_backend ,
653
685
oid_ptr : * const raw:: git_oid ,
0 commit comments