hgkw/keyword.py
branchkwmap-templates
changeset 177 261a6844145e
parent 176 3aed363c9eaf
child 178 4a27c306c6a2
equal deleted inserted replaced
176:3aed363c9eaf 177:261a6844145e
   165         '''Returns text with all keyword substitutions removed.'''
   165         '''Returns text with all keyword substitutions removed.'''
   166         if util.binary(text):
   166         if util.binary(text):
   167             return text
   167             return text
   168         return self.re_kw.sub(r'$\1$', text)
   168         return self.re_kw.sub(r'$\1$', text)
   169 
   169 
   170     def overwrite(self, candidates):
   170     def overwrite(self, candidates, mn):
   171         '''Overwrites candidates in working dir expanding keywords.'''
   171         '''Overwrites candidates in working dir expanding keywords.'''
   172         files = []
   172         files = []
       
   173         m = self.repo.manifest.read(mn)
   173         for f in candidates:
   174         for f in candidates:
   174             data = self.repo.wfile(f).read()
   175             data = self.repo.wread(f)
   175             if not util.binary(data):
   176             if not util.binary(data):
   176                 self.path = f
   177                 self.path = f
   177                 data, kwct = self.re_kw.subn(self.kwsub, data)
   178                 data, kwct = self.re_kw.subn(self.kwsub, data)
   178                 if kwct:
   179                 if kwct:
   179                     self.ui.debug(_('overwriting %s expanding keywords\n') % f)
   180                     self.ui.debug(_('overwriting %s expanding keywords\n') % f)
   180                     self.repo.wfile(f, 'w').write(data)
   181                     self.repo.wwrite(f, data, m.flags(f))
   181                     files.append(f)
   182                     files.append(f)
   182         if files:
   183         if files:
   183             self.repo.dirstate.update(files, 'n')
   184             self.repo.dirstate.update(files, 'n')
   184 
   185 
   185 class kwfilelog(filelog.filelog):
   186 class kwfilelog(filelog.filelog):
   269                                           force_editor=force_editor,
   270                                           force_editor=force_editor,
   270                                           p1=p1, p2=p2, extra=extra)
   271                                           p1=p1, p2=p2, extra=extra)
   271                 if node is None:
   272                 if node is None:
   272                     return node
   273                     return node
   273 
   274 
   274                 candidates = self.changelog.read(node)[3]
   275                 cl = self.changelog.read(node)
   275                 candidates = [f for f in candidates if kwfmatcher(f)
   276                 candidates = [f for f in cl[3] if kwfmatcher(f)
   276                               and f not in removed
   277                               and f not in removed
   277                               and not os.path.islink(self.wjoin(f))]
   278                               and not os.path.islink(self.wjoin(f))]
   278                 if candidates:
   279                 if candidates:
   279                     kwt = kwtemplater(ui, self, node=node)
   280                     kwt = kwtemplater(ui, self, node=node)
   280                     kwt.overwrite(candidates)
   281                     kwt.overwrite(candidates, cl[0])
   281 
   282 
   282                 return node
   283                 return node
   283             finally:
   284             finally:
   284                 if wrelease:
   285                 if wrelease:
   285                     wlock.release()
   286                     wlock.release()