hgkw/keyword.py
changeset 1079 502c40551c8d
parent 1077 2a1ab2f6559c
child 1080 4ee1c08706c4
equal deleted inserted replaced
1078:834f71467ecc 1079:502c40551c8d
   186     def __init__(self, ui, repo, inc, exc):
   186     def __init__(self, ui, repo, inc, exc):
   187         self.ui = ui
   187         self.ui = ui
   188         self.repo = repo
   188         self.repo = repo
   189         self.match = match.match(repo.root, '', [], inc, exc)
   189         self.match = match.match(repo.root, '', [], inc, exc)
   190         self.restrict = kwtools['hgcmd'] in restricted.split()
   190         self.restrict = kwtools['hgcmd'] in restricted.split()
   191         self.record = False
   191         self.postcommit = False
   192 
   192 
   193         kwmaps = self.ui.configitems('keywordmaps')
   193         kwmaps = self.ui.configitems('keywordmaps')
   194         if kwmaps: # override default templates
   194         if kwmaps: # override default templates
   195             self.templates = dict((k, templater.parsestring(v, False))
   195             self.templates = dict((k, templater.parsestring(v, False))
   196                                   for k, v in kwmaps)
   196                                   for k, v in kwmaps)
   241         expansion but are not symbolic links.'''
   241         expansion but are not symbolic links.'''
   242         return [f for f in cand if self.match(f) and 'l' not in ctx.flags(f)]
   242         return [f for f in cand if self.match(f) and 'l' not in ctx.flags(f)]
   243 
   243 
   244     def overwrite(self, ctx, candidates, lookup, expand, rekw=False):
   244     def overwrite(self, ctx, candidates, lookup, expand, rekw=False):
   245         '''Overwrites selected files expanding/shrinking keywords.'''
   245         '''Overwrites selected files expanding/shrinking keywords.'''
   246         if self.restrict or lookup or self.record: # exclude kw_copy
   246         if self.restrict or lookup or self.postcommit: # exclude kw_copy
   247             candidates = self.iskwfile(candidates, ctx)
   247             candidates = self.iskwfile(candidates, ctx)
   248         if not candidates:
   248         if not candidates:
   249             return
   249             return
   250         kwcmd = self.restrict and lookup # kwexpand/kwshrink
   250         kwcmd = self.restrict and lookup # kwexpand/kwshrink
   251         if self.restrict or expand and lookup:
   251         if self.restrict or expand and lookup:
   278                 fp = self.repo.wopener(f, "wb", atomictemp=True)
   278                 fp = self.repo.wopener(f, "wb", atomictemp=True)
   279                 fp.write(data)
   279                 fp.write(data)
   280                 fp.close()
   280                 fp.close()
   281                 if kwcmd:
   281                 if kwcmd:
   282                     self.repo.dirstate.normal(f)
   282                     self.repo.dirstate.normal(f)
   283                 elif self.record:
   283                 elif self.postcommit:
   284                     self.repo.dirstate.normallookup(f)
   284                     self.repo.dirstate.normallookup(f)
   285 
   285 
   286     def shrink(self, fname, text):
   286     def shrink(self, fname, text):
   287         '''Returns text with all keyword substitutions removed.'''
   287         '''Returns text with all keyword substitutions removed.'''
   288         if self.match(fname) and not util.binary(text):
   288         if self.match(fname) and not util.binary(text):
   581                 del self.commitctx
   581                 del self.commitctx
   582 
   582 
   583         def kwcommitctx(self, ctx, error=False):
   583         def kwcommitctx(self, ctx, error=False):
   584             n = super(kwrepo, self).commitctx(ctx, error)
   584             n = super(kwrepo, self).commitctx(ctx, error)
   585             # no lock needed, only called from repo.commit() which already locks
   585             # no lock needed, only called from repo.commit() which already locks
   586             if not kwt.record:
   586             if not kwt.postcommit:
   587                 restrict = kwt.restrict
   587                 restrict = kwt.restrict
   588                 kwt.restrict = True
   588                 kwt.restrict = True
   589                 kwt.overwrite(self[n], sorted(ctx.added() + ctx.modified()),
   589                 kwt.overwrite(self[n], sorted(ctx.added() + ctx.modified()),
   590                               False, True)
   590                               False, True)
   591                 kwt.restrict = restrict
   591                 kwt.restrict = restrict
   659         '''Wraps record.dorecord expanding keywords after recording.'''
   659         '''Wraps record.dorecord expanding keywords after recording.'''
   660         wlock = repo.wlock()
   660         wlock = repo.wlock()
   661         try:
   661         try:
   662             # record returns 0 even when nothing has changed
   662             # record returns 0 even when nothing has changed
   663             # therefore compare nodes before and after
   663             # therefore compare nodes before and after
   664             kwt.record = True
   664             kwt.postcommit = True
   665             ctx = repo['.']
   665             ctx = repo['.']
   666             wstatus = repo[None].status()
   666             wstatus = repo[None].status()
   667             ret = orig(ui, repo, commitfunc, *pats, **opts)
   667             ret = orig(ui, repo, commitfunc, *pats, **opts)
   668             recctx = repo['.']
   668             recctx = repo['.']
   669             if ctx != recctx:
   669             if ctx != recctx: