[meld: 11/12] avoid pyobjects for column types by avoiding None use



commit 5750d70536e81f923ef75c83733d4bba83ea86c1
Author: hugosenari <hugosenari gmail com>
Date:   Mon Aug 20 00:59:54 2018 -0300

    avoid pyobjects for column types by avoiding None use

 meld/dirdiff.py          | 28 +++++++++++++++++++++++-----
 meld/tree.py             |  6 ++++--
 meld/ui/cellrenderers.py |  6 +++---
 3 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 97af3df6..cd6fc54b 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -719,7 +719,11 @@ class DirDiff(MeldDoc, Component):
                 try:
                     entries = os.listdir(root)
                 except OSError as err:
-                    self.model.add_error(it, err.strerror, pane)
+                    self.model.add_error(it, err.strerror, pane, {
+                        COL_TIME: -1.0,
+                        COL_SIZE: -1,
+                        COL_PERMS: -1
+                    })
                     differences = True
                     continue
 
@@ -742,7 +746,11 @@ class DirDiff(MeldDoc, Component):
                     # Covers certain unreadable symlink cases; see bgo#585895
                     except OSError as err:
                         error_string = e + err.strerror
-                        self.model.add_error(it, error_string, pane)
+                        self.model.add_error(it, error_string, pane, {
+                            COL_TIME: -1.0,
+                            COL_SIZE: -1,
+                            COL_PERMS: -1
+                        })
                         continue
 
                     if stat.S_ISLNK(s.st_mode):
@@ -763,7 +771,11 @@ class DirDiff(MeldDoc, Component):
                                 error_string = e + ": Dangling symlink"
                             else:
                                 error_string = e + err.strerror
-                            self.model.add_error(it, error_string, pane)
+                            self.model.add_error(it, error_string, pane, {
+                                COL_TIME: -1.0,
+                                COL_SIZE: -1,
+                                COL_PERMS: -1
+                            })
                             differences = True
                     elif stat.S_ISREG(s.st_mode):
                         files.add(pane, e)
@@ -1407,10 +1419,16 @@ class DirDiff(MeldDoc, Component):
                     COL_PERMS: perms[j]
                 })
             else:
-                # TODO: More consistent state setting here would let us avoid
-                # pyobjects for column types by avoiding None use.
                 self.model.set_path_state(
                     it, j, tree.STATE_NONEXIST, any(isdir))
+                # SET time, size and perms to -1 since None of GInt is 0
+                # TODO: change it to math.nan some day
+                # https://gitlab.gnome.org/GNOME/glib/issues/183
+                self.model.unsafe_set(it, j, {
+                    COL_TIME: -1.0,
+                    COL_SIZE: -1,
+                    COL_PERMS: -1
+                })
         return different
 
     def popup_in_pane(self, pane, event):
diff --git a/meld/tree.py b/meld/tree.py
index 349ae32b..18ac870d 100644
--- a/meld/tree.py
+++ b/meld/tree.py
@@ -138,10 +138,12 @@ class DiffTreeStore(SearchableTreeStore):
             self.set_state(it, pane, STATE_EMPTY, text)
         return it
 
-    def add_error(self, parent, msg, pane):
+    def add_error(self, parent, msg, pane, defaults={}):
         it = self.append(parent)
+        key_values = {COL_STATE: str(STATE_ERROR)}
+        key_values.update(defaults)
         for i in range(self.ntree):
-            self.unsafe_set(it, i, {COL_STATE: str(STATE_ERROR)})
+            self.unsafe_set(it, i, key_values)
         self.set_state(it, pane, STATE_ERROR, msg)
 
     def set_path_state(self, it, pane, state, isdir=0, display_text=None):
diff --git a/meld/ui/cellrenderers.py b/meld/ui/cellrenderers.py
index 76e90b14..807e5bb3 100644
--- a/meld/ui/cellrenderers.py
+++ b/meld/ui/cellrenderers.py
@@ -31,7 +31,7 @@ class CellRendererDate(Gtk.CellRendererText):
     def set_timestamp(self, value):
         if value == self.get_timestamp():
             return
-        if value is None:
+        if value == -1.0:
             time_str = ''
         else:
             mod_datetime = datetime.datetime.fromtimestamp(value)
@@ -57,7 +57,7 @@ class CellRendererByteSize(Gtk.CellRendererText):
     def set_bytesize(self, value):
         if value == self.get_bytesize():
             return
-        if value is None:
+        if value == -1:
             byte_str = ''
         else:
             suffixes = (
@@ -91,7 +91,7 @@ class CellRendererFileMode(Gtk.CellRendererText):
     def set_file_mode(self, value):
         if value == self.get_file_mode():
             return
-        if value is None:
+        if value == -1.0:
             mode_str = ''
         else:
             perms = []


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