| 144 | |
| 145 | |
| 146 | int |
| 147 | Oid_init(Oid *self, PyObject *args, PyObject *kw) |
| 148 | { |
| 149 | char *keywords[] = {"raw", "hex", NULL}; |
| 150 | PyObject *raw = NULL, *hex = NULL; |
| 151 | int err; |
| 152 | char *bytes; |
| 153 | Py_ssize_t len; |
| 154 | |
| 155 | if (!PyArg_ParseTupleAndKeywords(args, kw, "|OO", keywords, &raw, &hex)) |
| 156 | return -1; |
| 157 | |
| 158 | /* We expect one or the other, but not both. */ |
| 159 | if (raw == NULL && hex == NULL) { |
| 160 | PyErr_SetString(PyExc_ValueError, "Expected raw or hex."); |
| 161 | return -1; |
| 162 | } |
| 163 | if (raw != NULL && hex != NULL) { |
| 164 | PyErr_SetString(PyExc_ValueError, "Expected raw or hex, not both."); |
| 165 | return -1; |
| 166 | } |
| 167 | |
| 168 | /* Case 1: raw */ |
| 169 | if (raw != NULL) { |
| 170 | err = PyBytes_AsStringAndSize(raw, &bytes, &len); |
| 171 | if (err) |
| 172 | return -1; |
| 173 | |
| 174 | if (len > GIT_OID_RAWSZ) { |
| 175 | PyErr_SetObject(PyExc_ValueError, raw); |
| 176 | return -1; |
| 177 | } |
| 178 | |
| 179 | memcpy(self->oid.id, (const unsigned char*)bytes, len); |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | /* Case 2: hex */ |
| 184 | len = py_hex_to_git_oid(hex, &self->oid); |
| 185 | if (len == 0) |
| 186 | return -1; |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | |
| 192 | Py_hash_t |
nothing calls this directly
no test coverage detected
searching dependent graphs…