# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1376251157 -7200 # Node ID cbc48ed3b56cd111e6add0cf980c143fb49f5e77 # Parent e31c288e5059bebfdc133300d82af8a0f1419445 rebuildmeta: extract utility function for iterating over repositories diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- 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'): diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- 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