[meld] dirdiff: Significantly simplify the logic for tree pruning



commit 5ee3773dea9f90a7369a16b95b993de09defc831
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Thu Jan 16 07:20:05 2014 +1000

    dirdiff: Significantly simplify the logic for tree pruning

 meld/dirdiff.py |   32 ++++++++++++++++----------------
 meld/tree.py    |    5 -----
 2 files changed, 16 insertions(+), 21 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 63b53d8..fa0edfa 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -816,24 +816,24 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
                     assert it and not self.model.iter_has_child(it)
                     while not self.model.iter_has_child(it):
                         parent = self.model.iter_parent(it)
-                        if self.model.iter_next(it) is None:
-                            # all siblings of it have been processed, none are left on the todo stack
-                            if parent is None:             # don't remove top of the tree
-                                self.model.add_empty(it)
-                                expanded.add(rootpath)     # expand roothpath to show entire tree is empty
-                                break
-                            self.model.remove(it)
-                            # if parent has more children: state of these children is in state_filters;
-                            # parent may not be removed in this case : stop while loop
-                        else:
-                            # Remove the current row, and then revalidate all
-                            # sibling paths on the stack by removing and
-                            # readding them
-                            deleted_path = self.model.get_path(it)
-                            self.model.remove(it)
+
+                        # In our tree, there is always a top-level parent with
+                        # no siblings. If we're here, we have an empty tree.
+                        if parent is None:
+                            self.model.add_empty(it)
+                            expanded.add(rootpath)
+                            break
+
+                        # Remove the current row, and then revalidate all
+                        # sibling paths on the stack by removing and
+                        # readding them.
+                        had_siblings = self.model.remove(it)
+                        if had_siblings:
+                            parent_path = self.model.get_path(parent)
                             for path in todo:
-                                if tree.path_is_sibling(path, deleted_path):
+                                if parent_path.is_ancestor(path):
                                     path.prev()
+
                         it = parent
 
             if differences:
diff --git a/meld/tree.py b/meld/tree.py
index 3d5287d..98a1048 100644
--- a/meld/tree.py
+++ b/meld/tree.py
@@ -35,11 +35,6 @@ from meld.vc._vc import \
     CONFLICT_MERGED, CONFLICT_OTHER, CONFLICT_THIS
 
 
-def path_is_sibling(path1, path2):
-    return (len(path1) == len(path2) and
-            path1.get_indices()[:-1] == path2.get_indices()[:-1])
-
-
 class DiffTreeStore(Gtk.TreeStore):
 
     def __init__(self, ntree, types):


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