Merge with crew-stable
authorPatrick Mezard <pmezard@gmail.com>
Fri, 25 Jul 2008 20:47:04 +0200
changeset 6849 1a9577da9d02
parent 6846 54b7c79575fa (current diff)
parent 6848 59c40c60d8d8 (diff)
child 6852 8dc510c4caee
Merge with crew-stable
hgext/convert/subversion.py
--- a/hgext/convert/subversion.py	Mon Jul 21 13:26:42 2008 +0200
+++ b/hgext/convert/subversion.py	Fri Jul 25 20:47:04 2008 +0200
@@ -188,6 +188,7 @@
             # Module is either empty or a repository path starting with
             # a slash and not ending with a slash.
             self.module = self.url[len(self.base):]
+            self.prevmodule = None
             self.rootmodule = self.module
             self.commits = {}
             self.paths = {}
@@ -250,7 +251,7 @@
     def getheads(self):
 
         def isdir(path, revnum):
-            kind = svn.ra.check_path(self.ra, path, revnum)
+            kind = self._checkpath(path, revnum)
             return kind == svn.core.svn_node_dir
 
         def getcfgpath(name, rev):
@@ -478,9 +479,9 @@
         if not stop:
             stop = svn.ra.get_latest_revnum(self.ra)
         try:
-            self.reparent('')
+            prevmodule = self.reparent('')
             dirent = svn.ra.stat(self.ra, path.strip('/'), stop)
-            self.reparent(self.module)
+            self.reparent(prevmodule)
         except SubversionException:
             dirent = None
         if not dirent:
@@ -532,9 +533,17 @@
         return svn_rev in self.blacklist
 
     def reparent(self, module):
-        svn_url = self.base + module
-        self.ui.debug("reparent to %s\n" % svn_url.encode(self.encoding))
-        svn.ra.reparent(self.ra, svn_url.encode(self.encoding))
+        """Reparent the svn transport and return the previous parent."""
+        if self.prevmodule == module:
+            return module
+        svn_url = (self.base + module).encode(self.encoding)
+        prevmodule = self.prevmodule
+        if prevmodule is None:
+            prevmodule = ''
+        self.ui.debug("reparent to %s\n" % svn_url)
+        svn.ra.reparent(self.ra, svn_url)
+        self.prevmodule = module
+        return prevmodule
 
     def expandpaths(self, rev, paths, parents):
         entries = []
@@ -550,7 +559,7 @@
             entrypath = self.getrelpath(path)
             entry = entrypath.decode(self.encoding)
 
-            kind = svn.ra.check_path(self.ra, entrypath, revnum)
+            kind = self._checkpath(entrypath, revnum)
             if kind == svn.core.svn_node_file:
                 entries.append(self.recode(entry))
                 if not ent.copyfrom_path or not parents:
@@ -604,9 +613,9 @@
 
                 # We can avoid the reparent calls if the module has not changed
                 # but it probably does not worth the pain.
-                self.reparent('')
+                prevmodule = self.reparent('')
                 fromkind = svn.ra.check_path(self.ra, entrypath.strip('/'), fromrev)
-                self.reparent(self.module)
+                self.reparent(prevmodule)
 
                 if fromkind == svn.core.svn_node_file:   # a deleted file
                     entries.append(self.recode(entry))
@@ -668,7 +677,7 @@
                     # print child, self.module, entrypath
                     if entrypath:
                         # Need to filter out directories here...
-                        kind = svn.ra.check_path(self.ra, entrypath, revnum)
+                        kind = self._checkpath(entrypath, revnum)
                         if kind != svn.core.svn_node_dir:
                             entries.append(self.recode(entrypath))
 
@@ -896,6 +905,11 @@
         self.ui.debug('%r is not under %r, ignoring\n' % (path, module))
         return None
 
+    def _checkpath(self, path, revnum):
+        # ra.check_path does not like leading slashes very much, it leads
+        # to PROPFIND subversion errors
+        return svn.ra.check_path(self.ra, path.strip('/'), revnum)
+
 pre_revprop_change = '''#!/bin/sh
 
 REPOS="$1"