mercurial/extensions.py
changeset 40440 09a37a5d8f5d
parent 39511 1ab185c78cc3
child 40463 cfa564037789
equal deleted inserted replaced
40439:25f1c7bd649d 40440:09a37a5d8f5d
   173         shortname = name
   173         shortname = name
   174     if shortname in _builtin:
   174     if shortname in _builtin:
   175         return None
   175         return None
   176     if shortname in _extensions:
   176     if shortname in _extensions:
   177         return _extensions[shortname]
   177         return _extensions[shortname]
   178     log('  - loading extension: %r\n', shortname)
   178     log('  - loading extension: %s\n', shortname)
   179     _extensions[shortname] = None
   179     _extensions[shortname] = None
   180     with util.timedcm('load extension %r', shortname) as stats:
   180     with util.timedcm('load extension %s', shortname) as stats:
   181         mod = _importext(name, path, bind(_reportimporterror, ui))
   181         mod = _importext(name, path, bind(_reportimporterror, ui))
   182     log('  > %r extension loaded in %s\n', shortname, stats)
   182     log('  > %s extension loaded in %s\n', shortname, stats)
   183     if loadingtime is not None:
   183     if loadingtime is not None:
   184         loadingtime[shortname] += stats.elapsed
   184         loadingtime[shortname] += stats.elapsed
   185 
   185 
   186     # Before we do anything with the extension, check against minimum stated
   186     # Before we do anything with the extension, check against minimum stated
   187     # compatibility. This gives extension authors a mechanism to have their
   187     # compatibility. This gives extension authors a mechanism to have their
   190     minver = getattr(mod, 'minimumhgversion', None)
   190     minver = getattr(mod, 'minimumhgversion', None)
   191     if minver and util.versiontuple(minver, 2) > util.versiontuple(n=2):
   191     if minver and util.versiontuple(minver, 2) > util.versiontuple(n=2):
   192         ui.warn(_('(third party extension %s requires version %s or newer '
   192         ui.warn(_('(third party extension %s requires version %s or newer '
   193                   'of Mercurial; disabling)\n') % (shortname, minver))
   193                   'of Mercurial; disabling)\n') % (shortname, minver))
   194         return
   194         return
   195     log('    - validating extension tables: %r\n', shortname)
   195     log('    - validating extension tables: %s\n', shortname)
   196     _validatetables(ui, mod)
   196     _validatetables(ui, mod)
   197 
   197 
   198     _extensions[shortname] = mod
   198     _extensions[shortname] = mod
   199     _order.append(shortname)
   199     _order.append(shortname)
   200     log('    - invoking registered callbacks: %r\n', shortname)
   200     log('    - invoking registered callbacks: %s\n', shortname)
   201     with util.timedcm('callbacks extension %r', shortname) as stats:
   201     with util.timedcm('callbacks extension %s', shortname) as stats:
   202         for fn in _aftercallbacks.get(shortname, []):
   202         for fn in _aftercallbacks.get(shortname, []):
   203             fn(loaded=True)
   203             fn(loaded=True)
   204     log('    > callbacks completed in %s\n', stats)
   204     log('    > callbacks completed in %s\n', stats)
   205     return mod
   205     return mod
   206 
   206 
   249     with util.timedcm('load all extensions') as stats:
   249     with util.timedcm('load all extensions') as stats:
   250         for (name, path) in result:
   250         for (name, path) in result:
   251             if path:
   251             if path:
   252                 if path[0:1] == '!':
   252                 if path[0:1] == '!':
   253                     if name not in _disabledextensions:
   253                     if name not in _disabledextensions:
   254                         log('  - skipping disabled extension: %r\n', name)
   254                         log('  - skipping disabled extension: %s\n', name)
   255                     _disabledextensions[name] = path[1:]
   255                     _disabledextensions[name] = path[1:]
   256                     continue
   256                     continue
   257             try:
   257             try:
   258                 load(ui, name, path, log, loadingtime)
   258                 load(ui, name, path, log, loadingtime)
   259             except Exception as inst:
   259             except Exception as inst:
   287 
   287 
   288     broken = set()
   288     broken = set()
   289     log('- executing uisetup hooks\n')
   289     log('- executing uisetup hooks\n')
   290     with util.timedcm('all uisetup') as alluisetupstats:
   290     with util.timedcm('all uisetup') as alluisetupstats:
   291         for name in _order[newindex:]:
   291         for name in _order[newindex:]:
   292             log('  - running uisetup for %r\n', name)
   292             log('  - running uisetup for %s\n', name)
   293             with util.timedcm('uisetup %r', name) as stats:
   293             with util.timedcm('uisetup %s', name) as stats:
   294                 if not _runuisetup(name, ui):
   294                 if not _runuisetup(name, ui):
   295                     log('    - the %r extension uisetup failed\n', name)
   295                     log('    - the %s extension uisetup failed\n', name)
   296                     broken.add(name)
   296                     broken.add(name)
   297             log('  > uisetup for %r took %s\n', name, stats)
   297             log('  > uisetup for %s took %s\n', name, stats)
   298             loadingtime[name] += stats.elapsed
   298             loadingtime[name] += stats.elapsed
   299     log('> all uisetup took %s\n', alluisetupstats)
   299     log('> all uisetup took %s\n', alluisetupstats)
   300 
   300 
   301     log('- executing extsetup hooks\n')
   301     log('- executing extsetup hooks\n')
   302     with util.timedcm('all extsetup') as allextetupstats:
   302     with util.timedcm('all extsetup') as allextetupstats:
   303         for name in _order[newindex:]:
   303         for name in _order[newindex:]:
   304             if name in broken:
   304             if name in broken:
   305                 continue
   305                 continue
   306             log('  - running extsetup for %r\n', name)
   306             log('  - running extsetup for %s\n', name)
   307             with util.timedcm('extsetup %r', name) as stats:
   307             with util.timedcm('extsetup %s', name) as stats:
   308                 if not _runextsetup(name, ui):
   308                 if not _runextsetup(name, ui):
   309                     log('    - the %r extension extsetup failed\n', name)
   309                     log('    - the %s extension extsetup failed\n', name)
   310                     broken.add(name)
   310                     broken.add(name)
   311             log('  > extsetup for %r took %s\n', name, stats)
   311             log('  > extsetup for %s took %s\n', name, stats)
   312             loadingtime[name] += stats.elapsed
   312             loadingtime[name] += stats.elapsed
   313     log('> all extsetup took %s\n', allextetupstats)
   313     log('> all extsetup took %s\n', allextetupstats)
   314 
   314 
   315     for name in broken:
   315     for name in broken:
   316         log('    - disabling broken %r extension\n', name)
   316         log('    - disabling broken %s extension\n', name)
   317         _extensions[name] = None
   317         _extensions[name] = None
   318 
   318 
   319     # Call aftercallbacks that were never met.
   319     # Call aftercallbacks that were never met.
   320     log('- executing remaining aftercallbacks\n')
   320     log('- executing remaining aftercallbacks\n')
   321     with util.timedcm('aftercallbacks') as stats:
   321     with util.timedcm('aftercallbacks') as stats:
   322         for shortname in _aftercallbacks:
   322         for shortname in _aftercallbacks:
   323             if shortname in _extensions:
   323             if shortname in _extensions:
   324                 continue
   324                 continue
   325 
   325 
   326             for fn in _aftercallbacks[shortname]:
   326             for fn in _aftercallbacks[shortname]:
   327                 log('  - extension %r not loaded, notify callbacks\n',
   327                 log('  - extension %s not loaded, notify callbacks\n',
   328                     shortname)
   328                     shortname)
   329                 fn(loaded=False)
   329                 fn(loaded=False)
   330     log('> remaining aftercallbacks completed in %s\n', stats)
   330     log('> remaining aftercallbacks completed in %s\n', stats)
   331 
   331 
   332     # loadall() is called multiple times and lingering _aftercallbacks
   332     # loadall() is called multiple times and lingering _aftercallbacks