annotate prompt.py @ 138:920255137b9d

Include a "status" flag Also now default to "u=" when no changes, as Git prompt does
author IBBoard <dev@ibboard.co.uk>
date Sat, 18 Jan 2020 20:40:07 +0000
parents f71524147eb4
children c09729100dd2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 #!/usr/bin/env python
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 '''get repository information for use in a shell prompt
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 Take a string, parse any special variables inside, and output the result.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 Useful mostly for putting information about the current repository into
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 a shell prompt.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 '''
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 from __future__ import with_statement
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 import re
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 import os
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
15 import platform
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 import subprocess
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 from datetime import datetime, timedelta
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 from os import path
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 from mercurial import extensions, commands, cmdutil, help
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 from mercurial.i18n import _
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 from mercurial.node import hex, short
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
23 # command registration moved into `registrar` module in v3.7.
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 cmdtable = {}
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
25 try:
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
26 from mercurial import registrar
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
27 command = registrar.command(cmdtable)
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
28 except ImportError:
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
29 command = cmdutil.command(cmdtable)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 # `revrange' has been moved into module `scmutil' since v1.9.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 try :
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 from mercurial import scmutil
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 revrange = scmutil.revrange
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 except :
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 revrange = cmdutil.revrange
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
38 CACHE_PATH = b".hg/prompt/cache"
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
39 CACHE_TIMEOUT = timedelta(minutes=15)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
40
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
41 FILTER_ARG = re.compile(rb'\|.+\((.*)\)')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
43 def _cache_remote(repo, kind):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
44 cache = path.join(repo.root, CACHE_PATH, kind)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
45 c_tmp = cache + b'.temp'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
46
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
47 # This is kind of a hack and I feel a little bit dirty for doing it.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
48 IGNORE = open('NUL:','w') if platform.system() == 'Windows' else open('/dev/null','w')
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
49
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
50 subprocess.call(['hg', kind, '--quiet'], stdout=open(c_tmp, 'w'), stderr=IGNORE)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
51 os.rename(c_tmp, cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
52 return
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 def _with_groups(groups, out):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 out_groups = [groups[0]] + [groups[-1]]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 if any(out_groups) and not all(out_groups):
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
58 print('Error parsing prompt string. Mismatched braces?')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
60 out = out.replace(b'%', b'%%')
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
61 return (b"%b" + out + b"%b") % (out_groups[0][:-1] if out_groups[0] else b'',
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
62 out_groups[1][1:] if out_groups[1] else b'')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 def _get_filter(name, g):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 '''Return the filter with the given name, or None if it was not used.'''
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
66 matching_filters = list(filter(lambda s: s and s.startswith(b'|%b' % name), g))
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 if not matching_filters:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 return None
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 # Later filters will override earlier ones, for now.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 f = matching_filters[-1]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 return f
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 def _get_filter_arg(f):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 if not f:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 return None
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 args = FILTER_ARG.match(f).groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 if args:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 return args[0]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 else:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 return None
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
85 @command(b'prompt',
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
86 [(b'', b'angle-brackets', None, b'use angle brackets (<>) for keywords'),
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
87 (b'', b'cache-incoming', None, b'used internally by hg-prompt'),
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
88 (b'', b'cache-outgoing', None, b'used internally by hg-prompt')],
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
89 b'hg prompt STRING')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 def prompt(ui, repo, fs='', **opts):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 '''get repository information for use in a shell prompt
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 Take a string and output it for use in a shell prompt. You can use
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 keywords in curly braces::
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 $ hg prompt "currently on {branch}"
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 currently on default
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 You can also use an extended form of any keyword::
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 {optional text here{keyword}more optional text}
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 This will expand the inner {keyword} and output it along with the extra
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 text only if the {keyword} expands successfully. This is useful if you
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 have a keyword that may not always apply to the current state and you
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 have some text that you would like to see only if it is appropriate::
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 $ hg prompt "currently at {bookmark}"
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 currently at
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 $ hg prompt "{currently at {bookmark}}"
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 $ hg bookmark my-bookmark
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 $ hg prompt "{currently at {bookmark}}"
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 currently at my-bookmark
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 See 'hg help prompt-keywords' for a list of available keywords.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 '''
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 def _basename(m):
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
119 return _with_groups(m.groups(), path.basename(repo.root)) if repo.root else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121 def _bookmark(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122 try:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
123 book = extensions.find(b'bookmarks').current(repo)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 except AttributeError:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 book = getattr(repo, '_bookmarkcurrent', None)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 except KeyError:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 book = getattr(repo, '_bookmarkcurrent', None)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 if book is None:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 book = getattr(repo, '_activebookmark', None)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130 if book:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 cur = repo['.'].node()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 if repo._bookmarks[book] == cur:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 return _with_groups(m.groups(), book)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 else:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
135 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 def _branch(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140 branch = repo.dirstate.branch()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
141 quiet = _get_filter(b'quiet', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
143 out = branch if (not quiet) or (branch != b'default') else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
145 return _with_groups(g, out) if out else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 def _closed(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
150 quiet = _get_filter(b'quiet', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
152 p = repo[None].parents()[0]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153 pn = p.node()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 branch = repo.dirstate.branch()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
155 closed = (p.extra().get(b'close')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 and pn in repo.branchheads(branch, closed=True))
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
157 out = b'X' if (not quiet) and closed else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
159 return _with_groups(g, out) if out else b'b'
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
160
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161 def _count(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162 g = m.groups()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
163 query = [g[1][1:]] if g[1] else [b'all()']
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164 return _with_groups(g, str(len(revrange(repo, query))))
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 def _node(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169 parents = repo[None].parents()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
170 p = 0 if b'|merge' not in g else 1
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 p = p if len(parents) > p else None
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
173 format = short if b'|short' in g else hex
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 node = format(parents[p].node()) if p is not None else None
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
176 return _with_groups(g, str(node)) if node else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 def _patch(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
179 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181 try:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
182 extensions.find(b'mq')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
183 except KeyError:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
184 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
185
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 q = repo.mq
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
188 if _get_filter(b'quiet', g) and not len(q.series):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
189 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
191 if _get_filter(b'topindex', g):
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
192 if len(q.applied):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
193 out = str(len(q.applied) - 1)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
194 else:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
195 out = b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
196 elif _get_filter(b'applied', g):
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
197 out = str(len(q.applied))
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
198 elif _get_filter(b'unapplied', g):
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
199 out = str(len(q.unapplied(repo)))
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
200 elif _get_filter(b'count', g):
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 out = str(len(q.series))
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 else:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
203 out = q.applied[-1].name if q.applied else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
205 return _with_groups(g, out) if out else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
206
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207 def _patches(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
208 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
209
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
210 try:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
211 extensions.find(b'mq')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212 except KeyError:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
213 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
215 join_filter = _get_filter(b'join', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
216 join_filter_arg = _get_filter_arg(join_filter)
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
217 sep = join_filter_arg if join_filter else b' -> '
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
218
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 patches = repo.mq.series
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220 applied = [p.name for p in repo.mq.applied]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
221 unapplied = filter(lambda p: p not in applied, patches)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
222
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
223 if _get_filter(b'hide_applied', g):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
224 patches = list(filter(lambda p: p not in applied, patches))
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
225 if _get_filter(b'hide_unapplied', g):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
226 patches = list(filter(lambda p: p not in unapplied, patches))
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
228 if _get_filter(b'reverse', g):
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
229 patches = reversed(patches)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
230
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
231 pre_applied_filter = _get_filter(b'pre_applied', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
232 pre_applied_filter_arg = _get_filter_arg(pre_applied_filter)
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
233 post_applied_filter = _get_filter(b'post_applied', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
234 post_applied_filter_arg = _get_filter_arg(post_applied_filter)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
235
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
236 pre_unapplied_filter = _get_filter(b'pre_unapplied', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
237 pre_unapplied_filter_arg = _get_filter_arg(pre_unapplied_filter)
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
238 post_unapplied_filter = _get_filter(b'post_unapplied', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 post_unapplied_filter_arg = _get_filter_arg(post_unapplied_filter)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
241 for n, patch in enumerate(patches):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
242 if patch in applied:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243 if pre_applied_filter:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244 patches[n] = pre_applied_filter_arg + patches[n]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 if post_applied_filter:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
246 patches[n] = patches[n] + post_applied_filter_arg
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
247 elif patch in unapplied:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
248 if pre_unapplied_filter:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249 patches[n] = pre_unapplied_filter_arg + patches[n]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250 if post_unapplied_filter:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 patches[n] = patches[n] + post_unapplied_filter_arg
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
253 return _with_groups(g, sep.join(patches)) if patches else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
254
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
255 def _queue(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
256 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
257
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
258 try:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
259 extensions.find(b'mq')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
260 except KeyError:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
261 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
262
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
263 q = repo.mq
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
264
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
265 out = os.path.basename(q.path)
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
266 if out == b'patches' and not os.path.isdir(q.path):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
267 out = b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
268 elif out.startswith(b'patches-'):
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
269 out = out[8:]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
271 return _with_groups(g, out) if out else b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
272
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
273 def _remote(kind):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
274 def _r(m):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
275 g = m.groups()
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
276
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
277 cache_dir = path.join(repo.root, CACHE_PATH)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
278 cache = path.join(cache_dir, kind)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
279 if not path.isdir(cache_dir):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
280 os.makedirs(cache_dir)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
281
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
282 cache_exists = path.isfile(cache)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
283
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
284 cache_time = (datetime.fromtimestamp(os.stat(cache).st_mtime)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
285 if cache_exists else None)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
286 if not cache_exists or cache_time < datetime.now() - CACHE_TIMEOUT:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
287 if not cache_exists:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
288 open(cache, 'w').close()
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
289 subprocess.Popen(['hg', 'prompt', '--cache-%s' % kind.decode('ascii')])
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
290
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
291 if cache_exists:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
292 with open(cache) as c:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
293 count = len(c.readlines())
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
294 if g[1]:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
295 return _with_groups(g, str(count).encode()) if count else b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
296 else:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
297 return _with_groups(g, b'') if count else b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
298 else:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
299 return b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
300 return _r
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
301
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
302 def _rev(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
303 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
304
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
305 parents = repo[None].parents()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
306 parent = 0 if b'|merge' not in g else 1
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
307 parent = parent if len(parents) > parent else None
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
308
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
309 rev = parents[parent].rev() if parent is not None else -1
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
310 return _with_groups(g, str(rev)) if rev >= 0 else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
311
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
312 def _root(m):
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
313 return _with_groups(m.groups(), repo.root) if repo.root else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
314
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
315 def _status(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
316 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
317
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
318 st = repo.status(unknown=True)[:5]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
319 modified = any(st[:4])
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
320 unknown = len(st[-1]) > 0
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
321
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
322 flag = b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
323 if b'|modified' not in g and b'|unknown' not in g:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
324 flag = b'!' if modified else b'?' if unknown else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
325 else:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
326 if b'|modified' in g:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
327 flag += b'!' if modified else b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
328 if b'|unknown' in g:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
329 flag += b'?' if unknown else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
330
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
331 return _with_groups(g, flag) if flag else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
332
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
333 def _tags(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
334 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
335
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
336 sep = g[2][1:] if g[2] else b' '
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
337 tags = repo[None].tags()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
338
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
339 quiet = _get_filter(b'quiet', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
340 if quiet:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
341 tags = list(filter(lambda tag: tag != b'tip', tags))
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
342
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
343 return _with_groups(g, sep.join(tags)) if tags else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
344
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
345 def _task(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346 try:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
347 task = extensions.find(b'tasks').current(repo)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
348 return _with_groups(m.groups(), task) if task else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
349 except KeyError:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
350 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
351
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
352 def _tip(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
353 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
354
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
355 format = short if b'|short' in g else hex
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
356
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
357 tip = repo[len(repo) - 1]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
358 rev = tip.rev()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
359 tip = format(tip.node()) if b'|node' in g else tip.rev()
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
360
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
361 return _with_groups(g, str(tip)) if rev >= 0 else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
362
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
363 def _update(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
364 current_rev = repo[None].parents()[0]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
365
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
366 # Get the tip of the branch for the current branch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
367 try:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
368 heads = repo.branchmap()[current_rev.branch()]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
369 tip = heads[-1]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
370 except (KeyError, IndexError):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
371 # We are in an empty repository.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
372
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
373 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
374
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
375 for head in reversed(heads):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
376 if not repo[head].closesbranch():
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
377 tip = head
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
378 break
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
379
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
380 return _with_groups(m.groups(), b'^') if current_rev != repo[tip] else b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
381
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
382
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
383 if opts.get("angle_brackets"):
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
384 tag_start = rb'\<([^><]*?\<)?'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
385 tag_end = rb'(\>[^><]*?)?>'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
386 brackets = b'<>'
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
387 else:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
388 tag_start = rb'\{([^{}]*?\{)?'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
389 tag_end = rb'(\}[^{}]*?)?\}'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
390 brackets = b'{}'
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
391
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
392 patterns = {
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
393 b'bookmark': _bookmark,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
394 b'branch(\|quiet)?': _branch,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
395 b'closed(\|quiet)?': _closed,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
396 b'count(\|[^%b]*?)?' % brackets[-1:]: _count,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
397 b'node(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
398 b'(\|short)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
399 b'|(\|merge)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
400 b')*': _node,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
401 b'patch(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
402 b'(\|topindex)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
403 b'|(\|applied)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
404 b'|(\|unapplied)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
405 b'|(\|count)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
406 b'|(\|quiet)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
407 b')*': _patch,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
408 b'patches(?:' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
409 b'(\|join\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
410 b'|(\|reverse)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
411 b'|(\|hide_applied)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
412 b'|(\|hide_unapplied)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
413 b'|(\|pre_applied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
414 b'|(\|post_applied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
415 b'|(\|pre_unapplied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
416 b'|(\|post_unapplied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
417 b')*': _patches,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
418 b'queue': _queue,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
419 b'rev(\|merge)?': _rev,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
420 b'root': _root,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
421 b'root\|basename': _basename,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
422 b'status(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
423 b'(\|modified)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
424 b'|(\|unknown)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
425 b')*': _status,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
426 b'tags(?:' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
427 b'(\|quiet)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
428 b'|(\|[^%b]*?)' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
429 b')*': _tags,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
430 b'task': _task,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
431 b'tip(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
432 b'(\|node)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
433 b'|(\|short)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
434 b')*': _tip,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
435 b'update': _update,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
436
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
437 b'incoming(\|count)?': _remote(b'incoming'),
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
438 b'outgoing(\|count)?': _remote(b'outgoing'),
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
439 }
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
440
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
441 if opts.get("cache_incoming"):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
442 _cache_remote(repo, b'incoming')
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
443
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
444 if opts.get("cache_outgoing"):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
445 _cache_remote(repo, b'outgoing')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
446
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
447 for tag, repl in patterns.items():
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
448 fs = re.sub(tag_start + tag + tag_end, repl, fs)
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
449
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
450 ui.status(fs)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
451
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
452 def _pull_with_cache(orig, ui, repo, *args, **opts):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
453 """Wrap the pull command to delete the incoming cache as well."""
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
454 res = orig(ui, repo, *args, **opts)
137
f71524147eb4 Fix some more binary vs str handling that I missed
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
455 cache = path.join(repo.root, CACHE_PATH, b'incoming')
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
456 if path.isfile(cache):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
457 os.remove(cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
458 return res
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
459
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
460 def _push_with_cache(orig, ui, repo, *args, **opts):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
461 """Wrap the push command to delete the outgoing cache as well."""
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
462 res = orig(ui, repo, *args, **opts)
137
f71524147eb4 Fix some more binary vs str handling that I missed
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
463 cache = path.join(repo.root, CACHE_PATH, b'outgoing')
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
464 if path.isfile(cache):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
465 os.remove(cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
466 return res
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
467
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
468 def uisetup(ui):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
469 extensions.wrapcommand(commands.table, b'pull', _pull_with_cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
470 extensions.wrapcommand(commands.table, b'push', _push_with_cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
471 try:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
472 extensions.wrapcommand(extensions.find(b"fetch").cmdtable, b'fetch', _pull_with_cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
473 except KeyError:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
474 pass
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
475
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
476 help.helptable += (
137
f71524147eb4 Fix some more binary vs str handling that I missed
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
477 ([b'prompt-keywords'], _(b'Keywords supported by hg-prompt'),
f71524147eb4 Fix some more binary vs str handling that I missed
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
478 lambda _: rb'''hg-prompt currently supports a number of keywords.
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
479
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
480 Some keywords support filters. Filters can be chained when it makes
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
481 sense to do so. When in doubt, try it!
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
482
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
483 bookmark
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
484 Display the current bookmark (requires the bookmarks extension).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
485
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
486 branch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
487 Display the current branch.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
488
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
489 |quiet
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
490 Display the current branch only if it is not the default branch.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
491
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
492 closed
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
493 Display `X` if working on a closed branch (i.e. committing now would reopen
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
494 the branch).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
495
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
496 count
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
497 Display the number of revisions in the given revset (the revset `all()`
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
498 will be used if none is given).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
499
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
500 See `hg help revsets` for more information.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
501
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
502 |REVSET
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
503 The revset to count.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
504
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
505 incoming
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
506 Display nothing, but if the default path contains incoming changesets the
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
507 extra text will be expanded.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
508
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
509 For example: `{incoming changes{incoming}}` will expand to
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
510 `incoming changes` if there are changes, otherwise nothing.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
511
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
512 Checking for incoming changesets is an expensive operation, so `hg-prompt`
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
513 will cache the results in `.hg/prompt/cache/` and refresh them every 15
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
514 minutes.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
515
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
516 |count
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
517 Display the number of incoming changesets (if greater than 0).
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
518
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
519 node
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
520 Display the (full) changeset hash of the current parent.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
521
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
522 |short
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
523 Display the hash as the short, 12-character form.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
524
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
525 |merge
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
526 Display the hash of the changeset you're merging with.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
527
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
528 outgoing
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
529 Display nothing, but if the current repository contains outgoing
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
530 changesets (to default) the extra text will be expanded.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
531
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
532 For example: `{outgoing changes{outgoing}}` will expand to
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
533 `outgoing changes` if there are changes, otherwise nothing.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
534
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
535 Checking for outgoing changesets is an expensive operation, so `hg-prompt`
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
536 will cache the results in `.hg/prompt/cache/` and refresh them every 15
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
537 minutes.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
538
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
539 |count
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
540 Display the number of outgoing changesets (if greater than 0).
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
541
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
542 patch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
543 Display the topmost currently-applied patch (requires the mq
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
544 extension).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
545
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
546 |count
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
547 Display the number of patches in the queue.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
548
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
549 |topindex
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
550 Display (zero-based) index of the topmost applied patch in the series
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
551 list (as displayed by :hg:`qtop -v`), or the empty string if no patch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
552 is applied.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
553
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
554 |applied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
555 Display the number of currently applied patches in the queue.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
556
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
557 |unapplied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
558 Display the number of currently unapplied patches in the queue.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
559
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
560 |quiet
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
561 Display a number only if there are any patches in the queue.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
562
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
563 patches
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
564 Display a list of the current patches in the queue. It will look like
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
565 this:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
566
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
567 :::console
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
568 $ hg prompt '{patches}'
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
569 bottom-patch -> middle-patch -> top-patch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
570
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
571 |reverse
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
572 Display the patches in reverse order (i.e. topmost first).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
573
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
574 |hide_applied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
575 Do not display applied patches.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
576
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
577 |hide_unapplied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
578 Do not display unapplied patches.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
579
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
580 |join(SEP)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
581 Display SEP between each patch, instead of the default ` -> `.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
582
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
583 |pre_applied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
584 Display STRING immediately before each applied patch. Useful for
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
585 adding color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
586
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
587 |post_applied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
588 Display STRING immediately after each applied patch. Useful for
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
589 resetting color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
590
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
591 |pre_unapplied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
592 Display STRING immediately before each unapplied patch. Useful for
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
593 adding color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
594
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
595 |post_unapplied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
596 Display STRING immediately after each unapplied patch. Useful for
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
597 resetting color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
598
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
599 queue
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
600 Display the name of the current MQ queue.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
601
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
602 rev
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
603 Display the repository-local changeset number of the current parent.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
604
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
605 |merge
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
606 Display the repository-local changeset number of the changeset you're
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
607 merging with.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
608
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
609 root
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
610 Display the full path to the root of the current repository, without a
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
611 trailing slash.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
612
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
613 |basename
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
614 Display the directory name of the root of the current repository. For
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
615 example, if the repository is in `/home/u/myrepo` then this keyword
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
616 would expand to `myrepo`.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
617
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
618 status
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
619 Display `!` if the repository has any changed/added/removed files,
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
620 otherwise `?` if it has any untracked (but not ignored) files, otherwise
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
621 nothing.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
622
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
623 |modified
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
624 Display `!` if the current repository contains files that have been
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
625 modified, added, removed, or deleted, otherwise nothing.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
626
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
627 |unknown
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
628 Display `?` if the current repository contains untracked files,
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
629 otherwise nothing.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
630
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
631 tags
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
632 Display the tags of the current parent, separated by a space.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
633
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
634 |quiet
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
635 Display the tags of the current parent, excluding the tag "tip".
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
636
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
637 |SEP
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
638 Display the tags of the current parent, separated by `SEP`.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
639
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
640 task
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
641 Display the current task (requires the tasks extension).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
642
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
643 tip
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
644 Display the repository-local changeset number of the current tip.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
645
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
646 |node
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
647 Display the (full) changeset hash of the current tip.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
648
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
649 |short
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
650 Display a short form of the changeset hash of the current tip (must be
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
651 used with the **|node** filter)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
652
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
653 update
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
654 Display `^` if the current parent is not the tip of the current branch,
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
655 otherwise nothing. In effect, this lets you see if running `hg update`
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
656 would do something.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
657 '''),
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
658 )