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