Mercurial > public > mercurial-scm > hg-stable
diff mercurial/patch.py @ 13100:66d7a1250c9b stable
patch: write .rej files without rewriting EOLs
Do not pass reject file content to patchfile.writelines() to:
- Avoid line endings transformations
- Avoid polluting overriding implementations with unrelated data. They should
override write_rej() to deal or ignore reject files properly.
Bug report, analysis and original patch and test by
Shun-ichi GOTO <shunichi.goto@gmail.com>
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 03 Dec 2010 11:40:30 +0900 |
parents | 61f48581d8ef |
children | 5dac0d04b838 |
line wrap: on
line diff
--- a/mercurial/patch.py Thu Dec 02 01:28:38 2010 -0200 +++ b/mercurial/patch.py Fri Dec 03 11:40:30 2010 +0900 @@ -485,6 +485,15 @@ for x, s in enumerate(self.lines): self.hash.setdefault(s, []).append(x) + def makerejlines(self, fname): + base = os.path.basename(fname) + yield "--- %s\n+++ %s\n" % (base, base) + for x in self.rej: + for l in x.hunk: + yield l + if l[-1] != '\n': + yield "\n\ No newline at end of file\n" + def write_rej(self): # our rejects are a little different from patch(1). This always # creates rejects in the same form as the original patch. A file @@ -499,16 +508,9 @@ _("%d out of %d hunks FAILED -- saving rejects to file %s\n") % (len(self.rej), self.hunks, fname)) - def rejlines(): - base = os.path.basename(self.fname) - yield "--- %s\n+++ %s\n" % (base, base) - for x in self.rej: - for l in x.hunk: - yield l - if l[-1] != '\n': - yield "\n\ No newline at end of file\n" - - self.writelines(fname, rejlines()) + fp = self.opener(fname, 'w') + fp.writelines(self.makerejlines(self.fname)) + fp.close() def apply(self, h): if not h.complete():