[meld] filediff, meldbuffer: Support file comparisons from pipes (bgo#765021)



commit a2f22b6503a0f1b07789b0180f6a99108e83962d
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed Jun 8 08:18:05 2016 +1000

    filediff, meldbuffer: Support file comparisons from pipes (bgo#765021)
    
    With the move to GtkSourceFileLoader, etc., we unintentionally lost the
    ability to read from named pipes, because yours truly had no idea this
    worked at all. This patch is a slightly hacky approach to handle
    switching to the stream-based loading in GtkSourceFileLoader if it
    appears that the GFile we have doesn't point to a regular file.

 meld/filediff.py   |   11 ++++++++---
 meld/meldbuffer.py |    9 +++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 357fb8d..b1e3c59 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1047,10 +1047,15 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             self.fileentry[pane].set_file(gfile)
             self.msgarea_mgr[pane].clear()
 
-            self.textbuffer[pane].data.reset(gfile)
+            buf = self.textbuffer[pane]
+            buf.data.reset(gfile)
+
+            if buf.data.is_special:
+                loader = GtkSource.FileLoader.new_from_stream(
+                    buf, buf.data.sourcefile, buf.data.gfile.read())
+            else:
+                loader = GtkSource.FileLoader.new(buf, buf.data.sourcefile)
 
-            loader = GtkSource.FileLoader.new(
-                self.textbuffer[pane], self.textbuffer[pane].data.sourcefile)
             if custom_candidates:
                 loader.set_candidate_encodings(custom_candidates)
             loader.load_async(
diff --git a/meld/meldbuffer.py b/meld/meldbuffer.py
index 9e75887..0e7a935 100644
--- a/meld/meldbuffer.py
+++ b/meld/meldbuffer.py
@@ -197,6 +197,15 @@ class MeldBufferData(GObject.GObject):
         return self.gfile
 
     @property
+    def is_special(self):
+        try:
+            info = self._gfile.query_info(
+                Gio.FILE_ATTRIBUTE_STANDARD_TYPE, 0, None)
+            return info.get_file_type() == Gio.FileType.SPECIAL
+        except (AttributeError, GLib.GError):
+            return False
+
+    @property
     def writable(self):
         try:
             info = self.gfiletarget.query_info(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]