hgkw/keyword.py
branchstable
changeset 655 2b60823c4506
parent 654 e188e35ff4ad
child 656 89e0584cdc5c
equal deleted inserted replaced
649:c01143cef2c7 655:2b60823c4506
   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('all')
   252         return repo.status(match=match, unknown=unknown, clean=True)
   252                    or opts.get('untracked'))
       
   253         return repo.status(match=cmdutil.match(repo, pats, opts), clean=True,
       
   254                            unknown=unknown)
   253     if ui.configitems('keyword'):
   255     if ui.configitems('keyword'):
   254         raise util.Abort(_('[keyword] patterns cannot match'))
   256         raise util.Abort(_('[keyword] patterns cannot match'))
   255     raise util.Abort(_('no [keyword] patterns configured'))
   257     raise util.Abort(_('no [keyword] patterns configured'))
   256 
   258 
   257 def _kwfwrite(ui, repo, expand, *pats, **opts):
   259 def _kwfwrite(ui, repo, expand, *pats, **opts):
   258     '''Selects files and passes them to kwtemplater.overwrite.'''
   260     '''Selects files and passes them to kwtemplater.overwrite.'''
   259     if repo.dirstate.parents()[1] != nullid:
   261     if repo.dirstate.parents()[1] != nullid:
   260         raise util.Abort(_('outstanding uncommitted merge'))
   262         raise util.Abort(_('outstanding uncommitted merge'))
   261     kwt = kwtools['templater']
   263     kwt = kwtools['templater']
   262     status = _status(ui, repo, kwt, False, *pats, **opts)
   264     status = _status(ui, repo, kwt, *pats, **opts)
   263     modified, added, removed, deleted = status[:4]
   265     modified, added, removed, deleted = status[:4]
   264     if modified or added or removed or deleted:
   266     if modified or added or removed or deleted:
   265         raise util.Abort(_('outstanding uncommitted changes'))
   267         raise util.Abort(_('outstanding uncommitted changes'))
   266     wlock = lock = None
   268     wlock = lock = None
   267     try:
   269     try:
   378     expansion.
   380     expansion.
   379 
   381 
   380     See "hg help keyword" on how to construct patterns both for
   382     See "hg help keyword" on how to construct patterns both for
   381     inclusion and exclusion of files.
   383     inclusion and exclusion of files.
   382 
   384 
   383     Use -u/--untracked to list untracked files as well.
   385     With -A/--all and -v/--verbose the codes used to show the status
   384 
       
   385     With -a/--all and -v/--verbose the codes used to show the status
       
   386     of files are::
   386     of files are::
   387 
   387 
   388       K = keyword expansion candidate
   388       K = keyword expansion candidate
   389       k = keyword expansion candidate (untracked)
   389       k = keyword expansion candidate (not tracked)
   390       I = ignored
   390       I = ignored
   391       i = ignored (untracked)
   391       i = ignored (not tracked)
   392     '''
   392     '''
   393     kwt = kwtools['templater']
   393     kwt = kwtools['templater']
   394     status = _status(ui, repo, kwt, opts.get('untracked'), *pats, **opts)
   394     status = _status(ui, repo, kwt, *pats, **opts)
       
   395     cwd = pats and repo.getcwd() or ''
   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 = []
       
   398     if not (opts.get('unknown') or opts.get('untracked')) or opts.get('all'):
       
   399         files = sorted(modified + added + clean)
   397     wctx = repo[None]
   400     wctx = repo[None]
   398     kwfiles = [f for f in files if kwt.iskwfile(f, wctx.flags)]
   401     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)]
   402     kwunknown = [f for f in unknown if kwt.iskwfile(f, wctx.flags)]
   400     cwd = pats and repo.getcwd() or ''
   403     if not opts.get('ignore') or opts.get('all'):
   401     kwfstats = (not opts.get('ignore') and
   404         showfiles = kwfiles, kwunknown
   402                 (('K', kwfiles), ('k', kwuntracked),) or ())
   405     else:
       
   406         showfiles = [], []
   403     if opts.get('all') or opts.get('ignore'):
   407     if opts.get('all') or opts.get('ignore'):
   404         kwfstats += (('I', [f for f in files if f not in kwfiles]),
   408         showfiles += ([f for f in files if f not in kwfiles],
   405                      ('i', [f for f in unknown if f not in kwuntracked]),)
   409                       [f for f in unknown if f not in kwunknown])
   406     for char, filenames in kwfstats:
   410     for char, filenames in zip('KkIi', showfiles):
   407         fmt = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n'
   411         fmt = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n'
   408         for f in filenames:
   412         for f in filenames:
   409             ui.write(fmt % repo.pathto(f, cwd))
   413             ui.write(fmt % repo.pathto(f, cwd))
   410 
   414 
   411 def shrink(ui, repo, *pats, **opts):
   415 def shrink(ui, repo, *pats, **opts):
   543          _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')),
   547          _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')),
   544     'kwexpand': (expand, commands.walkopts,
   548     'kwexpand': (expand, commands.walkopts,
   545                  _('hg kwexpand [OPTION]... [FILE]...')),
   549                  _('hg kwexpand [OPTION]... [FILE]...')),
   546     'kwfiles':
   550     'kwfiles':
   547         (files,
   551         (files,
   548          [('a', 'all', None, _('show keyword status flags of all files')),
   552          [('A', 'all', None, _('show keyword status flags of all files')),
   549           ('i', 'ignore', None, _('show files excluded from expansion')),
   553           ('i', 'ignore', None, _('show files excluded from expansion')),
   550           ('u', 'untracked', None, _('additionally show untracked files')),
   554           ('u', 'unknown', None, _('only show unknown (not tracked) files')),
       
   555           ('a', 'all', None,
       
   556            _('show keyword status flags of all files (DEPRECATED)')),
       
   557           ('u', 'untracked', None, _('only show untracked files (DEPRECATED)')),
   551          ] + commands.walkopts,
   558          ] + commands.walkopts,
   552          _('hg kwfiles [OPTION]... [FILE]...')),
   559          _('hg kwfiles [OPTION]... [FILE]...')),
   553     'kwshrink': (shrink, commands.walkopts,
   560     'kwshrink': (shrink, commands.walkopts,
   554                  _('hg kwshrink [OPTION]... [FILE]...')),
   561                  _('hg kwshrink [OPTION]... [FILE]...')),
   555 }
   562 }