[PATCH 1 of 6] cmdutil: extract increasing_windows() from walkchangerevs()

Patrick Mezard patrick at mezard.eu
Tue May 8 15:58:06 CDT 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1336509824 -7200
# Node ID d30440da7b38c671266ae1734db3921475a63caa
# Parent  ddd4996740c785cc187766249977ea3ece8c17ab
cmdutil: extract increasing_windows() from walkchangerevs()

It will be reused in the revset-based version.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -955,6 +955,20 @@
 
     raise util.Abort(_("revision matching date not found"))
 
+def increasingwindows(start, end, windowsize=8, sizelimit=512):
+    if start < end:
+        while start < end:
+            yield start, min(windowsize, end - start)
+            start += windowsize
+            if windowsize < sizelimit:
+                windowsize *= 2
+    else:
+        while start > end:
+            yield start, min(windowsize, start - end - 1)
+            start -= windowsize
+            if windowsize < sizelimit:
+                windowsize *= 2
+
 def walkchangerevs(repo, match, opts, prepare):
     '''Iterate over files and the revs in which they changed.
 
@@ -970,20 +984,6 @@
     yielding each context, the iterator will first call the prepare
     function on each context in the window in forward order.'''
 
-    def increasing_windows(start, end, windowsize=8, sizelimit=512):
-        if start < end:
-            while start < end:
-                yield start, min(windowsize, end - start)
-                start += windowsize
-                if windowsize < sizelimit:
-                    windowsize *= 2
-        else:
-            while start > end:
-                yield start, min(windowsize, start - end - 1)
-                start -= windowsize
-                if windowsize < sizelimit:
-                    windowsize *= 2
-
     follow = opts.get('follow') or opts.get('follow_first')
 
     if not len(repo):
@@ -1173,7 +1173,7 @@
             def want(rev):
                 return rev in wanted
 
-        for i, window in increasing_windows(0, len(revs)):
+        for i, window in increasingwindows(0, len(revs)):
             nrevs = [rev for rev in revs[i:i + window] if want(rev)]
             for rev in sorted(nrevs):
                 fns = fncache.get(rev)


More information about the Mercurial-devel mailing list