[meld] dirdiff: Refactor sibling revalidating logic
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] dirdiff: Refactor sibling revalidating logic
- Date: Fri, 17 Jan 2014 22:50:16 +0000 (UTC)
commit ae1e5497c6016e0da6bf8e67c1a70a60e057c0a2
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Jan 12 08:31:07 2014 +1000
dirdiff: Refactor sibling revalidating logic
meld/dirdiff.py | 23 ++++++++++-------------
meld/tree.py | 5 +++++
2 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index a83249f..7a7c84a 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -827,19 +827,16 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
# 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:
- self.model.remove(it) # all paths of sibling dirs still on the stack are now
invalid!
- index = 0
- # siblings that are on the stack, all occupy the top positions (in reverse order)
- while it is not None:
- one_dir = any(os.path.isdir(f) for f in self.model.value_paths(it))
- if one_dir:
- index += 1
- todo[-index] = self.model.get_path(it) # correct the path for this
sibling
- else:
- # stop while loop: it == sibling files and sibling dirs come first in
tree
- break
- it = self.model.iter_next(it)
- break # parent of current level in tree has children : stop while loop
+ # 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)
+ for path in todo:
+ if tree.path_is_sibling(path, deleted_path):
+ path.prev()
+ # parent of current level in tree has children : stop while loop
+ break
if differences:
expanded.add(path)
diff --git a/meld/tree.py b/meld/tree.py
index 98a1048..3d5287d 100644
--- a/meld/tree.py
+++ b/meld/tree.py
@@ -35,6 +35,11 @@ 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]