Vote #79305
完了Mercurial 4.6 compatibility
0%
説明
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:
** 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 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 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
journals
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).
<pre>
# 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)
</pre>
--------------------------------------------------------------------------------
Marc Schlaich, thank you for posting the patch. I will test with the latest version of Mercurial.
--------------------------------------------------------------------------------
Thanks a lot !
Redmine seems back to normal using this patch with HG 4.6 !
--------------------------------------------------------------------------------
Some tests still fail after applying the patch. Could you look into this?
{{collapse(failed tests)
<pre>
$ hg --version
Mercurial Distributed SCM (version 4.6)
(see https://mercurial-scm.org for more information)
Copyright (C) 2005-2018 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ find test/ -name '*mercurial*' | xargs -n1 ruby
Run options: --seed 24364
# Running:
.............F
Failure:
MercurialAdapterTest#test_branches [test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb:338]:
Expected: 7
Actual: 0
bin/rails test test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb:333
........F
Failure:
MercurialAdapterTest#test_branchmap [test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb:372]:
--- expected
+++ actual
@@ -1 +1 @@
-{"default"=>"31eeee7395c8c78e66dd54c50addd078d10b2355", "test_branch.latin-1"=>"c2ffe7da686aa3d956e59f2a2854cf8980a8b768", "branch (1)[2]&,%.-3_4"=>"afc61e85bde74de930e5846c8451bd55b5bafc9c", "test-branch-00"=>"3a330eb329586ea2adb3f83237c23310e744ebe9", "test-branch-01"=>"ad4dc4f80284a4f9168b77e0b6de288e5d207ee7", "branch-Ü-00"=>"c8d3e4887474af6a589190140508037ebaa9d9c3", "branch-Ü-01"=>"7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914"}
+{}
bin/rails test test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb:362
...
Finished in 11.952060s, 2.1754 runs/s, 42.6705 assertions/s.
26 runs, 510 assertions, 2 failures, 0 errors, 0 skips
Run options: --seed 46581
# Running:
....F
Failure:
RepositoryMercurialTest#test_latest_changesets_default_branch_short_id [test/unit/repository_mercurial_test.rb:385]:
--- expected
+++ actual
@@ -1 +1 @@
-["31", "28", "24", "6", "4", "3", "2", "1", "0"]
+["33", "32", "31", "30", "29", "28", "27", "26", "25", "24"]
bin/rails test test/unit/repository_mercurial_test.rb:378
.......F
Failure:
RepositoryMercurialTest#test_latest_changesets_branch [test/unit/repository_mercurial_test.rb:357]:
--- expected
+++ actual
@@ -1 +1 @@
-["27", "26"]
+["33", "32", "31", "30", "29", "28", "27", "26", "25", "24"]
bin/rails test test/unit/repository_mercurial_test.rb:349
........F
Failure:
RepositoryMercurialTest#test_latest_changesets_default_branch [test/unit/repository_mercurial_test.rb:375]:
--- expected
+++ actual
@@ -1 +1 @@
-["31", "28", "24", "6", "4", "3", "2", "1", "0"]
+["33", "32", "31", "30", "29", "28", "27", "26", "25", "24"]
bin/rails test test/unit/repository_mercurial_test.rb:370
...................
Finished in 18.781790s, 2.1830 runs/s, 25.5034 assertions/s.
41 runs, 479 assertions, 3 failures, 0 errors, 0 skips
test/fixtures/repositories/mercurial_repository.hg:1:in `<main>': uninitialized constant HG10BZh91AY (NameError)
Run options: --seed 14690
# Running:
...F
Failure:
RepositoriesMercurialControllerTest#test_show_tag [test/functional/repositories_mercurial_controller_test.rb:249]:
Expected response to be a <2XX: success>, but was a <404: Not Found>
bin/rails test test/functional/repositories_mercurial_controller_test.rb:235
.......................F
Failure:
RepositoriesMercurialControllerTest#test_show_branch [test/functional/repositories_mercurial_controller_test.rb:228]:
Expected response to be a <2XX: success>, but was a <404: Not Found>
bin/rails test test/functional/repositories_mercurial_controller_test.rb:211
.
Finished in 18.196709s, 1.5937 runs/s, 17.0910 assertions/s.
29 runs, 311 assertions, 2 failures, 0 errors, 0 skips
</pre>
}}
--------------------------------------------------------------------------------
Indeed, branches are not shown in 4.6
I got branches back with the following change in the patch:
<pre><code>+ 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):
</code></pre>
But I have no idea whether this is correct !
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Committed to the trunk and stable branches.
Thank you all for reporting and fixing this issue.
--------------------------------------------------------------------------------