[meld] Check validity of tree cursor path (closes rhbz#832969 and rhbz#837133)



commit ee6a60c02983e169d6493dd749fcfb92af64c71a
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Oct 12 17:51:20 2012 +1000

    Check validity of tree cursor path (closes rhbz#832969 and rhbz#837133)

 meld/dirdiff.py |    8 +++++---
 meld/vcview.py  |    8 +++++---
 2 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index c5d1cae..36772b6 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -814,15 +814,17 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
         if not cursor_path:
             self.emit("next-diff-changed", False, False)
         else:
-            if self.current_path:
+            try:
                 old_cursor = self.model.get_iter(self.current_path)
+            except (ValueError, TypeError):
+                # An invalid path gives ValueError; None gives a TypeError
+                skip = False
+            else:
                 state = self.model.get_state(old_cursor, 0)
                 # We can skip recalculation if the new cursor is between the
                 # previous/next bounds, and we weren't on a changed row
                 skip = state in (tree.STATE_NORMAL, tree.STATE_EMPTY) and \
                        self.prev_path < cursor_path < self.next_path
-            else:
-                skip = False
 
             if not skip:
                 prev, next = self.model._find_next_prev_diff(cursor_path)
diff --git a/meld/vcview.py b/meld/vcview.py
index ab0049d..6c837a8 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -705,15 +705,17 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
         if not cursor_path:
             self.emit("next-diff-changed", False, False)
         else:
-            if self.current_path:
+            try:
                 old_cursor = self.model.get_iter(self.current_path)
+            except (ValueError, TypeError):
+                # An invalid path gives ValueError; None gives a TypeError
+                skip = False
+            else:
                 state = self.model.get_state(old_cursor, 0)
                 # We can skip recalculation if the new cursor is between the
                 # previous/next bounds, and we weren't on a changed row
                 skip = state in (tree.STATE_NORMAL, tree.STATE_EMPTY) and \
                        self.prev_path < cursor_path < self.next_path
-            else:
-                skip = False
 
             if not skip:
                 prev, next = self.model._find_next_prev_diff(cursor_path)



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