hgkw/keyword.py
changeset 217 e55e3f6c6608
parent 216 f35a0c382168
child 221 2990d6aa10ff
equal deleted inserted replaced
216:f35a0c382168 217:e55e3f6c6608
   184         Keywords are expanded if keyword templater is initialized,
   184         Keywords are expanded if keyword templater is initialized,
   185         otherwise their substitution is removed.'''
   185         otherwise their substitution is removed.'''
   186         expand = self.t is not None
   186         expand = self.t is not None
   187         action = ('shrinking', 'expanding')[expand]
   187         action = ('shrinking', 'expanding')[expand]
   188         notify = (self.ui.note, self.ui.debug)[commit]
   188         notify = (self.ui.note, self.ui.debug)[commit]
   189         # backwards compatibility: older versions have dirstate.update
   189         overwritten = []
   190         nodirstateupdate = not hasattr(self.repo.dirstate, 'update')
       
   191         files = []
       
   192         for f in candidates:
   190         for f in candidates:
   193             fp = self.repo.file(f, kwexp=expand, kwcnt=True)
   191             fp = self.repo.file(f, kwexp=expand, kwcnt=True)
   194             data, kwfound = fp.read(man[f])
   192             data, kwfound = fp.read(man[f])
   195             if kwfound:
   193             if kwfound:
   196                 notify(_('overwriting %s %s keywords\n') % (f, action))
   194                 notify(_('overwriting %s %s keywords\n') % (f, action))
   197                 try:
   195                 try:
   198                     self.repo.wwrite(f, data, man.flags(f))
   196                     self.repo.wwrite(f, data, man.flags(f))
   199                 except AttributeError:
   197                 except AttributeError:
   200                     # older versions want file descriptor as 3. optional arg
   198                     # older versions want file descriptor as 3. optional arg
   201                     self.repo.wwrite(f, data)
   199                     self.repo.wwrite(f, data)
   202                 if nodirstateupdate:
   200                 overwritten.append(f)
       
   201         if overwritten:
       
   202             try:
       
   203                 for f in overwritten:
   203                     self.repo.dirstate.normal(f)
   204                     self.repo.dirstate.normal(f)
   204                 else:
   205             except AttributeError:
   205                     files.append(f)
   206                 # older versions don't know about dirstate.normal
   206         if files:
   207                 self.repo.dirstate.update(overwritten, 'n')
   207             self.repo.dirstate.update(files, 'n')
       
   208 
   208 
   209 class kwfilelog(filelog.filelog):
   209 class kwfilelog(filelog.filelog):
   210     '''
   210     '''
   211     Subclass of filelog to hook into its read, add, cmp methods.
   211     Subclass of filelog to hook into its read, add, cmp methods.
   212     Keywords are "stored" unexpanded, and processed on reading.
   212     Keywords are "stored" unexpanded, and processed on reading.