[meld] patchdialog: Fix patch creation for missing newline (bgo#770336)



commit f15ad70846bb14ffdddeb97b95e9ceb87223368d
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 d42fada..5f513ee 100644
--- a/meld/patchdialog.py
+++ b/meld/patchdialog.py
@@ -85,6 +85,17 @@ class PatchDialog(gnomeglade.Component):
             start, end = b.get_bounds()
             text = b.get_text(start, end, False)
             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]