hgkw/keyword.py
changeset 317 b18631f0dbdc
parent 315 c1ec4ffd1279
child 318 12d26936a315
equal deleted inserted replaced
316:98656ffb1cec 317:b18631f0dbdc
   197             t2 = super(kwfilelog, self).read(node)
   197             t2 = super(kwfilelog, self).read(node)
   198             return t2 != text
   198             return t2 != text
   199         return revlog.revlog.cmp(self, node, text)
   199         return revlog.revlog.cmp(self, node, text)
   200 
   200 
   201 
   201 
       
   202 # store original patch.patchfile.__init__
       
   203 _patchfile_init = patch.patchfile.__init__
       
   204 
   202 def _kwpatchfile_init(self, ui, fname, missing=False):
   205 def _kwpatchfile_init(self, ui, fname, missing=False):
   203     '''Monkeypatch patch.patchfile.__init__, to avoid
   206     '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
   204     rejects or conflicts due to expanded keywords in working dir.'''
   207     rejects or conflicts due to expanded keywords in working dir.'''
   205     self.fname = fname
   208     _patchfile_init(self, ui, fname, missing=missing)
   206     self.ui = ui
   209 
   207     self.lines = []
   210     if _kwtemplater.matcher(self.fname):
   208     self.exists = False
   211         # shrink keywords read from working dir
   209     self.missing = missing
   212         kwshrunk = _kwtemplater.shrink(''.join(self.lines))
   210     if not missing:
   213         self.lines = kwshrunk.splitlines(True)
   211         try:
       
   212             fp = file(fname, 'rb')
       
   213             
       
   214             if _kwtemplater.matcher(self.fname):
       
   215                 # shrink keywords in working dir
       
   216                 kwshrunk = _kwtemplater.shrink(fp.read())
       
   217                 self.lines = kwshrunk.splitlines(True)
       
   218 
       
   219             else:
       
   220                 self.lines = fp.readlines()
       
   221             self.exists = True
       
   222         except IOError:
       
   223             pass
       
   224     else:
       
   225         self.ui.warn(_("unable to find '%s' for patching\n") % self.fname)
       
   226 
       
   227     if not self.exists:
       
   228         dirname = os.path.dirname(fname)
       
   229         if dirname and not os.path.isdir(dirname):
       
   230             os.makedirs(dirname)
       
   231 
       
   232     self.hash = {}
       
   233     self.dirty = 0
       
   234     self.offset = 0
       
   235     self.rej = []
       
   236     self.fileprinted = False
       
   237     self.printfile(False)
       
   238     self.hunks = 0
       
   239 
   214 
   240 
   215 
   241 def _iskwfile(f, link):
   216 def _iskwfile(f, link):
   242     return not link(f) and _kwtemplater.matcher(f)
   217     return not link(f) and _kwtemplater.matcher(f)
   243 
   218