hgext/keyword.py
changeset 11253 d50e943a2acf
parent 11252 56f306238256
child 11296 0054a328b98f
equal deleted inserted replaced
11252:56f306238256 11253:d50e943a2acf
   192 
   192 
   193     def overwrite(self, node, expand, candidates):
   193     def overwrite(self, node, expand, candidates):
   194         '''Overwrites selected files expanding/shrinking keywords.'''
   194         '''Overwrites selected files expanding/shrinking keywords.'''
   195         ctx = self.repo[node]
   195         ctx = self.repo[node]
   196         mf = ctx.manifest()
   196         mf = ctx.manifest()
   197         if node is not None:     # commit, record
   197         if self.record:
   198             candidates = [f for f in ctx.files() if f in mf]
   198             candidates = [f for f in ctx.files() if f in mf]
   199         candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)]
   199         candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)]
   200         if candidates:
   200         if candidates:
   201             self.restrict = True # do not expand when reading
   201             self.restrict = True # do not expand when reading
   202             msg = (expand and _('overwriting %s expanding keywords\n')
   202             msg = (expand and _('overwriting %s expanding keywords\n')
   207                 else:
   207                 else:
   208                     data = self.repo.wread(f)
   208                     data = self.repo.wread(f)
   209                 if util.binary(data):
   209                 if util.binary(data):
   210                     continue
   210                     continue
   211                 if expand:
   211                 if expand:
   212                     if node is None:
   212                     if node is None: # kwexpand/kwshrink
   213                         ctx = self.repo.filectx(f, fileid=mf[f]).changectx()
   213                         ctx = self.repo.filectx(f, fileid=mf[f]).changectx()
   214                     data, found = self.substitute(data, f, ctx,
   214                     data, found = self.substitute(data, f, ctx,
   215                                                   self.re_kw.subn)
   215                                                   self.re_kw.subn)
   216                 else:
   216                 else:
   217                     found = self.re_kw.search(data)
   217                     found = self.re_kw.search(data)
   497 
   497 
   498         def kwcommitctx(self, ctx, error=False):
   498         def kwcommitctx(self, ctx, error=False):
   499             n = super(kwrepo, self).commitctx(ctx, error)
   499             n = super(kwrepo, self).commitctx(ctx, error)
   500             # no lock needed, only called from repo.commit() which already locks
   500             # no lock needed, only called from repo.commit() which already locks
   501             if not kwt.record:
   501             if not kwt.record:
   502                 kwt.overwrite(n, True, None)
   502                 kwt.overwrite(n, True, sorted(ctx.added() + ctx.modified()))
   503             return n
   503             return n
   504 
   504 
   505     # monkeypatches
   505     # monkeypatches
   506     def kwpatchfile_init(orig, self, ui, fname, opener,
   506     def kwpatchfile_init(orig, self, ui, fname, opener,
   507                          missing=False, eolmode=None):
   507                          missing=False, eolmode=None):