Project

General

Profile

Actions

Defect #28725

closed

Mercurial 4.6 compatibility

Added by Frédéric Fondement almost 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
SCM
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Hello,

My Redmine 3.4.5 can't display any info when checking a mercurial repository when I upgrade Mercurial from 4.5.3 to 4.6.

The following error is shown in production.log:

Started GET "/redmine/projects/nerdsarmy/repository" for aaa.bbb.ccc.ddd at 2018-05-09 21:07:37 +0200
Processing by RepositoriesController#show as HTML  Parameters: {"id"=>"nerdsarmy"}                                                                                                                                                       
  Current user: me@mydot.com (id=86)
hg: error during getting info: hg exited with non-zero status: 1
  Rendered common/error.html.erb within layouts/base (1.6ms)
  Rendered plugins/redmine_code_review/app/views/code_review/_html_header.html.erb (5.3ms)
  Rendered plugins/redmine_code_review/app/views/code_review/_change_repository_view.html.erb (0.1ms)
  Rendered plugins/redmine_code_review/app/views/code_review/_body_bottom.html.erb (2.2ms)
Completed 404 Not Found in 524ms (Views: 77.3ms | ActiveRecord: 10.2ms)

The command that triggers the error:

hg -R/hg/gl1718-nerdsarmy-model --encoding=utf-8 --config extensions.redminehelper=/redmine-3.4.5/lib/redmine/scm/adapters/mercurial/redminehelper.py --config diff.git=false rhsummary

whose result is:
<?xml version="1.0"?>
<rhsummary>
<repository root="/hg/gl1718-nerdsarmy-model">
</repository>
</rhsummary>
** Unknown exception encountered with possibly-broken third-party extension redminehelper
** 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 2.7.15 (default, May  9 2018, 19:47:00) [GCC 7.2.1 20170829 (Red Hat 7.2.1-1)]
** Mercurial version 4.6, système de gestion de sources distribué
** Extensions chargées : highlight, strip, redminehelper
Traceback (most recent call last):
  File "/usr/local/bin/hg", line 41, in <module>
    dispatch.run()
  File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py", line 90, in run
    status = (dispatch(req) or 0)
  File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py", line 210, in dispatch
    ret = _runcatch(req)
  File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py", line 351, in _runcatch
    return _callcatch(ui, _runcatchfunc)
  File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py", line 359, in _callcatch
    return scmutil.callcatch(ui, func)
  File "/usr/local/lib/python2.7/site-packages/mercurial/scmutil.py", line 160, in callcatch
    return func()
  File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py", line 341, in _runcatchfunc
    return _dispatch(req)
  File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py", line 971, in _dispatch
    cmdpats, cmdoptions)
  File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py", line 727, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py", line 979, in _runcommand
    return cmdfunc()
  File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py", line 968, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
  File "/usr/local/lib/python2.7/site-packages/mercurial/util.py", line 1553, in check
    return func(*args, **kwargs)
  File "/usr/share/redmine-3.4.5/lib/redmine/scm/adapters/mercurial/redminehelper.py", line 219, in rhsummary
    _tip(ui, repo)
  File "/usr/share/redmine-3.4.5/lib/redmine/scm/adapters/mercurial/redminehelper.py", line 64, in _tip
    tipctx = repo.changectx(tiprev())
  File "/usr/local/lib/python2.7/site-packages/mercurial/repoview.py", line 255, in __getattr
    return getattr(self._unfilteredrepo, attr)
AttributeError: 'localrepository' object has no attribute 'changectx'

All of this is back to normal when downgrading mercurial to 4.5.3

Regards


Files

