Commits

Andrew Godwin committed 0827940

Pretty much almost checks out a whole working tree now.

  • Participants
  • Parent commits fa4366d

Comments (0)

Files changed (3)

File heechee/__init__.py

+ 

File heechee/repo.py

         hg_rev = self.hg_repo.changectx("tip")
         
         root = Directory(name=None, parent=None, rev=rev)
-        # Loop through the files. We sort them by length - that ensures
-        # a directory will always come before its children
-        stack = [""]
+        
+        # Loop through the files, and make a tree.
+        dirs = {"": root}
         for path in sorted(hg_rev, key=lambda x: len(x)):
+            # Make sure we have directories for our full path.
+            prev_path = ""
+            for part in path.split("/")[:-1]:
+                # If this directory isn't made yet...
+                our_path = prev_path + "/" + part
+                if our_path not in dirs:
+                    # Make it.
+                    dirs[our_path] = Directory(
+                        name = part, 
+                        parent = dirs[prev_path],
+                        rev = rev,
+                    )
+                prev_path = our_path
+            
             File(
-                name = path,
+                name = path.split("/")[-1],
                 contents = hg_rev[path].data(),
-                parent = root,
+                parent = dirs[prev_path],
                 rev = rev,
             )
         # Return!
         if parent is not None:
             parent.add_child(self)
     
+    def get_path(self):
+        if self.parent is None:
+            return ""
+        else:
+            return self.parent.get_path + "/" + self.name
+    
+    def parents(self):
+        "Returns the list of parents, up to the root node, which comes first."
+        if self.parent is None:
+            return []
+        else:
+            return self.parent.parents() + [self.parent]
+    
     
 
 class Directory(Versioned):
     
     def get_children(self):
         return self.children
+    
+    def __repr__(self):
+        if self.parent is None:
+            return "<Root Directory>"
+        else:
+            return "<Directory '%s' in '%s'>" % (self.name, self.parent.get_path())
 
 
 
     def __init__(self, contents, *args, **kwargs):
         self.contents = contents
         Versioned.__init__(self, *args, **kwargs)
+    
+    def __repr__(self):
+        return "<File '%s' in '%s'>" % (self.name, self.parent.get_path())
     

File heechee/webdav.py

         dir_ch_in = SubElement(dir, DAV_NS+"checked-in")
         dir_ch_in.append(self._href("/!svn/ver/1/"))
         
+        print root_directory, root_directory.children
+        
         # The queue is a list of (parent, item) tuples.
         queue = [(dir, child) for child in root_directory.get_children()]
         while queue: