97 'Id': '{file|basename},v {node|short} {date|utcdate} {author|user}', |
97 'Id': '{file|basename},v {node|short} {date|utcdate} {author|user}', |
98 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', |
98 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', |
99 } |
99 } |
100 |
100 |
101 kwcommands = ('status', 'commit', 'update', 'revert', 'backout', 'diff', 'cat', |
101 kwcommands = ('status', 'commit', 'update', 'revert', 'backout', 'diff', 'cat', |
102 'archive', 'pull', 'unbundle', 'import') |
102 'archive', 'pull', 'unbundle', 'import') |
103 |
103 |
104 def utcdate(date): |
104 def utcdate(date): |
105 '''Returns hgdate in cvs-like UTC format.''' |
105 '''Returns hgdate in cvs-like UTC format.''' |
106 return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0])) |
106 return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0])) |
107 |
107 |
130 templates = dict(ui.configitems('keywordmaps')) |
130 templates = dict(ui.configitems('keywordmaps')) |
131 if templates: |
131 if templates: |
132 # parse templates here for less overhead in kwsub matchfunc |
132 # parse templates here for less overhead in kwsub matchfunc |
133 for k in templates.keys(): |
133 for k in templates.keys(): |
134 templates[k] = templater.parsestring(templates[k], |
134 templates[k] = templater.parsestring(templates[k], |
135 quoted=False) |
135 quoted=False) |
136 self.templates = templates or deftemplates |
136 self.templates = templates or deftemplates |
137 self.re_kw = re.compile(r'\$(%s)[^$]*?\$' % |
137 escaped = [re.escape(k) for k in self.templates.keys()] |
138 '|'.join([re.escape(k) for k in self.templates.keys()])) |
138 self.re_kw = re.compile(r'\$(%s)[^$]*?\$' % '|'.join(escaped)) |
139 templater.common_filters['utcdate'] = utcdate |
139 templater.common_filters['utcdate'] = utcdate |
140 try: |
140 try: |
141 self.t = cmdutil.changeset_templater(ui, repo, |
141 self.t = cmdutil.changeset_templater(ui, repo, False, '', False) |
142 False, '', False) |
|
143 except TypeError: |
142 except TypeError: |
144 # depending on hg rev changeset_templater has extra "brinfo" arg |
143 # depending on hg rev changeset_templater has extra "brinfo" arg |
145 self.t = cmdutil.changeset_templater(ui, repo, |
144 self.t = cmdutil.changeset_templater(ui, repo, |
146 False, None, '', False) |
145 False, None, '', False) |
147 |
146 |
148 def kwsub(self, mobj): |
147 def kwsub(self, mobj): |
149 '''Substitutes keyword using corresponding template.''' |
148 '''Substitutes keyword using corresponding template.''' |
150 kw = mobj.group(1) |
149 kw = mobj.group(1) |
151 self.t.use_template(self.templates[kw]) |
150 self.t.use_template(self.templates[kw]) |
199 return self.kwtemplater.expand(node, self, data) |
198 return self.kwtemplater.expand(node, self, data) |
200 |
199 |
201 def add(self, text, meta, tr, link, p1=None, p2=None): |
200 def add(self, text, meta, tr, link, p1=None, p2=None): |
202 '''Removes keyword substitutions when adding to filelog.''' |
201 '''Removes keyword substitutions when adding to filelog.''' |
203 text = self.kwtemplater.shrink(text) |
202 text = self.kwtemplater.shrink(text) |
204 return super(kwfilelog, self).add(text, |
203 return super(kwfilelog, self).add(text, meta, tr, link, p1=p1, p2=p2) |
205 meta, tr, link, p1=p1, p2=p2) |
|
206 |
204 |
207 def cmp(self, node, text): |
205 def cmp(self, node, text): |
208 '''Removes keyword substitutions for comparison.''' |
206 '''Removes keyword substitutions for comparison.''' |
209 text = self.kwtemplater.shrink(text) |
207 text = self.kwtemplater.shrink(text) |
210 return super(kwfilelog, self).cmp(node, text) |
208 return super(kwfilelog, self).cmp(node, text) |
243 return kwfilelog(self.sopener, f, kwt) |
241 return kwfilelog(self.sopener, f, kwt) |
244 else: |
242 else: |
245 return filelog.filelog(self.sopener, f) |
243 return filelog.filelog(self.sopener, f) |
246 |
244 |
247 def commit(self, files=None, text="", user=None, date=None, |
245 def commit(self, files=None, text="", user=None, date=None, |
248 match=util.always, force=False, lock=None, wlock=None, |
246 match=util.always, force=False, lock=None, wlock=None, |
249 force_editor=False, p1=None, p2=None, extra={}): |
247 force_editor=False, p1=None, p2=None, extra={}): |
250 '''Wraps commit, expanding keywords of committed and |
248 '''Wraps commit, expanding keywords of committed and |
251 configured files in working directory.''' |
249 configured files in working directory.''' |
252 wrelease = False |
250 wrelease = False |
253 if not wlock: |
251 if not wlock: |
254 wlock = self.wlock() |
252 wlock = self.wlock() |
255 wrelease = True |
253 wrelease = True |
256 try: |
254 try: |
257 removed = self.status()[2] |
255 removed = self.status()[2] |
258 |
256 |
259 node = super(kwrepo, self).commit(files=files, |
257 node = super(kwrepo, |
260 text=text, user=user, date=date, |
258 self).commit(files=files, text=text, user=user, |
261 match=match, force=force, lock=lock, wlock=wlock, |
259 date=date, match=match, force=force, |
262 force_editor=force_editor, p1=p1, p2=p2, extra=extra) |
260 lock=lock, wlock=wlock, |
|
261 force_editor=force_editor, |
|
262 p1=p1, p2=p2, extra=extra) |
263 if node is None: |
263 if node is None: |
264 return node |
264 return node |
265 |
265 |
266 candidates = self.changelog.read(node)[3] |
266 candidates = self.changelog.read(node)[3] |
267 candidates = [f for f in candidates if self.kwfmatcher(f) |
267 candidates = [f for f in candidates if self.kwfmatcher(f) |
268 and f not in removed |
268 and f not in removed |
269 and not os.path.islink(self.wjoin(f))] |
269 and not os.path.islink(self.wjoin(f))] |
270 if not candidates: |
270 if not candidates: |
271 return node |
271 return node |
272 |
272 |
273 kwt = kwtemplater(self.ui, self, node=node) |
273 kwt = kwtemplater(self.ui, self, node=node) |
274 kwt.overwrite(candidates) |
274 kwt.overwrite(candidates) |