changeset 1461:cbc48ed3b56c

rebuildmeta: extract utility function for iterating over repositories
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Sun, 11 Aug 2013 21:59:17 +0200
parents e31c288e5059
children 7dc5c4368837
files hgsubversion/svncommands.py hgsubversion/util.py
diffstat 2 files changed, 14 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -106,13 +106,8 @@ def _buildmeta(ui, repo, args, partial=F
     # it would make us use O(revisions^2) time, so we perform an extra traversal
     # of the repository instead. During this traversal, we find all converted
     # changesets that close a branch, and store their first parent
-    for rev in xrange(startrev, len(repo)):
-        ui.progress('prepare', rev - startrev, total=numrevs)
-        try:
-            ctx = repo[rev]
-        except error.RepoError:
-            # this revision is hidden
-            continue
+    for ctx in util.get_contexts(repo, startrev):
+        ui.progress('prepare', ctx.rev() - startrev, total=numrevs)
 
         convinfo = util.getsvnrev(ctx, None)
         if not convinfo:
@@ -139,13 +134,8 @@ def _buildmeta(ui, repo, args, partial=F
     ui.progress('prepare', None, total=numrevs)
 
     revmapbuf = []
-    for rev in xrange(startrev, len(repo)):
-        ui.progress('rebuild', rev-startrev, total=numrevs)
-        try:
-            ctx = repo[rev]
-        except error.RepoError:
-            # this revision is hidden
-            continue
+    for ctx in util.get_contexts(repo, startrev):
+        ui.progress('rebuild', ctx.rev() - startrev, total=numrevs)
 
         convinfo = util.getsvnrev(ctx, None)
         if not convinfo:
@@ -253,7 +243,7 @@ def _buildmeta(ui, repo, args, partial=F
                 branch = meta.layoutobj.localname(parentpath)
                 break
 
-        if rev in closed:
+        if ctx.rev() in closed:
             # a direct child of this changeset closes the branch; drop it
             branchinfo.pop(branch, None)
         elif ctx.extra().get('close'):
--- a/hgsubversion/util.py
+++ b/hgsubversion/util.py
@@ -398,3 +398,12 @@ def parse_revnum(svnrepo, r):
             return svnrepo.last_changed_rev
         else:
             raise error.RepoLookupError("unknown Subversion revision %r" % r)
+
+def get_contexts(repo, fromrev=0):
+    """Generator yielding contexts from the repository."""
+
+    for rev in xrange(fromrev, len(repo)):
+        try:
+            yield repo[rev]
+        except error.RepoLookupError:
+            pass