##// END OF EJS Templates
parsers: fix invariant bug in find_deepest (issue5623)...
Sune Foldager -
r33475:f5013225 default
parent child Browse files
Show More
@@ -1464,7 +1464,7 b' static PyObject *find_deepest(indexObjec'
1464 goto bail;
1464 goto bail;
1465 }
1465 }
1466
1466
1467 interesting = calloc(sizeof(*interesting), 2 << revcount);
1467 interesting = calloc(sizeof(*interesting), 1 << revcount);
1468 if (interesting == NULL) {
1468 if (interesting == NULL) {
1469 PyErr_NoMemory();
1469 PyErr_NoMemory();
1470 goto bail;
1470 goto bail;
@@ -1481,6 +1481,8 b' static PyObject *find_deepest(indexObjec'
1481 interesting[b] = 1;
1481 interesting[b] = 1;
1482 }
1482 }
1483
1483
1484 /* invariant: ninteresting is the number of non-zero entries in
1485 * interesting. */
1484 ninteresting = (int)revcount;
1486 ninteresting = (int)revcount;
1485
1487
1486 for (v = maxrev; v >= 0 && ninteresting > 1; v--) {
1488 for (v = maxrev; v >= 0 && ninteresting > 1; v--) {
@@ -1523,8 +1525,10 b' static PyObject *find_deepest(indexObjec'
1523 continue;
1525 continue;
1524 seen[p] = nsp;
1526 seen[p] = nsp;
1525 interesting[sp] -= 1;
1527 interesting[sp] -= 1;
1526 if (interesting[sp] == 0 && interesting[nsp] > 0)
1528 if (interesting[sp] == 0)
1527 ninteresting -= 1;
1529 ninteresting -= 1;
1530 if (interesting[nsp] == 0)
1531 ninteresting += 1;
1528 interesting[nsp] += 1;
1532 interesting[nsp] += 1;
1529 }
1533 }
1530 }
1534 }
@@ -217,14 +217,16 b' def test_lazyancestors():'
217
217
218
218
219 # The C gca algorithm requires a real repo. These are textual descriptions of
219 # The C gca algorithm requires a real repo. These are textual descriptions of
220 # DAGs that have been known to be problematic.
220 # DAGs that have been known to be problematic, and, optionally, known pairs
221 # of revisions and their expected ancestor list.
221 dagtests = [
222 dagtests = [
222 '+2*2*2/*3/2',
223 ('+2*2*2/*3/2', {}),
223 '+3*3/*2*2/*4*4/*4/2*4/2*2',
224 ('+3*3/*2*2/*4*4/*4/2*4/2*2', {}),
225 ('+2*2*/2*4*/4*/3*2/4', {(6, 7): [3, 5]}),
224 ]
226 ]
225 def test_gca():
227 def test_gca():
226 u = uimod.ui.load()
228 u = uimod.ui.load()
227 for i, dag in enumerate(dagtests):
229 for i, (dag, tests) in enumerate(dagtests):
228 repo = hg.repository(u, b'gca%d' % i, create=1)
230 repo = hg.repository(u, b'gca%d' % i, create=1)
229 cl = repo.changelog
231 cl = repo.changelog
230 if not util.safehasattr(cl.index, 'ancestors'):
232 if not util.safehasattr(cl.index, 'ancestors'):
@@ -235,15 +237,21 b' def test_gca():'
235 # Compare the results of the Python and C versions. This does not
237 # Compare the results of the Python and C versions. This does not
236 # include choosing a winner when more than one gca exists -- we make
238 # include choosing a winner when more than one gca exists -- we make
237 # sure both return exactly the same set of gcas.
239 # sure both return exactly the same set of gcas.
240 # Also compare against expected results, if available.
238 for a in cl:
241 for a in cl:
239 for b in cl:
242 for b in cl:
240 cgcas = sorted(cl.index.ancestors(a, b))
243 cgcas = sorted(cl.index.ancestors(a, b))
241 pygcas = sorted(ancestor.ancestors(cl.parentrevs, a, b))
244 pygcas = sorted(ancestor.ancestors(cl.parentrevs, a, b))
242 if cgcas != pygcas:
245 expected = None
246 if (a, b) in tests:
247 expected = tests[(a, b)]
248 if cgcas != pygcas or (expected and cgcas != expected):
243 print("test_gca: for dag %s, gcas for %d, %d:"
249 print("test_gca: for dag %s, gcas for %d, %d:"
244 % (dag, a, b))
250 % (dag, a, b))
245 print(" C returned: %s" % cgcas)
251 print(" C returned: %s" % cgcas)
246 print(" Python returned: %s" % pygcas)
252 print(" Python returned: %s" % pygcas)
253 if expected:
254 print(" expected: %s" % expected)
247
255
248 def main():
256 def main():
249 seed = None
257 seed = None
General Comments 0
You need to be logged in to leave comments. Login now