hgext/keyword.py
branchstable
changeset 13069 6aff4f144ad3
parent 13025 99210fb3bc0a
child 13072 8c6b7a5f38c4
equal deleted inserted replaced
13068:adff480db558 13069:6aff4f144ad3
    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'
   553         return orig(web, req, tmpl)
   553         return orig(web, req, tmpl)
   554 
   554 
   555     def kw_copy(orig, ui, repo, pats, opts, rename=False):
   555     def kw_copy(orig, ui, repo, pats, opts, rename=False):
   556         '''Wraps cmdutil.copy so that copy/rename destinations do not
   556         '''Wraps cmdutil.copy so that copy/rename destinations do not
   557         contain expanded keywords.
   557         contain expanded keywords.
   558         Note that the source may also be a symlink as:
   558         Note that the source of a regular file destination may also be a
       
   559         symlink:
   559         hg cp sym x                -> x is symlink
   560         hg cp sym x                -> x is symlink
   560         cp sym x; hg cp -A sym x   -> x is file (maybe expanded keywords)
   561         cp sym x; hg cp -A sym x   -> x is file (maybe expanded keywords)
   561         '''
   562         For the latter we have to follow the symlink to find out whether its
       
   563         target is configured for expansion and we therefore must unexpand the
       
   564         keywords in the destination.'''
   562         orig(ui, repo, pats, opts, rename)
   565         orig(ui, repo, pats, opts, rename)
   563         if opts.get('dry_run'):
   566         if opts.get('dry_run'):
   564             return
   567             return
   565         wctx = repo[None]
   568         wctx = repo[None]
       
   569         cwd = repo.getcwd()
       
   570 
       
   571         def haskwsource(dest):
       
   572             '''Returns true if dest is a regular file and configured for
       
   573             expansion or a symlink which points to a file configured for
       
   574             expansion. '''
       
   575             source = repo.dirstate.copied(dest)
       
   576             if 'l' in wctx.flags(source):
       
   577                 source = util.canonpath(repo.root, cwd,
       
   578                                         os.path.realpath(source))
       
   579             return kwt.match(source)
       
   580 
   566         candidates = [f for f in repo.dirstate.copies() if
   581         candidates = [f for f in repo.dirstate.copies() if
   567                       kwt.match(repo.dirstate.copied(f)) and
   582                       not 'l' in wctx.flags(f) and haskwsource(f)]
   568                       not 'l' in wctx.flags(f)]
       
   569         kwt.overwrite(wctx, candidates, False, False)
   583         kwt.overwrite(wctx, candidates, False, False)
   570 
   584 
   571     def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts):
   585     def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts):
   572         '''Wraps record.dorecord expanding keywords after recording.'''
   586         '''Wraps record.dorecord expanding keywords after recording.'''
   573         wlock = repo.wlock()
   587         wlock = repo.wlock()