97 _patchfile_init = patchfile.__init__ |
97 _patchfile_init = patchfile.__init__ |
98 except ImportError: |
98 except ImportError: |
99 _patchfile_init = None |
99 _patchfile_init = None |
100 |
100 |
101 # backwards compatibility hacks |
101 # backwards compatibility hacks |
|
102 |
|
103 try: |
|
104 # templatefilters module introduced in 9f1e6ab76069 |
|
105 from mercurial import templatefilters |
|
106 template_filters = templatefilters.filters |
|
107 template_firstline = templatefilters.firstline |
|
108 except ImportError: |
|
109 template_filters = templater.common_filters |
|
110 template_firstline = templater.firstline |
102 |
111 |
103 def _normal(repo, files): |
112 def _normal(repo, files): |
104 '''Backwards compatible repo.dirstate.normal/update.''' |
113 '''Backwards compatible repo.dirstate.normal/update.''' |
105 # 6fd953d5faea introduced dirstate.normal() |
114 # 6fd953d5faea introduced dirstate.normal() |
106 try: |
115 try: |
107 for f in files: |
116 for f in files: |
108 repo.dirstate.normal(f) |
117 repo.dirstate.normal(f) |
109 except AttributeError: |
118 except AttributeError: |
110 repo.dirstate.update(files, 'n') |
119 repo.dirstate.update(files, 'n') |
111 |
|
112 def _link(repo, f): |
|
113 try: |
|
114 return repo._link(f) |
|
115 except AttributeError: |
|
116 return os.path.islink(repo.wjoin(f)) |
|
117 |
120 |
118 def _pathto(repo, f, cwd=None): |
121 def _pathto(repo, f, cwd=None): |
119 '''kwfiles behaves similar to status, using pathto since 78b6add1f966.''' |
122 '''kwfiles behaves similar to status, using pathto since 78b6add1f966.''' |
120 try: |
123 try: |
121 return repo.pathto(f, cwd) |
124 return repo.pathto(f, cwd) |
157 self.templates = dict(kwmaps) |
160 self.templates = dict(kwmaps) |
158 escaped = map(re.escape, self.templates.keys()) |
161 escaped = map(re.escape, self.templates.keys()) |
159 kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped) |
162 kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped) |
160 self.re_kw = re.compile(kwpat) |
163 self.re_kw = re.compile(kwpat) |
161 |
164 |
162 templater.common_filters['utcdate'] = utcdate |
165 template_filters['utcdate'] = utcdate |
163 self.ct = self._changeset_templater() |
166 self.ct = self._changeset_templater() |
164 |
167 |
165 def _changeset_templater(self): |
168 def _changeset_templater(self): |
166 '''Backwards compatible cmdutil.changeset_templater.''' |
169 '''Backwards compatible cmdutil.changeset_templater.''' |
167 # before 1e0b94cfba0e there was an extra "brinfo" argument |
170 # before 1e0b94cfba0e there was an extra "brinfo" argument |
196 '''Substitutes keyword using corresponding template.''' |
199 '''Substitutes keyword using corresponding template.''' |
197 kw = mobj.group(1) |
200 kw = mobj.group(1) |
198 self.ct.use_template(self.templates[kw]) |
201 self.ct.use_template(self.templates[kw]) |
199 self.ui.pushbuffer() |
202 self.ui.pushbuffer() |
200 self.ct.show(changenode=node, root=self.repo.root, file=path) |
203 self.ct.show(changenode=node, root=self.repo.root, file=path) |
201 return '$%s: %s $' % (kw, templater.firstline(self.ui.popbuffer())) |
204 ekw = template_firstline(self.ui.popbuffer()) |
|
205 return '$%s: %s $' % (kw, ekw) |
202 |
206 |
203 return subfunc(kwsub, data) |
207 return subfunc(kwsub, data) |
204 |
208 |
205 def expand(self, path, data, node): |
209 def expand(self, path, data, node): |
206 '''Returns data with keywords expanded.''' |
210 '''Returns data with keywords expanded.''' |
410 modified, added, removed, deleted, unknown, ignored, clean = status |
414 modified, added, removed, deleted, unknown, ignored, clean = status |
411 files = modified + added + clean |
415 files = modified + added + clean |
412 if opts.get('untracked'): |
416 if opts.get('untracked'): |
413 files += unknown |
417 files += unknown |
414 files.sort() |
418 files.sort() |
415 kwfiles = [f for f in files if not _link(repo, f) and repo._kwt.matcher(f)] |
419 # use full def of repo._link for backwards compatibility |
|
420 kwfiles = [f for f in files if |
|
421 not os.path.islink(repo.wjoin(f)) and repo._kwt.matcher(f)] |
416 cwd = pats and repo.getcwd() or '' |
422 cwd = pats and repo.getcwd() or '' |
417 kwfstats = not opts.get('ignore') and (('K', kwfiles),) or () |
423 kwfstats = not opts.get('ignore') and (('K', kwfiles),) or () |
418 if opts.get('all') or opts.get('ignore'): |
424 if opts.get('all') or opts.get('ignore'): |
419 kwfstats += (('I', [f for f in files if f not in kwfiles]),) |
425 kwfstats += (('I', [f for f in files if f not in kwfiles]),) |
420 for char, filenames in kwfstats: |
426 for char, filenames in kwfstats: |
433 # 3rd argument sets expansion to False |
439 # 3rd argument sets expansion to False |
434 _kwfwrite(ui, repo, False, *pats, **opts) |
440 _kwfwrite(ui, repo, False, *pats, **opts) |
435 |
441 |
436 |
442 |
437 def reposetup(ui, repo): |
443 def reposetup(ui, repo): |
438 if not repo.local(): |
444 if not repo.local() or repo.root.endswith('/.hg/patches'): |
439 return |
445 return |
440 |
446 |
441 inc, exc = [], ['.hgtags', '.hg_archival.txt'] |
447 inc, exc = [], ['.hgtags', '.hg_archival.txt'] |
442 for pat, opt in ui.configitems('keyword'): |
448 for pat, opt in ui.configitems('keyword'): |
443 if opt != 'ignore': |
449 if opt != 'ignore': |