Project

General

Profile

Actions

Defect #44231

closed

Mercurial repository support is broken with Mercurial 7.2 or later

Added by Holger Just 4 months ago. Updated 8 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
SCM
Target version:
Resolution:
Fixed
Affected version:

Description

It seems that the redmine_helper.py needs to be updated for more modern Mercurial versions. At least the rhsummary call used by Redmine::Scm::Adaptes::MercurialAdapter#summary seems to fail. I tested this with the current trunk at r24831.

hg -R tmp/test/mercurial_repository --encoding=utf-8 --config extensions.redminehelper=lib/redmine/scm/adapters/mercurial/redminehelper.py --config redminehelper.path_encoding= --config diff.git=false rhsummary

This outputs the following:

<?xml version="1.0"?>
<rhsummary>
<repository root="/redmine/tmp/test/mercurial_repository">
<tip revision="42" node="ba20ebce08dbd2f0320b93faf7bba7c86186a1f7"/>
<tag revision="37" node="cf5f7c556f5a643e1ec7cb01775be539f64eeefb" name="double%22quote%22tag"/>
<tag revision="21" node="adf805632193500ad3b615cd04f58f9b0769f576" name="tag-%C3%9C-00"/>
<tag revision="5" node="6987191f453a5f6557018d522feea2c450d5588d" name="tag_test.00"/>
<tag revision="0" node="0885933ad4f68d77c2649cd11f8311276e7ef7ce" name="tag-init-revision"/>
</repository>
</rhsummary>
** Unknown exception encountered with possibly-broken third-party extension "redminehelper" (version N/A)
** which supports versions unknown of Mercurial.
** Please disable "redminehelper" and try your action again.
** If that fixes the bug please report it to the extension author.
** Python 3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]
** Mercurial Distributed SCM (version 7.2.3)
** Extensions loaded: redminehelper
Traceback (most recent call last):
  File "/opt/homebrew/bin/hg", line 51, in <module>
    dispatch.run()
    ~~~~~~~~~~~~^^
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 100, in run
    status = dispatch(req)
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 189, in dispatch
    status = _rundispatch(req)
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 239, in _rundispatch
    ret = _runcatch(req) or 0
          ~~~~~~~~~^^^^^
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 435, in _runcatch
    return _callcatch(ui, _runcatchfunc)
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 445, in _callcatch
    return scmutil.callcatch(ui, func)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/scmutil.py", line 202, in callcatch
    return func()
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 425, in _runcatchfunc
    return _dispatch(req)
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 930, in _dispatch
    return _dispatch_post_cwd(req)
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 1195, in _dispatch_post_cwd
    return runcommand(
        lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions
    )
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 862, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 1208, in _runcommand
    return cmdfunc()
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/dispatch.py", line 1193, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
                ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.14/site-packages/mercurial/util.py", line 1998, in check
    return func(*args, **kwargs)
  File "lib/redmine/scm/adapters/mercurial/redminehelper.py", line 251, in rhsummary
    _branches(ui, repo)
    ~~~~~~~~~^^^^^^^^^^
  File "lib/redmine/scm/adapters/mercurial/redminehelper.py", line 116, in _branches
    for t, n, r in sorted(iterbranches(), key=lambda e: e[2], reverse=True):
                   ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/redmine/scm/adapters/mercurial/redminehelper.py", line 104, in iterbranches
    for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'BranchCacheV2' object has no attribute 'iterbranches'

Files

Actions #1

Updated by Holger Just 4 months ago

It seems that the iterbranches method was removed in Mercurial 7.2 with https://repo.mercurial-scm.org/hg/rev/02010bf96a32

Possibly related to this is the TortoiseHG project working on this very issue: https://groups.google.com/g/thg-dev/c/4ATavKiCuDA

Actions #3

Updated by Go MAEDA 10 days ago

I am attaching two patches that fix this issue.

Mercurial 7.2 removed two methods that the rhsummary command in redminehelper.py uses to list branches:

  • branchcache.iterbranches(), as Holger Just pointed out
  • localrepo.branchheads()

Because of this, rhsummary fails with AttributeError. The Mercurial adapter depends on the output of rhsummary, so other operations such as cat and annotate fail as well.

The first patch removes code for Mercurial versions older than 5.1 from redminehelper.py. Redmine has not supported those versions since #33784, so this code can no longer be reached. This patch does not change any behavior. It only makes the second patch smaller and easier to review.

The second patch fixes the issue. It replaces the two removed methods as follows:

  • repo.branchmap().iterbranches() is replaced with iteration over the branchmap and branchtip()
  • repo.branchheads() is replaced with repo.branchmap().branchheads()

These replacements return the same values as the removed methods. They also exist in Mercurial 5.1, which is the oldest version that Redmine supports.

With both patches applied, all Mercurial tests pass with both Mercurial 7.1.2 and 7.2.4. In addition, with Mercurial 7.1.2, the output of rhsummary for the test repository is identical with and without the patches. The output with Mercurial 7.2.4 and the patches is also the same.

Actions #4

Updated by Go MAEDA 10 days ago

  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patches in r25235 and r25236.

Actions #5

Updated by Go MAEDA 8 days ago

  • Status changed from Resolved to Closed

Merged the fix into the stable branches in r25250 and r25251.

Actions #6

Updated by Holger Just 8 days ago

Thank you!

Actions

Also available in: Atom PDF