106 svnisodate = lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)') |
106 svnisodate = lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)') |
107 # date like in svn's $Id |
107 # date like in svn's $Id |
108 svnutcdate = lambda x: util.datestr((x[0], 0), '%Y-%m-%d %H:%M:%SZ') |
108 svnutcdate = lambda x: util.datestr((x[0], 0), '%Y-%m-%d %H:%M:%SZ') |
109 |
109 |
110 # make keyword tools accessible |
110 # make keyword tools accessible |
111 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']} |
111 kwtools = {'templater': None, 'hgcmd': ''} |
112 |
112 |
113 |
113 |
114 def _defaultkwmaps(ui): |
114 def _defaultkwmaps(ui): |
115 '''Returns default keywordmaps according to keywordset configuration.''' |
115 '''Returns default keywordmaps according to keywordset configuration.''' |
116 templates = { |
116 templates = { |
139 ''' |
139 ''' |
140 Sets up keyword templates, corresponding keyword regex, and |
140 Sets up keyword templates, corresponding keyword regex, and |
141 provides keyword substitution functions. |
141 provides keyword substitution functions. |
142 ''' |
142 ''' |
143 |
143 |
144 def __init__(self, ui, repo): |
144 def __init__(self, ui, repo, inc, exc): |
145 self.ui = ui |
145 self.ui = ui |
146 self.repo = repo |
146 self.repo = repo |
147 self.match = match.match(repo.root, '', [], |
147 self.match = match.match(repo.root, '', [], inc, exc) |
148 kwtools['inc'], kwtools['exc']) |
|
149 self.restrict = kwtools['hgcmd'] in restricted.split() |
148 self.restrict = kwtools['hgcmd'] in restricted.split() |
150 self.record = kwtools['hgcmd'] in recordcommands.split() |
149 self.record = kwtools['hgcmd'] in recordcommands.split() |
151 |
150 |
152 kwmaps = self.ui.configitems('keywordmaps') |
151 kwmaps = self.ui.configitems('keywordmaps') |
153 if kwmaps: # override default templates |
152 if kwmaps: # override default templates |
436 # 3rd argument sets expansion to False |
435 # 3rd argument sets expansion to False |
437 _kwfwrite(ui, repo, False, *pats, **opts) |
436 _kwfwrite(ui, repo, False, *pats, **opts) |
438 |
437 |
439 |
438 |
440 def uisetup(ui): |
439 def uisetup(ui): |
441 '''Collects [keyword] config in kwtools. |
440 ''' Monkeypatches dispatch._parse to retrieve user command.''' |
442 Monkeypatches dispatch._parse if needed.''' |
441 |
443 |
442 def kwdispatch_parse(orig, ui, args): |
444 for pat, opt in ui.configitems('keyword'): |
443 '''Monkeypatch dispatch._parse to obtain running hg command.''' |
445 if opt != 'ignore': |
444 cmd, func, args, options, cmdoptions = orig(ui, args) |
446 kwtools['inc'].append(pat) |
445 kwtools['hgcmd'] = cmd |
447 else: |
446 return cmd, func, args, options, cmdoptions |
448 kwtools['exc'].append(pat) |
447 |
449 |
448 extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse) |
450 if kwtools['inc']: |
|
451 def kwdispatch_parse(orig, ui, args): |
|
452 '''Monkeypatch dispatch._parse to obtain running hg command.''' |
|
453 cmd, func, args, options, cmdoptions = orig(ui, args) |
|
454 kwtools['hgcmd'] = cmd |
|
455 return cmd, func, args, options, cmdoptions |
|
456 |
|
457 extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse) |
|
458 |
449 |
459 def reposetup(ui, repo): |
450 def reposetup(ui, repo): |
460 '''Sets up repo as kwrepo for keyword substitution. |
451 '''Sets up repo as kwrepo for keyword substitution. |
461 Overrides file method to return kwfilelog instead of filelog |
452 Overrides file method to return kwfilelog instead of filelog |
462 if file matches user configuration. |
453 if file matches user configuration. |
463 Wraps commit to overwrite configured files with updated |
454 Wraps commit to overwrite configured files with updated |
464 keyword substitutions. |
455 keyword substitutions. |
465 Monkeypatches patch and webcommands.''' |
456 Monkeypatches patch and webcommands.''' |
466 |
457 |
467 try: |
458 try: |
468 if (not repo.local() or not kwtools['inc'] |
459 if (not repo.local() or kwtools['hgcmd'] in nokwcommands.split() |
469 or kwtools['hgcmd'] in nokwcommands.split() |
|
470 or '.hg' in util.splitpath(repo.root) |
460 or '.hg' in util.splitpath(repo.root) |
471 or repo._url.startswith('bundle:')): |
461 or repo._url.startswith('bundle:')): |
472 return |
462 return |
473 except AttributeError: |
463 except AttributeError: |
474 pass |
464 pass |
475 |
465 |
476 kwtools['templater'] = kwt = kwtemplater(ui, repo) |
466 inc, exc = [], ['.hg*'] |
|
467 for pat, opt in ui.configitems('keyword'): |
|
468 if opt != 'ignore': |
|
469 inc.append(pat) |
|
470 else: |
|
471 exc.append(pat) |
|
472 if not inc: |
|
473 return |
|
474 |
|
475 kwtools['templater'] = kwt = kwtemplater(ui, repo, inc, exc) |
477 |
476 |
478 class kwrepo(repo.__class__): |
477 class kwrepo(repo.__class__): |
479 def file(self, f): |
478 def file(self, f): |
480 if f[0] == '/': |
479 if f[0] == '/': |
481 f = f[1:] |
480 f = f[1:] |