87 |
87 |
88 from mercurial import commands, cmdutil, context, fancyopts |
88 from mercurial import commands, cmdutil, context, fancyopts |
89 from mercurial import filelog, localrepo, revlog, templater, util |
89 from mercurial import filelog, localrepo, revlog, templater, util |
90 from mercurial.node import * |
90 from mercurial.node import * |
91 from mercurial.i18n import gettext as _ |
91 from mercurial.i18n import gettext as _ |
92 import getopt, os.path, re, shutil, tempfile, time |
92 import getopt, os, re, shutil, tempfile, time |
93 |
93 |
94 commands.optionalrepo += ' kwdemo' |
94 commands.optionalrepo += ' kwdemo' |
95 |
95 |
96 # hg commands that do not act on keywords |
96 # hg commands that do not act on keywords |
97 nokwcommands = ('add addremove bundle copy export grep identify incoming init' |
97 nokwcommands = ('add addremove bundle copy export grep identify incoming init' |
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 |
108 |
108 |
109 _kwtemplater, _cmd, _cmdoptions = None, None, None |
109 _kwtemplater = _cmd = _cmdoptions = None |
110 |
110 |
111 # backwards compatibility hacks |
111 # backwards compatibility hacks |
112 |
112 |
113 try: |
113 try: |
114 # cmdutil.parse moves to dispatch._parse in 18a9fbb5cd78 |
114 # cmdutil.parse moves to dispatch._parse in 18a9fbb5cd78 |
263 'Source': '{root}/{file},v', |
263 'Source': '{root}/{file},v', |
264 'Id': '{file|basename},v {node|short} {date|utcdate} {author|user}', |
264 'Id': '{file|basename},v {node|short} {date|utcdate} {author|user}', |
265 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', |
265 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', |
266 } |
266 } |
267 |
267 |
268 def __init__(self, ui, repo, inc, exc, restrict): |
268 def __init__(self, ui, repo, inc, exc, hgcmd): |
269 self.ui = ui |
269 self.ui = ui |
270 self.repo = repo |
270 self.repo = repo |
271 self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] |
271 self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] |
272 self.restrict = restrict |
272 self.restrict = hgcmd in restricted.split() |
273 self.commitnode = None |
273 self.commitnode = None |
274 self.path = '' |
274 self.path = '' |
275 |
275 |
276 kwmaps = self.ui.configitems('keywordmaps') |
276 kwmaps = self.ui.configitems('keywordmaps') |
277 if kwmaps: # override default templates |
277 if kwmaps: # override default templates |
521 modified, added, removed, deleted, unknown, ignored, clean = status |
521 modified, added, removed, deleted, unknown, ignored, clean = status |
522 files = modified + added + clean |
522 files = modified + added + clean |
523 if opts.get('untracked'): |
523 if opts.get('untracked'): |
524 files += unknown |
524 files += unknown |
525 files.sort() |
525 files.sort() |
526 # use the full definition of repo._link for backwards compatibility |
526 wctx = repo.workingctx() |
527 kwfiles = [f for f in files if _kwtemplater.matcher(f) |
527 if hasattr(wctx, 'fileflags'): |
528 and not os.path.islink(repo.wjoin(f))] |
528 islink = lambda p: 'l' in wctx.fileflags(p) |
|
529 else: |
|
530 mf = wctx.manifest() |
|
531 islink = mf.linkf |
|
532 kwfiles = [f for f in files if _iskwfile(f, islink)] |
529 cwd = pats and repo.getcwd() or '' |
533 cwd = pats and repo.getcwd() or '' |
530 kwfstats = not opts.get('ignore') and (('K', kwfiles),) or () |
534 kwfstats = not opts.get('ignore') and (('K', kwfiles),) or () |
531 if opts.get('all') or opts.get('ignore'): |
535 if opts.get('all') or opts.get('ignore'): |
532 kwfstats += (('I', [f for f in files if f not in kwfiles]),) |
536 kwfstats += (('I', [f for f in files if f not in kwfiles]),) |
533 for char, filenames in kwfstats: |
537 for char, filenames in kwfstats: |
559 global _kwtemplater |
563 global _kwtemplater |
560 hgcmd, hgcmdopts = _cmd, _cmdoptions |
564 hgcmd, hgcmdopts = _cmd, _cmdoptions |
561 |
565 |
562 try: |
566 try: |
563 if (not repo.local() or hgcmd in nokwcommands.split() |
567 if (not repo.local() or hgcmd in nokwcommands.split() |
564 or '.hg' in repo.root.split('/') |
568 or '.hg' in repo.root.split(os.sep) |
565 or repo._url.startswith('bundle:')): |
569 or repo._url.startswith('bundle:')): |
566 return |
570 return |
567 except AttributeError: |
571 except AttributeError: |
568 pass |
572 pass |
569 |
573 |
583 return |
587 return |
584 # shrink if rev is not current node |
588 # shrink if rev is not current node |
585 if node1 is not None and node1 != repo.changectx().node(): |
589 if node1 is not None and node1 != repo.changectx().node(): |
586 hgcmd = 'diff1' |
590 hgcmd = 'diff1' |
587 |
591 |
588 restrict = hgcmd in restricted.split() |
592 _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd) |
589 _kwtemplater = kwtemplater(ui, repo, inc, exc, restrict) |
|
590 |
593 |
591 class kwrepo(repo.__class__): |
594 class kwrepo(repo.__class__): |
592 def file(self, f, kwmatch=False): |
595 def file(self, f, kwmatch=False): |
593 if f[0] == '/': |
596 if f[0] == '/': |
594 f = f[1:] |
597 f = f[1:] |
596 return kwfilelog(self.sopener, f) |
599 return kwfilelog(self.sopener, f) |
597 return filelog.filelog(self.sopener, f) |
600 return filelog.filelog(self.sopener, f) |
598 |
601 |
599 def wread(self, filename): |
602 def wread(self, filename): |
600 data = super(kwrepo, self).wread(filename) |
603 data = super(kwrepo, self).wread(filename) |
601 if restrict and _kwtemplater.matcher(filename): |
604 if _kwtemplater.restrict and _kwtemplater.matcher(filename): |
602 return _kwtemplater.shrink(data) |
605 return _kwtemplater.shrink(data) |
603 return data |
606 return data |
604 |
607 |
605 def _commit(self, files, text, user, date, match, force, lock, wlock, |
608 def _commit(self, files, text, user, date, match, force, lock, wlock, |
606 force_editor, p1, p2, extra, empty_ok): |
609 force_editor, p1, p2, extra, empty_ok): |