Edgewall Software

Opened 3 years ago

Closed 21 months ago

Last modified 21 months ago

#13419 closed defect (fixed)

walkchangerevs has been moved to scmutil from cmdutil in Mercurial 5.6 — at Version 8

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone:
Component: plugin/mercurial Version: 1.4.3
Severity: normal Keywords: patch
Cc: Branch:
Release Notes:

Compatibility fix with Mercurial 5.6+.

API Changes:
Internal Changes:

Description

TracMercurial tests fail with Mercurial 5.6+, due to walkchangerevs being moved to scmutil from cmdutil.

refs: https://www.mercurial-scm.org/repo/hg/rev/508dfd1c18df

======================================================================
ERROR: test_on_empty_repos (tracext.hg.tests.backend.MercurialNormalTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 223, in test_on_empty_repos
    self.assertEqual([(u'/', nullrev, 'add')], list(node.get_history()))
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/backend.py", line 1184, in get_history
    if arity(cmdutil.walkchangerevs) == 4:
AttributeError: 'module' object has no attribute 'walkchangerevs'

----------------------------------------------------------------------
Ran 17 tests in 0.335s

FAILED (errors=1)
Test failed: <unittest.runner.TextTestResult run=17 errors=1 failures=0>
error: Test failed: <unittest.runner.TextTestResult run=17 errors=1 failures=0>

I applied the following patch to quickly fix it, but TypeError: 'alwaysmatcher' object is not iterable is raised. walkchangerevs's interface has been changed in https://www.mercurial-scm.org/repo/hg/rev/0356b41fe01d.

diff -r c29da66b9469 tracext/hg/backend.py
--- a/tracext/hg/backend.py     Thu Jan 17 15:29:26 2019 -0800
+++ b/tracext/hg/backend.py     Thu Sep 16 13:04:29 2021 +0900
@@ -132,6 +132,11 @@
     has_bookmarks = bool(listbookmarks)
     has_phasestr = None

+    if hasattr(cmdutil, 'walkchangerevs'):
+        from mercurial.cmdutil import walkchangerevs
+    else:
+        from mercurial.scmutil import walkchangerevs
+
 except ImportError, e:
     hg_import_error = exception_to_unicode(e)
     ui = object
@@ -1181,7 +1186,7 @@
         opts = {'rev': ['%s:0' % self.changectx.hex()]}
         if self.isfile and self.repos.version_info < (2, 1, 1):
             opts['follow'] = True
-        if arity(cmdutil.walkchangerevs) == 4:
+        if arity(walkchangerevs) == 4:
             return self._get_history_1_4(repo, pats, opts, limit)
         else:
             return self._get_history_1_3(repo, pats, opts, limit)
@@ -1201,7 +1206,7 @@
         path = self.path
         entry = None
         count = 0
-        for ctx in cmdutil.walkchangerevs(repo, matcher, opts, prep):
+        for ctx in walkchangerevs(repo, matcher, opts, prep):
             if self.isfile and entry:
                 path = fncache[ctx.rev()]
                 if path != entry[0]:
@@ -1225,8 +1230,7 @@
         get = cachefunc(changefn)
         if self.isfile:
             fncache = {}
-        chgiter, matchfn = cmdutil.walkchangerevs(self.repos.ui, repo, pats,
-                                                  get, opts)
+        chgiter, matchfn = walkchangerevs(self.repos.ui, repo, pats, get, opts)
         # keep one lookahead entry so that we can detect renames
         path = self.path
         entry = None
======================================================================
ERROR: test_on_empty_repos (tracext.hg.tests.backend.MercurialNormalTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 223, in test_on_empty_repos
    self.assertEqual([(u'/', nullrev, 'add')], list(node.get_history()))
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/backend.py", line 1209, in _get_history_1_4
    for ctx in walkchangerevs(repo, matcher, opts, prep):
  File "/home/jun66j5/src/mercurial-plugin/.tox/py27-trac14-hg56/lib/python2.7/site-packages/mercurial/scmutil.py", line 790, in iterate
    it = iter(revs)
TypeError: 'alwaysmatcher' object is not iterable

----------------------------------------------------------------------
Ran 17 tests in 0.344s

FAILED (errors=1)
Test failed: <unittest.runner.TextTestResult run=17 errors=1 failures=0>
error: Test failed: <unittest.runner.TextTestResult run=17 errors=1 failures=0>

Change History (9)

by Jun Omae, 3 years ago

Attachment: t13419.diff added

comment:1 by Jun Omae, 3 years ago

Owner: set to Jun Omae
Status: newassigned

Proposed changes in attachment:t13419.diff (verified with Mercurial 4.5 - 5.9 on Python 2.7).

comment:2 by Jun Omae, 3 years ago

Mercurial 6.0 has been released on 2021-11-23, the last release to support Python 2.

Verified all tests pass on Mercurial 6.0 with proposed patch in comment:1.

comment:3 by Jun Omae, 2 years ago

Release6.1 released on 2022-03-01. This release still supports Python 2. Verified all tests pass on Mercurial 6.1 with the patch.

comment:4 by figaro, 21 months ago

Keywords: patch added

The latest releases Mercurial 6.2 (2022-07-11) to 6.2.1 (2022-07-28) support Py3 only: https://www.mercurial-scm.org/wiki/Release6.2

Jun, are you okay to run your tests against the newest version(s), just so that Trac does not run into a regression?

comment:5 by Jun Omae, 21 months ago

Mercurial plugin doesn't work with Mercurial 6.2+ because the plugin is not compatible with Python 3 yet. We need work to make compatible with Python 3.

Traceback (most recent call last):
  File "/vol/src/mercurial-plugin/setup.py", line 38, in <module>
    setup(name='TracMercurial',
  File "/vol/src/mercurial-plugin/.tox/py310-trac15-hg62/lib/python3.10/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.10/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.10/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.10/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/vol/src/mercurial-plugin/.tox/py310-trac15-hg62/lib/python3.10/site-packages/setuptools/command/test.py", line 232, in run
    self.run_tests()
  File "/vol/src/mercurial-plugin/.tox/py310-trac15-hg62/lib/python3.10/site-packages/setuptools/command/test.py", line 250, in run_tests
    test = unittest.main(
  File "/usr/lib/python3.10/unittest/main.py", line 100, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python3.10/unittest/main.py", line 147, in parseArgs
    self.createTests()
  File "/usr/lib/python3.10/unittest/main.py", line 158, in createTests
    self.test = self.testLoader.loadTestsFromNames(self.testNames,
  File "/usr/lib/python3.10/unittest/loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python3.10/unittest/loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python3.10/unittest/loader.py", line 154, in loadTestsFromName
    module = __import__(module_name)
  File "/vol/src/mercurial-plugin/tracext/hg/tests/__init__.py", line 15, in <module>
    from tracext.hg.tests import backend
  File "/vol/src/mercurial-plugin/tracext/hg/tests/backend.py", line 36, in <module>
    from tracext.hg.backend import MercurialConnector, MercurialRepository
  File "/vol/src/mercurial-plugin/tracext/hg/backend.py", line 69
    except ImportError, hg_import_error:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized

comment:6 by figaro, 21 months ago

Ok, thanks. But that means that this ticket can be closed?

comment:7 by Jun Omae, 21 months ago

I'm going to push the patch. Also, I just filed #13493 to make compatible mercurial plugin with Python 3 (Mercurial 6.2+ and Trac 1.5.3+).

comment:8 by Jun Omae, 21 months ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.