hgkw/keyword.py
changeset 814 0588121c815b
parent 813 9d01f9cab5e2
child 815 1c9959ca570a
equal deleted inserted replaced
813:9d01f9cab5e2 814:0588121c815b
    89 import re, shutil, tempfile
    89 import 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 copy export grep incoming init'
    94 nokwcommands = ('add addremove annotate bundle export grep incoming init log'
    95                 ' log outgoing push rename tip verify convert email glog')
    95                 ' outgoing push tip verify convert email glog')
    96 
    96 
    97 # hg commands that trigger expansion only when writing to working dir,
    97 # hg commands that trigger expansion only when writing to working dir,
    98 # not when reading filelog, and unexpand when reading from working dir
    98 # not when reading filelog, and unexpand when reading from working dir
    99 restricted = 'merge kwexpand kwshrink record qrecord resolve transplant'
    99 restricted = 'merge kwexpand kwshrink record qrecord resolve transplant'
   100 
   100 
   197         Caveat: localrepository._link fails on Windows.'''
   197         Caveat: localrepository._link fails on Windows.'''
   198         return self.match(path) and not 'l' in flagfunc(path)
   198         return self.match(path) and not 'l' in flagfunc(path)
   199 
   199 
   200     def overwrite(self, ctx, candidates, lookup, expand):
   200     def overwrite(self, ctx, candidates, lookup, expand):
   201         '''Overwrites selected files expanding/shrinking keywords.'''
   201         '''Overwrites selected files expanding/shrinking keywords.'''
   202         candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)]
   202         if self.restrict or lookup: # exclude kw_copy
       
   203             candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)]
   203         if not candidates:
   204         if not candidates:
   204             return
   205             return
   205         commit = self.restrict and not lookup
   206         commit = self.restrict and not lookup
   206         if self.restrict or expand and lookup:
   207         if self.restrict or expand and lookup:
   207             mf = ctx.manifest()
   208             mf = ctx.manifest()
   545     def kwweb_skip(orig, web, req, tmpl):
   546     def kwweb_skip(orig, web, req, tmpl):
   546         '''Wraps webcommands.x turning off keyword expansion.'''
   547         '''Wraps webcommands.x turning off keyword expansion.'''
   547         kwt.match = util.never
   548         kwt.match = util.never
   548         return orig(web, req, tmpl)
   549         return orig(web, req, tmpl)
   549 
   550 
       
   551     def kw_copy(orig, ui, repo, pats, opts, rename=False):
       
   552         '''Wraps cmdutil.copy so that copy/rename destinations do not
       
   553         contain expanded keywords.
       
   554         Note that the source may also be a symlink as:
       
   555         hg cp sym x                -> x is symlink
       
   556         cp sym x; hg cp -A sym x   -> x is file (maybe expanded keywords)
       
   557         '''
       
   558         orig(ui, repo, pats, opts, rename)
       
   559         if opts.get('dry_run'):
       
   560             return
       
   561         wctx = repo[None]
       
   562         candidates = [f for f in repo.dirstate.copies() if
       
   563                       kwt.match(repo.dirstate.copied(f)) and
       
   564                       not 'l' in wctx.flags(f)]
       
   565         kwt.overwrite(wctx, candidates, False, False)
       
   566 
   550     def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts):
   567     def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts):
   551         '''Wraps record.dorecord expanding keywords after recording.'''
   568         '''Wraps record.dorecord expanding keywords after recording.'''
   552         wlock = repo.wlock()
   569         wlock = repo.wlock()
   553         try:
   570         try:
   554             # record returns 0 even when nothing has changed
   571             # record returns 0 even when nothing has changed
   567 
   584 
   568     repo.__class__ = kwrepo
   585     repo.__class__ = kwrepo
   569 
   586 
   570     extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init)
   587     extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init)
   571     extensions.wrapfunction(patch, 'diff', kw_diff)
   588     extensions.wrapfunction(patch, 'diff', kw_diff)
       
   589     extensions.wrapfunction(cmdutil, 'copy', kw_copy)
   572     for c in 'annotate changeset rev filediff diff'.split():
   590     for c in 'annotate changeset rev filediff diff'.split():
   573         extensions.wrapfunction(webcommands, c, kwweb_skip)
   591         extensions.wrapfunction(webcommands, c, kwweb_skip)
   574     for name in recordextensions.split():
   592     for name in recordextensions.split():
   575         try:
   593         try:
   576             record = extensions.find(name)
   594             record = extensions.find(name)