annotate prompt.py @ 147:7718e4d9a019

Fix hg "status" object changing from tuple to object This should still work with the older tuple version as well because it had properties and index-based access was a hack
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Mar 2020 18:51:07 +0000
parents c1520aabcdd4
children 1c3ec0b529c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 #!/usr/bin/env python
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 '''get repository information for use in a shell prompt
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 Take a string, parse any special variables inside, and output the result.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 Useful mostly for putting information about the current repository into
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 a shell prompt.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 '''
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 from __future__ import with_statement
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 import re
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 import os
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
15 import platform
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 import subprocess
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 from datetime import datetime, timedelta
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 from os import path
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 from mercurial import extensions, commands, cmdutil, help
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 from mercurial.i18n import _
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 from mercurial.node import hex, short
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
23 # command registration moved into `registrar` module in v3.7.
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 cmdtable = {}
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
25 try:
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
26 from mercurial import registrar
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
27 command = registrar.command(cmdtable)
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
28 except ImportError:
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
29 command = cmdutil.command(cmdtable)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 # `revrange' has been moved into module `scmutil' since v1.9.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 try :
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 from mercurial import scmutil
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 revrange = scmutil.revrange
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 except :
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 revrange = cmdutil.revrange
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
38 CACHE_PATH = b".hg/prompt/cache"
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
39 CACHE_TIMEOUT = timedelta(minutes=15)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
40
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
41 FILTER_ARG = re.compile(rb'\|.+\((.*)\)')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
43 def _cache_remote(repo, kind):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
44 cache = path.join(repo.root, CACHE_PATH, kind)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
45 c_tmp = cache + b'.temp'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
46
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
47 # This is kind of a hack and I feel a little bit dirty for doing it.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
48 IGNORE = open('NUL:','w') if platform.system() == 'Windows' else open('/dev/null','w')
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
49
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
50 subprocess.call(['hg', kind, '--quiet'], stdout=open(c_tmp, 'w'), stderr=IGNORE)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
51 os.rename(c_tmp, cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
52 return
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 def _with_groups(groups, out):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 out_groups = [groups[0]] + [groups[-1]]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 if any(out_groups) and not all(out_groups):
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
58 print('Error parsing prompt string. Mismatched braces?')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
60 out = out.replace(b'%', b'%%')
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
61 return (b"%b" + out + b"%b") % (out_groups[0][:-1] if out_groups[0] else b'',
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
62 out_groups[1][1:] if out_groups[1] else b'')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 def _get_filter(name, g):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 '''Return the filter with the given name, or None if it was not used.'''
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
66 matching_filters = list(filter(lambda s: s and s.startswith(b'|%b' % name), g))
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 if not matching_filters:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 return None
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 # Later filters will override earlier ones, for now.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 f = matching_filters[-1]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 return f
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 def _get_filter_arg(f):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 if not f:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 return None
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 args = FILTER_ARG.match(f).groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 if args:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 return args[0]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 else:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 return None
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
85 @command(b'prompt',
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
86 [(b'', b'angle-brackets', None, b'use angle brackets (<>) for keywords'),
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
87 (b'', b'cache-incoming', None, b'used internally by hg-prompt'),
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
88 (b'', b'cache-outgoing', None, b'used internally by hg-prompt')],
135
298fa524406a Update to latest HG Prompt and make it Python 3 compliant
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
89 b'hg prompt STRING')
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
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
273 def _remote(kind):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
274 def _r(m):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
275 g = m.groups()
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
276
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
277 cache_dir = path.join(repo.root, CACHE_PATH)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
278 cache = path.join(cache_dir, kind)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
279 if not path.isdir(cache_dir):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
280 os.makedirs(cache_dir)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
281
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
282 cache_exists = path.isfile(cache)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
283
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
284 cache_time = (datetime.fromtimestamp(os.stat(cache).st_mtime)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
285 if cache_exists else None)
141
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
286 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
287 if not cache_exists:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
288 open(cache, 'w').close()
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
289 subprocess.Popen(['hg', 'prompt', '--cache-%s' % kind.decode('ascii')])
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
290
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
291 if cache_exists:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
292 with open(cache) as c:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
293 count = len(c.readlines())
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
294 if g[1]:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
295 return _with_groups(g, str(count).encode()) if count else b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
296 else:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
297 return _with_groups(g, b'') if count else b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
298 else:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
299 return b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
300 return _r
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
301
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
302 def _rev(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
303 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
304
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
305 parents = repo[None].parents()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
306 parent = 0 if b'|merge' not in g else 1
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
307 parent = parent if len(parents) > parent else None
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
308
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
309 rev = parents[parent].rev() if parent is not None else -1
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
310 return _with_groups(g, str(rev)) if rev >= 0 else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
311
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
312 def _root(m):
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
313 return _with_groups(m.groups(), repo.root) if repo.root else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
314
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
315 def _status(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
316 g = m.groups()
147
7718e4d9a019 Fix hg "status" object changing from tuple to object
IBBoard <dev@ibboard.co.uk>
parents: 145
diff changeset
317 st = repo.status(unknown=True)
7718e4d9a019 Fix hg "status" object changing from tuple to object
IBBoard <dev@ibboard.co.uk>
parents: 145
diff changeset
318 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
319 unknown = len(st.unknown) > 0
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
320
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
321 flag = b''
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
322 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
323 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
324 else:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
325 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
326 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
327 if b'|unknown' in g:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
328 flag += b'?' if unknown else b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
329
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
330 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
331
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
332 def _tags(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
333 g = m.groups()
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 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
336 tags = repo[None].tags()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
337
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
338 quiet = _get_filter(b'quiet', g)
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
339 if quiet:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
340 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
341
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
342 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
343
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
344 def _task(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
345 try:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
346 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
347 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
348 except KeyError:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
349 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
350
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
351 def _tip(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
352 g = m.groups()
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
353
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
354 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
355
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
356 tip = repo[len(repo) - 1]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
357 rev = tip.rev()
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
358 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
359
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
360 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
361
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
362 def _update(m):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
363 current_rev = repo[None].parents()[0]
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 # 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
366 try:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
367 heads = repo.branchmap()[current_rev.branch()]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
368 tip = heads[-1]
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
369 except (KeyError, IndexError):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
370 # We are in an empty repository.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
371
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
372 return b''
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
373
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
374 for head in reversed(heads):
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
375 if not repo[head].closesbranch():
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
376 tip = head
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
377 break
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
378
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
379 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
380
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
381
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
382 if opts.get("angle_brackets"):
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
383 tag_start = rb'\<([^><]*?\<)?'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
384 tag_end = rb'(\>[^><]*?)?>'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
385 brackets = b'<>'
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
386 else:
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
387 tag_start = rb'\{([^{}]*?\{)?'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
388 tag_end = rb'(\}[^{}]*?)?\}'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
389 brackets = b'{}'
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
390
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
391 patterns = {
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
392 b'bookmark': _bookmark,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
393 b'branch(\|quiet)?': _branch,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
394 b'closed(\|quiet)?': _closed,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
395 b'count(\|[^%b]*?)?' % brackets[-1:]: _count,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
396 b'node(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
397 b'(\|short)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
398 b'|(\|merge)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
399 b')*': _node,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
400 b'patch(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
401 b'(\|topindex)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
402 b'|(\|applied)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
403 b'|(\|unapplied)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
404 b'|(\|count)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
405 b'|(\|quiet)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
406 b')*': _patch,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
407 b'patches(?:' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
408 b'(\|join\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
409 b'|(\|reverse)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
410 b'|(\|hide_applied)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
411 b'|(\|hide_unapplied)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
412 b'|(\|pre_applied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
413 b'|(\|post_applied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
414 b'|(\|pre_unapplied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
415 b'|(\|post_unapplied\([^%b]*?\))' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
416 b')*': _patches,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
417 b'queue': _queue,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
418 b'rev(\|merge)?': _rev,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
419 b'root': _root,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
420 b'root\|basename': _basename,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
421 b'status(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
422 b'(\|modified)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
423 b'|(\|unknown)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
424 b')*': _status,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
425 b'tags(?:' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
426 b'(\|quiet)' +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
427 b'|(\|[^%b]*?)' % brackets[-1:] +
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
428 b')*': _tags,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
429 b'task': _task,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
430 b'tip(?:'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
431 b'(\|node)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
432 b'|(\|short)'
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
433 b')*': _tip,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
434 b'update': _update,
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
435
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
436 b'incoming(\|count)?': _remote(b'incoming'),
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
437 b'outgoing(\|count)?': _remote(b'outgoing'),
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
438 }
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
439
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
440 if opts.get("cache_incoming"):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
441 _cache_remote(repo, b'incoming')
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
442
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
443 if opts.get("cache_outgoing"):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
444 _cache_remote(repo, b'outgoing')
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
445
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
446 for tag, repl in patterns.items():
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
447 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
448
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
449 ui.status(fs)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
450
141
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
451 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
452 """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
453 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
454 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
455 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
456 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
457 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
458 if not opts['amend']:
141
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
459 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
460 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
461 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
462
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
463 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
464 """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
465 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
466 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
467 if path.isfile(cache):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
468 os.remove(cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
469 return res
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
470
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
471 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
472 """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
473 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
474 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
475 if path.isfile(cache):
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
476 os.remove(cache)
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
477 return res
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
478
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
479 def uisetup(ui):
141
13435b80c672 Replace c09729100dd2 with a wrapper hook implementation
IBBoard <dev@ibboard.co.uk>
parents: 139
diff changeset
480 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
481 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
482 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
483 try:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
484 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
485 except KeyError:
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
486 pass
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
487
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
488 help.helptable += (
137
f71524147eb4 Fix some more binary vs str handling that I missed
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
489 ([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
490 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
491
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
492 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
493 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
494
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
495 bookmark
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
496 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
497
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
498 branch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
499 Display the current branch.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
500
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
501 |quiet
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
502 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
503
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
504 closed
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
505 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
506 the branch).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
507
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
508 count
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
509 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
510 will be used if none is given).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
511
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
512 See `hg help revsets` for more information.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
513
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
514 |REVSET
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
515 The revset to count.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
516
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
517 incoming
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
518 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
519 extra text will be expanded.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
520
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
521 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
522 `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
523
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
524 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
525 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
526 minutes.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
527
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
528 |count
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
529 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
530
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
531 node
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
532 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
533
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
534 |short
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
535 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
536
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
537 |merge
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
538 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
539
136
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
540 outgoing
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
541 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
542 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
543
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
544 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
545 `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
546
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
547 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
548 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
549 minutes.
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
550
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
551 |count
fcd34011b0f0 Fix hg prompt functionality for Python 3.8
IBBoard <dev@ibboard.co.uk>
parents: 135
diff changeset
552 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
553
64
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
554 patch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
555 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
556 extension).
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
557
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
558 |count
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
559 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
560
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
561 |topindex
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
562 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
563 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
564 is applied.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
565
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
566 |applied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
567 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
568
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
569 |unapplied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
570 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
571
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
572 |quiet
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
573 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
574
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
575 patches
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
576 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
577 this:
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
578
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
579 :::console
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
580 $ hg prompt '{patches}'
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
581 bottom-patch -> middle-patch -> top-patch
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
582
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
583 |reverse
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
584 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
585
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
586 |hide_applied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
587 Do not display applied patches.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
588
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
589 |hide_unapplied
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
590 Do not display unapplied patches.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
591
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
592 |join(SEP)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
593 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
594
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
595 |pre_applied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
596 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
597 adding color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
598
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
599 |post_applied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
600 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
601 resetting color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
602
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
603 |pre_unapplied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
604 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
605 adding color codes.
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 |post_unapplied(STRING)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
608 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
609 resetting color codes.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
610
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
611 queue
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
612 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
613
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
614 rev
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
615 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
616
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
617 |merge
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
618 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
619 merging with.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
620
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
621 root
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
622 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
623 trailing slash.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
624
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
625 |basename
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
626 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
627 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
628 would expand to `myrepo`.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
629
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
630 status
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
631 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
632 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
633 nothing.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
634
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
635 |modified
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
636 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
637 modified, added, removed, or deleted, otherwise nothing.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
638
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
639 |unknown
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
640 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
641 otherwise nothing.
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
642
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
643 tags
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
644 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
645
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
646 |quiet
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
647 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
648
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
649 |SEP
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
650 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
651
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
652 task
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
653 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
654
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
655 tip
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
656 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
657
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
658 |node
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
659 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
660
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
661 |short
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
662 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
663 used with the **|node** filter)
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
664
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
665 update
39b07c5f8785 Add Git and Mercurial support to command prompt
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
666 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
667 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
668 would do something.
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 )