46 lastlog = {desc} ## same as {desc|firstline} in this context |
46 lastlog = {desc} ## same as {desc|firstline} in this context |
47 checked in by = {author} |
47 checked in by = {author} |
48 ... |
48 ... |
49 ''' |
49 ''' |
50 |
50 |
|
51 from mercurial.i18n import gettext as _ |
|
52 # above line for backwards compatibility; can be changed to |
|
53 # from mercurial.i18n import _ |
|
54 # some day |
51 from mercurial import cmdutil, templater, util |
55 from mercurial import cmdutil, templater, util |
52 from mercurial.node import * |
56 from mercurial.node import * |
53 import os.path, re, sys, time |
57 import os.path, re, sys, time |
54 |
58 |
55 deftemplates = { |
59 deftemplates = { |
69 templater.common_filters['utcdate'] = utcdate |
73 templater.common_filters['utcdate'] = utcdate |
70 |
74 |
71 def kwfmatches(ui, repo, files): |
75 def kwfmatches(ui, repo, files): |
72 '''Selects candidates for keyword substitution |
76 '''Selects candidates for keyword substitution |
73 configured in keyword section in hgrc.''' |
77 configured in keyword section in hgrc.''' |
74 files = [f for f in files if not f.startswith('.hg')] |
78 names = [pat for pat, opt in ui.configitems('keyword') if opt == 'expand'] |
75 if not files: |
79 if not names: |
|
80 ui.warn(_('keyword: no filename patterns for expansion\n')) |
76 return [] |
81 return [] |
77 candidates = [] |
82 kwfmatcher = util.matcher(repo.root, cwd='', names=names, exc=['.hg*'])[1] |
78 kwfmatchers = [util.matcher(repo.root, '', [pat], [], [])[1] |
83 return [f for f in files if kwfmatcher(f)] |
79 for pat, opt in ui.configitems('keyword') if opt == 'expand'] |
|
80 for f in files: |
|
81 for mf in kwfmatchers: |
|
82 if mf(f): |
|
83 candidates.append(f) |
|
84 break |
|
85 return candidates |
|
86 |
84 |
87 |
85 |
88 class kwtemplater(object): |
86 class kwtemplater(object): |
89 ''' |
87 ''' |
90 Sets up keyword templates, corresponding keyword regex, and |
88 Sets up keyword templates, corresponding keyword regex, and |
181 |
179 |
182 |
180 |
183 def pretxnkw(ui, repo, hooktype, **args): |
181 def pretxnkw(ui, repo, hooktype, **args): |
184 '''pretxncommit hook that collects candidates for keyword expansion |
182 '''pretxncommit hook that collects candidates for keyword expansion |
185 on commit and expands keywords in working dir.''' |
183 on commit and expands keywords in working dir.''' |
186 from mercurial.i18n import gettext as _ |
|
187 # above line for backwards compatibility; can be changed to |
|
188 # from mercurial.i18n import _ |
|
189 # some day |
|
190 from mercurial import commands |
184 from mercurial import commands |
191 |
185 |
192 cmd, sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[1:] |
186 cmd, sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[1:] |
193 if repr(cmd).split()[1] in ('tag', 'import_'): |
187 if repr(cmd).split()[1] in ('tag', 'import_'): |
194 return |
188 return |