10000 Implement OdbBackend.refresh · libgit2/pygit2@ded2b4e · GitHub
[go: up one dir, main page]

Skip to content

Commit ded2b4e

Browse files
committed
Implement OdbBackend.refresh
1 parent 2767e5f commit ded2b4e

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/odb_backend.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,23 @@ pygit2_odb_backend_exists_prefix(git_oid *out, git_odb_backend *_be,
235235
return 0;
236236
}
237237

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+
238255
static void
239256
pygit2_odb_backend_free(git_odb_backend *_be)
240257
{
@@ -318,14 +335,14 @@ OdbBackend_init(OdbBackend *self, PyObject *args, PyObject *kwds)
318335
Py_INCREF(be->exists_prefix);
319336
}
320337

321-
/*
322338
be->refresh = PyObject_GetAttrString(
323339
(PyObject *)self, "refresh");
324340
if (be->refresh) {
325341
be->backend.refresh = pygit2_odb_backend_refresh;
326342
Py_INCREF(be->refresh);
327343
}
328344

345+
/*
329346
be->writepack = PyObject_GetAttrString(
330347
(PyObject *)self, "writepack");
331348
if (be->writepack) {
@@ -584,12 +601,35 @@ OdbBackend_exists_prefix(OdbBackend *self, PyObject *py_hex)
584601
return git_oid_to_python(&out);
585602
}
586603

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+
587626
PyMethodDef OdbBackend_methods[] = {
588627
METHOD(OdbBackend, read, METH_O),
589628
METHOD(OdbBackend, read_prefix, METH_O),
590629
METHOD(OdbBackend, read_header, METH_O),
591630
METHOD(OdbBackend, exists, METH_O),
592631
METHOD(OdbBackend, exists_prefix, METH_O),
632+
METHOD(OdbBackend, refresh, METH_NOARGS),
593633
{NULL}
594634
};
595635

0 commit comments

Comments
 (0)
0