[PATCH] keyword: store functions before their monkey redefinitions
Christian Ebert
blacktrash at gmx.net
Tue Aug 26 12:35:48 UTC 2008
Hi,
Enticed by djc I regrouped the monkey patch code, with a
paedagogic message for laymen longing for a standard procedure ;)
c
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1219753690 -7200
# Node ID 4dd0b1e00140ee81ce8467472a1770a583af12c5
# Parent ce94b3236ea4541aa4b96512a1155d4694a36e62
keyword: store functions before their monkey redefinitions
monkey creation step by step:
1. store original function in variable
2. redefine function using stored original
3. assign original name to redefined function
diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -416,13 +416,14 @@
kwtools['exc'].append(pat)
if kwtools['inc']:
+ dispatch_parse = dispatch._parse
+
def kwdispatch_parse(ui, args):
'''Monkeypatch dispatch._parse to obtain running hg command.'''
cmd, func, args, options, cmdoptions = dispatch_parse(ui, args)
kwtools['hgcmd'] = cmd
return cmd, func, args, options, cmdoptions
- dispatch_parse = dispatch._parse
dispatch._parse = kwdispatch_parse
def reposetup(ui, repo):
@@ -494,7 +495,12 @@
finally:
del wlock, lock
- # monkeypatches
+ repo.__class__ = kwrepo
+
+ # monkeypatch diff/patch methods
+ patchfile_init = patch.patchfile.__init__
+ patch_diff = patch.diff
+
def kwpatchfile_init(self, ui, fname, missing=False):
'''Monkeypatch/wrap patch.patchfile.__init__ to avoid
rejects or conflicts due to expanded keywords in working dir.'''
@@ -512,6 +518,14 @@
kwt.restrict = True
patch_diff(repo, node1, node2, match, fp, changes, opts)
+ patch.patchfile.__init__ = kwpatchfile_init
+ patch.diff = kw_diff
+
+ # monkeypatch hgweb methods
+ webcommands_annotate = webcommands.annotate
+ webcommands_changeset = webcommands.changeset
+ webcommands_filediff = webcommands.filediff
+
def kwweb_annotate(web, req, tmpl):
'''Wraps webcommands.annotate turning off keyword expansion.'''
kwt.matcher = util.never
@@ -527,16 +541,6 @@
kwt.matcher = util.never
return webcommands_filediff(web, req, tmpl)
- 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
More information about the Mercurial-devel
mailing list