Commits

Ivan Andrus committed d625101 Merge

merge from upstream

  • Participants
  • Parent commits 4cbcbbd, c4095c3

Comments (0)

Files changed (2)

File docs/wiki/documentation/keywords/index.mdown

 Keywords
 ========
 
-There a number of keywords available.  If you have any suggestions for more please [let me know][issues].
+There a number of keywords available.  If you have any suggestions for more
+please [let me know][issues].
 
 [issues]: http://bitbucket.org/sjl/issues
 
-Some of the keywords support filters.  These filters can be combined when it makes sense.  If in doubt, try it!
+Some of the keywords support filters.  These filters can be combined when it
+makes sense.  If in doubt, try it!
 
 [TOC]
 
     |quiet
     :   Display the current branch only if it is not the default branch.
 
+##closed##
+:   Display `X` if working on a closed branch (i.e. if committing now would
+    reopen the 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.
     :   Display STRING immediately after each unapplied patch.  Useful for
         resetting color codes.
 
+##queue##
+:   Display the name of the current MQ queue.
+
 ##rev##
 :   Display the repository-local changeset number of the current parent.
     
 
 [bookmarks]: http://mercurial.selenic.com/wiki/BookmarksExtension
 [tasks]: http://bitbucket.org/alu/hgtasks/wiki/Home
-[mq]: http://mercurial.selenic.com/wiki/MqExtension
+[mq]: http://mercurial.selenic.com/wiki/MqExtension
 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"
     See 'hg help prompt-keywords' for a list of available keywords.
     '''
 
+    def _basename(m):
+        return _with_groups(m.groups(), path.basename(repo.root)) if repo.root else ''
+
+    def _bookmark(m):
+        try:
+            book = extensions.find('bookmarks').current(repo)
+        except AttributeError:
+            book = getattr(repo, '_bookmarkcurrent', None)
+        except KeyError:
+            book = getattr(repo, '_bookmarkcurrent', None)
+        return _with_groups(m.groups(), book) if book else ''
+
     def _branch(m):
         g = m.groups()
 
 
         return _with_groups(g, out) if out else ''
 
-    def _status(m):
+    def _closed(m):
         g = m.groups()
 
-        st = repo.status(unknown=True)[:5]
-        modified = any(st[:4])
-        unknown = len(st[-1]) > 0
+        quiet = _get_filter('quiet', g)
 
-        flag = ''
-        if '|modified' not in g and '|unknown' not in g:
-            flag = '!' if modified else '?' if unknown else ''
-        else:
-            if '|modified' in g:
-                flag += '!' if modified else ''
-            if '|unknown' in g:
-                flag += '?' if unknown else ''
+        p = repo[None].parents()[0]
+        pn = p.node()
+        branch = repo.dirstate.branch()
+        closed = (p.extra().get('close')
+                  and pn in repo.branchheads(branch, closed=True))
+        out = 'X' if (not quiet) and closed else ''
 
-        return _with_groups(g, flag) if flag else ''
+        return _with_groups(g, out) if out else ''
 
-    def _bookmark(m):
-        try:
-            book = extensions.find('bookmarks').current(repo)
-        except AttributeError:
-            book = getattr(repo, '_bookmarkcurrent', None)
-        return _with_groups(m.groups(), book) if book 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 _tags(m):
+    def _node(m):
         g = m.groups()
 
-        sep = g[1][1:] if g[1] else ' '
-        tags = repo[None].tags()
+        parents = repo[None].parents()
+        p = 0 if '|merge' not in g else 1
+        p = p if len(parents) > p else None
 
-        return _with_groups(g, sep.join(tags)) if tags else ''
+        format = short if '|short' in g else hex
 
-    def _task(m):
-        try:
-            task = extensions.find('tasks').current(repo)
-            return _with_groups(m.groups(), task) if task else ''
-        except KeyError:
-            return ''
+        node = format(parents[p].node()) if p is not None else None
+        return _with_groups(g, str(node)) if node else ''
 
     def _patch(m):
         g = m.groups()
         if _get_filter('quiet', g) and not len(q.series):
             return ''
 
-        if _get_filter('applied', g):
+        if _get_filter('topindex', g):
+            if len(q.applied):
+                out = str(len(q.applied) - 1)
+            else:
+                out = ''
+        elif _get_filter('applied', g):
             out = str(len(q.applied))
         elif _get_filter('unapplied', g):
             out = str(len(q.unapplied(repo)))
 
         return _with_groups(g, sep.join(patches)) if patches else ''
 
-    def _root(m):
-        return _with_groups(m.groups(), repo.root) if repo.root else ''
+    def _queue(m):
+        g = m.groups()
 
-    def _basename(m):
-        return _with_groups(m.groups(), path.basename(repo.root)) if repo.root else ''
-
-    def _update(m):
-        if not repo.branchtags():
-            # We are in an empty repository.
+        try:
+            extensions.find('mq')
+        except KeyError:
             return ''
 
-        current_rev = repo[None].parents()[0]
-        to = repo[repo.branchtags()[current_rev.branch()]]
-        return _with_groups(m.groups(), '^') if current_rev != to else ''
+        q = repo.mq
 
-    def _rev(m):
-        g = m.groups()
+        out = os.path.basename(q.path)
+        if out == 'patches' and not os.path.isdir(q.path):
+            out = ''
+        elif out.startswith('patches-'):
+            out = out[8:]
 
-        parents = repo[None].parents()
-        parent = 0 if '|merge' not in g else 1
-        parent = parent if len(parents) > parent else None
-
-        rev = parents[parent].rev() if parent is not None else -1
-        return _with_groups(g, str(rev)) if rev >= 0 else ''
-
-    def _tip(m):
-        g = m.groups()
-
-        format = short if '|short' in g else hex
-
-        tip = repo[len(repo) - 1]
-        rev = tip.rev()
-        tip = format(tip.node()) if '|node' in g else tip.rev()
-
-        return _with_groups(g, str(tip)) if rev >= 0 else ''
-
-    def _node(m):
-        g = m.groups()
-
-        parents = repo[None].parents()
-        p = 0 if '|merge' not in g else 1
-        p = p if len(parents) > p else None
-
-        format = short if '|short' in g else hex
-
-        node = format(parents[p].node()) if p is not None else None
-        return _with_groups(g, str(node)) if node else ''
+        return _with_groups(g, out) if out else ''
 
     def _remote(kind):
         def _r(m):
                 return ''
         return _r
 
+    def _rev(m):
+        g = m.groups()
+
+        parents = repo[None].parents()
+        parent = 0 if '|merge' not in g else 1
+        parent = parent if len(parents) > parent else None
+
+        rev = parents[parent].rev() if parent is not None else -1
+        return _with_groups(g, str(rev)) if rev >= 0 else ''
+
+    def _root(m):
+        return _with_groups(m.groups(), repo.root) if repo.root else ''
+
+    def _status(m):
+        g = m.groups()
+
+        st = repo.status(unknown=True)[:5]
+        modified = any(st[:4])
+        unknown = len(st[-1]) > 0
+
+        flag = ''
+        if '|modified' not in g and '|unknown' not in g:
+            flag = '!' if modified else '?' if unknown else ''
+        else:
+            if '|modified' in g:
+                flag += '!' if modified else ''
+            if '|unknown' in g:
+                flag += '?' if unknown else ''
+
+        return _with_groups(g, flag) if flag else ''
+
+    def _tags(m):
+        g = m.groups()
+
+        sep = g[1][1:] if g[1] else ' '
+        tags = repo[None].tags()
+
+        return _with_groups(g, sep.join(tags)) if tags else ''
+
+    def _task(m):
+        try:
+            task = extensions.find('tasks').current(repo)
+            return _with_groups(m.groups(), task) if task else ''
+        except KeyError:
+            return ''
+
+    def _tip(m):
+        g = m.groups()
+
+        format = short if '|short' in g else hex
+
+        tip = repo[len(repo) - 1]
+        rev = tip.rev()
+        tip = format(tip.node()) if '|node' in g else tip.rev()
+
+        return _with_groups(g, str(tip)) if rev >= 0 else ''
+
+    def _update(m):
+        if not repo.branchtags():
+            # We are in an empty repository.
+            return ''
+
+        current_rev = repo[None].parents()[0]
+        to = repo[repo.branchtags()[current_rev.branch()]]
+        return _with_groups(m.groups(), '^') if current_rev != to else ''
+
 
     if opts.get("angle_brackets"):
         tag_start = r'\<([^><]*?\<)?'
     patterns = {
         'bookmark': _bookmark,
         'branch(\|quiet)?': _branch,
+        'closed(\|quiet)?': _closed,
+        'count(\|[^%s]*?)?' % brackets[-1]: _count,
         'node(?:'
             '(\|short)'
             '|(\|merge)'
             ')*': _node,
         'patch(?:'
-            '(\|applied)'
+            '(\|topindex)'
+            '|(\|applied)'
             '|(\|unapplied)'
             '|(\|count)'
             '|(\|quiet)'
             '|(\|pre_unapplied\([^%s]*?\))' % brackets[-1] +
             '|(\|post_unapplied\([^%s]*?\))' % brackets[-1] +
             ')*': _patches,
+        'queue': _queue,
         'rev(\|merge)?': _rev,
         'root': _root,
         'root\|basename': _basename,
 def uisetup(ui):
     extensions.wrapcommand(commands.table, 'pull', _pull_with_cache)
     extensions.wrapcommand(commands.table, 'push', _push_with_cache)
+    try:
+        extensions.wrapcommand(extensions.find("fetch").cmdtable, 'fetch', _pull_with_cache)
+    except KeyError:
+        pass
 
 cmdtable = {
     "prompt":
      |quiet
          Display the current branch only if it is not the default branch.
 
+closed
+     Display `X` if working on a closed branch (i.e. committing now would reopen
+     the 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.
      |count
          Display the number of patches in the queue.
 
+     |topindex
+         Display (zero-based) index of the topmost applied patch in the series
+         list (as displayed by :hg:`qtop -v`), or the empty string if no patch
+         is applied.
+
      |applied
          Display the number of currently applied patches in the queue.
 
          Display STRING immediately after each unapplied patch.  Useful for
          resetting color codes.
 
+queue
+     Display the name of the current MQ queue.
+
 rev
      Display the repository-local changeset number of the current parent.