I had to apply the attached two fixes to make Mercurial -> Subversion
migration work.  It'd be great if they could make it into the next
release.  I hope the log messages are self-explanatory.

Note that I'm the worst kind of Python amateur.  These probably need
cleaning up.

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla
changeset:   2:ea6a45e79212
tag:         qtip
tag:         svn-move-over.patch
tag:         tip
user:        Mike Sperber <[EMAIL PROTECTED]>
date:        Mon Jan 07 14:04:21 2008 +0100
files:       vcpx/repository/svn.py
description:
Make Subversion not fail when moving over existing files.

Subversion doesn't like "svn mv <src> <dest>" when <dest> already
exists.  Detect this case and "svn mv <dest>" when it occurs.


diff --git a/vcpx/repository/svn.py b/vcpx/repository/svn.py
--- a/vcpx/repository/svn.py
+++ b/vcpx/repository/svn.py
@@ -740,6 +740,10 @@ class SvnWorkingDir(UpdatableSourceWorki
 
         # --force in case the file has been changed and moved in one revision
         cmd = self.repository.command("mv", "--quiet", "--force")
+
+        oldpath = join(self.repository.basedir, oldname)
+        newpath = join(self.repository.basedir, newname)
+
         # Subversion does not seem to allow
         #   $ mv a.txt b.txt
         #   $ svn mv a.txt b.txt
@@ -748,8 +752,6 @@ class SvnWorkingDir(UpdatableSourceWorki
         # It may be better to let subversion do the move itself. For one thing,
         # svn's cp+rm is different from rm+add (cp preserves history).
         unmoved = False
-        oldpath = join(self.repository.basedir, oldname)
-        newpath = join(self.repository.basedir, newname)
         if not exists(oldpath):
             try:
                 rename(newpath, oldpath)
@@ -758,6 +760,19 @@ class SvnWorkingDir(UpdatableSourceWorki
                                   newpath, oldpath)
                 raise
             unmoved = True
+
+        # Subversion doesn't like if a file is moved to an existing one
+        lscmd = self.repository.command("ls")
+        svnls = ExternalCommand(cwd=self.repository.basedir, command=lscmd)
+        svnls.execute(newname)
+        if not svnls.exit_status:
+            rmcmd = self.repository.command("rm", "--quiet", "--force")
+            rmnew = ExternalCommand(cwd=self.repository.basedir, command=rmcmd)
+            out, err = rmnew.execute(newname, stdout=PIPE, stderr=PIPE)
+            if rmnew.exit_status:
+                raise ChangesetApplicationFailure("%s returned status %d 
saying\n%s"
+                                                  % (str(rmnew), 
rmnew.exit_status,
+                                                     err.read()))
 
         # Ticket #135: Need a timediff between rsync and directory move
         if isdir(oldpath):

changeset:   1:9e2619afd611
tag:         new-dir.patch
tag:         qbase
user:        Mike Sperber <[EMAIL PROTECTED]>
date:        Mon Jan 07 13:11:01 2008 +0100
files:       vcpx/repository/hg.py
description:
Handle directory additions from Mercurial.

As Mercurial doesn't record added directories directly, we need to
figure out if that's in fact what happened.


diff --git a/vcpx/repository/hg.py b/vcpx/repository/hg.py
--- a/vcpx/repository/hg.py
+++ b/vcpx/repository/hg.py
@@ -181,6 +181,13 @@ class HgWorkingDir(UpdatableSourceWorkin
                 if pms.has_key(f):
                     e.action_kind = ChangesetEntry.UPDATED
                 else:
+                    # figure out if it was really a directory that was added
+                    from os.path import dirname
+                    p = f
+                    if dirname(p) and not pms.has_key(dirname(p)):
+                        while dirname(p) and not pms.has_key(dirname(p)):
+                            p = dirname(p)
+                        e = ChangesetEntry(p)
                     e.action_kind = ChangesetEntry.ADDED
 
             entries.append(e)
@@ -392,7 +399,7 @@ class HgWorkingDir(UpdatableSourceWorkin
     def _renamePathname(self, oldname, newname):
         """Rename an entry"""
 
-        from os.path import join, isdir, normpath
+        from os.path import join, isdir, normpath, exists, islink
 
         repo = self._getRepo()
 
@@ -406,6 +413,10 @@ class HgWorkingDir(UpdatableSourceWorkin
                 repo.copy(oldpath, join(newname, f))
                 repo.remove([oldpath], unlink=True)
         else:
+            # Create dummy file so Mercurial doesn't barf
+            newpath = join(self.repository.basedir, normpath(newname))
+            if not (exists(newpath) or islink(newpath)):
+                open(newpath, 'wb').close()
             repo.copy(oldname, newname)
             repo.remove([oldname], unlink=True)
 

_______________________________________________
Tailor mailing list
[email protected]
http://lists.zooko.com/mailman/listinfo/tailor

Reply via email to