[meld/meld-3-16] patchdialog: Fix patch creation for missing newline (bgo#770336)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/meld-3-16] patchdialog: Fix patch creation for missing newline (bgo#770336)
- Date: Fri, 26 Aug 2016 21:51:26 +0000 (UTC)
commit f0d42a73cf5dcdb25c4d009c78ef8d2d5840092b
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Aug 27 07:45:08 2016 +1000
patchdialog: Fix patch creation for missing newline (bgo#770336)
The patch formatted by our patch dialog ends up weirdly joining
together the two parts of a changed chunk if the left hand side of the
chunk doesn't end in a newline. This will only be the case if the chunk
in question covers the last line of a file, and the file doesn't end in
a newline.
The workaround here is more annoying than it should have to be, because
Python doesn't expose what it considers to be a newline character
anywhere.
meld/patchdialog.py | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/meld/patchdialog.py b/meld/patchdialog.py
index 916a45d..cabaa5f 100644
--- a/meld/patchdialog.py
+++ b/meld/patchdialog.py
@@ -86,6 +86,17 @@ class PatchDialog(gnomeglade.Component):
start, end = b.get_bounds()
text = text_type(b.get_text(start, end, False), 'utf8')
lines = text.splitlines(True)
+
+ # Ensure that the last line ends in a newline
+ barelines = text.splitlines(False)
+ if barelines and lines and barelines[-1] == lines[-1]:
+ # Final line lacks a line-break; add in a best guess
+ if len(lines) > 1:
+ previous_linebreak = lines[-2][len(barelines[-2]):]
+ else:
+ previous_linebreak = "\n"
+ lines[-1] += previous_linebreak
+
texts.append(lines)
names = [self.filediff.textbuffer[i].data.label for i in range(3)]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]