fix-28725.diff (2.06 KB) fix-28725.diff updated patch by Frédéric Fondement (#28725#note-5) Go MAEDA, 2018-05-24 23:49
Actions #1

Updated by Marc Schlaich almost 6 years ago

Here is a patch.

BTW, the correct way communicating with Mercurial would be using the Command Server and not the internal API (see https://www.mercurial-scm.org/wiki/MercurialApi and https://www.mercurial-scm.org/wiki/CommandServer).

# HG changeset patch
# User schlamar <marc.schlaich@gmail.com>
# Date 1527142395 -7200
#      Thu May 24 08:13:15 2018 +0200
# Branch 3.4-stable
# Node ID ecbaecb1254177457490746a20060732b17fa642
# Parent  487d3d81d8a89f719f5e3d340472a13a29e1df62

diff -r 487d3d81d8a8 -r ecbaecb12541 lib/redmine/scm/adapters/mercurial/redminehelper.py
--- a/lib/redmine/scm/adapters/mercurial/redminehelper.py   Sat Apr 07 12:26:31 2018 +0000
+++ b/lib/redmine/scm/adapters/mercurial/redminehelper.py   Thu May 24 08:13:15 2018 +0200
@@ -54,6 +54,12 @@
 _x = cgi.escape
 _u = lambda s: cgi.escape(urllib.quote(s))

+def _changectx(repo, rev):
+    if hasattr(repo, 'changectx'):
+        return repo.changectx(rev)
+    else:
+        return repo[rev]
+
 def _tip(ui, repo):
     # see mercurial/commands.py:tip
     def tiprev():
@@ -61,7 +67,7 @@
             return len(repo) - 1
         except TypeError:  # Mercurial < 1.1
             return repo.changelog.count() - 1
-    tipctx = repo.changectx(tiprev())
+    tipctx = _changectx(repo, tiprev())
     ui.write('<tip revision="%d" node="%s"/>\n'
              % (tipctx.rev(), _x(node.hex(tipctx.node()))))

@@ -94,13 +100,18 @@
             return repo.branchheads(branch, closed=False)
         except TypeError:  # Mercurial < 1.2
             return repo.branchheads(branch)
+    def lookup(rev):
+        try:
+            return repo.lookup(rev)
+        except RuntimeError:
+            return repo[rev]
     for t, n, r in sorted(iterbranches(), key=lambda e: e[2], reverse=True):
-        if repo.lookup(r) in branchheads(t):
+        if lookup(r) in branchheads(t):
             ui.write('<branch revision="%d" node="%s" name="%s"/>\n'
                      % (r, _x(node.hex(n)), _x(t)))

 def _manifest(ui, repo, path, rev):
-    ctx = repo.changectx(rev)
+    ctx = _changectx(repo, rev)
     ui.write('<manifest revision="%d" path="%s">\n'
              % (ctx.rev(), _u(path)))

@@ -155,7 +166,7 @@
     """diff repository (or selected files)""" 
     change = opts.pop('change', None)
     if change:  # add -c option for Mercurial<1.1
-        base = repo.changectx(change).parents()[0].rev()
+        base = _changectx(repo, change).parents()[0].rev()
         opts['rev'] = [str(base), change]
     opts['nodates'] = True
     return commands.diff(ui, repo, *map(urllib.unquote_plus, pats), **opts)

Actions #2

Updated by Go MAEDA almost 6 years ago

  • Target version set to Candidate for next minor release

Marc Schlaich, thank you for posting the patch. I will test with the latest version of Mercurial.

Actions #3

Updated by Frédéric Fondement almost 6 years ago

Thanks a lot !
Redmine seems back to normal using this patch with HG 4.6 !

Actions #4

Updated by Go MAEDA almost 6 years ago

Some tests still fail after applying the patch. Could you look into this?

failed tests

Actions #5

Updated by Frédéric Fondement almost 6 years ago

Indeed, branches are not shown in 4.6

I got branches back with the following change in the patch:

+    def lookup(rev, n):
+        try:
+            return repo.lookup(rev)
+        except RuntimeError:
+            return n
     for t, n, r in sorted(iterbranches(), key=lambda e: e[2], reverse=True):
-        if repo.lookup(r) in branchheads(t):
+        if lookup(r, n) in branchheads(t):

But I have no idea whether this is correct !

Actions #6

Updated by Go MAEDA almost 6 years ago

  • File fix-28725.diff fix-28725.diff added
  • Subject changed from Mercurial 4.6 to Mercurial 4.6 compatibility
  • Target version changed from Candidate for next minor release to 3.3.8

Frédéric Fondement wrote:

Indeed, branches are not shown in 4.6

I got branches back with the following change in the patch:
[...]

Great, the updated patch passed all tests.
Setting target version to 3.3.8.

Actions #7

Updated by Go MAEDA almost 6 years ago

  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
Actions #8

Updated by Go MAEDA almost 6 years ago

  • Status changed from Resolved to Closed
  • Resolution set to Fixed

Committed to the trunk and stable branches.
Thank you all for reporting and fixing this issue.

Actions

Also available in: Atom PDF