changeset 2901:9826af4841ef

Test for log --prune.
author Brendan Cully <brendan@kublai.com>
date Mon, 14 Aug 2006 10:27:02 -0700
parents 26c37ebda1bb
children 2fe4d99ae726
files mercurial/commands.py tests/test-log tests/test-log.out
diffstat 3 files changed, 78 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Aug 14 16:06:37 2006 +0300
+++ b/mercurial/commands.py	Mon Aug 14 10:27:02 2006 -0700
@@ -183,49 +183,59 @@
                 fncache[rev] = matches
                 wanted[rev] = 1
 
-    def iterate():
-        class followfilter:
-            def __init__(self, onlyfirst=False):
-                self.startrev = -1
-                self.roots = []
-                self.onlyfirst = onlyfirst
-
-            def match(self, rev):
-                def realparents(rev):
-                    if self.onlyfirst:
-                        return repo.changelog.parentrevs(rev)[0:1]
-                    else:
-                        return filter(lambda x: x != -1, repo.changelog.parentrevs(rev))
-
-                if self.startrev == -1:
-                    self.startrev = rev
+    class followfilter:
+        def __init__(self, onlyfirst=False):
+            self.startrev = -1
+            self.roots = []
+            self.onlyfirst = onlyfirst
+
+        def match(self, rev):
+            def realparents(rev):
+                if self.onlyfirst:
+                    return repo.changelog.parentrevs(rev)[0:1]
+                else:
+                    return filter(lambda x: x != -1, repo.changelog.parentrevs(rev))
+
+            if self.startrev == -1:
+                self.startrev = rev
+                return True
+
+            if rev > self.startrev:
+                # forward: all descendants
+                if not self.roots:
+                    self.roots.append(self.startrev)
+                for parent in realparents(rev):
+                    if parent in self.roots:
+                        self.roots.append(rev)
+                        return True
+            else:
+                # backwards: all parents
+                if not self.roots:
+                    self.roots.extend(realparents(self.startrev))
+                if rev in self.roots:
+                    self.roots.remove(rev)
+                    self.roots.extend(realparents(rev))
                     return True
 
-                if rev > self.startrev:
-                    # forward: all descendants
-                    if not self.roots:
-                        self.roots.append(self.startrev)
-                    for parent in realparents(rev):
-                        if parent in self.roots:
-                            self.roots.append(rev)
-                            return True
-                else:
-                    # backwards: all parents
-                    if not self.roots:
-                        self.roots.extend(realparents(self.startrev))
-                    if rev in self.roots:
-                        self.roots.remove(rev)
-                        self.roots.extend(realparents(rev))
-                        return True
-
-                return False
-
+            return False
+
+    # it might be worthwhile to do this in the iterator if the rev range
+    # is descending and the prune args are all within that range
+    for rev in opts.get('prune'):
+        rev = repo.changelog.rev(repo.lookup(rev))
+        ff = followfilter()
+        stop = min(revs[0], revs[-1])
+        for x in range(rev, stop-1, -1):
+            if ff.match(x) and wanted.has_key(x):
+                del wanted[x]
+
+    def iterate():
         if follow and not files:
             ff = followfilter(onlyfirst=opts.get('follow_first'))
             def want(rev):
-                if rev not in wanted:
-                    return False
-                return ff.match(rev)
+                if ff.match(rev) and rev in wanted:
+                    return True
+                return False
         else:
             def want(rev):
                 return rev in wanted
@@ -2966,6 +2976,7 @@
           ('', 'style', '', _('display using template map file')),
           ('m', 'only-merges', None, _('show only merges')),
           ('p', 'patch', None, _('show patch')),
+          ('P', 'prune', [], _('do not display revision or any of its ancestors')),
           ('', 'template', '', _('display with template')),
           ('I', 'include', [], _('include names matching the given patterns')),
           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
--- a/tests/test-log	Mon Aug 14 16:06:37 2006 +0300
+++ b/tests/test-log	Mon Aug 14 10:27:02 2006 -0700
@@ -63,3 +63,6 @@
 
 echo % log --follow-first
 hg log --follow-first
+
+echo % log -P 2
+hg log -P 2
--- a/tests/test-log.out	Mon Aug 14 16:06:37 2006 +0300
+++ b/tests/test-log.out	Mon Aug 14 10:27:02 2006 -0700
@@ -149,3 +149,29 @@
 date:        Thu Jan 01 00:00:01 1970 +0000
 summary:     base
 
+% log -P 2
+changeset:   6:2404bbcab562
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:01 1970 +0000
+summary:     b1.1
+
+changeset:   5:302e9dd6890d
+parent:      3:e62f78d544b4
+parent:      4:ddb82e70d1a1
+user:        test
+date:        Thu Jan 01 00:00:01 1970 +0000
+summary:     m12
+
+changeset:   4:ddb82e70d1a1
+parent:      0:67e992f2c4f3
+user:        test
+date:        Thu Jan 01 00:00:01 1970 +0000
+summary:     b2
+
+changeset:   3:e62f78d544b4
+parent:      1:3d5bf5654eda
+user:        test
+date:        Thu Jan 01 00:00:01 1970 +0000
+summary:     b1
+