Patchwork [1,of,3] changelog: introduce count argument to revs() function

login
register
mail settings
Submitter Alexander Plavin
Date July 20, 2013, 1:32 p.m.
Message ID <2f40791f03b930ba39b2.1374327178@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/1936/
State Superseded
Headers show

Comments

Alexander Plavin - July 20, 2013, 1:32 p.m.
# HG changeset patch
# User Alexander Plavin <me@aplavin.ru>
# Date 1374321959 -14400
#      Sat Jul 20 16:05:59 2013 +0400
# Branch stable
# Node ID 2f40791f03b930ba39b2305c5bbd6163b324222b
# Parent  612dd3f4e28910a0ef08ec7a5a423e263676d6cf
changelog: introduce count argument to revs() function

This allows specifying count of revisions to yield, which is convenient when
some revs are filtered.

Patch

diff -r 612dd3f4e289 -r 2f40791f03b9 mercurial/changelog.py
--- a/mercurial/changelog.py	Fri Jul 19 03:12:12 2013 +0400
+++ b/mercurial/changelog.py	Sat Jul 20 16:05:59 2013 +0400
@@ -147,11 +147,23 @@ 
 
         return filterediter()
 
-    def revs(self, start=0, stop=None):
+    def revs(self, start=0, stop=None, count=None):
         """filtered version of revlog.revs"""
+        if count is not None:
+            if count < 0:
+                stop = 0
+            elif count > 0:
+                stop = len(self)
+            else:
+                stop = start
+
+        curcount = 0
         for i in super(changelog, self).revs(start, stop):
             if i not in self.filteredrevs:
                 yield i
+                curcount += 1
+                if count is not None and curcount >= abs(count):
+                    break
 
     @util.propertycache
     def nodemap(self):