comparison mercurial/parsers.c @ 26044:b3ad349d0e50

reachableroots: extend "revstates" to array of bit flags
author Yuya Nishihara <yuya@tcha.org>
date Fri, 14 Aug 2015 15:30:52 +0900
parents f2f0a3ab6e41
children 0be2f81aadc3
comparison
equal deleted inserted replaced
26043:f2f0a3ab6e41 26044:b3ad349d0e50
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 * revstates: array of length len+1 (all revs + nullrev) 0: not seen, 1 seen*/ 1133 * revstates: array of length len+1 (all revs + nullrev) */
1134 int *tovisit = NULL; 1134 int *tovisit = NULL;
1135 long lentovisit = 0; 1135 long lentovisit = 0;
1136 enum { RS_SEEN = 1 };
1136 char *revstates = NULL; 1137 char *revstates = NULL;
1137 1138
1138 /* Get arguments */ 1139 /* Get arguments */
1139 if (!PyArg_ParseTuple(args, "lO!O!O!", &minroot, &PyList_Type, &heads, 1140 if (!PyArg_ParseTuple(args, "lO!O!O!", &minroot, &PyList_Type, &heads,
1140 &PySet_Type, &roots, &PyBool_Type, &includepatharg)) 1141 &PySet_Type, &roots, &PyBool_Type, &includepatharg))
1171 goto bail; 1172 goto bail;
1172 if (revnum + 1 < 0 || revnum + 1 >= len + 1) { 1173 if (revnum + 1 < 0 || revnum + 1 >= len + 1) {
1173 PyErr_SetString(PyExc_IndexError, "head out of range"); 1174 PyErr_SetString(PyExc_IndexError, "head out of range");
1174 goto bail; 1175 goto bail;
1175 } 1176 }
1176 if (revstates[revnum+1] == 0) { 1177 if (!(revstates[revnum + 1] & RS_SEEN)) {
1177 tovisit[lentovisit++] = revnum; 1178 tovisit[lentovisit++] = revnum;
1178 revstates[revnum+1]=1; 1179 revstates[revnum + 1] |= RS_SEEN;
1179 } 1180 }
1180 } 1181 }
1181 1182
1182 /* Visit the tovisit list and find the reachable roots */ 1183 /* Visit the tovisit list and find the reachable roots */
1183 k = 0; 1184 k = 0;
1201 continue; 1202 continue;
1202 r = index_get_parents(self, revnum, parents, (int)len - 1); 1203 r = index_get_parents(self, revnum, parents, (int)len - 1);
1203 if (r < 0) 1204 if (r < 0)
1204 goto bail; 1205 goto bail;
1205 for (i = 0; i < 2; i++) { 1206 for (i = 0; i < 2; i++) {
1206 if (revstates[parents[i] + 1] == 0 1207 if (!(revstates[parents[i] + 1] & RS_SEEN)
1207 && parents[i] >= minroot) { 1208 && parents[i] >= minroot) {
1208 tovisit[lentovisit++] = parents[i]; 1209 tovisit[lentovisit++] = parents[i];
1209 revstates[parents[i] + 1] = 1; 1210 revstates[parents[i] + 1] |= RS_SEEN;
1210 } 1211 }
1211 } 1212 }
1212 } 1213 }
1213 1214
1214 /* Find all the nodes in between the roots we found and the heads 1215 /* Find all the nodes in between the roots we found and the heads
1216 if (includepath == 1) { 1217 if (includepath == 1) {
1217 minidx = minroot; 1218 minidx = minroot;
1218 if (minidx < 0) 1219 if (minidx < 0)
1219 minidx = 0; 1220 minidx = 0;
1220 for (i = minidx; i < len; i++) { 1221 for (i = minidx; i < len; i++) {
1221 if (revstates[i + 1] != 1) 1222 if (!(revstates[i + 1] & RS_SEEN))
1222 continue; 1223 continue;
1223 r = index_get_parents(self, i, parents, (int)len - 1); 1224 r = index_get_parents(self, i, parents, (int)len - 1);
1224 /* Corrupted index file, error is set from 1225 /* Corrupted index file, error is set from
1225 * index_get_parents */ 1226 * index_get_parents */
1226 if (r < 0) 1227 if (r < 0)