hgkw/keyword.py
changeset 868 16cfcb56859a
parent 864 2cadbd48a31b
child 870 ef8b368bf24b
equal deleted inserted replaced
867:e560e379ce30 868:16cfcb56859a
    84 
    84 
    85 from mercurial import commands, context, cmdutil, dispatch, filelog, extensions
    85 from mercurial import commands, context, cmdutil, dispatch, filelog, extensions
    86 from mercurial import localrepo, match, patch, templatefilters, templater, util
    86 from mercurial import localrepo, match, patch, templatefilters, templater, util
    87 from mercurial.hgweb import webcommands
    87 from mercurial.hgweb import webcommands
    88 from mercurial.i18n import _
    88 from mercurial.i18n import _
    89 import re, shutil, tempfile
    89 import os, re, shutil, tempfile
    90 
    90 
    91 commands.optionalrepo += ' kwdemo'
    91 commands.optionalrepo += ' kwdemo'
    92 
    92 
    93 # hg commands that do not act on keywords
    93 # hg commands that do not act on keywords
    94 nokwcommands = ('add addremove annotate bundle export grep incoming init log'
    94 nokwcommands = ('add addremove annotate bundle export grep incoming init log'
   568         return orig(web, req, tmpl)
   568         return orig(web, req, tmpl)
   569 
   569 
   570     def kw_copy(orig, ui, repo, pats, opts, rename=False):
   570     def kw_copy(orig, ui, repo, pats, opts, rename=False):
   571         '''Wraps cmdutil.copy so that copy/rename destinations do not
   571         '''Wraps cmdutil.copy so that copy/rename destinations do not
   572         contain expanded keywords.
   572         contain expanded keywords.
   573         Note that the source may also be a symlink as:
   573         Note that the source of a regular file destination may also be a
       
   574         symlink:
   574         hg cp sym x                -> x is symlink
   575         hg cp sym x                -> x is symlink
   575         cp sym x; hg cp -A sym x   -> x is file (maybe expanded keywords)
   576         cp sym x; hg cp -A sym x   -> x is file (maybe expanded keywords)
   576         '''
   577         For the latter we have to follow the symlink to find out whether its
       
   578         target is configured for expansion and we therefore must unexpand the
       
   579         keywords in the destination.'''
   577         orig(ui, repo, pats, opts, rename)
   580         orig(ui, repo, pats, opts, rename)
   578         if opts.get('dry_run'):
   581         if opts.get('dry_run'):
   579             return
   582             return
   580         wctx = repo[None]
   583         wctx = repo[None]
       
   584         cwd = repo.getcwd()
       
   585 
       
   586         def haskwsource(dest):
       
   587             '''Returns true if dest is a regular file and configured for
       
   588             expansion or a symlink which points to a file configured for
       
   589             expansion. '''
       
   590             source = repo.dirstate.copied(dest)
       
   591             if 'l' in wctx.flags(source):
       
   592                 source = util.canonpath(repo.root, cwd,
       
   593                                         os.path.realpath(source))
       
   594             return kwt.match(source)
       
   595 
   581         candidates = [f for f in repo.dirstate.copies() if
   596         candidates = [f for f in repo.dirstate.copies() if
   582                       kwt.match(repo.dirstate.copied(f)) and
   597                       not 'l' in wctx.flags(f) and haskwsource(f)]
   583                       not 'l' in wctx.flags(f)]
       
   584         kwt.overwrite(wctx, candidates, False, False)
   598         kwt.overwrite(wctx, candidates, False, False)
   585 
   599 
   586     def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts):
   600     def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts):
   587         '''Wraps record.dorecord expanding keywords after recording.'''
   601         '''Wraps record.dorecord expanding keywords after recording.'''
   588         wlock = repo.wlock()
   602         wlock = repo.wlock()