Turn patch.patchfile.__init__ monkeypatch into a wrapper
While the nastiness is even more blatant, this makes us independent
from changes in patchfile.__init__.
After all we only need to potentially change patchfile.lines.
--- a/hgkw/keyword.py Fri Dec 21 00:42:09 2007 +0100
+++ b/hgkw/keyword.py Sat Dec 29 18:45:47 2007 +0100
@@ -199,43 +199,18 @@
return revlog.revlog.cmp(self, node, text)
-def _kwpatchfile_init(self, ui, fname, missing=False):
- '''Monkeypatch patch.patchfile.__init__, to avoid
- rejects or conflicts due to expanded keywords in working dir.'''
- self.fname = fname
- self.ui = ui
- self.lines = []
- self.exists = False
- self.missing = missing
- if not missing:
- try:
- fp = file(fname, 'rb')
-
- if _kwtemplater.matcher(self.fname):
- # shrink keywords in working dir
- kwshrunk = _kwtemplater.shrink(fp.read())
- self.lines = kwshrunk.splitlines(True)
+# store original patch.patchfile.__init__
+_patchfile_init = patch.patchfile.__init__
- else:
- self.lines = fp.readlines()
- self.exists = True
- except IOError:
- pass
- else:
- self.ui.warn(_("unable to find '%s' for patching\n") % self.fname)
+def _kwpatchfile_init(self, ui, fname, missing=False):
+ '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
+ rejects or conflicts due to expanded keywords in working dir.'''
+ _patchfile_init(self, ui, fname, missing=missing)
- if not self.exists:
- dirname = os.path.dirname(fname)
- if dirname and not os.path.isdir(dirname):
- os.makedirs(dirname)
-
- self.hash = {}
- self.dirty = 0
- self.offset = 0
- self.rej = []
- self.fileprinted = False
- self.printfile(False)
- self.hunks = 0
+ if _kwtemplater.matcher(self.fname):
+ # shrink keywords read from working dir
+ kwshrunk = _kwtemplater.shrink(''.join(self.lines))
+ self.lines = kwshrunk.splitlines(True)
def _iskwfile(f, link):