changeset 13705:73cfb7a5aa56

strip: simplify collectone
author Matt Mackall <mpm@selenic.com>
date Sun, 20 Mar 2011 19:43:28 -0500
parents a464763e99f1
children 7beb9834d185
files mercurial/repair.py
diffstat 1 files changed, 13 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/repair.py	Sun Mar 20 17:41:09 2011 -0400
+++ b/mercurial/repair.py	Sun Mar 20 19:43:28 2011 -0500
@@ -35,28 +35,24 @@
 
 def _collectbrokencsets(repo, files, striprev):
     """return the changesets which will be broken by the truncation"""
+    s = set()
     def collectone(revlog):
-        startrev = count = len(revlog)
+        links = (revlog.linkrev(i) for i in xrange(len(revlog)))
         # find the truncation point of the revlog
-        for i in xrange(count):
-            lrev = revlog.linkrev(i)
+        for lrev in links:
             if lrev >= striprev:
-                startrev = i + 1
                 break
+        # see if any revision after this point has a linkrev
+        # less than striprev (those will be broken by strip)
+        for lrev in links:
+            if lrev < striprev:
+                        s.add(lrev)
 
-        # see if any revision after that point has a linkrev less than striprev
-        # (those will be broken by strip)
-        for i in xrange(startrev, count):
-            lrev = revlog.linkrev(i)
-            if lrev < striprev:
-                yield lrev
+    collectone(repo.manifest)
+    for fname in files:
+        collectone(repo.file(fname))
 
-    for rev in collectone(repo.manifest):
-        yield rev
-    for fname in files:
-        f = repo.file(fname)
-        for rev in collectone(f):
-            yield rev
+    return s
 
 def strip(ui, repo, node, backup="all"):
     cl = repo.changelog
@@ -76,7 +72,7 @@
     tostrip.add(striprev)
 
     files = _collectfiles(repo, striprev)
-    saverevs = set(_collectbrokencsets(repo, files, striprev))
+    saverevs = _collectbrokencsets(repo, files, striprev)
 
     # compute heads
     saveheads = set(saverevs)