annotate prompt.py @ 157:c0730fa3d4a4

Add 😐 along side 😑
author IBBoard <dev@ibboard.co.uk>
date Sun, 03 Jul 2022 15:27:25 +0100
parents 8bf9fc90ce51
children 03886f17beef
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
155
1c3ec0b529c4 Make HG Prompt fail quickly with bad auth
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
50 subprocess.call(['hg', kind, '--quiet', '--config', 'ui.interactive=False'], stdout=open(c_tmp, 'w'), stderr=IGNORE)
136
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')
142
503a7a8df2e2 Fix "cannot use a bytes pattern on a string-like object"
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
90 def prompt(ui, repo, fs=b'', **opts):
64
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
156
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
273 def _inout(m):
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
274 g = m.groups()
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
275 class FakeMatch:
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
276 def __init__(self, groups):
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
277 self.__groups = groups
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
278 def groups(self):
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
279 return self.__groups
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
280 incoming = _remote(b'incoming')(FakeMatch([b"-{", b"|count", b"}"]))
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
281 outgoing = _remote(b'outgoing')(FakeMatch([b"+{", b"|count", b"}"]))
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
282 if not incoming and not outgoing:
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
283 return _with_groups(g, b'=')
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
284 else:
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
285 return _with_groups(g, incoming + outgoing)
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
286
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
287 def _remote(kind):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
288 def _r(m):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
289 g = m.groups()
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 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
292 cache = path.join(cache_dir, kind)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
293 if not path.isdir(cache_dir):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
294 os.makedirs(cache_dir)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
295
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
296 cache_exists = path.isfile(cache)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
297
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
298 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
299 if cache_exists else None)
141
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
300 if not cache_exists or cache_time < datetime.now() - CACHE_TIMEOUT:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
301 if not cache_exists:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
302 open(cache, 'w').close()
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
303 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
304
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
305 if cache_exists:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
306 with open(cache) as c:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
307 count = len(c.readlines())
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
308 if g[1]:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
309 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
310 else:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
311 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
312 else:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
313 return b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
314 return _r
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
315
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
316 def _rev(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
317 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
318
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
319 parents = repo[None].parents()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
320 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
321 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
322
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
323 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
324 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
325
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
326 def _root(m):
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
327 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
328
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
329 def _status(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
330 g = m.groups()
147
7718e4d9a019 Fix hg "status" object changing from tuple to object
IBBoard <dev@ibboard.co.uk>
parents: 145
diff changeset
331 st = repo.status(unknown=True)
7718e4d9a019 Fix hg "status" object changing from tuple to object
IBBoard <dev@ibboard.co.uk>
parents: 145
diff changeset
332 modified = any([st.modified, st.added, st.removed, st.deleted])
7718e4d9a019 Fix hg "status" object changing from tuple to object
IBBoard <dev@ibboard.co.uk>
parents: 145
diff changeset
333 unknown = len(st.unknown) > 0
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
334
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
335 flag = b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
336 if b'|modified' not in g and b'|unknown' not in g:
143
51d857786c5a Switch to using "*" for "local changes" in hg prompt
IBBoard <dev@ibboard.co.uk>
parents: 142
diff changeset
337 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
338 else:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
339 if b'|modified' in g:
143
51d857786c5a Switch to using "*" for "local changes" in hg prompt
IBBoard <dev@ibboard.co.uk>
parents: 142
diff changeset
340 flag += b'*' if modified else b''
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
341 if b'|unknown' in g:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
342 flag += b'?' if unknown else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
343
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
344 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
345
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346 def _tags(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
347 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
348
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
349 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
350 tags = repo[None].tags()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
351
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
352 quiet = _get_filter(b'quiet', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
353 if quiet:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
354 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
355
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
356 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
357
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
358 def _task(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
359 try:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
360 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
361 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
362 except KeyError:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
363 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
364
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
365 def _tip(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
366 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
367
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
368 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
369
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
370 tip = repo[len(repo) - 1]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
371 rev = tip.rev()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
372 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
373
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
374 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
375
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
376 def _update(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
377 current_rev = repo[None].parents()[0]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
378
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
379 # 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
380 try:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
381 heads = repo.branchmap()[current_rev.branch()]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
382 tip = heads[-1]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
383 except (KeyError, IndexError):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
384 # We are in an empty repository.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
385
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
386 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
387
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
388 for head in reversed(heads):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
389 if not repo[head].closesbranch():
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
390 tip = head
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
391 break
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
392
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
393 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
394
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
395
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
396 if opts.get("angle_brackets"):
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
397 tag_start = rb'\<([^><]*?\<)?'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
398 tag_end = rb'(\>[^><]*?)?>'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
399 brackets = b'<>'
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
400 else:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
401 tag_start = rb'\{([^{}]*?\{)?'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
402 tag_end = rb'(\}[^{}]*?)?\}'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
403 brackets = b'{}'
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
404
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
405 patterns = {
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
406 b'bookmark': _bookmark,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
407 b'branch(\|quiet)?': _branch,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
408 b'closed(\|quiet)?': _closed,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
409 b'count(\|[^%b]*?)?' % brackets[-1:]: _count,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
410 b'node(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
411 b'(\|short)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
412 b'|(\|merge)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
413 b')*': _node,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
414 b'patch(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
415 b'(\|topindex)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
416 b'|(\|applied)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
417 b'|(\|unapplied)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
418 b'|(\|count)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
419 b'|(\|quiet)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
420 b')*': _patch,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
421 b'patches(?:' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
422 b'(\|join\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
423 b'|(\|reverse)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
424 b'|(\|hide_applied)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
425 b'|(\|hide_unapplied)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
426 b'|(\|pre_applied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
427 b'|(\|post_applied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
428 b'|(\|pre_unapplied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
429 b'|(\|post_unapplied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
430 b')*': _patches,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
431 b'queue': _queue,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
432 b'rev(\|merge)?': _rev,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
433 b'root': _root,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
434 b'root\|basename': _basename,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
435 b'status(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
436 b'(\|modified)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
437 b'|(\|unknown)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
438 b')*': _status,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
439 b'tags(?:' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
440 b'(\|quiet)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
441 b'|(\|[^%b]*?)' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
442 b')*': _tags,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
443 b'task': _task,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
444 b'tip(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
445 b'(\|node)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
446 b'|(\|short)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
447 b')*': _tip,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
448 b'update': _update,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
449
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
450 b'incoming(\|count)?': _remote(b'incoming'),
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
451 b'outgoing(\|count)?': _remote(b'outgoing'),
156
8bf9fc90ce51 Streamline HG Prompt with `inout` command
IBBoard <dev@ibboard.co.uk>
parents: 155
diff changeset
452 b'inout': _inout,
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
453 }
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
454
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
455 if opts.get("cache_incoming"):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
456 _cache_remote(repo, b'incoming')
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
457
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
458 if opts.get("cache_outgoing"):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
459 _cache_remote(repo, b'outgoing')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
460
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
461 for tag, repl in patterns.items():
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
462 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
463
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
464 ui.status(fs)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
465
141
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
466 def _commit_with_cache(orig, ui, repo, *args, **opts):
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
467 """Wrap the commit command to fake an entry until we re-cache"""
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
468 res = orig(ui, repo, *args, **opts)
145
c1520aabcdd4 Avoid "No such file or directory: '<repo>/.hg/prompt/cache/outgoing'"
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
469 cache_dir = path.join(repo.root, CACHE_PATH)
c1520aabcdd4 Avoid "No such file or directory: '<repo>/.hg/prompt/cache/outgoing'"
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
470 cache = path.join(cache_dir, b'outgoing')
c1520aabcdd4 Avoid "No such file or directory: '<repo>/.hg/prompt/cache/outgoing'"
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
471 if not path.isdir(cache_dir):
c1520aabcdd4 Avoid "No such file or directory: '<repo>/.hg/prompt/cache/outgoing'"
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
472 os.makedirs(cache_dir)
144
c12350209a5c Make sure prompt logs changes from commit, even when no cache
IBBoard <dev@ibboard.co.uk>
parents: 143
diff changeset
473 if not opts['amend']:
141
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
474 with open(cache, 'a') as cache_file:
144
c12350209a5c Make sure prompt logs changes from commit, even when no cache
IBBoard <dev@ibboard.co.uk>
parents: 143
diff changeset
475 new_commit = repo[b'tip']
c12350209a5c Make sure prompt logs changes from commit, even when no cache
IBBoard <dev@ibboard.co.uk>
parents: 143
diff changeset
476 cache_file.write('{}:{}\n'.format(new_commit.rev(), new_commit.hex().decode('utf-8')))
141
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
477
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
478 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
479 """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
480 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
481 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
482 if path.isfile(cache):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
483 os.remove(cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
484 return res
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
485
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
486 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
487 """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
488 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
489 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
490 if path.isfile(cache):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
491 os.remove(cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
492 return res
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
493
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
494 def uisetup(ui):
141
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
495 extensions.wrapcommand(commands.table, b'commit', _commit_with_cache)
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
496 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
497 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
498 try:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
499 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
500 except KeyError:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
501 pass
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
502
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
503 help.helptable += (
137
f71524147eb4 Fix some more binary vs str handling that I missed
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
504 ([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
505 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
506
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
507 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
508 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
509
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
510 bookmark
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
511 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
512
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
513 branch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
514 Display the current branch.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
515
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
516 |quiet
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
517 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
518
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
519 closed
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
520 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
521 the branch).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
522
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
523 count
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
524 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
525 will be used if none is given).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
526
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
527 See `hg help revsets` for more information.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
528
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
529 |REVSET
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
530 The revset to count.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
531
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
532 incoming
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
533 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
534 extra text will be expanded.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
535
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
536 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
537 `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
538
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
539 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
540 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
541 minutes.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
542
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
543 |count
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
544 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
545
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
546 node
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
547 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
548
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
549 |short
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
550 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
551
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
552 |merge
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
553 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
554
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
555 outgoing
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
556 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
557 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
558
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
559 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
560 `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
561
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
562 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
563 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
564 minutes.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
565
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
566 |count
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
567 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
568
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
569 patch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
570 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
571 extension).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
572
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
573 |count
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
574 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
575
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
576 |topindex
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
577 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
578 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
579 is applied.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
580
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
581 |applied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
582 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
583
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
584 |unapplied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
585 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
586
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
587 |quiet
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
588 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
589
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
590 patches
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
591 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
592 this:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
593
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
594 :::console
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
595 $ hg prompt '{patches}'
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
596 bottom-patch -> middle-patch -> top-patch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
597
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
598 |reverse
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
599 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
600
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
601 |hide_applied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
602 Do not display applied patches.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
603
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
604 |hide_unapplied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
605 Do not display unapplied patches.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
606
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
607 |join(SEP)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
608 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
609
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
610 |pre_applied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
611 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
612 adding color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
613
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
614 |post_applied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
615 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
616 resetting color codes.
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 |pre_unapplied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
619 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
620 adding color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
621
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
622 |post_unapplied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
623 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
624 resetting color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
625
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
626 queue
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
627 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
628
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
629 rev
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
630 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
631
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
632 |merge
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
633 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
634 merging with.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
635
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
636 root
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
637 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
638 trailing slash.
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 |basename
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
641 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
642 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
643 would expand to `myrepo`.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
644
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
645 status
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
646 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
647 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
648 nothing.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
649
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
650 |modified
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
651 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
652 modified, added, removed, or deleted, otherwise nothing.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
653
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
654 |unknown
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
655 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
656 otherwise nothing.
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 tags
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
659 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
660
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
661 |quiet
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
662 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
663
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
664 |SEP
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
665 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
666
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
667 task
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
668 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
669
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
670 tip
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
671 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
672
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
673 |node
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
674 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
675
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
676 |short
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
677 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
678 used with the **|node** filter)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
679
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
680 update
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
681 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
682 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
683 would do something.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
684 '''),
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
685 )