--- a/prompt.py Mon Oct 03 11:46:47 2016 +0000
+++ b/prompt.py Tue Oct 04 10:49:19 2016 +0000
@@ -14,8 +14,10 @@
import os
import subprocess
from datetime import datetime, timedelta
+from contextlib import closing
from os import path
from mercurial import extensions, commands, cmdutil, help
+from mercurial.i18n import _
from mercurial.node import hex, short
cmdtable = {}
@@ -33,6 +35,7 @@
FILTER_ARG = re.compile(r'\|.+\((.*)\)')
+
def _cache_remote(repo, kind):
cache = path.join(repo.root, CACHE_PATH, kind)
c_tmp = cache + '.temp'
@@ -58,6 +61,7 @@
os.rename(c_tmp, cache)
return
+
def _with_groups(groups, out):
out_groups = [groups[0]] + [groups[-1]]
@@ -298,10 +302,12 @@
if cache_exists:
with open(cache) as c:
count = len(c.readlines())
- if g[1]:
- return _with_groups(g, str(count)) if count else ''
+ if g[1] and count > 0:
+ return _with_groups(g, str(count))
+ elif g[2]:
+ return _with_groups(g, '0') if not count else ''
else:
- return _with_groups(g, '') if count else ''
+ return _with_groups(g, '')
else:
return ''
return _r
@@ -441,8 +447,14 @@
')*': _tip,
'update': _update,
- 'incoming(\|count)?': _remote('incoming'),
- 'outgoing(\|count)?': _remote('outgoing'),
+ 'incoming(?:'
+ '(\|count)'
+ '|(\|zero)'
+ ')*': _remote('incoming'),
+ 'outgoing(?:'
+ '(\|count)'
+ '|(\|zero)'
+ ')*': _remote('outgoing')
}
if opts.get("cache_incoming"):
@@ -480,8 +492,8 @@
pass
help.helptable += (
- (['prompt-keywords', 'prompt-keywords'], ('Keywords supported by hg-prompt'),
- (r'''hg-prompt currently supports a number of keywords.
+ (['prompt-keywords'], _('Keywords supported by hg-prompt'),
+ lambda _: r'''hg-prompt currently supports a number of keywords.
Some keywords support filters. Filters can be chained when it makes
sense to do so. When in doubt, try it!
@@ -521,6 +533,8 @@
|count
Display the number of incoming changesets (if greater than 0).
+ |zero
+ Display 0 if there are no incoming changesets.
node
Display the (full) changeset hash of the current parent.
@@ -544,6 +558,8 @@
|count
Display the number of outgoing changesets (if greater than 0).
+ |zero
+ Display 0 if there are no incoming changesets.
patch
Display the topmost currently-applied patch (requires the mq
@@ -660,5 +676,5 @@
Display `^` if the current parent is not the tip of the current branch,
otherwise nothing. In effect, this lets you see if running `hg update`
would do something.
-''')),
+'''),
)