changeset 16465:ad38b96c88f9 stable

convert/svn: refactor svn_source.latest() with a nested function We will call it more than once for reasons detailed later.
author Patrick Mezard <patrick@mezard.eu>
date Wed, 18 Apr 2012 14:04:58 +0200
parents 0e1329d905df
children c53a49c345e1
files hgext/convert/subversion.py
diffstat 1 files changed, 25 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/subversion.py	Wed Apr 18 14:04:57 2012 +0200
+++ b/hgext/convert/subversion.py	Wed Apr 18 14:04:58 2012 +0200
@@ -563,6 +563,27 @@
         reported. Return None if computed module does not belong to
         rootmodule subtree.
         """
+        def findchanges(path, start, stop):
+            stream = self._getlog([path], start, stop)
+            try:
+                for entry in stream:
+                    paths, revnum, author, date, message = entry
+                    if revnum <= stop:
+                        break
+
+                    for p in paths:
+                        if (not path.startswith(p) or
+                            not paths[p].copyfrom_path):
+                            continue
+                        newpath = paths[p].copyfrom_path + path[len(p):]
+                        self.ui.debug("branch renamed from %s to %s at %d\n" %
+                                      (path, newpath, revnum))
+                        path = newpath
+                        break
+                return revnum, path
+            finally:
+                stream.close()
+
         if not path.startswith(self.rootmodule):
             # Requests on foreign branches may be forbidden at server level
             self.ui.debug('ignoring foreign branch %r\n' % path)
@@ -583,28 +604,11 @@
         # stat() gives us the previous revision on this line of
         # development, but it might be in *another module*. Fetch the
         # log and detect renames down to the latest revision.
-        stream = self._getlog([path], stop, dirent.created_rev)
-        try:
-            for entry in stream:
-                paths, revnum, author, date, message = entry
-                if revnum <= dirent.created_rev:
-                    break
-
-                for p in paths:
-                    if not path.startswith(p) or not paths[p].copyfrom_path:
-                        continue
-                    newpath = paths[p].copyfrom_path + path[len(p):]
-                    self.ui.debug("branch renamed from %s to %s at %d\n" %
-                                  (path, newpath, revnum))
-                    path = newpath
-                    break
-        finally:
-            stream.close()
-
-        if not path.startswith(self.rootmodule):
-            self.ui.debug('ignoring foreign branch %r\n' % path)
+        revnum, realpath = findchanges(path, stop, dirent.created_rev)
+        if not realpath.startswith(self.rootmodule):
+            self.ui.debug('ignoring foreign branch %r\n' % realpath)
             return None
-        return self.revid(dirent.created_rev, path)
+        return self.revid(revnum, realpath)
 
     def reparent(self, module):
         """Reparent the svn transport and return the previous parent."""