diff --git a/hgext/color.py b/hgext/color.py index 0ab5f21c390b7db5eace8530b4f9e3c73c77e9d9_aGdleHQvY29sb3IucHk=..292fb2ad28465737011826d4725af5b8db454b1b_aGdleHQvY29sb3IucHk= 100644 --- a/hgext/color.py +++ b/hgext/color.py @@ -51,7 +51,7 @@ import re, sys -from mercurial import commands, cmdutil +from mercurial import commands, cmdutil, extensions from mercurial.i18n import _ # start and stop parameters for effects @@ -89,10 +89,10 @@ stop = '\033[' + ';'.join(stop) + 'm' return start + text + stop -def colorstatus(statusfunc, ui, repo, *pats, **opts): +def colorstatus(orig, ui, repo, *pats, **opts): '''run the status command with colored output''' delimiter = opts['print0'] and '\0' or '\n' # run status and capture it's output ui.pushbuffer() @@ -93,10 +93,10 @@ '''run the status command with colored output''' delimiter = opts['print0'] and '\0' or '\n' # run status and capture it's output ui.pushbuffer() - retval = statusfunc(ui, repo, *pats, **opts) + retval = orig(ui, repo, *pats, **opts) # filter out empty strings lines = [ line for line in ui.popbuffer().split(delimiter) if line ] @@ -139,6 +139,6 @@ 'clean': ('none', ), 'copied': ('none', ), } -def colorqseries(qseriesfunc, ui, repo, *dummy, **opts): +def colorqseries(orig, ui, repo, *dummy, **opts): '''run the qseries command with colored output''' ui.pushbuffer() @@ -143,6 +143,6 @@ '''run the qseries command with colored output''' ui.pushbuffer() - retval = qseriesfunc(ui, repo, **opts) + retval = orig(ui, repo, **opts) patches = ui.popbuffer().splitlines() for patch in patches: patchname = patch @@ -168,9 +168,7 @@ def uisetup(ui): '''Initialize the extension.''' - nocoloropt = ('', 'no-color', None, _("don't colorize output")) - _decoratecmd(ui, 'status', commands.table, colorstatus, nocoloropt) - _configcmdeffects(ui, 'status', _status_effects); + _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects) if ui.config('extensions', 'hgext.mq') is not None or \ ui.config('extensions', 'mq') is not None: from hgext import mq @@ -174,25 +172,5 @@ if ui.config('extensions', 'hgext.mq') is not None or \ ui.config('extensions', 'mq') is not None: from hgext import mq - _decoratecmd(ui, 'qseries', mq.cmdtable, colorqseries, nocoloropt) - _configcmdeffects(ui, 'qseries', _patch_effects); - -def _decoratecmd(ui, cmd, table, delegate, *delegateoptions): - '''Replace the function that implements cmd in table with a decorator. - - The decorator that becomes the new implementation of cmd calls - delegate. The delegate's first argument is the replaced function, - followed by the normal Mercurial command arguments (ui, repo, ...). If - the delegate adds command options, supply them as delegateoptions. - ''' - cmdkey, cmdentry = _cmdtableitem(ui, cmd, table) - decorator = lambda ui, repo, *args, **opts: \ - _colordecorator(delegate, cmdentry[0], - ui, repo, *args, **opts) - # make sure 'hg help cmd' still works - decorator.__doc__ = cmdentry[0].__doc__ - decoratorentry = (decorator,) + cmdentry[1:] - for option in delegateoptions: - decoratorentry[1].append(option) - table[cmdkey] = decoratorentry + _setupcmd(ui, 'qseries', mq.cmdtable, colorqseries, _patch_effects) @@ -198,11 +176,8 @@ -def _cmdtableitem(ui, cmd, table): - '''Return key, value from table for cmd, or None if not found.''' - aliases, entry = cmdutil.findcmd(cmd, table) - for candidatekey, candidateentry in table.iteritems(): - if candidateentry is entry: - return candidatekey, entry - -def _colordecorator(colorfunc, nocolorfunc, ui, repo, *args, **opts): - '''Delegate to colorfunc or nocolorfunc, depending on conditions. +def _setupcmd(ui, cmd, table, func, effectsmap): + '''patch in command to command table and load effect map''' + def nocolor(orig, *args, **kwargs): + if kwargs['no_color']: + return orig(*args, **kwargs) + return func(orig, *args, **kwargs) @@ -208,8 +183,4 @@ - Delegate to colorfunc unless --no-color option is set or output is not - to a tty. - ''' - if opts['no_color'] or not sys.stdout.isatty(): - return nocolorfunc(ui, repo, *args, **opts) - return colorfunc(nocolorfunc, ui, repo, *args, **opts) + entry = extensions.wrapcommand(table, cmd, nocolor) + entry[1].append(('', 'no-color', None, _("don't colorize output"))) @@ -215,8 +186,2 @@ -def _configcmdeffects(ui, cmdname, effectsmap): - '''Override default effects for cmdname with those from .hgrc file. - - Entries in the .hgrc file are in the [color] section, and look like - 'cmdname'.'status' (for instance, 'status.modified = blue bold inverse'). - ''' for status in effectsmap: @@ -222,4 +187,4 @@ for status in effectsmap: - effects = ui.config('color', cmdname + '.' + status) + effects = ui.config('color', cmd + '.' + status) if effects: effectsmap[status] = re.split('\W+', effects) diff --git a/hgext/highlight/__init__.py b/hgext/highlight/__init__.py index 0ab5f21c390b7db5eace8530b4f9e3c73c77e9d9_aGdleHQvaGlnaGxpZ2h0L19faW5pdF9fLnB5..292fb2ad28465737011826d4725af5b8db454b1b_aGdleHQvaGlnaGxpZ2h0L19faW5pdF9fLnB5 100644 --- a/hgext/highlight/__init__.py +++ b/hgext/highlight/__init__.py @@ -20,4 +20,5 @@ import highlight from mercurial.hgweb import webcommands, webutil, common +from mercurial import extensions @@ -23,8 +24,5 @@ -web_filerevision = webcommands._filerevision -web_annotate = webcommands.annotate - -def filerevision_highlight(web, tmpl, fctx): +def filerevision_highlight(orig, web, tmpl, fctx): mt = ''.join(tmpl('mimetype', encoding=web.encoding)) # only pygmentize for mimetype containing 'html' so we both match # 'text/html' and possibly 'application/xhtml+xml' in the future @@ -36,5 +34,5 @@ if 'html' in mt: style = web.config('web', 'pygments_style', 'colorful') highlight.pygmentize('fileline', fctx, style, tmpl) - return web_filerevision(web, tmpl, fctx) + return orig(web, tmpl, fctx) @@ -40,7 +38,7 @@ -def annotate_highlight(web, req, tmpl): +def annotate_highlight(orig, web, req, tmpl): mt = ''.join(tmpl('mimetype', encoding=web.encoding)) if 'html' in mt: fctx = webutil.filectx(web.repo, req) style = web.config('web', 'pygments_style', 'colorful') highlight.pygmentize('annotateline', fctx, style, tmpl) @@ -42,9 +40,9 @@ mt = ''.join(tmpl('mimetype', encoding=web.encoding)) if 'html' in mt: fctx = webutil.filectx(web.repo, req) style = web.config('web', 'pygments_style', 'colorful') highlight.pygmentize('annotateline', fctx, style, tmpl) - return web_annotate(web, req, tmpl) + return orig(web, req, tmpl) def generate_css(web, req, tmpl): pg_style = web.config('web', 'pygments_style', 'colorful') @@ -52,5 +50,4 @@ req.respond(common.HTTP_OK, 'text/css') return ['/* pygments_style = %s */\n\n' % pg_style, fmter.get_style_defs('')] - # monkeypatch in the new version @@ -56,6 +53,5 @@ # monkeypatch in the new version - -webcommands._filerevision = filerevision_highlight -webcommands.annotate = annotate_highlight +extensions.wrapfunction(webcommands, '_filerevision', filerevision_highlight) +extensions.wrapfunction(webcommands, 'annotate', annotate_highlight) webcommands.highlightcss = generate_css webcommands.__all__.append('highlightcss') diff --git a/hgext/interhg.py b/hgext/interhg.py index 0ab5f21c390b7db5eace8530b4f9e3c73c77e9d9_aGdleHQvaW50ZXJoZy5weQ==..292fb2ad28465737011826d4725af5b8db454b1b_aGdleHQvaW50ZXJoZy5weQ== 100644 --- a/hgext/interhg.py +++ b/hgext/interhg.py @@ -27,7 +27,7 @@ import re from mercurial.hgweb import hgweb_mod -from mercurial import templatefilters +from mercurial import templatefilters, extensions from mercurial.i18n import _ orig_escape = templatefilters.filters["escape"] @@ -42,9 +42,7 @@ templatefilters.filters["escape"] = interhg_escape -orig_refresh = hgweb_mod.hgweb.refresh - -def interhg_refresh(self): +def interhg_refresh(orig, self): interhg_table[:] = [] for key, pattern in self.repo.ui.configitems('interhg'): # grab the delimiter from the character after the "s" @@ -79,5 +77,5 @@ except re.error: self.repo.ui.warn(_("interhg: invalid regexp for %s: %s\n") % (key, regexp)) - return orig_refresh(self) + return orig(self) @@ -83,2 +81,2 @@ -hgweb_mod.hgweb.refresh = interhg_refresh +extensions.wrapfunction(hgweb_mod.hgweb, 'refresh', interhg_refresh) diff --git a/hgext/keyword.py b/hgext/keyword.py index 0ab5f21c390b7db5eace8530b4f9e3c73c77e9d9_aGdleHQva2V5d29yZC5weQ==..292fb2ad28465737011826d4725af5b8db454b1b_aGdleHQva2V5d29yZC5weQ== 100644 --- a/hgext/keyword.py +++ b/hgext/keyword.py @@ -78,7 +78,7 @@ "Log = {desc}" expands to the first line of the changeset description. ''' -from mercurial import commands, cmdutil, dispatch, filelog, revlog +from mercurial import commands, cmdutil, dispatch, filelog, revlog, extensions from mercurial import patch, localrepo, templater, templatefilters, util from mercurial.hgweb import webcommands from mercurial.node import nullid, hex @@ -416,5 +416,5 @@ kwtools['exc'].append(pat) if kwtools['inc']: - def kwdispatch_parse(ui, args): + def kwdispatch_parse(orig, ui, args): '''Monkeypatch dispatch._parse to obtain running hg command.''' @@ -420,5 +420,5 @@ '''Monkeypatch dispatch._parse to obtain running hg command.''' - cmd, func, args, options, cmdoptions = dispatch_parse(ui, args) + cmd, func, args, options, cmdoptions = orig(ui, args) kwtools['hgcmd'] = cmd return cmd, func, args, options, cmdoptions @@ -422,8 +422,7 @@ kwtools['hgcmd'] = cmd return cmd, func, args, options, cmdoptions - dispatch_parse = dispatch._parse - dispatch._parse = kwdispatch_parse + extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse) def reposetup(ui, repo): '''Sets up repo as kwrepo for keyword substitution. @@ -495,6 +494,6 @@ del wlock, lock # monkeypatches - def kwpatchfile_init(self, ui, fname, missing=False): + def kwpatchfile_init(orig, self, ui, fname, missing=False): '''Monkeypatch/wrap patch.patchfile.__init__ to avoid rejects or conflicts due to expanded keywords in working dir.''' @@ -499,6 +498,6 @@ '''Monkeypatch/wrap patch.patchfile.__init__ to avoid rejects or conflicts due to expanded keywords in working dir.''' - patchfile_init(self, ui, fname, missing) + orig(self, ui, fname, missing) # shrink keywords read from working dir self.lines = kwt.shrinklines(self.fname, self.lines) @@ -502,7 +501,7 @@ # shrink keywords read from working dir self.lines = kwt.shrinklines(self.fname, self.lines) - def kw_diff(repo, node1=None, node2=None, match=None, + def kw_diff(orig, repo, node1=None, node2=None, match=None, fp=None, changes=None, opts=None): '''Monkeypatch patch.diff to avoid expansion except when comparing against working dir.''' @@ -510,10 +509,5 @@ kwt.matcher = util.never elif node1 is not None and node1 != repo['.'].node(): kwt.restrict = True - patch_diff(repo, node1, node2, match, fp, changes, opts) - - def kwweb_annotate(web, req, tmpl): - '''Wraps webcommands.annotate turning off keyword expansion.''' - kwt.matcher = util.never - return webcommands_annotate(web, req, tmpl) + orig(repo, node1, node2, match, fp, changes, opts) @@ -519,4 +513,4 @@ - def kwweb_changeset(web, req, tmpl): - '''Wraps webcommands.changeset turning off keyword expansion.''' + def kwweb_skip(orig, web, req, tmpl): + '''Wraps webcommands.x turning off keyword expansion.''' kwt.matcher = util.never @@ -522,10 +516,5 @@ kwt.matcher = util.never - return webcommands_changeset(web, req, tmpl) - - def kwweb_filediff(web, req, tmpl): - '''Wraps webcommands.filediff turning off keyword expansion.''' - kwt.matcher = util.never - return webcommands_filediff(web, req, tmpl) + return orig(web, req, tmpl) repo.__class__ = kwrepo @@ -529,18 +518,10 @@ repo.__class__ = kwrepo - patchfile_init = patch.patchfile.__init__ - patch_diff = patch.diff - webcommands_annotate = webcommands.annotate - webcommands_changeset = webcommands.changeset - webcommands_filediff = webcommands.filediff - - patch.patchfile.__init__ = kwpatchfile_init - patch.diff = kw_diff - webcommands.annotate = kwweb_annotate - webcommands.changeset = webcommands.rev = kwweb_changeset - webcommands.filediff = webcommands.diff = kwweb_filediff - + extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) + extensions.wrapfunction(patch, 'diff', kw_diff) + for c in 'annotate changeset rev filediff diff'.split(): + extensions.wrapfunction(webcommands, c, kwweb_skip) cmdtable = { 'kwdemo': diff --git a/hgext/mq.py b/hgext/mq.py index 0ab5f21c390b7db5eace8530b4f9e3c73c77e9d9_aGdleHQvbXEucHk=..292fb2ad28465737011826d4725af5b8db454b1b_aGdleHQvbXEucHk= 100644 --- a/hgext/mq.py +++ b/hgext/mq.py @@ -33,7 +33,7 @@ from mercurial.node import bin, hex, short from mercurial.repo import RepoError from mercurial import commands, cmdutil, hg, patch, revlog, util -from mercurial import repair +from mercurial import repair, extensions import os, sys, re, errno, urllib commands.norepo += " qclone" @@ -2366,4 +2366,10 @@ repo.__class__ = mqrepo repo.mq = queue(ui, repo.join("")) +def mqimport(orig, ui, repo, *args, **kwargs): + if hasattr(repo, 'abort_if_wdir_patched'): + repo.abort_if_wdir_patched(_('cannot import over an applied patch'), + kwargs.get('force')) + return orig(ui, repo, *args, **kwargs) + def uisetup(ui): @@ -2369,19 +2375,5 @@ def uisetup(ui): - # override import to disallow importing over patch - importalias, importcmd = cmdutil.findcmd('import', commands.table) - for alias, cmd in commands.table.iteritems(): - if cmd is importcmd: - importkey = alias - break - orig_import = importcmd[0] - def mqimport(ui, repo, patch1, *patches, **opts): - if hasattr(repo, 'abort_if_wdir_patched'): - repo.abort_if_wdir_patched(_('cannot import over an applied patch'), - opts.get('force')) - orig_import(ui, repo, patch1, *patches, **opts) - importcmd = list(importcmd) - importcmd[0] = mqimport - commands.table[importkey] = tuple(importcmd) + extensions.wrapcommand(commands.table, 'import', mqimport) seriesopts = [('s', 'summary', None, _('print first line of patch header'))] diff --git a/hgext/pager.py b/hgext/pager.py index 0ab5f21c390b7db5eace8530b4f9e3c73c77e9d9_aGdleHQvcGFnZXIucHk=..292fb2ad28465737011826d4725af5b8db454b1b_aGdleHQvcGFnZXIucHk= 100644 --- a/hgext/pager.py +++ b/hgext/pager.py @@ -47,6 +47,6 @@ ''' import sys, os, signal -from mercurial import dispatch, util +from mercurial import dispatch, util, extensions def uisetup(ui): @@ -51,6 +51,6 @@ def uisetup(ui): - def pagecmd(ui, options, cmd, cmdfunc): + def pagecmd(orig, ui, options, cmd, cmdfunc): p = ui.config("pager", "pager", os.environ.get("PAGER")) if p and sys.stdout.isatty() and '--debugger' not in sys.argv: attend = ui.configlist('pager', 'attend') @@ -59,5 +59,5 @@ sys.stderr = sys.stdout = util.popen(p, "wb") if ui.configbool('pager', 'quiet'): signal.signal(signal.SIGPIPE, signal.SIG_DFL) - return oldrun(ui, options, cmd, cmdfunc) + return orig(ui, options, cmd, cmdfunc) @@ -63,3 +63,2 @@ - oldrun = dispatch._runcommand - dispatch._runcommand = pagecmd + extensions.wrapfunction(dispatch, '_runcommand', pagecmd) diff --git a/hgext/rebase.py b/hgext/rebase.py index 0ab5f21c390b7db5eace8530b4f9e3c73c77e9d9_aGdleHQvcmViYXNlLnB5..292fb2ad28465737011826d4725af5b8db454b1b_aGdleHQvcmViYXNlLnB5 100644 --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -13,7 +13,7 @@ http://www.selenic.com/mercurial/wiki/index.cgi/RebaseProject ''' -from mercurial import util, repair, merge, cmdutil, dispatch, commands +from mercurial import util, repair, merge, cmdutil, dispatch, commands, extensions from mercurial.commands import templateopts from mercurial.node import nullrev from mercurial.i18n import _ @@ -352,7 +352,7 @@ state[source] = nullrev return repo['.'].rev(), repo[dest].rev(), state, external -def pulldelegate(pullfunction, repo, *args, **opts): +def pullrebase(orig, ui, repo, *args, **opts): 'Call rebase after pull if the latter has been invoked with --rebase' if opts.get('rebase'): if opts.get('update'): @@ -360,6 +360,6 @@ cmdutil.bail_if_changed(repo) revsprepull = len(repo) - pullfunction(repo.ui, repo, *args, **opts) + orig(ui, repo, *args, **opts) revspostpull = len(repo) if revspostpull > revsprepull: @@ -364,4 +364,4 @@ revspostpull = len(repo) if revspostpull > revsprepull: - rebase(repo.ui, repo, **opts) + rebase(ui, repo, **opts) else: @@ -367,5 +367,5 @@ else: - pullfunction(repo.ui, repo, *args, **opts) + orig(ui, repo, *args, **opts) def uisetup(ui): 'Replace pull with a decorator to provide --rebase option' @@ -369,22 +369,10 @@ def uisetup(ui): 'Replace pull with a decorator to provide --rebase option' - # cribbed from color.py - aliases, entry = cmdutil.findcmd('pull', commands.table) - for candidatekey, candidateentry in commands.table.iteritems(): - if candidateentry is entry: - cmdkey, cmdentry = candidatekey, entry - break - - decorator = lambda ui, repo, *args, **opts: \ - pulldelegate(cmdentry[0], repo, *args, **opts) - # make sure 'hg help cmd' still works - decorator.__doc__ = cmdentry[0].__doc__ - decoratorentry = (decorator,) + cmdentry[1:] - rebaseopt = ('', 'rebase', None, - _("rebase working directory to branch head")) - decoratorentry[1].append(rebaseopt) - commands.table[cmdkey] = decoratorentry + entry = extensions.wrapcommand(commands.table, 'pull', pullrebase) + entry[1].append(('', 'rebase', None, + _("rebase working directory to branch head")) +) cmdtable = { "rebase": diff --git a/hgext/zeroconf/__init__.py b/hgext/zeroconf/__init__.py index 0ab5f21c390b7db5eace8530b4f9e3c73c77e9d9_aGdleHQvemVyb2NvbmYvX19pbml0X18ucHk=..292fb2ad28465737011826d4725af5b8db454b1b_aGdleHQvemVyb2NvbmYvX19pbml0X18ucHk= 100644 --- a/hgext/zeroconf/__init__.py +++ b/hgext/zeroconf/__init__.py @@ -8,6 +8,7 @@ import Zeroconf, socket, time, os from mercurial import ui +from mercurial import extensions from mercurial.hgweb import hgweb_mod from mercurial.hgweb import hgwebdir_mod @@ -114,8 +115,8 @@ v.properties.get("path", "/")) yield "zc-" + n, u -def config(self, section, key, default=None, untrusted=False): +def config(orig, self, section, key, default=None, untrusted=False): if section == "paths" and key.startswith("zc-"): for n, p in getzcpaths(): if n == key: return p @@ -118,6 +119,6 @@ if section == "paths" and key.startswith("zc-"): for n, p in getzcpaths(): if n == key: return p - return oldconfig(self, section, key, default, untrusted) + return orig(self, section, key, default, untrusted) @@ -123,7 +124,7 @@ -def configitems(self, section): - r = oldconfigitems(self, section, untrusted=False) +def configitems(orig, self, section): + r = orig(self, section, untrusted=False) if section == "paths": r += getzcpaths() return r @@ -126,10 +127,8 @@ if section == "paths": r += getzcpaths() return r -oldconfig = ui.ui.config -oldconfigitems = ui.ui.configitems -ui.ui.config = config -ui.ui.configitems = configitems +extensions.wrapfunction(ui.ui, 'config', config) +extensions.wrapfunction(ui.ui, 'configitems', configitems) hgweb_mod.hgweb = hgwebzc hgwebdir_mod.hgwebdir = hgwebdirzc