hgkw/keyword.py
changeset 285 0aa02d36b3b1
parent 284 bc19ab02c5f9
child 286 0dac9b324b03
equal deleted inserted replaced
284:bc19ab02c5f9 285:0aa02d36b3b1
   336         # 7th argument sets commit to False
   336         # 7th argument sets commit to False
   337         _overwrite(ui, repo, candidates, ctx.node(), man, expand, False)
   337         _overwrite(ui, repo, candidates, ctx.node(), man, expand, False)
   338     finally:
   338     finally:
   339         del wlock, lock
   339         del wlock, lock
   340 
   340 
   341 
       
   342 def shrink(ui, repo, *pats, **opts):
       
   343     '''revert expanded keywords in working directory
       
   344 
       
   345     Run before changing/disabling active keywords
       
   346     or if you experience problems with "hg import" or "hg merge".
       
   347 
       
   348     kwshrink refuses to run if given files contain local changes.
       
   349     '''
       
   350     # 3rd argument sets expansion to False
       
   351     _kwfwrite(ui, repo, False, *pats, **opts)
       
   352 
       
   353 def expand(ui, repo, *pats, **opts):
       
   354     '''expand keywords in working directory
       
   355 
       
   356     Run after (re)enabling keyword expansion.
       
   357 
       
   358     kwexpand refuses to run if given files contain local changes.
       
   359     '''
       
   360     # 3rd argument sets expansion to True
       
   361     _kwfwrite(ui, repo, True, *pats, **opts)
       
   362 
       
   363 def files(ui, repo, *pats, **opts):
       
   364     '''print files currently configured for keyword expansion
       
   365 
       
   366     Crosscheck which files in working directory are potential targets for
       
   367     keyword expansion.
       
   368     That is, files matched by [keyword] config patterns but not symlinks.
       
   369     '''
       
   370     status = _status(ui, repo, *pats, **opts)
       
   371     modified, added, removed, deleted, unknown, ignored, clean = status
       
   372     if opts['untracked']:
       
   373         files = modified + added + unknown + clean
       
   374     else:
       
   375         files = modified + added + clean
       
   376     files.sort()
       
   377     # use the full definition of repo._link for backwards compatibility
       
   378     kwfiles = [f for f in files if ui.kwfmatcher(f)
       
   379                and not os.path.islink(repo.wjoin(f))]
       
   380     cwd = pats and repo.getcwd() or ''
       
   381     allf = opts['all']
       
   382     ignore = opts['ignore']
       
   383     flag = (allf or ui.verbose) and 1 or 0
       
   384     if not ignore:
       
   385         format = ('%s\n', 'K %s\n')[flag]
       
   386         for k in kwfiles:
       
   387             ui.write(format % _pathto(repo, k, cwd))
       
   388     if allf or ignore:
       
   389         format = ('%s\n', 'I %s\n')[flag]
       
   390         for i in [f for f in files if f not in kwfiles]:
       
   391             ui.write(format % _pathto(repo, i, cwd))
       
   392 
   341 
   393 def demo(ui, repo, *args, **opts):
   342 def demo(ui, repo, *args, **opts):
   394     '''print [keywordmaps] configuration and an expansion example
   343     '''print [keywordmaps] configuration and an expansion example
   395 
   344 
   396     Show current, custom, or default keyword template maps
   345     Show current, custom, or default keyword template maps
   465     demostatus('%s keywords expanded%s' % (kwstatus, pathinfo))
   414     demostatus('%s keywords expanded%s' % (kwstatus, pathinfo))
   466     ui.write(repo.wread(fn))
   415     ui.write(repo.wread(fn))
   467     ui.debug(_('\nremoving temporary repo %s\n') % tmpdir)
   416     ui.debug(_('\nremoving temporary repo %s\n') % tmpdir)
   468     shutil.rmtree(tmpdir, ignore_errors=True)
   417     shutil.rmtree(tmpdir, ignore_errors=True)
   469 
   418 
       
   419 def expand(ui, repo, *pats, **opts):
       
   420     '''expand keywords in working directory
       
   421 
       
   422     Run after (re)enabling keyword expansion.
       
   423 
       
   424     kwexpand refuses to run if given files contain local changes.
       
   425     '''
       
   426     # 3rd argument sets expansion to True
       
   427     _kwfwrite(ui, repo, True, *pats, **opts)
       
   428 
       
   429 def files(ui, repo, *pats, **opts):
       
   430     '''print files currently configured for keyword expansion
       
   431 
       
   432     Crosscheck which files in working directory are potential targets for
       
   433     keyword expansion.
       
   434     That is, files matched by [keyword] config patterns but not symlinks.
       
   435     '''
       
   436     status = _status(ui, repo, *pats, **opts)
       
   437     modified, added, removed, deleted, unknown, ignored, clean = status
       
   438     if opts['untracked']:
       
   439         files = modified + added + unknown + clean
       
   440     else:
       
   441         files = modified + added + clean
       
   442     files.sort()
       
   443     # use the full definition of repo._link for backwards compatibility
       
   444     kwfiles = [f for f in files if ui.kwfmatcher(f)
       
   445                and not os.path.islink(repo.wjoin(f))]
       
   446     cwd = pats and repo.getcwd() or ''
       
   447     allf = opts['all']
       
   448     ignore = opts['ignore']
       
   449     flag = (allf or ui.verbose) and 1 or 0
       
   450     if not ignore:
       
   451         format = ('%s\n', 'K %s\n')[flag]
       
   452         for k in kwfiles:
       
   453             ui.write(format % _pathto(repo, k, cwd))
       
   454     if allf or ignore:
       
   455         format = ('%s\n', 'I %s\n')[flag]
       
   456         for i in [f for f in files if f not in kwfiles]:
       
   457             ui.write(format % _pathto(repo, i, cwd))
       
   458 
       
   459 def shrink(ui, repo, *pats, **opts):
       
   460     '''revert expanded keywords in working directory
       
   461 
       
   462     Run before changing/disabling active keywords
       
   463     or if you experience problems with "hg import" or "hg merge".
       
   464 
       
   465     kwshrink refuses to run if given files contain local changes.
       
   466     '''
       
   467     # 3rd argument sets expansion to False
       
   468     _kwfwrite(ui, repo, False, *pats, **opts)
       
   469 
   470 
   470 
   471 def reposetup(ui, repo):
   471 def reposetup(ui, repo):
   472     '''Sets up repo as kwrepo for keyword substitution.
   472     '''Sets up repo as kwrepo for keyword substitution.
   473     Overrides file method to return kwfilelog instead of filelog
   473     Overrides file method to return kwfilelog instead of filelog
   474     if file matches user configuration.
   474     if file matches user configuration.
   555     'kwdemo':
   555     'kwdemo':
   556         (demo,
   556         (demo,
   557          [('d', 'default', None, _('show default keyword template maps')),
   557          [('d', 'default', None, _('show default keyword template maps')),
   558           ('f', 'rcfile', [], _('read maps from rcfile'))],
   558           ('f', 'rcfile', [], _('read maps from rcfile'))],
   559          _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')),
   559          _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')),
       
   560     'kwexpand': (expand, commands.walkopts,
       
   561                  _('hg kwexpand [OPTION]... [FILE]...')),
   560     'kwfiles':
   562     'kwfiles':
   561         (files,
   563         (files,
   562          [('a', 'all', None, _('show keyword status flags of all files')),
   564          [('a', 'all', None, _('show keyword status flags of all files')),
   563           ('i', 'ignore', None, _('show files excluded from expansion')),
   565           ('i', 'ignore', None, _('show files excluded from expansion')),
   564           ('u', 'untracked', None, _('additionally show untracked files')),
   566           ('u', 'untracked', None, _('additionally show untracked files')),
   565          ] + commands.walkopts,
   567          ] + commands.walkopts,
   566          _('hg kwfiles [OPTION]... [FILE]...')),
   568          _('hg kwfiles [OPTION]... [FILE]...')),
   567     'kwshrink': (shrink, commands.walkopts,
   569     'kwshrink': (shrink, commands.walkopts,
   568                  _('hg kwshrink [OPTION]... [FILE]...')),
   570                  _('hg kwshrink [OPTION]... [FILE]...')),
   569     'kwexpand': (expand, commands.walkopts,
       
   570                  _('hg kwexpand [OPTION]... [FILE]...')),
       
   571 }
   571 }