Commits

Andrew Godwin committed 748ed41

Fully-working commit of directories (add and removal)

  • Participants
  • Parent commits cf1e932

Comments (0)

Files changed (4)

File heechee/repo/hg.py

     def file_changes(self, path, source, target):
         """
         Given two revisions and a path, yields the numbers of SVN commits which
-        affected that file. Note that source = 5 will first look at changeset 6,
-        since that starts with commit 5.
+        affected that file/directory. Note that source = 5 will first look at
+        changeset 6, since that starts with commit 5.
         """
         path = path.strip("/")
         source = int(source)
                 "date": datetime.datetime.fromtimestamp(changectx.date()[0]),
             }
 
-    def commit(self, branch_name, parent, message, author, svndiffs):
+    def commit(self, branch_name, parent, message, author, changes, deletions):
         "Commits a change to the repository."
         
         # Work out the correct parent (i.e. go back till we hit the branch)
                 # The file wasn't in Mercurial before.
                 source = StringIO("")
             # Patch it with the svndiff (or mark as deleted)
-            svndiff = svndiffs[path]
-            if svndiff is False:
-                # File was deleted. Tell hg that.
+            try:
+                result = undiff(source, StringIO(changes[path]))
+            except KeyError:
+                # No svndiff, so this is a deletion.
                 raise IOError()
-            else:
-                result = undiff(source, StringIO(svndiff))
             # Return that as a memfilectx
             return memfilectx(path, result, False, False, None)
+    
+        # Work out what to actually delete (some of the deleted paths may be
+        # directories; do prefix checks)
+        actual_deletions = []
+        for path in self.hg_repo.changectx('tip'):
+            for delete_path in deletions:
+                if path.startswith(delete_path):
+                    actual_deletions.append(path)
         
         # Make the change context which represents this new commit
         ctx = memctx(
             repo = self.hg_repo,
             parents = [parent, None],
             text = message,
-            files = svndiffs.keys(),
+            files = changes.keys() + actual_deletions,
             filectxfn = filectxfn,
             user = author,
         )

File heechee/tests/base.py

         self.server = subprocess.Popen(
             ["python", "-m", "heechee.webdav.__init__", self.source_dir],
             stdout=subprocess.PIPE,
-            #stderr=subprocess.PIPE,
+            stderr=subprocess.PIPE,
         )
         # Wait for server to come up
         for i in range(20):
     
     def assert_contents(self, path, supposed_contents):
         "Asserts that a the contents of the given file are exactly as provided."
+        self.assert_exists(path)
         fh = open(os.path.join(self.target_dir, path))
         contents = fh.read()
         fh.close()
     
     def assert_contents_source(self, path, supposed_contents):
         "Asserts that a the contents of the given file are exactly as provided."
+        self.assert_exists_source(path)
         fh = open(os.path.join(self.source_dir, path))
         contents = fh.read()
         fh.close()

File heechee/tests/mercurial.py

             "svn mkdir checkout/newdir",
             "svn ci checkout -m 'Commit from SVN'",
         ])
-        # Update the mercurial repo to default, make sure it's not there
+        # Update the mercurial repo to default, make sure it's appeared
         self.source_cmds("hg up -C default")
-        self.assert_not_exists_source("newdir")
+        self.assert_exists_source("newdir")
         # Add a file into it, make sure that appears
         self.target_cmds([
             "echo ff > checkout/newdir/f",
             "svn ci checkout -m 'Commit 2 from SVN'",
         ])
         self.source_cmds("hg up -C default")
-        self.assert_exists_source("newdir/f")
+        self.assert_contents_source("newdir/f", "ff\n")
+        # Now, delete the directory, and make sure it deleted
+        self.target_cmds([
+            "svn rm checkout/newdir/",
+            "svn ci checkout -m 'Commit 3 from SVN'",
+        ])
+        self.source_cmds("hg up -C default")
+        self.assert_not_exists_source("newdir/f")
+        self.assert_not_exists_source("newdir")
 
 
 if __name__ == '__main__':

File heechee/webdav/commit.py

                 base_version,
                 log_message,
                 "SVN user",
-                files,
+                # Changed files
+                dict([(key, diff) for key, diff in files.items() if diff is not False]),
+                # Deleted files
+                [key for key, diff in files.items() if diff is False],
             )
         
         # Return the correct response
             path_parts = request.path.strip("/").split("/")
             activity_set = path_parts[2]
             filename = "/".join(path_parts[3:])
+            # Mark the file as deleted. This will trigger recursive deletion
+            # inside the repo backend if it's a directory.
             self.activities[activity_set][filename] = {'svndiff': False}
         else:
             # Deleting the activity set.