equal
deleted
inserted
replaced
70 Configuration is done in the [keyword] and [keywordmaps] sections of |
70 Configuration is done in the [keyword] and [keywordmaps] sections of |
71 hgrc files. |
71 hgrc files. |
72 ''' |
72 ''' |
73 |
73 |
74 from mercurial.i18n import gettext as _ |
74 from mercurial.i18n import gettext as _ |
75 # above line for backwards compatibility; can be changed to |
75 # above line for backwards compatibility of standalone version |
76 # from mercurial.i18n import _ |
76 from mercurial import commands, cmdutil, templater, util |
77 # some day |
|
78 from mercurial import context, filelog, revlog |
77 from mercurial import context, filelog, revlog |
79 from mercurial import commands, cmdutil, templater, util |
|
80 from mercurial.node import bin |
78 from mercurial.node import bin |
81 import os.path, re, sys, time |
79 import os.path, re, sys, time |
82 |
80 |
83 deftemplates = { |
81 deftemplates = { |
84 'Revision': '{node|short}', |
82 'Revision': '{node|short}', |
96 |
94 |
97 def getmodulename(): |
95 def getmodulename(): |
98 '''Makes sure pretxncommit-hook can import keyword module |
96 '''Makes sure pretxncommit-hook can import keyword module |
99 regardless of where its located.''' |
97 regardless of where its located.''' |
100 for k, v in sys.modules.iteritems(): |
98 for k, v in sys.modules.iteritems(): |
101 if v is None: |
99 if v is None or not hasattr(v, '__file__'): |
102 continue |
|
103 if not hasattr(v, '__file__'): |
|
104 continue |
100 continue |
105 if v.__file__.startswith(__file__): |
101 if v.__file__.startswith(__file__): |
106 return k |
102 return k |
107 else: |
103 else: |
108 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
104 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
119 self.templates = dict(ui.configitems('keywordmaps')) or deftemplates |
115 self.templates = dict(ui.configitems('keywordmaps')) or deftemplates |
120 self.re_kw = re.compile(r'\$(%s)[^$]*?\$' % |
116 self.re_kw = re.compile(r'\$(%s)[^$]*?\$' % |
121 '|'.join(re.escape(k) for k in self.templates.keys())) |
117 '|'.join(re.escape(k) for k in self.templates.keys())) |
122 templater.common_filters['utcdate'] = utcdate |
118 templater.common_filters['utcdate'] = utcdate |
123 self.t = cmdutil.changeset_templater(ui, repo, False, '', False) |
119 self.t = cmdutil.changeset_templater(ui, repo, False, '', False) |
124 |
|
125 |
120 |
126 def expand(self, mobj, path, node): |
121 def expand(self, mobj, path, node): |
127 '''Expands keyword using corresponding template.''' |
122 '''Expands keyword using corresponding template.''' |
128 kw = mobj.group(1) |
123 kw = mobj.group(1) |
129 template = templater.parsestring(self.templates[kw], quoted=False) |
124 template = templater.parsestring(self.templates[kw], quoted=False) |