Mercurial > hg
comparison hgext/keyword.py @ 6081:beb775df5630
keyword: enable all monkey patches using _kwtemplater at reposetup
- no need for try-except block
- underscore prefix for private methods
- add doc strings
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Sun, 10 Feb 2008 08:25:09 +0100 |
parents | e521ec1ad985 |
children | 875b745996e8 |
comparison
equal
deleted
inserted
replaced
6080:4baad19c4801 | 6081:beb775df5630 |
---|---|
113 if _kwtemplater.matcher(self.fname): | 113 if _kwtemplater.matcher(self.fname): |
114 # shrink keywords read from working dir | 114 # shrink keywords read from working dir |
115 kwshrunk = _kwtemplater.shrink(''.join(self.lines)) | 115 kwshrunk = _kwtemplater.shrink(''.join(self.lines)) |
116 self.lines = kwshrunk.splitlines(True) | 116 self.lines = kwshrunk.splitlines(True) |
117 | 117 |
118 def _kwweb_changeset(web, req, tmpl): | |
119 '''Wraps webcommands.changeset turning off keyword expansion.''' | |
120 _kwtemplater.matcher = util.never | |
121 return web.changeset(tmpl, web.changectx(req)) | |
122 | |
123 def _kwweb_filediff(web, req, tmpl): | |
124 '''Wraps webcommands.filediff turning off keyword expansion.''' | |
125 _kwtemplater.matcher = util.never | |
126 return web.filediff(tmpl, web.filectx(req)) | |
127 | |
118 def _kwdispatch_parse(ui, args): | 128 def _kwdispatch_parse(ui, args): |
119 '''Monkeypatch dispatch._parse to obtain | 129 '''Monkeypatch dispatch._parse to obtain |
120 current command and command options (global _cmd, _cmdoptions).''' | 130 current command and command options (global _cmd, _cmdoptions).''' |
121 global _cmd, _cmdoptions | 131 global _cmd, _cmdoptions |
122 _cmd, func, args, options, _cmdoptions = _dispatch_parse(ui, args) | 132 _cmd, func, args, options, _cmdoptions = _dispatch_parse(ui, args) |
123 return _cmd, func, args, options, _cmdoptions | 133 return _cmd, func, args, options, _cmdoptions |
124 | 134 |
125 def kwweb_changeset(web, req, tmpl): | 135 # dispatch._parse is run before reposetup, so wrap it here |
126 try: | |
127 _kwtemplater.matcher = util.never | |
128 except AttributeError: | |
129 pass | |
130 return web.changeset(tmpl, web.changectx(req)) | |
131 | |
132 def kwweb_filediff(web, req, tmpl): | |
133 try: | |
134 _kwtemplater.matcher = util.never | |
135 except AttributeError: | |
136 pass | |
137 return web.filediff(tmpl, web.filectx(req)) | |
138 | |
139 dispatch._parse = _kwdispatch_parse | 136 dispatch._parse = _kwdispatch_parse |
140 webcommands.changeset = webcommands.rev = kwweb_changeset | |
141 webcommands.filediff = webcommands.diff = kwweb_filediff | |
142 | 137 |
143 | 138 |
144 class kwtemplater(object): | 139 class kwtemplater(object): |
145 ''' | 140 ''' |
146 Sets up keyword templates, corresponding keyword regex, and | 141 Sets up keyword templates, corresponding keyword regex, and |
525 finally: | 520 finally: |
526 del wlock, lock | 521 del wlock, lock |
527 | 522 |
528 repo.__class__ = kwrepo | 523 repo.__class__ = kwrepo |
529 patch.patchfile.__init__ = _kwpatchfile_init | 524 patch.patchfile.__init__ = _kwpatchfile_init |
525 webcommands.changeset = webcommands.rev = _kwweb_changeset | |
526 webcommands.filediff = webcommands.diff = _kwweb_filediff | |
530 | 527 |
531 | 528 |
532 cmdtable = { | 529 cmdtable = { |
533 'kwdemo': | 530 'kwdemo': |
534 (demo, | 531 (demo, |