MCPcopy Create free account
hub / github.com/libgit2/pygit2 / Oid_init

Function Oid_init

src/oid.c:146–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144
145
146int
147Oid_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
192Py_hash_t

Callers

nothing calls this directly

Calls 1

py_hex_to_git_oidFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…