215 s = genlazyancestors([11, 13], stoprev=6, inclusive=True) |
215 s = genlazyancestors([11, 13], stoprev=6, inclusive=True) |
216 printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) |
216 printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) |
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'): |
231 # C version not available |
233 # C version not available |
232 return |
234 return |
233 |
235 |
234 debugcommands.debugbuilddag(u, repo, dag) |
236 debugcommands.debugbuilddag(u, repo, dag) |
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 |
250 opts, args = getopt.getopt(sys.argv[1:], 's:', ['seed=']) |
258 opts, args = getopt.getopt(sys.argv[1:], 's:', ['seed=']) |
251 for o, a in opts: |
259 for o, a in opts: |