d3e15364de2e

Add the count filter to count revsets.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 22 Jun 2010 18:11:43 -0400
parents 8ca1c9929313
children 5d808d1613f4
branches/tags (none)
files prompt.py

Changes

--- a/prompt.py	Fri Apr 23 10:16:09 2010 -0400
+++ b/prompt.py	Tue Jun 22 18:11:43 2010 -0400
@@ -15,7 +15,7 @@
 import subprocess
 from datetime import datetime, timedelta
 from os import path
-from mercurial import extensions, commands, help
+from mercurial import extensions, commands, cmdutil, help
 from mercurial.node import hex, short
 
 CACHE_PATH = ".hg/prompt/cache"
@@ -136,6 +136,11 @@
         
         return _with_groups(g, sep.join(tags)) if tags else ''
     
+    def _count(m):
+        g = m.groups()
+        query = [g[1][1:]] if g[1] else ['all()']
+        return _with_groups(g, str(len(cmdutil.revrange(repo, query))))
+    
     def _task(m):
         try:
             task = extensions.find('tasks').current(repo)
@@ -305,6 +310,7 @@
     patterns = {
         'bookmark': _bookmark,
         'branch(\|quiet)?': _branch,
+        'count(\|[^%s]*?)?' % brackets[-1]: _count,
         'node(?:'
             '(\|short)'
             '|(\|merge)'
@@ -399,6 +405,15 @@
      |quiet
          Display the current branch only if it is not the default branch.
 
+count
+     Display the number of revisions in the given revset (the revset `all()`
+     will be used if none is given.
+     
+     See `hg help revsets` for more information.
+     
+     |REVSET
+         The revset to count.
+
 incoming
      Display nothing, but if the default path contains incoming changesets the 
      extra text will be expanded.