Rev 2330: Use path_info tuples unaltered rather than recombining all the time. in file:///home/robertc/source/baz/dirstate2/

Robert Collins robertc at robertcollins.net
Sat Mar 10 04:24:09 GMT 2007


At file:///home/robertc/source/baz/dirstate2/

------------------------------------------------------------
revno: 2330
revision-id: robertc at robertcollins.net-20070310042406-uou98sc146xbva7n
parent: robertc at robertcollins.net-20070309213148-mmgmddc0a2yheitu
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate2
timestamp: Sat 2007-03-10 15:24:06 +1100
message:
  Use path_info tuples unaltered rather than recombining all the time.
modified:
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2007-03-09 15:52:13 +0000
+++ b/bzrlib/osutils.py	2007-03-10 04:24:06 +0000
@@ -1057,19 +1057,15 @@
     
     The data yielded is of the form:
     ((directory-relpath, directory-path-from-top),
-    [(directory-relpath, basename, kind, lstat, path-from-top), ...]),
+    [(directory-relpath, basename, path_info, path-from-top), ...]),
      - directory-relpath is the relative path of the directory being returned
        with respect to top. prefix is prepended to this.
      - directory-path-from-root is the path including top for this directory. 
        It is suitable for use with os functions.
      - relpath is the relative path within the subtree being walked.
      - basename is the basename of the path
-     - kind is the kind of the file now. If unknown then the file is not
-       present within the tree - but it may be recorded as versioned. See
-       versioned_kind.
-     - lstat is the stat data *if* the file was statted.
-     - planned, not implemented: 
-       path_from_tree_root is the path from the root of the tree.
+     - path_info is the output of bzrlib.path_info.path_info
+     - path_from_tree_root is the path from the root of the tree.
 
     :param prefix: Prefix the relpaths that are yielded with 'prefix'. This 
         allows one to walk a subtree but get paths that are relative to a tree
@@ -1084,13 +1080,12 @@
     _lstat = os.lstat
     _directory = _directory_kind
     _listdir = os.listdir
-    # 0 - relpath, 1- basename, 2- kind, 3 - size, 4- exe, 5-stattime, 6- statcache, 7-toppath
-    # But we don't actually uses 1-6 in pending, so set them to None
-    pending = [(safe_unicode(prefix), "", _directory, None, None, None, None, safe_unicode(top))]
+    # 0 - relpath, 1- basename, 2- path_info, 3-toppath
+    # But we don't actually use 1 & 2 in pending, so set them to None
+    pending = [(safe_unicode(prefix), "", None, safe_unicode(top))]
     native_encoding = sys.getfilesystemencoding()
     while pending:
-        # 0 - relpath, 1- basename, 2- kind, 3 - size, 4- exe, 5- statcache, 6-toppath
-        relroot, _, _, _, _, _, _, top = pending.pop()
+        relroot, _, _, top = pending.pop()
         if relroot:
             relprefix = relroot + u'/'
         else:
@@ -1102,12 +1097,11 @@
         for name in sorted(_listdir(top)):
             abspath = top_slash + name
             info = path_info(abspath.encode(native_encoding))
-            append((relprefix + name, name, info[0], info[1], info[2], info[3],
-                info[4], abspath))
+            append((relprefix + name, name, info, abspath))
         yield (relroot, top), dirblock
 
         # push the user specified dirs from dirblock
-        pending.extend(d for d in reversed(dirblock) if d[2] == _directory)
+        pending.extend(d for d in reversed(dirblock) if d[2][0] is _directory)
 
 
 def _walkdirs_utf8(top, prefix=""):
@@ -1143,11 +1137,11 @@
     _listdir = os.listdir
     _kind_from_mode = _formats.get
 
-    # 0 - relpath, 1- basename, 2- kind, 3 - size, 4- exe, 5-stattime, 6- statcache, 7-toppath
-    # But we don't actually uses 1-6 in pending, so set them to None
-    pending = [(safe_utf8(prefix), None, None, None, None, None, None, safe_utf8(top))]
+    # 0 - relpath, 1- basename, 2- path_info, 3-toppath
+    # But we don't actually use 1 & 2 in pending, so set them to None
+    pending = [(safe_utf8(prefix), None, None, safe_utf8(top))]
     while pending:
-        relroot, _, _, _, _, _, _, top = pending.pop()
+        relroot, _, _, top = pending.pop()
         if relroot:
             relprefix = relroot + '/'
         else:
@@ -1159,12 +1153,11 @@
         for name in sorted(_listdir(top)):
             abspath = top_slash + name
             info = path_info(abspath)
