@@ -235,6 +235,23 @@ pygit2_odb_backend_exists_prefix(git_oid *out, git_odb_backend *_be,
235
235
return 0 ;
236
236
}
237
237
238
+ static int
239
+ pygit2_odb_backend_refresh (git_odb_backend * _be )
240
+ {
241
+ int err ;
242
+ PyObject * args ;
243
+ struct pygit2_odb_backend * be = (struct pygit2_odb_backend * )_be ;
244
+
245
+ args = Py_BuildValue ("()" ); /* XXX: Is this necessary? */
246
+ PyObject_CallObject (be -> exists_prefix , args );
247
+
248
+ if ((err = git_error_for_exc ()) != 0 ) {
249
+ return err ;
250
+ }
251
+
252
+ return 0 ;
253
+ }
254
+
238
255
static void
239
256
pygit2_odb_backend_free (git_odb_backend * _be )
240
257
{
@@ -318,14 +335,14 @@ OdbBackend_init(OdbBackend *self, PyObject *args, PyObject *kwds)
318
335
Py_INCREF (be -> exists_prefix );
319
336
}
320
337
321
- /*
322
338
be -> refresh = PyObject_GetAttrString (
323
339
(PyObject * )self , "refresh" );
324
340
if (be -> refresh ) {
325
341
be -> backend .refresh = pygit2_odb_backend_refresh ;
326
342
Py_INCREF (be -> refresh );
327
343
}
328
344
345
+ /*
329
346
be->writepack = PyObject_GetAttrString(
330
347
(PyObject *)self, "writepack");
331
348
if (be->writepack) {
@@ -584,12 +601,35 @@ OdbBackend_exists_prefix(OdbBackend *self, PyObject *py_hex)
584
601
return git_oid_to_python (& out );
585
602
}
586
603
604
+ PyDoc_STRVAR (OdbBackend_refresh__doc__ ,
605
+ "refresh()\n"
606
+ "\n"
607
+ "If the backend supports a refreshing mechanism, this function will invoke\n"
608
+ "it. However, the backend implementation should try to stay up-to-date as\n"
609
+ "much as possible by itself as libgit2 will not automatically invoke this\n"
610
+ "function. For instance, a potential strategy for the backend\n"
611
+ "implementation to utilize this could be internally calling the refresh\n"
612
+ "function on failed lookups." );
613
+
614
+ PyObject *
615
+ OdbBackend_refresh (OdbBackend * self )
616
+ {
617
+ if (self -> odb_backend -> refresh == NULL ) {
618
+ /* XXX: Should we no-op instead? */
619
+ Py_INCREF (Py_NotImplemented );
620
+ return Py_NotImplemented ;
621
+ }
622
+ self -> odb_backend -> refresh (self -> odb_backend );
623
+ return Py_None ;
624
+ }
625
+
587
626
PyMethodDef OdbBackend_methods [] = {
588
627
METHOD (OdbBackend , read , METH_O ),
589
628
METHOD (OdbBackend , read_prefix , METH_O ),
590
629
METHOD (OdbBackend , read_header , METH_O ),
591
630
METHOD (OdbBackend , exists , METH_O ),
592
631
METHOD (OdbBackend , exists_prefix , METH_O ),
632
+ METHOD (OdbBackend , refresh , METH_NOARGS ),
593
633
{NULL }
594
634
};
595
635
0 commit comments