Edgewall Software
Modify

Opened 13 years ago

Closed 12 years ago

#10247 closed defect (fixed)

TracMercurial dies with Mercurial 1.9

Reported by: djc <dirkjan@…> Owned by: djc <dirkjan@…>
Priority: high Milestone: plugin - mercurial
Component: plugin/mercurial Version:
Severity: major Keywords: apichanges
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Christian Boos)

TracMercurial with Mercurial 1.9 dies here (using http://svn.edgewall.com/repos/trac/plugins/0.12/mercurial-plugin@10734):

File "/usr/lib64/python2.7/site-packages/trac/web/main.py", line 511, in _dispatch_request
  dispatcher.dispatch(req)
File "/usr/lib64/python2.7/site-packages/trac/web/main.py", line 237, in dispatch
  resp = chosen_handler.process_request(req)
File "/usr/lib64/python2.7/site-packages/trac/versioncontrol/web_ui/changeset.py", line 295, in process_request
  prev = repos.get_node(new_path, new).get_previous()
File "/usr/lib64/python2.7/site-packages/trac/versioncontrol/api.py", line 999, in get_previous
  for p in self.get_history(2):
File "/usr/lib64/python2.7/site-packages/TracMercurial-0.12.0.28dev_r10731-py2.7.egg/tracext/hg/backend.py", line 1047, in _get_history_1_4
  matcher = match(repo, pats, opts)
File "/usr/lib64/python2.7/site-packages/mercurial/scmutil.py", line 569, in match
  m = ctx.match(pats, opts.get('include'), opts.get('exclude'),
AttributeError: 'mqrepo' object has no attribute 'match'

This should help:

Index: tracext/hg/backend.py
===================================================================
--- tracext/hg/backend.py       (revision 10734)
+++ tracext/hg/backend.py       (working copy)
@@ -97,6 +97,7 @@

     try:
         match = cmdutil.match
+        match = lambda c, p, o: match(c._repo, p, o)
     except AttributeError:
         from mercurial.scmutil import match

@@ -1044,7 +1045,7 @@
             return self._get_history_1_3(repo, pats, opts, limit)

     def _get_history_1_4(self, repo, pats, opts, limit):
-        matcher = match(repo, pats, opts)
+        matcher = match(repo[None], pats, opts)
         if self.isfile:
             fncache = {}
             def prep(ctx, fns):

Bit of a hack; seems to work, though.

Attachments (0)

Change History (10)

in reply to:  description ; comment:1 by Remy Blank, 13 years ago

Milestone: plugin - mercurial
Priority: normalhigh

Replying to djc <dirkjan@…>:

Bit of a hack; seems to work, though.

Accessing a "private" member? Quite a hack, yes :)

Does this happen with all repositories, or only when viewing an MQ repository?

comment:2 by anonymous, 13 years ago

Any repository is a MQ repository when you have the mq extension disabled. I'm pretty sure it would happen on any repository. See also this bit from the hg api changes document:

scmutil.match (formerly cmdutil.match) now requires a context argument (35c2cc322ba8), typically "repo[None]"

comment:3 by djc <dirkjan@…>, 13 years ago

Err, sorry, that was me again.

in reply to:  1 comment:4 by Christian Boos, 13 years ago

Replying to rblank:

Replying to djc <dirkjan@…>:

Bit of a hack; seems to work, though.

Accessing a "private" member? Quite a hack, yes :)

As this _repo member was always present for the changectx, and we're only using that for the "legacy" versions (pre-scmutil), I'd say it's fine to use it there.

And anyway, isn't the whole Mercurial Python API supposed to be private? ;-)

comment:5 by djc <dirkjan@…>, 13 years ago

It's not so much private, it's just not guaranteed to be stable across major (1.x) releases. So will either of you commit this patch? :)

in reply to:  5 comment:6 by Remy Blank, 13 years ago

Owner: set to Remy Blank

Replying to djc <dirkjan@…>:

So will either of you commit this patch? :)

Sure. As Christian seems to be mostly off-line these days, I'll take care of it.

comment:7 by Remy Blank, 13 years ago

Resolution: fixed
Status: newclosed

Slightly modified patch applied in [10748] (the patch broke the revision log for Mercurial pre-1.8).

comment:8 by Remy Blank, 13 years ago

Owner: changed from Remy Blank to djc <dirkjan@…>

comment:9 by Christian Boos, 13 years ago

Description: modified (diff)
Keywords: apichanges added
Resolution: fixed
Status: closedreopened

It fails here with Mercurial 1.8.3+294-899feff0f5c2 (admittedly a bit old and an intermediate version even) and TracMercurial 0.13.0.5dev-r10900:

Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 478, in _dispatch_request
    dispatcher.dispatch(req)
  File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 198, in dispatch
    resp = chosen_handler.process_request(req)
  File "build/bdist.linux-x86_64/egg/trac/versioncontrol/web_ui/changeset.py", line 298, in process_request
    prev = repos.get_node(new_path, new).get_previous()
  File "build/bdist.linux-x86_64/egg/trac/versioncontrol/api.py", line 1020, in get_previous
    for p in self.get_history(2):
  File "build/bdist.linux-x86_64/egg/tracext/hg/backend.py", line 1058, in _get_history_1_4
    matcher = match(repo[None], pats, opts)
  File "usr/local/lib/python2.5/site-packages/mercurial/scmutil.py", line 566, in match
    m = matchmod.match(repo.root, repo.getcwd(), pats,
AttributeError: 'workingctx' object has no attribute 'root'

So it's not clear cut that scmutil.match uses the new convention. Indeed the switch was made in hg:19197fa4c41c, the parent of hg:35c2cc322ba8.

A simple getargspec should do the trick:

  • tracext/hg/backend.py

     
    1515
    1616from bisect import bisect
    1717from datetime import datetime
     18from inspect import getargspec
    1819import os
    1920import time
    2021import posixpath
     
    99100
    100101    # API compatibility (watch http://mercurial.selenic.com/wiki/ApiChanges)
    101102
     103    def get_compatible_match(mod):
     104        """match() used to take a repository argument (35c2cc322ba8)"""
     105        def match(ctx, *args, **kwargs):
     106            return mod.match(ctx._repo, *args, **kwargs)
     107        return match
     108
    102109    if hasattr(cmdutil, 'match'):
    103         def match(ctx, *args, **kwargs):
    104             return cmdutil.match(ctx._repo, *args, **kwargs)
     110        match = get_compatible_match(cmdutil)
    105111    else:
    106112        from mercurial.scmutil import match
     113        if getargspec(match)[0][0] == 'repo':
     114            from mercurial import scmutil
     115            match = get_compatible_match(scmutil)
    107116
    108117
    109118except ImportError, e:

(and having getargspec around will certainly prove to be useful again!)

Patch currently tested here.

comment:10 by Christian Boos, 12 years ago

Resolution: fixed
Status: reopenedclosed

I think [10748] was enough, and we can live with the fact that for some intermediate versions of hg (comment:9) it failed…

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain djc <dirkjan@…>.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from djc <dirkjan@…> 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.