Edgewall Software
Modify

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#13419 closed defect (fixed)

walkchangerevs has been moved to scmutil from cmdutil in Mercurial 5.6

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>

Attachments (1)

t13419.diff (4.6 KB ) - added by Jun Omae 3 years ago.

Download all attachments as: .zip

Change History (12)

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, 3 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, 2 years 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, 2 years 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, 2 years ago

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

comment:7 by Jun Omae, 2 years 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, 2 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

comment:9 by Jun Omae, 2 years ago

1.0.0.10 released ([3fedb001bed9/mercurial-plugin]) and 1.0.0.11dev prepared ([070b8c031955/mercurial-plugin]).

in reply to:  9 comment:10 by Ryan J Ollos, 2 years ago

Replying to Jun Omae:

1.0.0.10 released ([3fedb001bed9/mercurial-plugin])

Thanks, do you plan to push it to TracMercurial?

comment:11 by Jun Omae, 2 years ago

Thanks for the reminding me.

I just pushed as TracMercurial/1.0.0.10.

$ python2 setup.py compile_catalog sdist bdist_wheel
$ twine check dist/*
Checking dist/TracMercurial-1.0.0.10-py2-none-any.whl: PASSED with warnings
WARNING  `long_description_content_type` missing. defaulting to `text/x-rst`.
Checking dist/TracMercurial-1.0.0.10.tar.gz: PASSED with warnings
WARNING  `long_description_content_type` missing. defaulting to `text/x-rst`.
$ twine upload -r pypi dist/*
Uploading distributions to https://upload.pypi.org/legacy/
Uploading TracMercurial-1.0.0.10-py2-none-any.whl
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 34.6/34.6 kB • 00:00 • 130.6 MB/s
Uploading TracMercurial-1.0.0.10.tar.gz
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 25.2/25.2 kB • 00:00 • 112.4 MB/s

View at:
https://pypi.org/project/TracMercurial/1.0.0.10/

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.