hgkw/keyword.py
changeset 651 a047bb9bab24
parent 646 c2b1a05b35e1
child 652 d278bbd85f5d
equal deleted inserted replaced
650:3bfb3411f6f2 651:a047bb9bab24
   242         if self.renamed(node):
   242         if self.renamed(node):
   243             t2 = super(kwfilelog, self).read(node)
   243             t2 = super(kwfilelog, self).read(node)
   244             return t2 != text
   244             return t2 != text
   245         return revlog.revlog.cmp(self, node, text)
   245         return revlog.revlog.cmp(self, node, text)
   246 
   246 
   247 def _status(ui, repo, kwt, unknown, *pats, **opts):
   247 def _status(ui, repo, kwt, *pats, **opts):
   248     '''Bails out if [keyword] configuration is not active.
   248     '''Bails out if [keyword] configuration is not active.
   249     Returns status of working directory.'''
   249     Returns status of working directory.'''
   250     if kwt:
   250     if kwt:
   251         match = cmdutil.match(repo, pats, opts)
   251         unknown = opts.get('unknown') or opts.get('untracked')
   252         return repo.status(match=match, unknown=unknown, clean=True)
   252         return repo.status(match=cmdutil.match(repo, pats, opts), clean=True,
       
   253                            unknown=unknown)
   253     if ui.configitems('keyword'):
   254     if ui.configitems('keyword'):
   254         raise util.Abort(_('[keyword] patterns cannot match'))
   255         raise util.Abort(_('[keyword] patterns cannot match'))
   255     raise util.Abort(_('no [keyword] patterns configured'))
   256     raise util.Abort(_('no [keyword] patterns configured'))
   256 
   257 
   257 def _kwfwrite(ui, repo, expand, *pats, **opts):
   258 def _kwfwrite(ui, repo, expand, *pats, **opts):
   258     '''Selects files and passes them to kwtemplater.overwrite.'''
   259     '''Selects files and passes them to kwtemplater.overwrite.'''
   259     if repo.dirstate.parents()[1] != nullid:
   260     if repo.dirstate.parents()[1] != nullid:
   260         raise util.Abort(_('outstanding uncommitted merge'))
   261         raise util.Abort(_('outstanding uncommitted merge'))
   261     kwt = kwtools['templater']
   262     kwt = kwtools['templater']
   262     status = _status(ui, repo, kwt, False, *pats, **opts)
   263     status = _status(ui, repo, kwt, *pats, **opts)
   263     modified, added, removed, deleted = status[:4]
   264     modified, added, removed, deleted = status[:4]
   264     if modified or added or removed or deleted:
   265     if modified or added or removed or deleted:
   265         raise util.Abort(_('outstanding uncommitted changes'))
   266         raise util.Abort(_('outstanding uncommitted changes'))
   266     wlock = lock = None
   267     wlock = lock = None
   267     try:
   268     try:
   378     expansion.
   379     expansion.
   379 
   380 
   380     See "hg help keyword" on how to construct patterns both for
   381     See "hg help keyword" on how to construct patterns both for
   381     inclusion and exclusion of files.
   382     inclusion and exclusion of files.
   382 
   383 
   383     Use -u/--untracked to list untracked files as well.
   384     Use -u/--unknown to list unknown (not tracked) files as well.
   384 
   385 
   385     With -a/--all and -v/--verbose the codes used to show the status
   386     With -a/--all and -v/--verbose the codes used to show the status
   386     of files are::
   387     of files are::
   387 
   388 
   388       K = keyword expansion candidate
   389       K = keyword expansion candidate
   389       k = keyword expansion candidate (untracked)
   390       k = keyword expansion candidate (not tracked)
   390       I = ignored
   391       I = ignored
   391       i = ignored (untracked)
   392       i = ignored (not tracked)
   392     '''
   393     '''
   393     kwt = kwtools['templater']
   394     kwt = kwtools['templater']
   394     status = _status(ui, repo, kwt, opts.get('untracked'), *pats, **opts)
   395     status = _status(ui, repo, kwt, *pats, **opts)
   395     modified, added, removed, deleted, unknown, ignored, clean = status
   396     modified, added, removed, deleted, unknown, ignored, clean = status
   396     files = sorted(modified + added + clean)
   397     files = sorted(modified + added + clean)
   397     wctx = repo[None]
   398     wctx = repo[None]
   398     kwfiles = [f for f in files if kwt.iskwfile(f, wctx.flags)]
   399     kwfiles = [f for f in files if kwt.iskwfile(f, wctx.flags)]
   399     kwuntracked = [f for f in unknown if kwt.iskwfile(f, wctx.flags)]
   400     kwunknown = [f for f in unknown if kwt.iskwfile(f, wctx.flags)]
   400     cwd = pats and repo.getcwd() or ''
   401     cwd = pats and repo.getcwd() or ''
   401     kwfstats = (not opts.get('ignore') and
   402     kwfstats = (not opts.get('ignore') and
   402                 (('K', kwfiles), ('k', kwuntracked),) or ())
   403                 (('K', kwfiles), ('k', kwunknown),) or ())
   403     if opts.get('all') or opts.get('ignore'):
   404     if opts.get('all') or opts.get('ignore'):
   404         kwfstats += (('I', [f for f in files if f not in kwfiles]),
   405         kwfstats += (('I', [f for f in files if f not in kwfiles]),
   405                      ('i', [f for f in unknown if f not in kwuntracked]),)
   406                      ('i', [f for f in unknown if f not in kwunknown]),)
   406     for char, filenames in kwfstats:
   407     for char, filenames in kwfstats:
   407         fmt = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n'
   408         fmt = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n'
   408         for f in filenames:
   409         for f in filenames:
   409             ui.write(fmt % repo.pathto(f, cwd))
   410             ui.write(fmt % repo.pathto(f, cwd))
   410 
   411 
   545                  _('hg kwexpand [OPTION]... [FILE]...')),
   546                  _('hg kwexpand [OPTION]... [FILE]...')),
   546     'kwfiles':
   547     'kwfiles':
   547         (files,
   548         (files,
   548          [('a', 'all', None, _('show keyword status flags of all files')),
   549          [('a', 'all', None, _('show keyword status flags of all files')),
   549           ('i', 'ignore', None, _('show files excluded from expansion')),
   550           ('i', 'ignore', None, _('show files excluded from expansion')),
   550           ('u', 'untracked', None, _('additionally show untracked files')),
   551           ('u', 'unknown', None,
       
   552            _('additionally show unknown (not tracked) files')),
       
   553           ('u', 'untracked', None,
       
   554            _('additionally show untracked files (DEPRECATED)')),
   551          ] + commands.walkopts,
   555          ] + commands.walkopts,
   552          _('hg kwfiles [OPTION]... [FILE]...')),
   556          _('hg kwfiles [OPTION]... [FILE]...')),
   553     'kwshrink': (shrink, commands.walkopts,
   557     'kwshrink': (shrink, commands.walkopts,
   554                  _('hg kwshrink [OPTION]... [FILE]...')),
   558                  _('hg kwshrink [OPTION]... [FILE]...')),
   555 }
   559 }