Mercurial > hg
annotate hgext/show.py @ 44465:75ada5fe9b62
hghave: add a `rust` keyword to detect the use of compiled rust code
The content of some on disk cache can varies when using rust (because it is
faster to do so in the rust variant). So we need to be able to detect this case
for some test.
Differential Revision: https://phab.mercurial-scm.org/D8162
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 18 Feb 2020 18:32:31 +0100 |
parents | 86e4daa2d54c |
children | 6000f5b25c9b |
rev | line source |
---|---|
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # show.py - Extension implementing `hg show` |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com> |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 """unified command to show various repository information (EXPERIMENTAL) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 This extension provides the :hg:`show` command, which provides a central |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 command for displaying commonly-accessed repository data and views of that |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 data. |
33137
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
13 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
14 The following config options can influence operation. |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
15 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
16 ``commands`` |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
17 ------------ |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
18 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
19 ``show.aliasprefix`` |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
20 List of strings that will register aliases for views. e.g. ``s`` will |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
21 effectively set config options ``alias.s<view> = show <view>`` for all |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
22 views. i.e. `hg swork` would execute `hg show work`. |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
23 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
24 Aliases that would conflict with existing registrations will not be |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
25 performed. |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 """ |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 from __future__ import absolute_import |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 from mercurial.i18n import _ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
31 from mercurial.node import nullrev |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 from mercurial import ( |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 cmdutil, |
33137
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
34 commands, |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
35 destutil, |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 error, |
31859
8e282aa3c3ff
show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
31858
diff
changeset
|
37 formatter, |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
38 graphmod, |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35498
diff
changeset
|
39 logcmdutil, |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
40 phases, |
31820
45761ef1bc93
py3: have registrar process docstrings in bytes
Yuya Nishihara <yuya@tcha.org>
parents:
31765
diff
changeset
|
41 pycompat, |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 registrar, |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
43 revset, |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
44 revsetlang, |
37680
e743b8524d60
scmutil: introduce shortesthexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37134
diff
changeset
|
45 scmutil, |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 ) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 # be specifying the version(s) of Mercurial they are tested with, or |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 # leave the attribute unspecified. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
52 testedwith = b'ships-with-hg-core' |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 cmdtable = {} |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32291
diff
changeset
|
55 command = registrar.command(cmdtable) |
34518
592a3cc1ebc4
configitems: register the 'commands.show.aliasprefix' config
Boris Feld <boris.feld@octobus.net>
parents:
34191
diff
changeset
|
56 |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
57 revsetpredicate = registrar.revsetpredicate() |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
59 |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 class showcmdfunc(registrar._funcregistrarbase): |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 """Register a function to be invoked for an `hg show <thing>`.""" |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 # Used by _formatdoc(). |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
64 _docformat = b'%s -- %s' |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 |
33046
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
66 def _extrasetup(self, name, func, fmtopic=None, csettopic=None): |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 """Called with decorator arguments to register a show view. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 ``name`` is the sub-command name. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 ``func`` is the function being decorated. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 ``fmtopic`` is the topic in the style that will be rendered for |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 this view. |
33046
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
75 |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
76 ``csettopic`` is the topic in the style to be used for a changeset |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
77 printer. |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
78 |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
79 If ``fmtopic`` is specified, the view function will receive a |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
80 formatter instance. If ``csettopic`` is specified, the view |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
81 function will receive a changeset printer. |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 """ |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 func._fmtopic = fmtopic |
33046
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
84 func._csettopic = csettopic |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
86 |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 showview = showcmdfunc() |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
89 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
90 @command( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
91 b'show', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
92 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
93 # TODO: Switch this template flag to use cmdutil.formatteropts if |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
94 # 'hg show' becomes stable before --template/-T is stable. For now, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
95 # we are putting it here without the '(EXPERIMENTAL)' flag because it |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
96 # is an important part of the 'hg show' user experience and the entire |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
97 # 'hg show' experience is experimental. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 (b'T', b'template', b'', b'display with template', _(b'TEMPLATE')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
99 ], |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
100 _(b'VIEW'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
101 helpcategory=command.CATEGORY_CHANGE_NAVIGATION, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
102 ) |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 def show(ui, repo, view=None, template=None): |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
104 """show various repository information |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 A requested view of repository data is displayed. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 If no view is requested, the list of available views is shown and the |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 command aborts. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 .. note:: |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 There are no backwards compatibility guarantees for the output of this |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 command. Output may change in any future Mercurial release. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 Consumers wanting stable command output should specify a template via |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 ``-T/--template``. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 List of available views: |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 """ |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 if ui.plain() and not template: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
122 hint = _(b'invoke with -T/--template to control output format') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
123 raise error.Abort( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
124 _(b'must specify a template in plain mode'), hint=hint |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
125 ) |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 views = showview._table |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
129 if not view: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
130 ui.pager(b'show') |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 # TODO consider using formatter here so available views can be |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 # rendered to custom format. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
133 ui.write(_(b'available views:\n')) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
134 ui.write(b'\n') |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
135 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 for name, func in sorted(views.items()): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
137 ui.write(b'%s\n' % pycompat.sysbytes(func.__doc__)) |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
138 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 ui.write(b'\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
140 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
141 _(b'no view requested'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
142 hint=_(b'use "hg show VIEW" to choose a view'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
143 ) |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
144 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
145 # TODO use same logic as dispatch to perform prefix matching. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
146 if view not in views: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
147 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
148 _(b'unknown view: %s') % view, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
149 hint=_(b'run "hg show" to see available views'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
150 ) |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
152 template = template or b'show' |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 |
33046
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
154 fn = views[view] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
155 ui.pager(b'show') |
33046
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
156 |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
157 if fn._fmtopic: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
158 fmtopic = b'show%s' % fn._fmtopic |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
159 with ui.formatter(fmtopic, {b'template': template}) as fm: |
33046
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
160 return fn(ui, repo, fm) |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
161 elif fn._csettopic: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
162 ref = b'show%s' % fn._csettopic |
33046
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
163 spec = formatter.lookuptemplate(ui, ref, template) |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35498
diff
changeset
|
164 displayer = logcmdutil.changesettemplater(ui, repo, spec, buffered=True) |
33046
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
165 return fn(ui, repo, displayer) |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
166 else: |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
167 return fn(ui, repo) |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
169 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
170 @showview(b'bookmarks', fmtopic=b'bookmarks') |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 def showbookmarks(ui, repo, fm): |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 """bookmarks and their associated changeset""" |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 marks = repo._bookmarks |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 if not len(marks): |
31859
8e282aa3c3ff
show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
31858
diff
changeset
|
175 # This is a bit hacky. Ideally, templates would have a way to |
8e282aa3c3ff
show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
31858
diff
changeset
|
176 # specify an empty output, but we shouldn't corrupt JSON while |
8e282aa3c3ff
show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
31858
diff
changeset
|
177 # waiting for this functionality. |
8e282aa3c3ff
show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
31858
diff
changeset
|
178 if not isinstance(fm, formatter.jsonformatter): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
179 ui.write(_(b'(no bookmarks set)\n')) |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
180 return |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 |
34191
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
182 revs = [repo[node].rev() for node in marks.values()] |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 active = repo._activebookmark |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
184 longestname = max(len(b) for b in marks) |
34191
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
185 nodelen = longestshortest(repo, revs) |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 for bm, node in sorted(marks.items()): |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 fm.startitem() |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 fm.context(ctx=repo[node]) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
190 fm.write(b'bookmark', b'%s', bm) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
191 fm.write(b'node', fm.hexfunc(node), fm.hexfunc(node)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
192 fm.data( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
193 active=bm == active, longestbookmarklen=longestname, nodelen=nodelen |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
194 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
195 |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
196 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
197 @showview(b'stack', csettopic=b'stack') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
198 def showstack(ui, repo, displayer): |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
199 """current line of work""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
200 wdirctx = repo[b'.'] |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
201 if wdirctx.rev() == nullrev: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
202 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
203 _( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
204 b'stack view only available when there is a ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
205 b'working directory' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
206 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
207 ) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
208 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
209 if wdirctx.phase() == phases.public: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
210 ui.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
211 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
212 b'(empty stack; working directory parent is a published ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
213 b'changeset)\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
214 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
215 ) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
216 return |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
217 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
218 # TODO extract "find stack" into a function to facilitate |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
219 # customization and reuse. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
220 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
221 baserev = destutil.stackbase(ui, repo) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
222 basectx = None |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
223 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
224 if baserev is None: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
225 baserev = wdirctx.rev() |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
226 stackrevs = {wdirctx.rev()} |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
227 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
228 stackrevs = set(repo.revs(b'%d::.', baserev)) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
229 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
230 ctx = repo[baserev] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
231 if ctx.p1().rev() != nullrev: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
232 basectx = ctx.p1() |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
233 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
234 # And relevant descendants. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
235 branchpointattip = False |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
236 cl = repo.changelog |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
237 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
238 for rev in cl.descendants([wdirctx.rev()]): |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
239 ctx = repo[rev] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
240 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
241 # Will only happen if . is public. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
242 if ctx.phase() == phases.public: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
243 break |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
244 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
245 stackrevs.add(ctx.rev()) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
246 |
33211
f48422ab81aa
show: document why accidentally quadratic is (probably) acceptable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33210
diff
changeset
|
247 # ctx.children() within a function iterating on descandants |
f48422ab81aa
show: document why accidentally quadratic is (probably) acceptable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33210
diff
changeset
|
248 # potentially has severe performance concerns because revlog.children() |
f48422ab81aa
show: document why accidentally quadratic is (probably) acceptable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33210
diff
changeset
|
249 # iterates over all revisions after ctx's node. However, the number of |
f48422ab81aa
show: document why accidentally quadratic is (probably) acceptable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33210
diff
changeset
|
250 # draft changesets should be a reasonably small number. So even if |
f48422ab81aa
show: document why accidentally quadratic is (probably) acceptable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33210
diff
changeset
|
251 # this is quadratic, the perf impact should be minimal. |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
252 if len(ctx.children()) > 1: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
253 branchpointattip = True |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
254 break |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
255 |
33209
9718725dc02a
show: avoid extra list operations
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33208
diff
changeset
|
256 stackrevs = list(sorted(stackrevs, reverse=True)) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
257 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
258 # Find likely target heads for the current stack. These are likely |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
259 # merge or rebase targets. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
260 if basectx: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
261 # TODO make this customizable? |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
262 newheads = set( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
263 repo.revs( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
264 b'heads(%d::) - %ld - not public()', basectx.rev(), stackrevs |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
265 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
266 ) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
267 else: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
268 newheads = set() |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
269 |
42057
566daffc607d
cleanup: use set literals where possible
Martin von Zweigbergk <martinvonz@google.com>
parents:
40293
diff
changeset
|
270 allrevs = set(stackrevs) | newheads | {baserev} |
34191
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
271 nodelen = longestshortest(repo, allrevs) |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
272 |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
273 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
274 cmdutil.findcmd(b'rebase', commands.table) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
275 haverebase = True |
33210
b93df142485e
show: also catch AmbiguousCommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33209
diff
changeset
|
276 except (error.AmbiguousCommand, error.UnknownCommand): |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
277 haverebase = False |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
278 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
279 # TODO use templating. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
280 # TODO consider using graphmod. But it may not be necessary given |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
281 # our simplicity and the customizations required. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
282 # TODO use proper graph symbols from graphmod |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
283 |
35469
f1c54d003327
templater: move repo, ui and cache to per-engine resources
Yuya Nishihara <yuya@tcha.org>
parents:
34888
diff
changeset
|
284 tres = formatter.templateresources(ui, repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
285 shortesttmpl = formatter.maketemplater( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
286 ui, b'{shortest(node, %d)}' % nodelen, resources=tres |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
287 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
288 |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
289 def shortest(ctx): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
290 return shortesttmpl.renderdefault({b'ctx': ctx, b'node': ctx.hex()}) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
291 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
292 # We write out new heads to aid in DAG awareness and to help with decision |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
293 # making on how the stack should be reconciled with commits made since the |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
294 # branch point. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
295 if newheads: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
296 # Calculate distance from base so we can render the count and so we can |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
297 # sort display order by commit distance. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
298 revdistance = {} |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
299 for head in newheads: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
300 # There is some redundancy in DAG traversal here and therefore |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
301 # room to optimize. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
302 ancestors = cl.ancestors([head], stoprev=basectx.rev()) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
303 revdistance[head] = len(list(ancestors)) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
304 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
305 sourcectx = repo[stackrevs[-1]] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
306 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
307 sortedheads = sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
308 newheads, key=lambda x: revdistance[x], reverse=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
309 ) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
310 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
311 for i, rev in enumerate(sortedheads): |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
312 ctx = repo[rev] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
313 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
314 if i: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
315 ui.write(b': ') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
316 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
317 ui.write(b' ') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
318 |
43080
86e4daa2d54c
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents:
43077
diff
changeset
|
319 ui.writenoi18n(b'o ') |
34191
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
320 displayer.show(ctx, nodelen=nodelen) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
321 displayer.flush(ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
322 ui.write(b'\n') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
323 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
324 if i: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
325 ui.write(b':/') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
326 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
327 ui.write(b' /') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
328 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
329 ui.write(b' (') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
330 ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
331 _(b'%d commits ahead') % revdistance[rev], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
332 label=b'stack.commitdistance', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
333 ) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
334 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
335 if haverebase: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
336 # TODO may be able to omit --source in some scenarios |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
337 ui.write(b'; ') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
338 ui.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
339 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
340 b'hg rebase --source %s --dest %s' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
341 % (shortest(sourcectx), shortest(ctx)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
342 ), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
343 label=b'stack.rebasehint', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
344 ) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
345 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
346 ui.write(b')\n') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
347 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
348 ui.write(b':\n: ') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
349 ui.write(_(b'(stack head)\n'), label=b'stack.label') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
350 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
351 if branchpointattip: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
352 ui.write(b' \\ / ') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
353 ui.write(_(b'(multiple children)\n'), label=b'stack.label') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
354 ui.write(b' |\n') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
355 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
356 for rev in stackrevs: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
357 ctx = repo[rev] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
358 symbol = b'@' if rev == wdirctx.rev() else b'o' |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
359 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
360 if newheads: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
361 ui.write(b': ') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
362 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
363 ui.write(b' ') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
364 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
365 ui.write(symbol, b' ') |
34191
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
366 displayer.show(ctx, nodelen=nodelen) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
367 displayer.flush(ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
368 ui.write(b'\n') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
369 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
370 # TODO display histedit hint? |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
371 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
372 if basectx: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
373 # Vertically and horizontally separate stack base from parent |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
374 # to reinforce stack boundary. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
375 if newheads: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
376 ui.write(b':/ ') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
377 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
378 ui.write(b' / ') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
379 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
380 ui.write(_(b'(stack base)'), b'\n', label=b'stack.label') |
43080
86e4daa2d54c
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents:
43077
diff
changeset
|
381 ui.writenoi18n(b'o ') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
382 |
34191
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
383 displayer.show(basectx, nodelen=nodelen) |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
384 displayer.flush(basectx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
385 ui.write(b'\n') |
33197
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33137
diff
changeset
|
386 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
387 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
388 @revsetpredicate(b'_underway([commitage[, headage]])') |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
389 def underwayrevset(repo, subset, x): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
390 args = revset.getargsdict(x, b'underway', b'commitage headage') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
391 if b'commitage' not in args: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
392 args[b'commitage'] = None |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
393 if b'headage' not in args: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
394 args[b'headage'] = None |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
395 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
396 # We assume callers of this revset add a topographical sort on the |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
397 # result. This means there is no benefit to making the revset lazy |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
398 # since the topographical sort needs to consume all revs. |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
399 # |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
400 # With this in mind, we build up the set manually instead of constructing |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
401 # a complex revset. This enables faster execution. |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
402 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
403 # Mutable changesets (non-public) are the most important changesets |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
404 # to return. ``not public()`` will also pull in obsolete changesets if |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
405 # there is a non-obsolete changeset with obsolete ancestors. This is |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
406 # why we exclude obsolete changesets from this query. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
407 rs = b'not public() and not obsolete()' |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
408 rsargs = [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
409 if args[b'commitage']: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
410 rs += b' and date(%s)' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
411 rsargs.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
412 revsetlang.getstring( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
413 args[b'commitage'], _(b'commitage requires a string') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
414 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
415 ) |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
416 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
417 mutable = repo.revs(rs, *rsargs) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
418 relevant = revset.baseset(mutable) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
419 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
420 # Add parents of mutable changesets to provide context. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
421 relevant += repo.revs(b'parents(%ld)', mutable) |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
422 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
423 # We also pull in (public) heads if they a) aren't closing a branch |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
424 # b) are recent. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
425 rs = b'head() and not closed()' |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
426 rsargs = [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
427 if args[b'headage']: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
428 rs += b' and date(%s)' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
429 rsargs.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
430 revsetlang.getstring( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
431 args[b'headage'], _(b'headage requires a string') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
432 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
433 ) |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
434 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
435 relevant += repo.revs(rs, *rsargs) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
436 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
437 # Add working directory parent. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
438 wdirrev = repo[b'.'].rev() |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
439 if wdirrev != nullrev: |
32291
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32058
diff
changeset
|
440 relevant += revset.baseset({wdirrev}) |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
441 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
442 return subset & relevant |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
443 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
444 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
445 @showview(b'work', csettopic=b'work') |
33046
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32837
diff
changeset
|
446 def showwork(ui, repo, displayer): |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
447 """changesets that aren't finished""" |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
448 # TODO support date-based limiting when calling revset. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
449 revs = repo.revs(b'sort(_underway(), topo)') |
34191
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
450 nodelen = longestshortest(repo, revs) |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
451 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
452 revdag = graphmod.dagwalker(repo, revs) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
453 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
454 ui.setconfig(b'experimental', b'graphshorten', True) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
455 logcmdutil.displaygraph( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
456 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
457 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
458 revdag, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
459 displayer, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
460 graphmod.asciiedges, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
461 props={b'nodelen': nodelen}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
462 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
463 |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
464 |
33137
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
465 def extsetup(ui): |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
466 # Alias `hg <prefix><view>` to `hg show <view>`. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
467 for prefix in ui.configlist(b'commands', b'show.aliasprefix'): |
33137
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
468 for view in showview._table: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
469 name = b'%s%s' % (prefix, view) |
33137
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
470 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
471 choice, allcommands = cmdutil.findpossible( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
472 name, commands.table, strict=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
473 ) |
33137
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
474 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
475 # This alias is already a command name. Don't set it. |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
476 if name in choice: |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
477 continue |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
478 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
479 # Same for aliases. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
480 if ui.config(b'alias', name, None): |
33137
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
481 continue |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
482 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
483 ui.setconfig(b'alias', name, b'show %s' % view, source=b'show') |
33137
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33046
diff
changeset
|
484 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
485 |
34191
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
486 def longestshortest(repo, revs, minlen=4): |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
487 """Return the length of the longest shortest node to identify revisions. |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
488 |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
489 The result of this function can be used with the ``shortest()`` template |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
490 function to ensure that a value is unique and unambiguous for a given |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
491 set of nodes. |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
492 |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
493 The number of revisions in the repo is taken into account to prevent |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
494 a numeric node prefix from conflicting with an integer revision number. |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
495 If we fail to do this, a value of e.g. ``10023`` could mean either |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
496 revision 10023 or node ``10023abc...``. |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
497 """ |
35498
dfaf9f10e2e5
show: use revlog function to compute length of the longest shortest node
Yuya Nishihara <yuya@tcha.org>
parents:
35469
diff
changeset
|
498 if not revs: |
dfaf9f10e2e5
show: use revlog function to compute length of the longest shortest node
Yuya Nishihara <yuya@tcha.org>
parents:
35469
diff
changeset
|
499 return minlen |
37680
e743b8524d60
scmutil: introduce shortesthexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37134
diff
changeset
|
500 cl = repo.changelog |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
501 return max( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
502 len(scmutil.shortesthexnodeidprefix(repo, cl.node(r), minlen)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
503 for r in revs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
504 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
505 |
34191
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34190
diff
changeset
|
506 |
31765
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
507 # Adjust the docstring of the show command so it shows all registered views. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
508 # This is a bit hacky because it runs at the end of module load. When moved |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
509 # into core or when another extension wants to provide a view, we'll need |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
510 # to do this more robustly. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
511 # TODO make this more robust. |
31943
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
512 def _updatedocstring(): |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
513 longest = max(map(len, showview._table.keys())) |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
514 entries = [] |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
515 for key in sorted(showview._table.keys()): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
516 entries.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
517 r' %s %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
518 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
519 pycompat.sysstr(key.ljust(longest)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
520 showview._table[key]._origdoc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
521 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
522 ) |
31943
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
523 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
524 cmdtable[b'show'][0].__doc__ = pycompat.sysstr(b'%s\n\n%s\n ') % ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
525 cmdtable[b'show'][0].__doc__.rstrip(), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
526 pycompat.sysstr(b'\n\n').join(entries), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
527 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42596
diff
changeset
|
528 |
31943
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
529 |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
530 _updatedocstring() |