Edgewall Software
Modify

Ticket #10247 (reopened defect)

Opened 11 months ago

Last modified 4 months ago

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:
Release Notes:
API Changes:

Description (last modified by cboos) (diff)

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

Change History

comment:1 in reply to: ↑ description ; follow-up: Changed 11 months ago by rblank

  • Milestone set to plugin - mercurial
  • Priority changed from normal to high

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 Changed 11 months ago by anonymous

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 Changed 11 months ago by djc <dirkjan@…>

Err, sorry, that was me again.

comment:4 in reply to: ↑ 1 Changed 11 months ago by cboos

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 follow-up: Changed 11 months ago by djc <dirkjan@…>

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? :)

comment:6 in reply to: ↑ 5 Changed 11 months ago by rblank

  • Owner set to rblank

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 Changed 11 months ago by rblank

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:8 Changed 11 months ago by rblank

  • Owner changed from rblank to djc <dirkjan@…>

comment:9 Changed 4 months ago by cboos

  • Description modified (diff)
  • Keywords apichanges added
  • Resolution fixed deleted
  • Status changed from closed to reopened

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.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as reopened
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from djc <dirkjan@…>. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.