comparison mercurial/parsers.c @ 26043:f2f0a3ab6e41

reachableroots: rename "seen" array to "revstates" for future extension It will be an array of bit flags, SEEN | ROOT | REACHABLE.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 14 Aug 2015 15:23:42 +0900
parents 2a3010ba6f52
children b3ad349d0e50
comparison
equal deleted inserted replaced
26042:2a3010ba6f52 26043:f2f0a3ab6e41
1128 int minidx; 1128 int minidx;
1129 int parents[2]; 1129 int parents[2];
1130 1130
1131 /* Internal data structure: 1131 /* Internal data structure:
1132 * tovisit: array of length len+1 (all revs + nullrev), filled upto lentovisit 1132 * tovisit: array of length len+1 (all revs + nullrev), filled upto lentovisit
1133 * seen: array of length len+1 (all revs + nullrev) 0: not seen, 1 seen*/ 1133 * revstates: array of length len+1 (all revs + nullrev) 0: not seen, 1 seen*/
1134 int *tovisit = NULL; 1134 int *tovisit = NULL;
1135 long lentovisit = 0; 1135 long lentovisit = 0;
1136 char *seen = NULL; 1136 char *revstates = NULL;
1137 1137
1138 /* Get arguments */ 1138 /* Get arguments */
1139 if (!PyArg_ParseTuple(args, "lO!O!O!", &minroot, &PyList_Type, &heads, 1139 if (!PyArg_ParseTuple(args, "lO!O!O!", &minroot, &PyList_Type, &heads,
1140 &PySet_Type, &roots, &PyBool_Type, &includepatharg)) 1140 &PySet_Type, &roots, &PyBool_Type, &includepatharg))
1141 goto bail; 1141 goto bail;
1155 if (tovisit == NULL) { 1155 if (tovisit == NULL) {
1156 PyErr_NoMemory(); 1156 PyErr_NoMemory();
1157 goto bail; 1157 goto bail;
1158 } 1158 }
1159 1159
1160 seen = (char *)calloc(len+1, 1); 1160 revstates = (char *)calloc(len + 1, 1);
1161 if (seen == NULL) { 1161 if (revstates == NULL) {
1162 PyErr_NoMemory(); 1162 PyErr_NoMemory();
1163 goto bail; 1163 goto bail;
1164 } 1164 }
1165 1165
1166 /* Populate tovisit with all the heads */ 1166 /* Populate tovisit with all the heads */
1171 goto bail; 1171 goto bail;
1172 if (revnum + 1 < 0 || revnum + 1 >= len + 1) { 1172 if (revnum + 1 < 0 || revnum + 1 >= len + 1) {
1173 PyErr_SetString(PyExc_IndexError, "head out of range"); 1173 PyErr_SetString(PyExc_IndexError, "head out of range");
1174 goto bail; 1174 goto bail;
1175 } 1175 }
1176 if (seen[revnum+1] == 0) { 1176 if (revstates[revnum+1] == 0) {
1177 tovisit[lentovisit++] = revnum; 1177 tovisit[lentovisit++] = revnum;
1178 seen[revnum+1]=1; 1178 revstates[revnum+1]=1;
1179 } 1179 }
1180 } 1180 }
1181 1181
1182 /* Visit the tovisit list and find the reachable roots */ 1182 /* Visit the tovisit list and find the reachable roots */
1183 k = 0; 1183 k = 0;
1201 continue; 1201 continue;
1202 r = index_get_parents(self, revnum, parents, (int)len - 1); 1202 r = index_get_parents(self, revnum, parents, (int)len - 1);
1203 if (r < 0) 1203 if (r < 0)
1204 goto bail; 1204 goto bail;
1205 for (i = 0; i < 2; i++) { 1205 for (i = 0; i < 2; i++) {
1206 if (seen[parents[i] + 1] == 0 1206 if (revstates[parents[i] + 1] == 0
1207 && parents[i] >= minroot) { 1207 && parents[i] >= minroot) {
1208 tovisit[lentovisit++] = parents[i]; 1208 tovisit[lentovisit++] = parents[i];
1209 seen[parents[i] + 1] = 1; 1209 revstates[parents[i] + 1] = 1;
1210 } 1210 }
1211 } 1211 }
1212 } 1212 }
1213 1213
1214 /* Find all the nodes in between the roots we found and the heads 1214 /* Find all the nodes in between the roots we found and the heads
1216 if (includepath == 1) { 1216 if (includepath == 1) {
1217 minidx = minroot; 1217 minidx = minroot;
1218 if (minidx < 0) 1218 if (minidx < 0)
1219 minidx = 0; 1219 minidx = 0;
1220 for (i = minidx; i < len; i++) { 1220 for (i = minidx; i < len; i++) {
1221 if (seen[i + 1] != 1) 1221 if (revstates[i + 1] != 1)
1222 continue; 1222 continue;
1223 r = index_get_parents(self, i, parents, (int)len - 1); 1223 r = index_get_parents(self, i, parents, (int)len - 1);
1224 /* Corrupted index file, error is set from 1224 /* Corrupted index file, error is set from
1225 * index_get_parents */ 1225 * index_get_parents */
1226 if (r < 0) 1226 if (r < 0)
1239 Py_DECREF(p); 1239 Py_DECREF(p);
1240 } 1240 }
1241 } 1241 }
1242 } 1242 }
1243 1243
1244 free(seen); 1244 free(revstates);
1245 free(tovisit); 1245 free(tovisit);
1246 return reachable; 1246 return reachable;
1247 bail: 1247 bail:
1248 Py_XDECREF(reachable); 1248 Py_XDECREF(reachable);
1249 free(seen); 1249 free(revstates);
1250 free(tovisit); 1250 free(tovisit);
1251 return NULL; 1251 return NULL;
1252 } 1252 }
1253 1253
1254 static PyObject *compute_phases_map_sets(indexObject *self, PyObject *args) 1254 static PyObject *compute_phases_map_sets(indexObject *self, PyObject *args)