hgext/keyword.py
changeset 12723 eaa09d25e7c6
parent 12709 4147a292c508
child 12732 4bca87c29445
equal deleted inserted replaced
12722:22f45e53bb21 12723:eaa09d25e7c6
   138 
   138 
   139 def _shrinktext(text, subfunc):
   139 def _shrinktext(text, subfunc):
   140     '''Helper for keyword expansion removal in text.
   140     '''Helper for keyword expansion removal in text.
   141     Depending on subfunc also returns number of substitutions.'''
   141     Depending on subfunc also returns number of substitutions.'''
   142     return subfunc(r'$\1$', text)
   142     return subfunc(r'$\1$', text)
       
   143 
       
   144 def _preselect(wstatus, changed):
       
   145     '''Retrieves modfied and added files from a working directory state
       
   146     and returns the subset of each contained in given changed files
       
   147     retrieved from a change context.'''
       
   148     modified, added = wstatus[:2]
       
   149     modified = [f for f in modified if f in changed]
       
   150     added = [f for f in added if f in changed]
       
   151     return modified, added
   143 
   152 
   144 
   153 
   145 class kwtemplater(object):
   154 class kwtemplater(object):
   146     '''
   155     '''
   147     Sets up keyword templates, corresponding keyword regex, and
   156     Sets up keyword templates, corresponding keyword regex, and
   507                               False, True)
   516                               False, True)
   508                 kwt.restrict = restrict
   517                 kwt.restrict = restrict
   509             return n
   518             return n
   510 
   519 
   511         def rollback(self, dryrun=False):
   520         def rollback(self, dryrun=False):
   512             wlock = repo.wlock()
   521             wlock = self.wlock()
   513             try:
   522             try:
   514                 if not dryrun:
   523                 if not dryrun:
   515                     changed = self['.'].files()
   524                     changed = self['.'].files()
   516                 ret = super(kwrepo, self).rollback(dryrun)
   525                 ret = super(kwrepo, self).rollback(dryrun)
   517                 if not dryrun:
   526                 if not dryrun:
   518                     ctx = self['.']
   527                     ctx = self['.']
   519                     modified, added = self[None].status()[:2]
   528                     modified, added = _preselect(self[None].status(), changed)
   520                     modified = [f for f in modified if f in changed]
   529                     kwt.overwrite(ctx, modified, True, True)
   521                     added = [f for f in added if f in changed]
       
   522                     kwt.overwrite(ctx, added, True, False)
   530                     kwt.overwrite(ctx, added, True, False)
   523                     kwt.overwrite(ctx, modified, True, True)
       
   524                 return ret
   531                 return ret
   525             finally:
   532             finally:
   526                 wlock.release()
   533                 wlock.release()
   527 
   534 
   528     # monkeypatches
   535     # monkeypatches
   567         try:
   574         try:
   568             # record returns 0 even when nothing has changed
   575             # record returns 0 even when nothing has changed
   569             # therefore compare nodes before and after
   576             # therefore compare nodes before and after
   570             kwt.record = True
   577             kwt.record = True
   571             ctx = repo['.']
   578             ctx = repo['.']
   572             modified, added = repo[None].status()[:2]
   579             wstatus = repo[None].status()
   573             ret = orig(ui, repo, commitfunc, *pats, **opts)
   580             ret = orig(ui, repo, commitfunc, *pats, **opts)
   574             recctx = repo['.']
   581             recctx = repo['.']
   575             if ctx != recctx:
   582             if ctx != recctx:
   576                 changed = recctx.files()
   583                 modified, added = _preselect(wstatus, recctx.files())
   577                 modified = [f for f in modified if f in changed]
       
   578                 added = [f for f in added if f in changed]
       
   579                 kwt.restrict = False
   584                 kwt.restrict = False
   580                 kwt.overwrite(recctx, modified, False, True)
   585                 kwt.overwrite(recctx, modified, False, True)
   581                 kwt.overwrite(recctx, added, False, True, True)
   586                 kwt.overwrite(recctx, added, False, True, True)
   582                 kwt.restrict = True
   587                 kwt.restrict = True
   583             return ret
   588             return ret