125 } |
125 } |
126 |
126 |
127 def __init__(self, ui, repo): |
127 def __init__(self, ui, repo): |
128 self.ui = ui |
128 self.ui = ui |
129 self.repo = repo |
129 self.repo = repo |
130 self.matcher = match.match(repo.root, '', [], |
130 self.match = match.match(repo.root, '', [], |
131 kwtools['inc'], kwtools['exc']) |
131 kwtools['inc'], kwtools['exc']) |
132 self.restrict = kwtools['hgcmd'] in restricted.split() |
132 self.restrict = kwtools['hgcmd'] in restricted.split() |
133 |
133 |
134 kwmaps = self.ui.configitems('keywordmaps') |
134 kwmaps = self.ui.configitems('keywordmaps') |
135 if kwmaps: # override default templates |
135 if kwmaps: # override default templates |
136 kwmaps = [(k, templater.parsestring(v, False)) |
136 kwmaps = [(k, templater.parsestring(v, False)) |
155 return '$%s: %s $' % (kw, ekw) |
155 return '$%s: %s $' % (kw, ekw) |
156 return subfunc(kwsub, data) |
156 return subfunc(kwsub, data) |
157 |
157 |
158 def expand(self, path, node, data): |
158 def expand(self, path, node, data): |
159 '''Returns data with keywords expanded.''' |
159 '''Returns data with keywords expanded.''' |
160 if not self.restrict and self.matcher(path) and not util.binary(data): |
160 if not self.restrict and self.match(path) and not util.binary(data): |
161 ctx = self.repo.filectx(path, fileid=node).changectx() |
161 ctx = self.repo.filectx(path, fileid=node).changectx() |
162 return self.substitute(data, path, ctx, self.re_kw.sub) |
162 return self.substitute(data, path, ctx, self.re_kw.sub) |
163 return data |
163 return data |
164 |
164 |
165 def iskwfile(self, path, flagfunc): |
165 def iskwfile(self, path, flagfunc): |
166 '''Returns true if path matches [keyword] pattern |
166 '''Returns true if path matches [keyword] pattern |
167 and is not a symbolic link. |
167 and is not a symbolic link. |
168 Caveat: localrepository._link fails on Windows.''' |
168 Caveat: localrepository._link fails on Windows.''' |
169 return self.matcher(path) and not 'l' in flagfunc(path) |
169 return self.match(path) and not 'l' in flagfunc(path) |
170 |
170 |
171 def overwrite(self, node, expand, files): |
171 def overwrite(self, node, expand, files): |
172 '''Overwrites selected files expanding/shrinking keywords.''' |
172 '''Overwrites selected files expanding/shrinking keywords.''' |
173 ctx = self.repo[node] |
173 ctx = self.repo[node] |
174 mf = ctx.manifest() |
174 mf = ctx.manifest() |
204 '''Unconditionally removes all keyword substitutions from text.''' |
204 '''Unconditionally removes all keyword substitutions from text.''' |
205 return self.re_kw.sub(r'$\1$', text) |
205 return self.re_kw.sub(r'$\1$', text) |
206 |
206 |
207 def shrink(self, fname, text): |
207 def shrink(self, fname, text): |
208 '''Returns text with all keyword substitutions removed.''' |
208 '''Returns text with all keyword substitutions removed.''' |
209 if self.matcher(fname) and not util.binary(text): |
209 if self.match(fname) and not util.binary(text): |
210 return self.shrinktext(text) |
210 return self.shrinktext(text) |
211 return text |
211 return text |
212 |
212 |
213 def shrinklines(self, fname, lines): |
213 def shrinklines(self, fname, lines): |
214 '''Returns lines with keyword substitutions removed.''' |
214 '''Returns lines with keyword substitutions removed.''' |
215 if self.matcher(fname): |
215 if self.match(fname): |
216 text = ''.join(lines) |
216 text = ''.join(lines) |
217 if not util.binary(text): |
217 if not util.binary(text): |
218 return self.shrinktext(text).splitlines(True) |
218 return self.shrinktext(text).splitlines(True) |
219 return lines |
219 return lines |
220 |
220 |
253 |
253 |
254 def _status(ui, repo, kwt, unknown, *pats, **opts): |
254 def _status(ui, repo, kwt, unknown, *pats, **opts): |
255 '''Bails out if [keyword] configuration is not active. |
255 '''Bails out if [keyword] configuration is not active. |
256 Returns status of working directory.''' |
256 Returns status of working directory.''' |
257 if kwt: |
257 if kwt: |
258 matcher = cmdutil.match(repo, pats, opts) |
258 match = cmdutil.match(repo, pats, opts) |
259 return repo.status(match=matcher, unknown=unknown, clean=True) |
259 return repo.status(match=match, unknown=unknown, clean=True) |
260 if ui.configitems('keyword'): |
260 if ui.configitems('keyword'): |
261 raise util.Abort(_('[keyword] patterns cannot match')) |
261 raise util.Abort(_('[keyword] patterns cannot match')) |
262 raise util.Abort(_('no [keyword] patterns configured')) |
262 raise util.Abort(_('no [keyword] patterns configured')) |
263 |
263 |
264 def _kwfwrite(ui, repo, expand, *pats, **opts): |
264 def _kwfwrite(ui, repo, expand, *pats, **opts): |
497 def kw_diff(orig, repo, node1=None, node2=None, match=None, changes=None, |
497 def kw_diff(orig, repo, node1=None, node2=None, match=None, changes=None, |
498 opts=None): |
498 opts=None): |
499 '''Monkeypatch patch.diff to avoid expansion except when |
499 '''Monkeypatch patch.diff to avoid expansion except when |
500 comparing against working dir.''' |
500 comparing against working dir.''' |
501 if node2 is not None: |
501 if node2 is not None: |
502 kwt.matcher = util.never |
502 kwt.match = util.never |
503 elif node1 is not None and node1 != repo['.'].node(): |
503 elif node1 is not None and node1 != repo['.'].node(): |
504 kwt.restrict = True |
504 kwt.restrict = True |
505 return orig(repo, node1, node2, match, changes, opts) |
505 return orig(repo, node1, node2, match, changes, opts) |
506 |
506 |
507 def kwweb_skip(orig, web, req, tmpl): |
507 def kwweb_skip(orig, web, req, tmpl): |
508 '''Wraps webcommands.x turning off keyword expansion.''' |
508 '''Wraps webcommands.x turning off keyword expansion.''' |
509 kwt.matcher = util.never |
509 kwt.match = util.never |
510 return orig(web, req, tmpl) |
510 return orig(web, req, tmpl) |
511 |
511 |
512 repo.__class__ = kwrepo |
512 repo.__class__ = kwrepo |
513 |
513 |
514 extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) |
514 extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) |