Edgewall Software

Ticket #6796: unsupported-vcs-hg-r7031.diff

File unsupported-vcs-hg-r7031.diff, 2.1 KB (added by cboos, 8 months ago)

Related changes for the TracMercurial plugin (0.11). I had to fight a bit the demandimport stuff ...

  • tracext/hg/backend.py

     
    2727                                    NoSuchChangeset, NoSuchNode 
    2828from trac.wiki import IWikiSyntaxProvider 
    2929 
     30hg_import_error = [] 
    3031try: 
    3132    # The new `demandimport` mechanism doesn't play well with code relying 
    3233    # on the `ImportError` exception being caught. 
     
    3940    try: 
    4041        from mercurial import demandimport 
    4142        demandimport.enable(); 
    42     except ImportError: 
     43    except ImportError, hg_import_error: 
    4344        demandimport = None 
    4445 
    4546    from mercurial import hg 
     47    from mercurial.hg import repository 
    4648    from mercurial.ui import ui 
    4749    from mercurial.repo import RepoError 
    4850    from mercurial.revlog import LookupError 
     
    5052    from mercurial.util import pathto, cachefunc 
    5153    from mercurial.cmdutil import walkchangerevs 
    5254    from mercurial import extensions 
     55    from mercurial.extensions import loadall 
    5356 
     57    # Note: due to the nature of demandimport, there will be no actual  
     58    # import error until those symbols get accessed, so here we go: 
     59    for sym in ("repository ui RepoError LookupError hex short nullid pathto " 
     60                "cachefunc walkchangerevs loadall".split()): 
     61        if repr(globals()[sym]) == "<unloaded module '%s'>" % sym: 
     62            hg_import_error.append(sym) 
     63    if hg_import_error: 
     64        hg_import_error = "Couldn't import symbols: "+','.join(hg_import_error) 
     65     
    5466    if demandimport: 
    5567        demandimport.disable(); 
    5668     
    57     has_mercurial = True 
    58 except ImportError: 
    59     has_mercurial = False 
     69except ImportError, e: 
     70    hg_import_error = e 
    6071    ui = object 
    6172 
    6273try: 
     
    123134 
    124135    def get_supported_types(self): 
    125136        """Support for `repository_type = hg`""" 
    126         global has_mercurial 
    127         if has_mercurial: 
     137        global hg_import_error 
     138        if hg_import_error: 
     139            self.error = hg_import_error 
     140            yield ("hg", -1) 
     141        else: 
    128142            yield ("hg", 8) 
    129143 
    130144    def get_repository(self, type, dir, authname):