-            append((relprefix + name, name, info[0], info[1], info[2], info[3],
-                info[4], abspath))
+            append((relprefix + name, name, info, abspath))
         yield (relroot, top), dirblock
 
         # push the user specified dirs from dirblock
-        pending.extend(d for d in reversed(dirblock) if d[2] == _directory)
+        pending.extend(d for d in reversed(dirblock) if d[2][0] is _directory)
 
 
 def _walkdirs_unicode_to_utf8(top, prefix="", path_info=path_info.path_info):
@@ -1184,11 +1177,11 @@
     _kind_from_mode = _formats.get
     fs_encoder = codecs.getencoder(sys.getfilesystemencoding())
 
-    # 0 - relpath, 1- basename, 2- kind, 3 - size, 4- exe, 5-stattime, 6- statcache, 7-toppath
-    # But we don't actually uses 1-6 in pending, so set them to None
-    pending = [(safe_utf8(prefix), None, None, None, None, None, None, safe_unicode(top))]
+    # 0 - relpath, 1- basename, 2- path_info, 3-toppath
+    # But we don't actually use 1 & 2 in pending, so set them to None
+    pending = [(safe_utf8(prefix), None, None, safe_unicode(top))]
     while pending:
-        relroot, _, _, _, _, _, _, top = pending.pop()
+        relroot, _, _, top = pending.pop()
         if relroot:
             relprefix = relroot + '/'
         else:
@@ -1201,11 +1194,11 @@
             name_utf8 = _utf8_encode(name)[0]
             abspath = top_slash + name
             info = path_info(fs_encoder(abspath)[0])
-            append((relprefix + name_utf8, name_utf8, info[0], info[1], info[2], info[3], info[4], abspath))
+            append((relprefix + name_utf8, name_utf8, info, abspath))
         yield (relroot, top), dirblock
 
         # push the user specified dirs from dirblock
-        pending.extend(d for d in reversed(dirblock) if d[2] == _directory)
+        pending.extend(d for d in reversed(dirblock) if d[2][0] is _directory)
 
 
 def copy_tree(from_path, to_path, handlers={}):
@@ -1248,8 +1241,8 @@
     if from_path.__class__ != str:
         from_path = from_path.encode(sys.getfilesystemencoding())
     for dir_info, entries in walkdirs(from_path, prefix=to_path):
