Mercurial > hg-stable
annotate hgext/show.py @ 34203:e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
`hg show` makes heavy use of shortest() to limit the length of the node
hash.
For the "stack" and "work" views, you are often looking at multiple
lines of similar output for "lines" of work. It is visually appeasing
for things to vertically align. A naive use of {shortest(node, N)}
could result in variable length nodes and for the first character of
the description to vary by a column or two.
We implement a function to determine the longest shortest prefix for
a set of revisions. The new function is used to determine the printed
node length for all `hg show` views.
.. feature::
show: use consistent node length in views
Our previous shortest node length of 5 was arbitrarily chosen.
shortest() already does the work of ensuring that a partial node
isn't ambiguous with an integer revision, which is our primary risk
of a collision for very short nodes. It should be safe to go with the
shortest node possible.
Existing code is also optimized to handle nodes as short as 4.
So, we decrease the minimum hash length from 5 to 4.
We also add a test demonstrating that prefix collisions increase the
node length.
.. feature::
show: decrease minimum displayed hash length from 5 to 4
Differential Revision: https://phab.mercurial-scm.org/D558
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 13 Sep 2017 21:15:46 -0700 |
parents | 4441c1113eb2 |
children | 592a3cc1ebc4 |
rev | line source |
---|---|
31768
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. |
33144
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
13 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
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:
33058
diff
changeset
|
15 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
16 ``commands`` |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
17 ------------ |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
18 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
19 ``show.aliasprefix`` |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
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:
33058
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:
33058
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:
33058
diff
changeset
|
23 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
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:
33058
diff
changeset
|
25 performed. |
31768
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 _ |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
31 from mercurial.node import nullrev |
31768
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, |
33144
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
34 commands, |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
35 destutil, |
31768
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, |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
39 phases, |
31820
45761ef1bc93
py3: have registrar process docstrings in bytes
Yuya Nishihara <yuya@tcha.org>
parents:
31768
diff
changeset
|
40 pycompat, |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 registrar, |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
42 revset, |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
43 revsetlang, |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 ) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 # 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
|
47 # 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
|
48 # 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
|
49 # leave the attribute unspecified. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 testedwith = 'ships-with-hg-core' |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 cmdtable = {} |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32331
diff
changeset
|
53 command = registrar.command(cmdtable) |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
54 revsetpredicate = registrar.revsetpredicate() |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 class showcmdfunc(registrar._funcregistrarbase): |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 """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
|
58 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 # Used by _formatdoc(). |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 _docformat = '%s -- %s' |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 |
33058
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
62 def _extrasetup(self, name, func, fmtopic=None, csettopic=None): |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 """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
|
64 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 ``name`` is the sub-command name. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 ``func`` is the function being decorated. |
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 ``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
|
70 this view. |
33058
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
71 |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
72 ``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:
32855
diff
changeset
|
73 printer. |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
74 |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
75 If ``fmtopic`` is specified, the view function will receive a |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
76 formatter instance. If ``csettopic`` is specified, the view |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
77 function will receive a changeset printer. |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 """ |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 func._fmtopic = fmtopic |
33058
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
80 func._csettopic = csettopic |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 showview = showcmdfunc() |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
31945
02c3b1f396de
show: make template option actually show up in help
Ryan McElroy <rmcelroy@fb.com>
parents:
31944
diff
changeset
|
84 @command('show', [ |
32414
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
85 # TODO: Switch this template flag to use cmdutil.formatteropts if |
31945
02c3b1f396de
show: make template option actually show up in help
Ryan McElroy <rmcelroy@fb.com>
parents:
31944
diff
changeset
|
86 # 'hg show' becomes stable before --template/-T is stable. For now, |
02c3b1f396de
show: make template option actually show up in help
Ryan McElroy <rmcelroy@fb.com>
parents:
31944
diff
changeset
|
87 # we are putting it here without the '(EXPERIMENTAL)' flag because it |
02c3b1f396de
show: make template option actually show up in help
Ryan McElroy <rmcelroy@fb.com>
parents:
31944
diff
changeset
|
88 # is an important part of the 'hg show' user experience and the entire |
02c3b1f396de
show: make template option actually show up in help
Ryan McElroy <rmcelroy@fb.com>
parents:
31944
diff
changeset
|
89 # 'hg show' experience is experimental. |
02c3b1f396de
show: make template option actually show up in help
Ryan McElroy <rmcelroy@fb.com>
parents:
31944
diff
changeset
|
90 ('T', 'template', '', ('display with template'), _('TEMPLATE')), |
02c3b1f396de
show: make template option actually show up in help
Ryan McElroy <rmcelroy@fb.com>
parents:
31944
diff
changeset
|
91 ], _('VIEW')) |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 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
|
93 """show various repository information |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 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
|
96 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 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
|
98 command aborts. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 .. note:: |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
101 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
102 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
|
103 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
|
104 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 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
|
106 ``-T/--template``. |
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 List of available views: |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 """ |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 if ui.plain() and not template: |
31858
ad366d57d574
show: tweak plain abort language for clarity
Ryan McElroy <rmcelroy@fb.com>
parents:
31820
diff
changeset
|
111 hint = _('invoke with -T/--template to control output format') |
ad366d57d574
show: tweak plain abort language for clarity
Ryan McElroy <rmcelroy@fb.com>
parents:
31820
diff
changeset
|
112 raise error.Abort(_('must specify a template in plain mode'), hint=hint) |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 views = showview._table |
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 if not view: |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 ui.pager('show') |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 # 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
|
119 # rendered to custom format. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 ui.write(_('available views:\n')) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 ui.write('\n') |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 for name, func in sorted(views.items()): |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 ui.write(('%s\n') % func.__doc__) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 ui.write('\n') |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 raise error.Abort(_('no view requested'), |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 hint=_('use "hg show VIEW" to choose a view')) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
129 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 # 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
|
131 if view not in views: |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 raise error.Abort(_('unknown view: %s') % view, |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 hint=_('run "hg show" to see available views')) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
134 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
135 template = template or 'show' |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 |
33058
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
137 fn = views[view] |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
138 ui.pager('show') |
33058
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
139 |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
140 if fn._fmtopic: |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
141 fmtopic = 'show%s' % fn._fmtopic |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
142 with ui.formatter(fmtopic, {'template': template}) as fm: |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
143 return fn(ui, repo, fm) |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
144 elif fn._csettopic: |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
145 ref = 'show%s' % fn._csettopic |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
146 spec = formatter.lookuptemplate(ui, ref, template) |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
147 displayer = cmdutil.changeset_templater(ui, repo, spec, buffered=True) |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
148 return fn(ui, repo, displayer) |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
149 else: |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
150 return fn(ui, repo) |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 @showview('bookmarks', fmtopic='bookmarks') |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 def showbookmarks(ui, repo, fm): |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 """bookmarks and their associated changeset""" |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 marks = repo._bookmarks |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 if not len(marks): |
31859
8e282aa3c3ff
show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
31858
diff
changeset
|
157 # 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
|
158 # 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
|
159 # waiting for this functionality. |
8e282aa3c3ff
show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
31858
diff
changeset
|
160 if not isinstance(fm, formatter.jsonformatter): |
8e282aa3c3ff
show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
31858
diff
changeset
|
161 ui.write(_('(no bookmarks set)\n')) |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
162 return |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
163 |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
164 revs = [repo[node].rev() for node in marks.values()] |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
165 active = repo._activebookmark |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
166 longestname = max(len(b) for b in marks) |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
167 nodelen = longestshortest(repo, revs) |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
169 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
|
170 fm.startitem() |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 fm.context(ctx=repo[node]) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 fm.write('bookmark', '%s', bm) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 fm.write('node', fm.hexfunc(node), fm.hexfunc(node)) |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 fm.data(active=bm == active, |
34202
4441c1113eb2
show: pass the minimum length for nodes as a template keyword
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33211
diff
changeset
|
175 longestbookmarklen=longestname, |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
176 nodelen=nodelen) |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
177 |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
178 @showview('stack', csettopic='stack') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
179 def showstack(ui, repo, displayer): |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
180 """current line of work""" |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
181 wdirctx = repo['.'] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
182 if wdirctx.rev() == nullrev: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
183 raise error.Abort(_('stack view only available when there is a ' |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
184 'working directory')) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
185 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
186 if wdirctx.phase() == phases.public: |
33208
9e7efe421395
show: tweak warning message
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33199
diff
changeset
|
187 ui.write(_('(empty stack; working directory parent is a published ' |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
188 'changeset)\n')) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
189 return |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
190 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
191 # TODO extract "find stack" into a function to facilitate |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
192 # customization and reuse. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
193 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
194 baserev = destutil.stackbase(ui, repo) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
195 basectx = None |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
196 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
197 if baserev is None: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
198 baserev = wdirctx.rev() |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
199 stackrevs = {wdirctx.rev()} |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
200 else: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
201 stackrevs = set(repo.revs('%d::.', baserev)) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
202 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
203 ctx = repo[baserev] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
204 if ctx.p1().rev() != nullrev: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
205 basectx = ctx.p1() |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
206 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
207 # And relevant descendants. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
208 branchpointattip = False |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
209 cl = repo.changelog |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
210 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
211 for rev in cl.descendants([wdirctx.rev()]): |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
212 ctx = repo[rev] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
213 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
214 # Will only happen if . is public. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
215 if ctx.phase() == phases.public: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
216 break |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
217 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
218 stackrevs.add(ctx.rev()) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
219 |
33211
f48422ab81aa
show: document why accidentally quadratic is (probably) acceptable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33210
diff
changeset
|
220 # 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
|
221 # 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
|
222 # 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
|
223 # 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
|
224 # this is quadratic, the perf impact should be minimal. |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
225 if len(ctx.children()) > 1: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
226 branchpointattip = True |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
227 break |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
228 |
33209
9718725dc02a
show: avoid extra list operations
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33208
diff
changeset
|
229 stackrevs = list(sorted(stackrevs, reverse=True)) |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
230 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
231 # Find likely target heads for the current stack. These are likely |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
232 # merge or rebase targets. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
233 if basectx: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
234 # TODO make this customizable? |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
235 newheads = set(repo.revs('heads(%d::) - %ld - not public()', |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
236 basectx.rev(), stackrevs)) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
237 else: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
238 newheads = set() |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
239 |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
240 allrevs = set(stackrevs) | newheads | set([baserev]) |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
241 nodelen = longestshortest(repo, allrevs) |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
242 |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
243 try: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
244 cmdutil.findcmd('rebase', commands.table) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
245 haverebase = True |
33210
b93df142485e
show: also catch AmbiguousCommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33209
diff
changeset
|
246 except (error.AmbiguousCommand, error.UnknownCommand): |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
247 haverebase = False |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
248 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
249 # TODO use templating. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
250 # TODO consider using graphmod. But it may not be necessary given |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
251 # our simplicity and the customizations required. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
252 # TODO use proper graph symbols from graphmod |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
253 |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
254 shortesttmpl = formatter.maketemplater(ui, '{shortest(node, %d)}' % nodelen) |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
255 def shortest(ctx): |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
256 return shortesttmpl.render({'ctx': ctx, 'node': ctx.hex()}) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
257 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
258 # 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:
33144
diff
changeset
|
259 # 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:
33144
diff
changeset
|
260 # branch point. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
261 if newheads: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
262 # 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:
33144
diff
changeset
|
263 # sort display order by commit distance. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
264 revdistance = {} |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
265 for head in newheads: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
266 # There is some redundancy in DAG traversal here and therefore |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
267 # room to optimize. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
268 ancestors = cl.ancestors([head], stoprev=basectx.rev()) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
269 revdistance[head] = len(list(ancestors)) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
270 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
271 sourcectx = repo[stackrevs[-1]] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
272 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
273 sortedheads = sorted(newheads, key=lambda x: revdistance[x], |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
274 reverse=True) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
275 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
276 for i, rev in enumerate(sortedheads): |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
277 ctx = repo[rev] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
278 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
279 if i: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
280 ui.write(': ') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
281 else: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
282 ui.write(' ') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
283 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
284 ui.write(('o ')) |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
285 displayer.show(ctx, nodelen=nodelen) |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
286 displayer.flush(ctx) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
287 ui.write('\n') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
288 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
289 if i: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
290 ui.write(':/') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
291 else: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
292 ui.write(' /') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
293 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
294 ui.write(' (') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
295 ui.write(_('%d commits ahead') % revdistance[rev], |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
296 label='stack.commitdistance') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
297 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
298 if haverebase: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
299 # TODO may be able to omit --source in some scenarios |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
300 ui.write('; ') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
301 ui.write(('hg rebase --source %s --dest %s' % ( |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
302 shortest(sourcectx), shortest(ctx))), |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
303 label='stack.rebasehint') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
304 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
305 ui.write(')\n') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
306 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
307 ui.write(':\n: ') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
308 ui.write(_('(stack head)\n'), label='stack.label') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
309 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
310 if branchpointattip: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
311 ui.write(' \\ / ') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
312 ui.write(_('(multiple children)\n'), label='stack.label') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
313 ui.write(' |\n') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
314 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
315 for rev in stackrevs: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
316 ctx = repo[rev] |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
317 symbol = '@' if rev == wdirctx.rev() else 'o' |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
318 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
319 if newheads: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
320 ui.write(': ') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
321 else: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
322 ui.write(' ') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
323 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
324 ui.write(symbol, ' ') |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
325 displayer.show(ctx, nodelen=nodelen) |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
326 displayer.flush(ctx) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
327 ui.write('\n') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
328 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
329 # TODO display histedit hint? |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
330 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
331 if basectx: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
332 # Vertically and horizontally separate stack base from parent |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
333 # to reinforce stack boundary. |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
334 if newheads: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
335 ui.write(':/ ') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
336 else: |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
337 ui.write(' / ') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
338 |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
339 ui.write(_('(stack base)'), '\n', label='stack.label') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
340 ui.write(('o ')) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
341 |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
342 displayer.show(basectx, nodelen=nodelen) |
33199
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
343 displayer.flush(basectx) |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
344 ui.write('\n') |
c5a07a3abe7d
show: implement "stack" view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33144
diff
changeset
|
345 |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
346 @revsetpredicate('_underway([commitage[, headage]])') |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
347 def underwayrevset(repo, subset, x): |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
348 args = revset.getargsdict(x, 'underway', 'commitage headage') |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
349 if 'commitage' not in args: |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
350 args['commitage'] = None |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
351 if 'headage' not in args: |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
352 args['headage'] = None |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
353 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
354 # 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
|
355 # 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
|
356 # since the topographical sort needs to consume all revs. |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
357 # |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
358 # 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
|
359 # a complex revset. This enables faster execution. |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
360 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
361 # Mutable changesets (non-public) are the most important changesets |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
362 # 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
|
363 # 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
|
364 # why we exclude obsolete changesets from this query. |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
365 rs = 'not public() and not obsolete()' |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
366 rsargs = [] |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
367 if args['commitage']: |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
368 rs += ' and date(%s)' |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
369 rsargs.append(revsetlang.getstring(args['commitage'], |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
370 _('commitage requires a string'))) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
371 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
372 mutable = repo.revs(rs, *rsargs) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
373 relevant = revset.baseset(mutable) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
374 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
375 # Add parents of mutable changesets to provide context. |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
376 relevant += repo.revs('parents(%ld)', mutable) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
377 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
378 # 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
|
379 # b) are recent. |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
380 rs = 'head() and not closed()' |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
381 rsargs = [] |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
382 if args['headage']: |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
383 rs += ' and date(%s)' |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
384 rsargs.append(revsetlang.getstring(args['headage'], |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
385 _('headage requires a string'))) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
386 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
387 relevant += repo.revs(rs, *rsargs) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
388 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
389 # Add working directory parent. |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
390 wdirrev = repo['.'].rev() |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
391 if wdirrev != nullrev: |
32331
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32058
diff
changeset
|
392 relevant += revset.baseset({wdirrev}) |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
393 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
394 return subset & relevant |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
395 |
33058
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
396 @showview('work', csettopic='work') |
11f768258dcc
show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32855
diff
changeset
|
397 def showwork(ui, repo, displayer): |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
398 """changesets that aren't finished""" |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
399 # TODO support date-based limiting when calling revset. |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
400 revs = repo.revs('sort(_underway(), topo)') |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
401 nodelen = longestshortest(repo, revs) |
31944
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 revdag = graphmod.dagwalker(repo, revs) |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
404 |
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
405 ui.setconfig('experimental', 'graphshorten', True) |
34202
4441c1113eb2
show: pass the minimum length for nodes as a template keyword
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33211
diff
changeset
|
406 cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
407 props={'nodelen': nodelen}) |
31944
99bc93147d87
show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31943
diff
changeset
|
408 |
33144
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
409 def extsetup(ui): |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
410 # Alias `hg <prefix><view>` to `hg show <view>`. |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
411 for prefix in ui.configlist('commands', 'show.aliasprefix'): |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
412 for view in showview._table: |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
413 name = '%s%s' % (prefix, view) |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
414 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
415 choice, allcommands = cmdutil.findpossible(name, commands.table, |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
416 strict=True) |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
417 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
418 # 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:
33058
diff
changeset
|
419 if name in choice: |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
420 continue |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
421 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
422 # Same for aliases. |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
423 if ui.config('alias', name): |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
424 continue |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
425 |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
426 ui.setconfig('alias', name, 'show %s' % view, source='show') |
99ce2f586cd4
show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33058
diff
changeset
|
427 |
34203
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
428 def longestshortest(repo, revs, minlen=4): |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
429 """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:
34202
diff
changeset
|
430 |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
431 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:
34202
diff
changeset
|
432 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:
34202
diff
changeset
|
433 set of nodes. |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
434 |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
435 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:
34202
diff
changeset
|
436 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:
34202
diff
changeset
|
437 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:
34202
diff
changeset
|
438 revision 10023 or node ``10023abc...``. |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
439 """ |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
440 tmpl = formatter.maketemplater(repo.ui, '{shortest(node, %d)}' % minlen) |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
441 lens = [minlen] |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
442 for rev in revs: |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
443 ctx = repo[rev] |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
444 shortest = tmpl.render({'ctx': ctx, 'node': ctx.hex()}) |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
445 lens.append(len(shortest)) |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
446 |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
447 return max(lens) |
e6b5e7329ff2
show: use consistent (and possibly shorter) node lengths
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34202
diff
changeset
|
448 |
31768
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
449 # 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
|
450 # 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
|
451 # 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
|
452 # to do this more robustly. |
264baeef3588
show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
453 # TODO make this more robust. |
31943
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
454 def _updatedocstring(): |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
455 longest = max(map(len, showview._table.keys())) |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
456 entries = [] |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
457 for key in sorted(showview._table.keys()): |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
458 entries.append(pycompat.sysstr(' %s %s' % ( |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
459 key.ljust(longest), showview._table[key]._origdoc))) |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
460 |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
461 cmdtable['show'][0].__doc__ = pycompat.sysstr('%s\n\n%s\n ') % ( |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
462 cmdtable['show'][0].__doc__.rstrip(), |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
463 pycompat.sysstr('\n\n').join(entries)) |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
464 |
3e9f118cc834
show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31859
diff
changeset
|
465 _updatedocstring() |