hgkw/keyword.py
changeset 269 b5b64c9da876
parent 268 14ebaa9eaf1d
child 270 371ce7fe5f13
equal deleted inserted replaced
268:14ebaa9eaf1d 269:b5b64c9da876
   306         if self.renamed(node):
   306         if self.renamed(node):
   307             t2 = super(kwfilelog, self).read(node)
   307             t2 = super(kwfilelog, self).read(node)
   308             return t2 != text
   308             return t2 != text
   309         return revlog.revlog.cmp(self, node, text)
   309         return revlog.revlog.cmp(self, node, text)
   310 
   310 
   311 def _weedfiles(ui, repo, *pats, **opts):
   311 def _weedfiles(ui, repo, files):
   312     '''Collects files matching arguments and/or walkopts,
   312     '''Selects files that match [keyword] patterns and are not links.'''
   313     sorts out those that are configured for keyword expansion
       
   314     and not links, and returns both lists.'''
       
   315     files, match, anypats = cmdutil.matchpats(repo, pats, opts)
       
   316     status = repo.status(files=files, match=match, list_clean=True)
       
   317     modified, added, removed, deleted, unknown, ignored, clean = status
       
   318     files = modified + added + clean
       
   319     files.sort()
       
   320     try:
   313     try:
   321         # use the full definition of repo._link for backwards compatibility
   314         # use the full definition of repo._link for backwards compatibility
   322         kwfiles = [f for f in files if ui.kwfmatcher(f)
   315         return [f for f in files if ui.kwfmatcher(f)
   323                    and not os.path.islink(repo.wjoin(f))]
   316                 and not os.path.islink(repo.wjoin(f))]
   324         return kwfiles, files
       
   325     except AttributeError:
   317     except AttributeError:
   326         if ui.configitems('keyword'):
   318         if ui.configitems('keyword'):
   327             raise util.Abort(_('[keyword] patterns cannot match'))
   319             raise util.Abort(_('[keyword] patterns cannot match'))
   328         raise util.Abort(_('no [keyword] patterns configured'))
   320         raise util.Abort(_('no [keyword] patterns configured'))
   329 
   321 
   332     bail_if_changed(repo)
   324     bail_if_changed(repo)
   333     wlock = lock = None
   325     wlock = lock = None
   334     try:
   326     try:
   335         wlock = repo.wlock()
   327         wlock = repo.wlock()
   336         lock = repo.lock()
   328         lock = repo.lock()
   337         kwfiles, files = _weedfiles(ui, repo, *pats, **opts)
   329         files, match, anypats = cmdutil.matchpats(repo, pats, opts)
   338         if kwfiles:
   330         clean = repo.status(files=files, match=match, list_clean=True)[6]
       
   331         candidates = _weedfiles(ui, repo, clean)
       
   332         if candidates:
   339             ctx = repo.changectx()
   333             ctx = repo.changectx()
   340             kwt = kwtemplater(ui, repo, expand, node=ctx.node())
   334             kwt = kwtemplater(ui, repo, expand, node=ctx.node())
   341             # 3rd argument sets commit to False
   335             # 3rd argument sets commit to False
   342             kwt.overwrite(kwfiles, ctx.manifest(), False)
   336             kwt.overwrite(candidates, ctx.manifest(), False)
   343     finally:
   337     finally:
   344         del wlock, lock
   338         del wlock, lock
   345 
   339 
   346 
   340 
   347 def shrink(ui, repo, *pats, **opts):
   341 def shrink(ui, repo, *pats, **opts):
   365     '''print files currently configured for keyword expansion
   359     '''print files currently configured for keyword expansion
   366 
   360 
   367     Crosscheck which files in working directory are target of expansion,
   361     Crosscheck which files in working directory are target of expansion,
   368     that is, files matched by [keyword] config patterns but not symlinks.
   362     that is, files matched by [keyword] config patterns but not symlinks.
   369     '''
   363     '''
   370     kwfiles, files = _weedfiles(ui, repo, *pats, **opts)
   364     files, match, anypats = cmdutil.matchpats(repo, pats, opts)
       
   365     status = repo.status(files=files, match=match, list_clean=True)
       
   366     modified, added, removed, deleted, unknown, ignored, clean = status
       
   367     files = modified + added + clean
       
   368     files.sort()
       
   369     kwfiles = _weedfiles(ui, repo, files)
   371     cwd = pats and repo.getcwd() or ''
   370     cwd = pats and repo.getcwd() or ''
   372     allf = opts['all']
   371     allf = opts['all']
   373     ignored = opts['ignored']
   372     ignored = opts['ignored']
   374     flag = (allf or ui.verbose) and 1 or 0
   373     flag = (allf or ui.verbose) and 1 or 0
   375     if not ignored:
   374     if not ignored:
   376         format = ('%s\n', 'K %s\n')[flag]
   375         format = ('%s\n', 'K %s\n')[flag]
   377         for k in kwfiles:
   376         for k in kwfiles:
   378             ui.write(format % _pathto(repo, cwd, k))
   377             ui.write(format % _pathto(repo, cwd, k))
   379     if flag or ignored:
   378     if allf or ignored:
   380         format = ('%s\n', 'I %s\n')[flag]
   379         format = ('%s\n', 'I %s\n')[flag]
   381         for i in [f for f in files if f not in kwfiles]:
   380         for i in [f for f in files if f not in kwfiles]:
   382             ui.write(format % _pathto(repo, cwd, i))
   381             ui.write(format % _pathto(repo, cwd, i))
   383 
   382 
   384 def demo(ui, repo, *args, **opts):
   383 def demo(ui, repo, *args, **opts):