Mercurial > hg
comparison hgext/keyword.py @ 7216:292fb2ad2846
extensions: use new wrapper functions
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 22 Oct 2008 17:34:52 -0500 |
parents | 17bdcd59b9ad |
children | b6f5490effbf |
comparison
equal
deleted
inserted
replaced
7215:0ab5f21c390b | 7216:292fb2ad2846 |
---|---|
76 Expansions spanning more than one line and incremental expansions, | 76 Expansions spanning more than one line and incremental expansions, |
77 like CVS' $Log$, are not supported. A keyword template map | 77 like CVS' $Log$, are not supported. A keyword template map |
78 "Log = {desc}" expands to the first line of the changeset description. | 78 "Log = {desc}" expands to the first line of the changeset description. |
79 ''' | 79 ''' |
80 | 80 |
81 from mercurial import commands, cmdutil, dispatch, filelog, revlog | 81 from mercurial import commands, cmdutil, dispatch, filelog, revlog, extensions |
82 from mercurial import patch, localrepo, templater, templatefilters, util | 82 from mercurial import patch, localrepo, templater, templatefilters, util |
83 from mercurial.hgweb import webcommands | 83 from mercurial.hgweb import webcommands |
84 from mercurial.node import nullid, hex | 84 from mercurial.node import nullid, hex |
85 from mercurial.i18n import _ | 85 from mercurial.i18n import _ |
86 import re, shutil, tempfile, time | 86 import re, shutil, tempfile, time |
414 kwtools['inc'].append(pat) | 414 kwtools['inc'].append(pat) |
415 else: | 415 else: |
416 kwtools['exc'].append(pat) | 416 kwtools['exc'].append(pat) |
417 | 417 |
418 if kwtools['inc']: | 418 if kwtools['inc']: |
419 def kwdispatch_parse(ui, args): | 419 def kwdispatch_parse(orig, ui, args): |
420 '''Monkeypatch dispatch._parse to obtain running hg command.''' | 420 '''Monkeypatch dispatch._parse to obtain running hg command.''' |
421 cmd, func, args, options, cmdoptions = dispatch_parse(ui, args) | 421 cmd, func, args, options, cmdoptions = orig(ui, args) |
422 kwtools['hgcmd'] = cmd | 422 kwtools['hgcmd'] = cmd |
423 return cmd, func, args, options, cmdoptions | 423 return cmd, func, args, options, cmdoptions |
424 | 424 |
425 dispatch_parse = dispatch._parse | 425 extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse) |
426 dispatch._parse = kwdispatch_parse | |
427 | 426 |
428 def reposetup(ui, repo): | 427 def reposetup(ui, repo): |
429 '''Sets up repo as kwrepo for keyword substitution. | 428 '''Sets up repo as kwrepo for keyword substitution. |
430 Overrides file method to return kwfilelog instead of filelog | 429 Overrides file method to return kwfilelog instead of filelog |
431 if file matches user configuration. | 430 if file matches user configuration. |
493 return n | 492 return n |
494 finally: | 493 finally: |
495 del wlock, lock | 494 del wlock, lock |
496 | 495 |
497 # monkeypatches | 496 # monkeypatches |
498 def kwpatchfile_init(self, ui, fname, missing=False): | 497 def kwpatchfile_init(orig, self, ui, fname, missing=False): |
499 '''Monkeypatch/wrap patch.patchfile.__init__ to avoid | 498 '''Monkeypatch/wrap patch.patchfile.__init__ to avoid |
500 rejects or conflicts due to expanded keywords in working dir.''' | 499 rejects or conflicts due to expanded keywords in working dir.''' |
501 patchfile_init(self, ui, fname, missing) | 500 orig(self, ui, fname, missing) |
502 # shrink keywords read from working dir | 501 # shrink keywords read from working dir |
503 self.lines = kwt.shrinklines(self.fname, self.lines) | 502 self.lines = kwt.shrinklines(self.fname, self.lines) |
504 | 503 |
505 def kw_diff(repo, node1=None, node2=None, match=None, | 504 def kw_diff(orig, repo, node1=None, node2=None, match=None, |
506 fp=None, changes=None, opts=None): | 505 fp=None, changes=None, opts=None): |
507 '''Monkeypatch patch.diff to avoid expansion except when | 506 '''Monkeypatch patch.diff to avoid expansion except when |
508 comparing against working dir.''' | 507 comparing against working dir.''' |
509 if node2 is not None: | 508 if node2 is not None: |
510 kwt.matcher = util.never | 509 kwt.matcher = util.never |
511 elif node1 is not None and node1 != repo['.'].node(): | 510 elif node1 is not None and node1 != repo['.'].node(): |
512 kwt.restrict = True | 511 kwt.restrict = True |
513 patch_diff(repo, node1, node2, match, fp, changes, opts) | 512 orig(repo, node1, node2, match, fp, changes, opts) |
514 | 513 |
515 def kwweb_annotate(web, req, tmpl): | 514 def kwweb_skip(orig, web, req, tmpl): |
516 '''Wraps webcommands.annotate turning off keyword expansion.''' | 515 '''Wraps webcommands.x turning off keyword expansion.''' |
517 kwt.matcher = util.never | 516 kwt.matcher = util.never |
518 return webcommands_annotate(web, req, tmpl) | 517 return orig(web, req, tmpl) |
519 | |
520 def kwweb_changeset(web, req, tmpl): | |
521 '''Wraps webcommands.changeset turning off keyword expansion.''' | |
522 kwt.matcher = util.never | |
523 return webcommands_changeset(web, req, tmpl) | |
524 | |
525 def kwweb_filediff(web, req, tmpl): | |
526 '''Wraps webcommands.filediff turning off keyword expansion.''' | |
527 kwt.matcher = util.never | |
528 return webcommands_filediff(web, req, tmpl) | |
529 | 518 |
530 repo.__class__ = kwrepo | 519 repo.__class__ = kwrepo |
531 | 520 |
532 patchfile_init = patch.patchfile.__init__ | 521 extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) |
533 patch_diff = patch.diff | 522 extensions.wrapfunction(patch, 'diff', kw_diff) |
534 webcommands_annotate = webcommands.annotate | 523 for c in 'annotate changeset rev filediff diff'.split(): |
535 webcommands_changeset = webcommands.changeset | 524 extensions.wrapfunction(webcommands, c, kwweb_skip) |
536 webcommands_filediff = webcommands.filediff | |
537 | |
538 patch.patchfile.__init__ = kwpatchfile_init | |
539 patch.diff = kw_diff | |
540 webcommands.annotate = kwweb_annotate | |
541 webcommands.changeset = webcommands.rev = kwweb_changeset | |
542 webcommands.filediff = webcommands.diff = kwweb_filediff | |
543 | |
544 | 525 |
545 cmdtable = { | 526 cmdtable = { |
546 'kwdemo': | 527 'kwdemo': |
547 (demo, | 528 (demo, |
548 [('d', 'default', None, _('show default keyword template maps')), | 529 [('d', 'default', None, _('show default keyword template maps')), |