| 200 | |
| 201 | |
| 202 | PyObject * |
| 203 | Oid_richcompare(PyObject *self, PyObject *other, int op) |
| 204 | { |
| 205 | git_oid *oid = &((Oid*)self)->oid; |
| 206 | int cmp; |
| 207 | |
| 208 | // Can compare an oid against another oid or a unicode string |
| 209 | if (PyObject_TypeCheck(other, &OidType)) { |
| 210 | cmp = git_oid_cmp(oid, &((Oid*)other)->oid); |
| 211 | } |
| 212 | else if (PyObject_TypeCheck(other, &PyUnicode_Type)) { |
| 213 | const char * str = PyUnicode_AsUTF8(other); |
| 214 | if (str == NULL) { |
| 215 | return NULL; |
| 216 | } |
| 217 | cmp = git_oid_strcmp(oid, str); |
| 218 | } |
| 219 | else { |
| 220 | Py_INCREF(Py_NotImplemented); |
| 221 | return Py_NotImplemented; |
| 222 | } |
| 223 | |
| 224 | // Return boolean |
| 225 | PyObject *res; |
| 226 | switch (op) { |
| 227 | case Py_LT: |
| 228 | res = (cmp <= 0) ? Py_True: Py_False; |
| 229 | break; |
| 230 | case Py_LE: |
| 231 | res = (cmp < 0) ? Py_True: Py_False; |
| 232 | break; |
| 233 | case Py_EQ: |
| 234 | res = (cmp == 0) ? Py_True: Py_False; |
| 235 | break; |
| 236 | case Py_NE: |
| 237 | res = (cmp != 0) ? Py_True: Py_False; |
| 238 | break; |
| 239 | case Py_GT: |
| 240 | res = (cmp > 0) ? Py_True: Py_False; |
| 241 | break; |
| 242 | case Py_GE: |
| 243 | res = (cmp >= 0) ? Py_True: Py_False; |
| 244 | break; |
| 245 | default: |
| 246 | PyErr_Format(PyExc_RuntimeError, "Unexpected '%d' op", op); |
| 247 | return NULL; |
| 248 | } |
| 249 | |
| 250 | Py_INCREF(res); |
| 251 | return res; |
| 252 | } |
| 253 | |
| 254 | PyObject * |
| 255 | Oid__str__(Oid *self) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…