comparison mercurial/cext/revlog.c @ 39219:f85b25608252

index: move raise_revlog_error() further up I will add another caller below it. Differential Revision: https://phab.mercurial-scm.org/D4119
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 03 Aug 2018 23:03:13 -0700
parents b85b377e7fc2
children fcaffbd7e635
comparison
equal deleted inserted replaced
39218:b85b377e7fc2 39219:f85b25608252
100 static const char *const tuple_format = PY23("kiiiiiis#", "kiiiiiiy#"); 100 static const char *const tuple_format = PY23("kiiiiiis#", "kiiiiiiy#");
101 #endif 101 #endif
102 102
103 /* A RevlogNG v1 index entry is 64 bytes long. */ 103 /* A RevlogNG v1 index entry is 64 bytes long. */
104 static const long v1_hdrsize = 64; 104 static const long v1_hdrsize = 64;
105
106 static void raise_revlog_error(void)
107 {
108 PyObject *mod = NULL, *dict = NULL, *errclass = NULL;
109
110 mod = PyImport_ImportModule("mercurial.error");
111 if (mod == NULL) {
112 goto cleanup;
113 }
114
115 dict = PyModule_GetDict(mod);
116 if (dict == NULL) {
117 goto cleanup;
118 }
119 Py_INCREF(dict);
120
121 errclass = PyDict_GetItemString(dict, "RevlogError");
122 if (errclass == NULL) {
123 PyErr_SetString(PyExc_SystemError,
124 "could not find RevlogError");
125 goto cleanup;
126 }
127
128 /* value of exception is ignored by callers */
129 PyErr_SetString(errclass, "RevlogError");
130
131 cleanup:
132 Py_XDECREF(dict);
133 Py_XDECREF(mod);
134 }
105 135
106 /* 136 /*
107 * Return a pointer to the beginning of a RevlogNG record. 137 * Return a pointer to the beginning of a RevlogNG record.
108 */ 138 */
109 static const char *index_deref(indexObject *self, Py_ssize_t pos) 139 static const char *index_deref(indexObject *self, Py_ssize_t pos)
1282 if (rev >= 0) 1312 if (rev >= 0)
1283 return rev; 1313 return rev;
1284 return -2; 1314 return -2;
1285 } 1315 }
1286 1316
1287 static void raise_revlog_error(void)
1288 {
1289 PyObject *mod = NULL, *dict = NULL, *errclass = NULL;
1290
1291 mod = PyImport_ImportModule("mercurial.error");
1292 if (mod == NULL) {
1293 goto cleanup;
1294 }
1295
1296 dict = PyModule_GetDict(mod);
1297 if (dict == NULL) {
1298 goto cleanup;
1299 }
1300 Py_INCREF(dict);
1301
1302 errclass = PyDict_GetItemString(dict, "RevlogError");
1303 if (errclass == NULL) {
1304 PyErr_SetString(PyExc_SystemError,
1305 "could not find RevlogError");
1306 goto cleanup;
1307 }
1308
1309 /* value of exception is ignored by callers */
1310 PyErr_SetString(errclass, "RevlogError");
1311
1312 cleanup:
1313 Py_XDECREF(dict);
1314 Py_XDECREF(mod);
1315 }
1316
1317 static PyObject *index_getitem(indexObject *self, PyObject *value) 1317 static PyObject *index_getitem(indexObject *self, PyObject *value)
1318 { 1318 {
1319 char *node; 1319 char *node;
1320 int rev; 1320 int rev;
1321 1321