##// END OF EJS Templates
keyword: specific regular expressions depending on read mode...
Christian Ebert -
r12630:94926263 default
parent child Browse files
Show More
@@ -163,9 +163,9 b' class kwtemplater(object):'
163 for k, v in kwmaps)
163 for k, v in kwmaps)
164 else:
164 else:
165 self.templates = _defaultkwmaps(self.ui)
165 self.templates = _defaultkwmaps(self.ui)
166 escaped = map(re.escape, self.templates.keys())
166 escaped = '|'.join(map(re.escape, self.templates.keys()))
167 kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
167 self.re_kw = re.compile(r'\$(%s)\$' % escaped)
168 self.re_kw = re.compile(kwpat)
168 self.re_kwexp = re.compile(r'\$(%s): [^$\n\r]*? \$' % escaped)
169
169
170 templatefilters.filters.update({'utcdate': utcdate,
170 templatefilters.filters.update({'utcdate': utcdate,
171 'svnisodate': svnisodate,
171 'svnisodate': svnisodate,
@@ -196,7 +196,7 b' class kwtemplater(object):'
196 expansion are not symbolic links.'''
196 expansion are not symbolic links.'''
197 return [f for f in cand if self.match(f) and not 'l' in ctx.flags(f)]
197 return [f for f in cand if self.match(f) and not 'l' in ctx.flags(f)]
198
198
199 def overwrite(self, ctx, candidates, lookup, expand):
199 def overwrite(self, ctx, candidates, lookup, expand, recsubn=None):
200 '''Overwrites selected files expanding/shrinking keywords.'''
200 '''Overwrites selected files expanding/shrinking keywords.'''
201 if self.restrict or lookup: # exclude kw_copy
201 if self.restrict or lookup: # exclude kw_copy
202 candidates = self.iskwfile(candidates, ctx)
202 candidates = self.iskwfile(candidates, ctx)
@@ -206,6 +206,8 b' class kwtemplater(object):'
206 if self.restrict or expand and lookup:
206 if self.restrict or expand and lookup:
207 mf = ctx.manifest()
207 mf = ctx.manifest()
208 fctx = ctx
208 fctx = ctx
209 subn = (self.restrict and self.re_kw.subn or
210 recsubn or self.re_kwexp.subn)
209 msg = (expand and _('overwriting %s expanding keywords\n')
211 msg = (expand and _('overwriting %s expanding keywords\n')
210 or _('overwriting %s shrinking keywords\n'))
212 or _('overwriting %s shrinking keywords\n'))
211 for f in candidates:
213 for f in candidates:
@@ -218,11 +220,11 b' class kwtemplater(object):'
218 if expand:
220 if expand:
219 if lookup:
221 if lookup:
220 fctx = self.repo.filectx(f, fileid=mf[f]).changectx()
222 fctx = self.repo.filectx(f, fileid=mf[f]).changectx()
221 data, found = self.substitute(data, f, fctx, self.re_kw.subn)
223 data, found = self.substitute(data, f, fctx, subn)
222 elif self.restrict:
224 elif self.restrict:
223 found = self.re_kw.search(data)
225 found = self.re_kw.search(data)
224 else:
226 else:
225 data, found = _shrinktext(data, self.re_kw.subn)
227 data, found = _shrinktext(data, subn)
226 if found:
228 if found:
227 self.ui.note(msg % f)
229 self.ui.note(msg % f)
228 self.repo.wwrite(f, data, ctx.flags(f))
230 self.repo.wwrite(f, data, ctx.flags(f))
@@ -234,7 +236,7 b' class kwtemplater(object):'
234 def shrink(self, fname, text):
236 def shrink(self, fname, text):
235 '''Returns text with all keyword substitutions removed.'''
237 '''Returns text with all keyword substitutions removed.'''
236 if self.match(fname) and not util.binary(text):
238 if self.match(fname) and not util.binary(text):
237 return _shrinktext(text, self.re_kw.sub)
239 return _shrinktext(text, self.re_kwexp.sub)
238 return text
240 return text
239
241
240 def shrinklines(self, fname, lines):
242 def shrinklines(self, fname, lines):
@@ -242,7 +244,7 b' class kwtemplater(object):'
242 if self.match(fname):
244 if self.match(fname):
243 text = ''.join(lines)
245 text = ''.join(lines)
244 if not util.binary(text):
246 if not util.binary(text):
245 return _shrinktext(text, self.re_kw.sub).splitlines(True)
247 return _shrinktext(text, self.re_kwexp.sub).splitlines(True)
246 return lines
248 return lines
247
249
248 def wread(self, fname, data):
250 def wread(self, fname, data):
@@ -569,12 +571,15 b' def reposetup(ui, repo):'
569 # record returns 0 even when nothing has changed
571 # record returns 0 even when nothing has changed
570 # therefore compare nodes before and after
572 # therefore compare nodes before and after
571 ctx = repo['.']
573 ctx = repo['.']
574 modified, added = repo[None].status()[:2]
572 ret = orig(ui, repo, commitfunc, *pats, **opts)
575 ret = orig(ui, repo, commitfunc, *pats, **opts)
573 recordctx = repo['.']
576 recctx = repo['.']
574 if ctx != recordctx:
577 if ctx != recctx:
575 candidates = [f for f in recordctx.files() if f in recordctx]
578 modified = [f for f in modified if f in recctx]
579 added = [f for f in added if f in recctx]
576 kwt.restrict = False
580 kwt.restrict = False
577 kwt.overwrite(recordctx, candidates, False, True)
581 kwt.overwrite(recctx, modified, False, True, kwt.re_kwexp.subn)
582 kwt.overwrite(recctx, added, False, True, kwt.re_kw.subn)
578 kwt.restrict = True
583 kwt.restrict = True
579 return ret
584 return ret
580 finally:
585 finally:
@@ -373,7 +373,6 b' File a should be clean'
373
373
374 $ hg status -A a
374 $ hg status -A a
375 C a
375 C a
376 $ rm msg
377
376
378 rollback and revert expansion
377 rollback and revert expansion
379
378
@@ -418,6 +417,25 b' Only z should be overwritten'
418 $ hg update -C
417 $ hg update -C
419 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
418 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
420
419
420 record added file
421
422 $ echo '$Id$' > r
423 $ hg add r
424 $ hg -v record -l msg -d '1 12' r<<EOF
425 > y
426 > EOF
427 diff --git a/r b/r
428 new file mode 100644
429 examine changes to 'r'? [Ynsfdaq?]
430 r
431 committed changeset 3:899491280810
432 overwriting r expanding keywords
433 $ hg --verbose rollback
434 rolling back to revision 2 (undo commit)
435 overwriting r shrinking keywords
436 $ hg forget r
437 $ rm msg r
438
421 Test patch queue repo
439 Test patch queue repo
422
440
423 $ hg init --mq
441 $ hg init --mq
General Comments 0
You need to be logged in to leave comments. Login now