##// END OF EJS Templates
keyword: collect filename patterns, wrap dispatch._parse in uisetup...
Christian Ebert -
r6502:ba8a0338 default
parent child Browse files
Show More
@@ -102,12 +102,12 b' def utcdate(date):'
102 102
103 103
104 104 # make keyword tools accessible
105 kwtools = {'templater': None, 'hgcmd': None}
105 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
106 106
107 # store originals of monkeypatches
107 # store originals of monkeypatches to be done at end of reposetup
108 # that is, only if needed
108 109 _patchfile_init = patch.patchfile.__init__
109 110 _patch_diff = patch.diff
110 _dispatch_parse = dispatch._parse
111 111 _webcommands_changeset = webcommands.changeset
112 112 _webcommands_filediff = webcommands.filediff
113 113
@@ -140,16 +140,6 b' def _kwweb_filediff(web, req, tmpl):'
140 140 kwtools['templater'].matcher = util.never
141 141 return _webcommands_filediff(web, req, tmpl)
142 142
143 def _kwdispatch_parse(ui, args):
144 '''Monkeypatch dispatch._parse to obtain running hg command.'''
145 cmd, func, args, options, cmdoptions = _dispatch_parse(ui, args)
146 kwtools['hgcmd'] = cmd
147 return cmd, func, args, options, cmdoptions
148
149 # dispatch._parse is run before reposetup, so wrap it here
150 # all other actual monkey patching is done at end of reposetup
151 dispatch._parse = _kwdispatch_parse
152
153 143
154 144 class kwtemplater(object):
155 145 '''
@@ -166,10 +156,11 b' class kwtemplater(object):'
166 156 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}',
167 157 }
168 158
169 def __init__(self, ui, repo, inc, exc):
159 def __init__(self, ui, repo):
170 160 self.ui = ui
171 161 self.repo = repo
172 self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
162 self.matcher = util.matcher(repo.root,
163 inc=kwtools['inc'], exc=kwtools['exc'])[1]
173 164 self.restrict = kwtools['hgcmd'] in restricted.split()
174 165
175 166 kwmaps = self.ui.configitems('keywordmaps')
@@ -370,6 +361,7 b' def demo(ui, repo, *args, **opts):'
370 361 ui.readconfig(repo.join('hgrc'))
371 362 if not opts.get('default'):
372 363 kwmaps = dict(ui.configitems('keywordmaps')) or kwtemplater.templates
364 uisetup(ui)
373 365 reposetup(ui, repo)
374 366 for k, v in ui.configitems('extensions'):
375 367 if k.endswith('keyword'):
@@ -451,6 +443,26 b' def shrink(ui, repo, *pats, **opts):'
451 443 _kwfwrite(ui, repo, False, *pats, **opts)
452 444
453 445
446 def uisetup(ui):
447 '''Collects [keyword] config in kwtools.
448 Monkeypatches dispatch._parse if needed.'''
449
450 for pat, opt in ui.configitems('keyword'):
451 if opt != 'ignore':
452 kwtools['inc'].append(pat)
453 else:
454 kwtools['exc'].append(pat)
455
456 if kwtools['inc']:
457 def kwdispatch_parse(ui, args):
458 '''Monkeypatch dispatch._parse to obtain running hg command.'''
459 cmd, func, args, options, cmdoptions = dispatch_parse(ui, args)
460 kwtools['hgcmd'] = cmd
461 return cmd, func, args, options, cmdoptions
462
463 dispatch_parse = dispatch._parse
464 dispatch._parse = kwdispatch_parse
465
454 466 def reposetup(ui, repo):
455 467 '''Sets up repo as kwrepo for keyword substitution.
456 468 Overrides file method to return kwfilelog instead of filelog
@@ -461,23 +473,15 b' def reposetup(ui, repo):'
461 473 files configured at all for keyword substitution.'''
462 474
463 475 try:
464 if (not repo.local() or kwtools['hgcmd'] in nokwcommands.split()
476 if (not repo.local() or not kwtools['inc']
477 or kwtools['hgcmd'] in nokwcommands.split()
465 478 or '.hg' in util.splitpath(repo.root)
466 479 or repo._url.startswith('bundle:')):
467 480 return
468 481 except AttributeError:
469 482 pass
470 483
471 inc, exc = [], ['.hg*']
472 for pat, opt in ui.configitems('keyword'):
473 if opt != 'ignore':
474 inc.append(pat)
475 else:
476 exc.append(pat)
477 if not inc:
478 return
479
480 kwtools['templater'] = kwt = kwtemplater(ui, repo, inc, exc)
484 kwtools['templater'] = kwt = kwtemplater(ui, repo)
481 485
482 486 class kwrepo(repo.__class__):
483 487 def file(self, f):
General Comments 0
You need to be logged in to leave comments. Login now