-        for relpath, _, kind, _, _, _, _, abspath in entries:
-            real_handlers[kind](abspath, relpath)
+        for relpath, _, info, abspath in entries:
+            real_handlers[info[0]](abspath, relpath)
 
 
 def path_prefix_key(path):

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2007-03-09 15:52:13 +0000
+++ b/bzrlib/tests/test_osutils.py	2007-03-10 04:24:06 +0000
@@ -526,14 +526,24 @@
         packs = [path_info.pack_stat(st) for st in stats]
         expected_dirblocks = [
                 (('', '.'),
-                 [('0file', '0file', 'file', 18, False, stats[1].st_mtime, packs[1], './0file'),
-                  ('1dir', '1dir', 'directory', 0, False, stats[2].st_mtime, packs[2], './1dir'),
-                  ('2file', '2file', 'file', 18, False, stats[5].st_mtime, packs[5], './2file'),
+                 [('0file', '0file',
+                   ('file', 18, False, stats[1].st_mtime, packs[1]),
+                   './0file'),
+                  ('1dir', '1dir',
+                   ('directory', 0, False, stats[2].st_mtime, packs[2]),
+                   './1dir'),
+                  ('2file', '2file',
+                   ('file', 18, False, stats[5].st_mtime, packs[5]),
+                   './2file'),
                  ]
                 ),
                 (('1dir', './1dir'),
-                 [('1dir/0file', '0file', 'file', 23, False, stats[3].st_mtime, packs[3], './1dir/0file'),
-                  ('1dir/1dir', '1dir', 'directory', 0, False, stats[4].st_mtime, packs[4], './1dir/1dir'),
+                 [('1dir/0file', '0file',
+                   ('file', 23, False, stats[3].st_mtime, packs[3]),
+                   './1dir/0file'),
+                  ('1dir/1dir', '1dir',
+                   ('directory', 0, False, stats[4].st_mtime, packs[4]),
+                   './1dir/1dir'),
                  ]
                 ),
                 (('1dir/1dir', './1dir/1dir'),
@@ -572,14 +582,24 @@
         packs = [path_info.pack_stat(st) for st in stats]
         expected_dirblocks = [
                 (('', '.'),
-                 [('0file', '0file', 'file', 18, False, stats[1].st_mtime, packs[1], './0file'),
-                  ('1dir', '1dir', 'directory', 0, False, stats[2].st_mtime, packs[2], './1dir'),
-                  ('2file', '2file', 'file', 18, False, stats[5].st_mtime, packs[5], './2file'),
+                 [('0file', '0file',
+                   ('file', 18, False, stats[1].st_mtime, packs[1]),
+                   './0file'),
+                  ('1dir', '1dir',
+                   ('directory', 0, False, stats[2].st_mtime, packs[2]),
+                   './1dir'),
+                  ('2file', '2file',
+                   ('file', 18, False, stats[5].st_mtime, packs[5]),
+                   './2file'),
                  ]
                 ),
                 (('1dir', './1dir'),
-                 [('1dir/0file', '0file', 'file', 23, False, stats[3].st_mtime, packs[3], './1dir/0file'),
-                  ('1dir/1dir', '1dir', 'directory', 0, False, stats[4].st_mtime, packs[4], './1dir/1dir'),
+                 [('1dir/0file', '0file',
+                  ('file', 23, False, stats[3].st_mtime, packs[3]),
+                  './1dir/0file'),
+                  ('1dir/1dir', '1dir',
+                   ('directory', 0, False, stats[4].st_mtime, packs[4]),
+                   './1dir/1dir'),
                  ]
                 ),
                 (('1dir/1dir', './1dir/1dir'),
@@ -609,8 +629,8 @@
         for dirdetail, dirblock in result:
             new_dirblock = []
             for info in dirblock:
-                # Ignore info[3] which is the stat
-                new_dirblock.append((info[0], info[1], info[2], info[7]))
+                # extract kind from path_info- field 2
+                new_dirblock.append((info[0], info[1], info[2][0], info[3]))
             dirblock[:] = new_dirblock
 
     def test_unicode_walkdirs(self):
@@ -713,9 +733,9 @@
             for info in dirblock:
                 self.assertIsInstance(info[0], str)
                 self.assertIsInstance(info[1], str)
-                self.assertIsInstance(info[7], str)
+                self.assertIsInstance(info[3], str)
                 # Remove the stat information
-                new_dirblock.append((info[0], info[1], info[2], info[7]))
+                new_dirblock.append((info[0], info[1], info[2][0], info[3]))
             result.append((dirdetail, new_dirblock))
         self.assertEqual(expected_dirblocks, result)
 

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2007-03-07 06:04:53 +0000
+++ b/bzrlib/workingtree.py	2007-03-10 04:24:06 +0000
@@ -2174,8 +2174,8 @@
                 direction = cmp(current_inv[0][0], current_disk[0][0])
             if direction > 0:
                 # disk is before inventory - unknown
-                dirblock = [(relpath, basename, kind, stat, None, None) for
-                    relpath, basename, kind, stat, top_path in current_disk[1]]
+                dirblock = [(relpath, basename, info[0], info, None, None) for
+                    relpath, basename, info, top_path in current_disk[1]]
                 yield (current_disk[0][0], None), dirblock
                 try:
                     current_disk = disk_iterator.next()

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2007-03-09 15:52:13 +0000
+++ b/bzrlib/workingtree_4.py	2007-03-10 04:24:06 +0000
@@ -1540,7 +1540,7 @@
         # This should be cleaned up to use the much faster Dirstate code
         # So for now, we just build up the parent inventory, and extract
         # it the same way RevisionTree does.
-        _directory = 'directory'
+        _directory = path_info._directory_kind
         inv = self._get_inventory()
         top_id = inv.path2id(prefix)
         if top_id is None:
@@ -1565,7 +1565,7 @@
             yield (relpath, entry.file_id), dirblock
             # push the user specified dirs from dirblock
             for dir in reversed(dirblock):
-                if dir[2] == _directory:
+                if dir[2] is _directory:
                     pending.append((dir[0], dir[4]))
 
 
@@ -1710,9 +1710,10 @@
                 # this is a top level path, we must check it.
                 search_specific_files.add(path)
         # sketch: 
-        # compare source_index and target_index at or under each element of search_specific_files.
-        # follow the following comparison table. Note that we only want to do diff operations when
-        # the target is fdl because thats when the walkdirs logic will have exposed the pathinfo 
+        # compare source_index and target_index at or under each element of
+        # search_specific_files. follow the following comparison table. Note
+        # that we only want to do diff operations when # the target is fdlt
+        # because thats when the walkdirs logic will have exposed the pathinfo
         # for the target.
         # cases:
         # 
@@ -1776,8 +1777,8 @@
             if path_info is not None and target_minikind in 'fdlt':
                 # we have a versioned path here, and there is disk data for it.
                 assert target_index == 0
-                link_or_sha1 = state.update_entry(entry, path_info[7],
-                    path_info[2:7])
+                link_or_sha1 = state.update_entry(entry, path_info[3],
+                    path_info[2])
                 # The entry may have been modified by update_entry
                 target_details = entry[1][target_index]
                 target_minikind = target_details[0]
@@ -1818,7 +1819,7 @@
                     target_exec = False
                 else:
                     # source and target are both versioned and disk file is present.
-                    target_kind = path_info[2]
+                    target_kind = path_info[2][0]
                     # Target details is updated at update_entry time
                     target_exec = target_details[3]
                     if target_kind == 'directory':
@@ -1901,7 +1902,7 @@
                             (False, True),
                             (None, parent_id),
                             (None, entry[0][1]),
-                            (None, path_info[2]),
+                            (None, path_info[2][0]),
                             (None, target_exec)),)
                 else:
                     # but its not on disk: we deliberately treat this as just
@@ -1955,12 +1956,13 @@
             if root_info[0] is path_info.kind_missing:
                 root_dir_info = None
             else:
-                root_dir_info = ('', current_root, root_info[0], root_info[1], root_info[2], root_info[3], root_info[4], root_abspath)
-                if root_dir_info[2] == 'directory':
+                root_dir_info = ('', current_root, root_info, root_abspath)
+                if root_dir_info[2][0] == 'directory':
                     if self.target._directory_is_tree_reference(
                         current_root.decode('utf8')):
                         root_dir_info = root_dir_info[:2] + \
-                            ('tree-reference',) + root_dir_info[3:]
+                            (('tree-reference',) + root_dir_info[2][1:] ,) + \
+                            root_dir_info[3:]
 
             if not root_entries and not root_dir_info:
                 # this specified path is not present at all, skip it.
@@ -1988,7 +1990,7 @@
                 yield (None, (None, current_root), True, (False, False),
                     (None, None),
                     (None, splitpath(current_root)[-1]),
-                    (None, root_dir_info[2]), (None, root_dir_info[4]))
+                    (None, root_dir_info[2][0]), (None, root_dir_info[2][2]))
             dir_iterator = osutils._walkdirs_utf8(root_abspath, prefix=current_root)
             initial_key = (current_root, '', '')
             block_index, _ = state._find_block_index_from_key(initial_key)
@@ -2081,11 +2083,12 @@
                 path_index = 0
                 if current_dir_info and path_index < len(current_dir_info[1]):
                     current_path_info = current_dir_info[1][path_index]
-                    if current_path_info[2] == 'directory':
+                    if current_path_info[2][0] == 'directory':
                         if self.target._directory_is_tree_reference(
                             current_path_info[0].decode('utf8')):
                             current_path_info = current_path_info[:2] + \
-                                ('tree-reference',) + current_path_info[3:]
+                                (('tree-reference',) + current_path_info[2][1:] ,) + \
+                                current_path_info[3:]
                 else:
                     current_path_info = None
                 advance_path = True
@@ -2175,22 +2178,23 @@
                                     (False, False),
                                     (None, None),
                                     (None, current_path_info[1]),
-                                    (None, current_path_info[2]),
-                                    (None, current_path_info[4]))
+                                    (None, current_path_info[2][0]),
+                                    (None, current_path_info[2][2]))
                             # dont descend into this unversioned path if it is
                             # a dir
-                            if current_path_info[2] in (
+                            if current_path_info[2][0] in (
                                 'directory', 'tree-referene'):
                                 del current_dir_info[1][path_index]
                                 path_index -= 1
                         path_index += 1
                         if path_index < len(current_dir_info[1]):
                             current_path_info = current_dir_info[1][path_index]
-                            if current_path_info[2] == 'directory':
+                            if current_path_info[2][0] == 'directory':
                                 if self.target._directory_is_tree_reference(
                                     current_path_info[0].decode('utf8')):
                                     current_path_info = current_path_info[:2] + \
-                                        ('tree-reference',) + current_path_info[3:]
+                                        (('tree-reference',) + current_path_info[2][1:] ,) + \
+                                        current_path_info[3:]
                         else:
                             current_path_info = None
                         path_handled = False



More information about the bazaar-commits mailing list