[Pkg-bazaar-commits] ./bzr/unstable r156: new "directories" command

mbp at sourcefrog.net mbp at sourcefrog.net
Fri Apr 10 07:44:08 UTC 2009


------------------------------------------------------------
revno: 156
committer: mbp at sourcefrog.net
timestamp: Thu 2005-03-31 15:02:20 +1000
message:
  new "directories" command
modified:
  NEWS
  bzrlib/commands.py
  bzrlib/inventory.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2005-03-31 03:24:21 +0000
+++ b/NEWS	2005-03-31 05:02:20 +0000
@@ -4,6 +4,11 @@
 
     * Refactored inventory storage to insert a root entry at the top.
 
+  ENHANCEMENTS:
+
+    * New "directories" internal command lists versioned directories
+      in the tree.
+
 
 
 bzr-0.0.2  "black cube"  2003-03-31

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-03-30 23:34:24 +0000
+++ b/bzrlib/commands.py	2005-03-31 05:02:20 +0000
@@ -232,6 +232,13 @@
         print patchid
 
 
+def cmd_directories():
+    for name, ie in Branch('.').read_working_inventory().directories():
+        if name == '':
+            print '.'
+        else:
+            print name
+
 
 def cmd_init():
     # TODO: Check we're not already in a working directory?  At the

=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2005-03-31 03:24:21 +0000
+++ b/bzrlib/inventory.py	2005-03-31 05:02:20 +0000
@@ -128,6 +128,12 @@
             self.children = {}
 
 
+    def sorted_children(self):
+        l = self.children.items()
+        l.sort()
+        return l
+
+
     def copy(self):
         other = InventoryEntry(self.file_id, self.name, self.kind,
                                self.text_id, self.parent_id)
@@ -205,6 +211,7 @@
         self.children = {}
         self.kind = 'root_directory'
         self.parent_id = None
+        self.name = ''
 
     def __cmp__(self, other):
         if self is other:
@@ -318,11 +325,25 @@
     def directories(self, from_dir=None):
         """Return (path, entry) pairs for all directories.
         """
-        assert self.root
-        yield '', self.root
-        for path, entry in self.iter_entries():
-            if entry.kind == 'directory':
-                yield path, entry
+        def descend(parent_ie):
+            parent_name = parent_ie.name
+            if parent_name == '':
+                parent_name = '.'
+            yield parent_name, parent_ie
+
+            # directory children in sorted order
+            dn = []
+            for ie in parent_ie.children.itervalues():
+                if ie.kind == 'directory':
+                    dn.append((ie.name, ie))
+            dn.sort()
+            
+            for name, child_ie in dn:
+                for sub_name, sub_ie in descend(child_ie):
+                    yield appendpath(parent_name, sub_name), sub_ie
+
+        for name, ie in descend(self.root):
+            yield name, ie
         
 
 



More information about the Pkg-bazaar-commits mailing list