3434
3535PyTypeObject OidType ;
3636
37+ static const git_oid oid_zero = GIT_OID_SHA1_ZERO ;
38+
3739
3840PyObject *
3941git_oid_to_python (const git_oid * oid )
@@ -255,6 +257,13 @@ Oid__str__(Oid *self)
255257 return git_oid_to_py_str (& self -> oid );
256258}
257259
260+ int
261+ Oid__bool (PyObject * self )
262+ {
263+ git_oid * oid = & ((Oid * )self )-> oid ;
264+ return !git_oid_equal (oid , & oid_zero );
265+ }
266+
258267PyDoc_STRVAR (Oid_raw__doc__ , "Raw oid, a 20 bytes string." );
259268
260269PyObject *
@@ -269,6 +278,45 @@ PyGetSetDef Oid_getseters[] = {
269278 {NULL },
270279};
271280
281+ PyNumberMethods Oid_as_number = {
282+ 0 , /* nb_add */
283+ 0 , /* nb_subtract */
284+ 0 , /* nb_multiply */
285+ 0 , /* nb_remainder */
286+ 0 , /* nb_divmod */
287+ 0 , /* nb_power */
288+ 0 , /* nb_negative */
289+ 0 , /* nb_positive */
290+ 0 , /* nb_absolute */
291+ Oid__bool , /* nb_bool */
292+ 0 , /* nb_invert */
293+ 0 , /* nb_lshift */
294+ 0 , /* nb_rshift */
295+ 0 , /* nb_and */
296+ 0 , /* nb_xor */
297+ 0 , /* nb_or */
298+ 0 , /* nb_int */
299+ 0 , /* nb_reserved */
300+ 0 , /* nb_float */
301+ 0 , /* nb_inplace_add */
302+ 0 , /* nb_inplace_subtract */
303+ 0 , /* nb_inplace_multiply */
304+ 0 , /* nb_inplace_remainder */
305+ 0 , /* nb_inplace_power */
306+ 0 , /* nb_inplace_lshift */
307+ 0 , /* nb_inplace_rshift */
308+ 0 , /* nb_inplace_and */
309+ 0 , /* nb_inplace_xor */
310+ 0 , /* nb_inplace_or */
311+ 0 , /* nb_floor_divide */
312+ 0 , /* nb_true_divide */
313+ 0 , /* nb_inplace_floor_divide */
314+ 0 , /* nb_inplace_true_divide */
315+ 0 , /* nb_index */
316+ 0 , /* nb_matrix_multiply */
317+ 0 , /* nb_inplace_matrix_multiply */
318+ };
319+
272320PyDoc_STRVAR (Oid__doc__ , "Object id." );
273321
274322PyTypeObject OidType = {
@@ -282,7 +330,7 @@ PyTypeObject OidType = {
282330 0 , /* tp_setattr */
283331 0 , /* tp_compare */
284332 (reprfunc )Oid__str__ , /* tp_repr */
285- 0 , /* tp_as_number */
333+ & Oid_as_number , /* tp_as_number */
286334 0 , /* tp_as_sequence */
287335 0 , /* tp_as_mapping */
288336 (hashfunc )Oid_hash , /* tp_hash */
0 commit comments