[PATCH 2 of 3] convert/svn: refactor svn_source.latest() with a nested function
Patrick Mezard
patrick at mezard.eu
Wed Apr 18 07:12:58 CDT 2012
# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1334750698 -7200
# Branch stable
# Node ID 2197bdc3a83a252ad723ceef2b3220024054ce81
# Parent a292161acb176b1f59efc7c411a6ab2d0dbb8af8
convert/svn: refactor svn_source.latest() with a nested function
We will call it more than once for reasons detailed later.
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -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."""
More information about the Mercurial-devel
mailing list