Defect #29413

Mercurial 4.7 compatibility

Added by Frédéric Fondement 29 days ago. Updated 24 days ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:SCM
Target version:3.3.9
Resolution:Fixed Affected version:

Description

Hello,

Redmine 3.4.6 doesn't work with mercurial 4.7.
Logs say that in redmine/lib/redmine/scm/adapters/mercurial/redminehelper.py, module cmdutil does not have a command method.
Checking mercurial 4.6.1 source, this method is indeed deprecated ; it must have been removed from 4.7.
I got it back to work by following deprecation instruction which was "used registrar.command instead":

import re, time, cgi, urllib
from mercurial import cmdutil, commands, node, error, hg, registrar # added registrar

cmdtable = {}
command = registrar.command(cmdtable) # replaced cmdutil with registrar

Regards.

29413-mercurial-fix.diff Magnifier - Patch by Frédéric Fondement (#29413#note-5) (866 Bytes) Go MAEDA, 2018-08-22 05:47

Associated revisions

Revision 17474
Added by Go MAEDA 24 days ago

Mercurial 4.7 compatibility (#29413).

Patch by Frédéric Fondement.

Revision 17475
Added by Go MAEDA 24 days ago

Merged r17474 from trunk to 3.4-stable (#29413).

Revision 17476
Added by Go MAEDA 24 days ago

Merged r17474 from trunk to 3.3-stable (#29413).

History

#1 Updated by Go MAEDA 29 days ago

  • Target version set to 3.3.9

#2 Updated by Frédéric Fondement 29 days ago

Another problem with exploring branches using hg 4.7.
It can be solved by modifying _changectx of redmine/scm/adapters/mercurial/redminehelper.py:

def _changectx(repo, rev):
    if hasattr(repo, 'branchtip') and rev in repo.branchmap(): # mercurial 4.7 doesn't select on branch name
        rev = repo.branchtip(rev)
    if hasattr(repo, 'changectx'):
        return repo.changectx(rev)
    else:
        return repo[rev]

#3 Updated by Frédéric Fondement 29 days ago

Maybe clever:

def _changectx(repo, rev):
    if isinstance(rev, str):
        rev = repo.lookup(rev)
    if hasattr(repo, 'changectx'):
        return repo.changectx(rev)
    else:
        return repo[rev]

#4 Updated by Go MAEDA 29 days ago

Frédéric Fondement, thank you for reporting the issue and submitting the workaround. Do you know it also work with Mercurial < 4.7?

#5 Updated by Frédéric Fondement 29 days ago

Good point !
The change I proposed fails with 4.0.

Here is the new version sucessfully tested with hg 4.7, 4.6, 4.5, 4.4, 4.1, 4.0, 3.9, 3.5, 2.6.2 (the older I can easily access - using pip):

import re, time, cgi, urllib
from mercurial import cmdutil, commands, node, error, hg, registrar

cmdtable = {}
command = registrar.command(cmdtable) if hasattr(registrar, 'command') else cmdutil.command(cmdtable)
def _changectx(repo, rev):
    if isinstance(rev, str):
        rev = repo.lookup(rev)
    if hasattr(repo, 'changectx'):
        return repo.changectx(rev)
    else:
        return repo[rev]

#6 Updated by Go MAEDA 27 days ago

I made a patch file from #29413#note-5.

#7 Updated by Go MAEDA 27 days ago

LGTM. The test suite passed with both Mercurial 2.6.2 and 4.7.

#8 Updated by Go MAEDA 24 days ago

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

#9 Updated by Go MAEDA 24 days ago

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

Committed. Thank you for reporting and fixing the issue.

Also available in: Atom PDF