Rev 181: We now pick a different bunch of columns. in http://bazaar.launchpad.net/~jameinel/bzr-explorer/wt_model

John Arbash Meinel john at arbash-meinel.com
Thu Jul 9 20:47:05 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr-explorer/wt_model

------------------------------------------------------------
revno: 181
revision-id: john at arbash-meinel.com-20090709194658-tr9d0ju4p2xzymhi
parent: john at arbash-meinel.com-20090709191558-63uuu9670ku37uth
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: wt_model
timestamp: Thu 2009-07-09 14:46:58 -0500
message:
  We now pick a different bunch of columns.
  
  It actually looks pretty interesting now.
-------------- next part --------------
=== modified file 'lib/wt_model.py'
--- a/lib/wt_model.py	2009-07-09 19:15:58 +0000
+++ b/lib/wt_model.py	2009-07-09 19:46:58 +0000
@@ -32,9 +32,16 @@
     :type children: A list of _WTItem objects
     """
 
+    _versioned_map = {(True, True): ' ', # versioned in both
+                      (True, False): '-', # versioned in source
+                      (False, True): '+', # versioned in target
+                      (False, False): '-', # versioned in neither
+                     }
+
     def __init__(self, file_id, is_modified, path, name, kind, versioned,
-                 executable, parent, old_path, old_name, old_kind,
-                 was_versioned, old_parent_id):
+                 executable, parent_id, old_path, old_name, old_kind,
+                 was_versioned, old_executable, old_parent_id, parent,
+                 ignore_pattern):
         """Create a new _WTItem
         """
         self.file_id = file_id
@@ -43,17 +50,57 @@
         self.kind = kind
         self.versioned = versioned
         self.is_modified = is_modified
+        self.ignore_pattern = ignore_pattern
         self.executable = executable
-        self.parent = parent
+        self.parent_id = parent_id
         self.old_path = old_path
         self.old_kind = old_kind
         self.old_name = old_name
         self.was_versioned = was_versioned
+        self.old_executable = old_executable
         self.old_parent_id = old_parent_id
+        self.parent = parent
         # Note: this creates a cyclical reference, consider using parent
         #       instead
         self.children = []
+        # Determine the status of this file
         self.status = None
+        if self.versioned is not None and self.was_versioned is not None:
+            self._determine_status()
+
+    def _determine_status(self):
+        if self.ignore_pattern is not None:
+            self.status = 'I  '
+            return
+        # Generally copied from bzrlib.delta.report_changes
+        exe_status = ' '
+        # files are "renamed" if they are moved or if name changes, as long
+        # as it had a value
+        if (self.old_name is not None and self.name is not None
+            and self.old_parent_id is not None
+            and self.parent_id is not None
+            and (self.old_name != self.name
+                 or self.parent_id != self.old_parent_id)):
+            versioned_status = 'R' # Renamed implies versioned in both
+        else:
+            versioned_status = self._versioned_map[
+                (self.was_versioned, self.versioned)]
+        if self.old_kind != self.kind:
+            if self.old_kind is None:
+                modified_status = 'N' # created
+            elif self.kind is None:
+                modified_status = 'D' # deleted
+            else:
+                modified_status = 'K' # kind changed
+        else:
+            if self.is_modified:
+                modified_status = 'M' # modified
+            else:
+                modified_status = ' ' # unchanged
+            if self.kind == 'file':
+                if (self.executable != self.old_executable):
+                    exe_status = '*'
+        self.status = modified_status + versioned_status + exe_status
 
     def __repr__(self):
         return '%s(%s)' % (self.__class__.__name__,
@@ -65,8 +112,7 @@
             return 0
         return self.parent.children.index(self)
 
-    def _from_iter_changes(self, changes):
-        # By file-id
+    def _from_iter_changes(self, wt, changes):
         dir_by_id = {}
         dir_by_path = {}
         for (file_id, paths, did_change, versions, parent_ids, names, kinds,
@@ -77,6 +123,7 @@
                 if names[1] == '': # unversioned root?
                     raise ValueError('not supported yet')
                 parent = dir_by_path[parent_dir]
+                ignore_pattern = wt.is_ignored(paths[1])
             else:
                 if parent_ids[1] is None: # Root entry
                     # Or maybe this happens for unversioned files?
@@ -84,10 +131,12 @@
                     parent = self
                 else:
                     parent = dir_by_id[parent_ids[1]]
+                ignore_pattern = None
             item = _WTItem(file_id, did_change, paths[1], names[1], kinds[1],
-                           versions[1], executables[1], parent,
+                           versions[1], executables[1], parent_ids[1],
                            paths[0], names[0], kinds[0], versions[0],
-                           parent_ids[0])
+                           executables[0], parent_ids[0], parent,
+                           ignore_pattern)
             parent.children.append(item)
             if kinds[1] == 'directory':
                 dir_by_id[file_id] = item
@@ -101,10 +150,10 @@
             basis_tree = wt.basis_tree()
             basis_tree.lock_read()
             try:
-                root_wt_item = cls(*([None]*13))
+                root_wt_item = cls(*([None]*16))
                 changes = wt.iter_changes(basis_tree, include_unchanged=True,
                     require_versioned=False, want_unversioned=True)
-                root_wt_item._from_iter_changes(changes)
+                root_wt_item._from_iter_changes(wt, changes)
             finally:
                 basis_tree.unlock()
         finally:
@@ -116,10 +165,8 @@
 
     _headers = [
         'name',
-        'file_id',
         'kind',
         'status',
-        'old_kind',
         'path',
         ]
     _column_to_attribute = dict(enumerate(_headers))
@@ -205,7 +252,6 @@
             # Return the decoration from an QDirModel
             dir_index = self._dirmodel.index(item.path)
             data = self._dirmodel.data(dir_index, role)
-            # print data
             return data
         if role != QtCore.Qt.DisplayRole:
             return QtCore.QVariant()

=== modified file 'tests/test_wt_model.py'
--- a/tests/test_wt_model.py	2009-07-09 19:03:30 +0000
+++ b/tests/test_wt_model.py	2009-07-09 19:46:58 +0000
@@ -68,15 +68,16 @@
         res = model.data(index, QtCore.Qt.DisplayRole)
         self.assertIsInstance(res, QtCore.QVariant)
         self.assertEqual('dir', res.toString())
-        index = model.index(1, 1, root_index)
+        index = model.index(1, 2, root_index)
         res = model.data(index, QtCore.Qt.DisplayRole)
         self.assertIsInstance(res, QtCore.QVariant)
-        self.assertEqual('dir-id', res.toString())
+        # New file, just added, no executable
+        self.assertEqual('N+ ', res.toString())
         a_index = model.index(0, 0, index)
         res = model.data(a_index, QtCore.Qt.DisplayRole)
         self.assertIsInstance(res, QtCore.QVariant)
         self.assertEqual('a_file', res.toString())
-        a_index = model.index(0, 5, index)
+        a_index = model.index(0, 3, index)
         res = model.data(a_index, QtCore.Qt.DisplayRole)
         self.assertIsInstance(res, QtCore.QVariant)
         self.assertEqual('dir/a_file', res.toString())
@@ -192,22 +193,19 @@
     def test_headerData(self):
         wt = self.make_branch_and_tree('.')
         model = wt_model.WorkingTreeModel(wt)
-        self.assertEqual(6, model.columnCount())
+        self.assertEqual(len(model._headers), model.columnCount())
         res = model.headerData(0, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)
         self.assertIsInstance(res, QtCore.QVariant)
         self.assertEqual('name', res.toString())
         res = model.headerData(1, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)
-        self.assertEqual('file_id', res.toString())
+        self.assertEqual('kind', res.toString())
         res = model.headerData(2, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)
-        self.assertEqual('kind', res.toString())
+        self.assertEqual('status', res.toString())
         res = model.headerData(3, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)
-        self.assertEqual('status', res.toString())
-        res = model.headerData(4, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)
-        self.assertEqual('old_kind', res.toString())
-        res = model.headerData(5, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)
         self.assertEqual('path', res.toString())
 
-        res = model.headerData(6, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)
+        res = model.headerData(len(model._headers),
+                               QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)
         self.assertIsInstance(res, QtCore.QVariant)
         self.assertTrue(res.isNull())
         res = model.headerData(0, QtCore.Qt.Vertical, QtCore.Qt.DisplayRole)



More information about the bazaar-commits mailing list