hgext/show.py
author Phil Cohen <phillco@fb.com>
Mon, 26 Jun 2017 22:52:15 -0700
changeset 33151 851825214aa3
parent 33137 99ce2f586cd4
child 33197 c5a07a3abe7d
permissions -rw-r--r--
filemerge: convert a couple of wvfs calls in internal mergetools to contexts One hitch is that sometimes fcd is actually an absentfilectx which does not expose any mutator functions. In order to still use the context functions, we look up the underlying workingfilectx to perform the write there. One alternate way would be to put the write functions on the absentfilectx and have them pass-through. While this makes the callsites cleaner, we would need to decide what its getter functions would return after this point, since returning None for `data` (and True for `isabsent()`) might no longer be correct after a write. I discussed with Sidd about just having the getters raise RuntimeErrors after a mutator has been called, but we actually call isabsent() in merge.py after running the internal merge tools.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 _
31944
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
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,
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
    error,
31859
8e282aa3c3ff show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents: 31858
diff changeset
    36
    formatter,
31944
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
    37
    graphmod,
31820
45761ef1bc93 py3: have registrar process docstrings in bytes
Yuya Nishihara <yuya@tcha.org>
parents: 31765
diff changeset
    38
    pycompat,
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
    registrar,
31944
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
    40
    revset,
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
    41
    revsetlang,
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    42
)
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    43
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    44
# 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
    45
# 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
    46
# 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
    47
# leave the attribute unspecified.
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    48
testedwith = 'ships-with-hg-core'
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    49
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    50
cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32291
diff changeset
    51
command = registrar.command(cmdtable)
31944
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
    52
revsetpredicate = registrar.revsetpredicate()
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
class showcmdfunc(registrar._funcregistrarbase):
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    55
    """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
    56
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    57
    # Used by _formatdoc().
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    58
    _docformat = '%s -- %s'
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
33046
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
    60
    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
    61
        """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
    62
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
        ``name`` is the sub-command name.
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
        ``func`` is the function being decorated.
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
        ``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
    68
        this view.
33046
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
    69
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
    70
        ``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
    71
        printer.
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
    72
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
    73
        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
    74
        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
    75
        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
    76
        """
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    77
        func._fmtopic = fmtopic
33046
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
    78
        func._csettopic = csettopic
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    79
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    80
showview = showcmdfunc()
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    81
31945
02c3b1f396de show: make template option actually show up in help
Ryan McElroy <rmcelroy@fb.com>
parents: 31944
diff changeset
    82
@command('show', [
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
    83
    # 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
    84
    # '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
    85
    # 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
    86
    # 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
    87
    # 'hg show' experience is experimental.
02c3b1f396de show: make template option actually show up in help
Ryan McElroy <rmcelroy@fb.com>
parents: 31944
diff changeset
    88
    ('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
    89
    ], _('VIEW'))
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    90
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
    91
    """show various repository information
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    92
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    93
    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
    94
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    95
    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
    96
    command aborts.
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    97
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    98
    .. note::
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
       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
   101
       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
   102
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   103
       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
   104
       ``-T/--template``.
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
    List of available views:
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 ui.plain() and not template:
31858
ad366d57d574 show: tweak plain abort language for clarity
Ryan McElroy <rmcelroy@fb.com>
parents: 31820
diff changeset
   109
        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
   110
        raise error.Abort(_('must specify a template in plain mode'), hint=hint)
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   111
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   112
    views = showview._table
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
    if not view:
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   115
        ui.pager('show')
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   116
        # 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
   117
        # rendered to custom format.
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   118
        ui.write(_('available views:\n'))
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   119
        ui.write('\n')
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
        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
   122
            ui.write(('%s\n') % func.__doc__)
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   123
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   124
        ui.write('\n')
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   125
        raise error.Abort(_('no view requested'),
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   126
                          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
   127
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   128
    # 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
   129
    if view not in views:
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   130
        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
   131
                          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
   132
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   133
    template = template or 'show'
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   134
33046
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   135
    fn = views[view]
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   136
    ui.pager('show')
33046
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   137
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   138
    if fn._fmtopic:
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   139
        fmtopic = 'show%s' % fn._fmtopic
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   140
        with ui.formatter(fmtopic, {'template': template}) as fm:
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   141
            return fn(ui, repo, fm)
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   142
    elif fn._csettopic:
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   143
        ref = 'show%s' % fn._csettopic
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   144
        spec = formatter.lookuptemplate(ui, ref, template)
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   145
        displayer = cmdutil.changeset_templater(ui, repo, spec, buffered=True)
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   146
        return fn(ui, repo, displayer)
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   147
    else:
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   148
        return fn(ui, repo)
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   149
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   150
@showview('bookmarks', fmtopic='bookmarks')
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   151
def showbookmarks(ui, repo, fm):
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   152
    """bookmarks and their associated changeset"""
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   153
    marks = repo._bookmarks
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   154
    if not len(marks):
31859
8e282aa3c3ff show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents: 31858
diff changeset
   155
        # 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
   156
        # 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
   157
        # waiting for this functionality.
8e282aa3c3ff show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents: 31858
diff changeset
   158
        if not isinstance(fm, formatter.jsonformatter):
8e282aa3c3ff show: fix corrupt json output with no bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents: 31858
diff changeset
   159
            ui.write(_('(no bookmarks set)\n'))
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   160
        return
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   161
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   162
    active = repo._activebookmark
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   163
    longestname = max(len(b) for b in marks)
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   164
    # TODO consider exposing longest shortest(node).
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   165
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   166
    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
   167
        fm.startitem()
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   168
        fm.context(ctx=repo[node])
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   169
        fm.write('bookmark', '%s', bm)
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   170
        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
   171
        fm.data(active=bm == active,
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   172
                longestbookmarklen=longestname)
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   173
31944
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   174
@revsetpredicate('_underway([commitage[, headage]])')
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   175
def underwayrevset(repo, subset, x):
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   176
    args = revset.getargsdict(x, 'underway', 'commitage headage')
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   177
    if 'commitage' not in args:
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   178
        args['commitage'] = None
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   179
    if 'headage' not in args:
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   180
        args['headage'] = None
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   181
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   182
    # 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
   183
    # 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
   184
    # since the topographical sort needs to consume all revs.
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   185
    #
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   186
    # 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
   187
    # a complex revset. This enables faster execution.
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   188
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   189
    # Mutable changesets (non-public) are the most important changesets
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   190
    # 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
   191
    # 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
   192
    # why we exclude obsolete changesets from this query.
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   193
    rs = 'not public() and not obsolete()'
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   194
    rsargs = []
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   195
    if args['commitage']:
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   196
        rs += ' and date(%s)'
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   197
        rsargs.append(revsetlang.getstring(args['commitage'],
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   198
                                           _('commitage requires a string')))
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   199
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   200
    mutable = repo.revs(rs, *rsargs)
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   201
    relevant = revset.baseset(mutable)
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   202
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   203
    # Add parents of mutable changesets to provide context.
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   204
    relevant += repo.revs('parents(%ld)', mutable)
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   205
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   206
    # 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
   207
    # b) are recent.
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   208
    rs = 'head() and not closed()'
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   209
    rsargs = []
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   210
    if args['headage']:
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   211
        rs += ' and date(%s)'
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   212
        rsargs.append(revsetlang.getstring(args['headage'],
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   213
                                           _('headage requires a string')))
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   214
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   215
    relevant += repo.revs(rs, *rsargs)
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   216
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   217
    # Add working directory parent.
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   218
    wdirrev = repo['.'].rev()
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   219
    if wdirrev != nullrev:
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32058
diff changeset
   220
        relevant += revset.baseset({wdirrev})
31944
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   221
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   222
    return subset & relevant
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   223
33046
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   224
@showview('work', csettopic='work')
11f768258dcc show: construct changeset templater during dispatch
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32837
diff changeset
   225
def showwork(ui, repo, displayer):
31944
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   226
    """changesets that aren't finished"""
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   227
    # TODO support date-based limiting when calling revset.
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   228
    revs = repo.revs('sort(_underway(), topo)')
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   229
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   230
    revdag = graphmod.dagwalker(repo, revs)
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   231
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   232
    ui.setconfig('experimental', 'graphshorten', True)
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   233
    cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges)
99bc93147d87 show: implement underway view
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31943
diff changeset
   234
33137
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   235
def extsetup(ui):
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   236
    # Alias `hg <prefix><view>` to `hg show <view>`.
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   237
    for prefix in ui.configlist('commands', 'show.aliasprefix'):
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   238
        for view in showview._table:
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   239
            name = '%s%s' % (prefix, view)
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   240
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   241
            choice, allcommands = cmdutil.findpossible(name, commands.table,
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   242
                                                       strict=True)
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   243
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   244
            # 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
   245
            if name in choice:
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   246
                continue
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   247
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   248
            # Same for aliases.
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   249
            if ui.config('alias', name):
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   250
                continue
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   251
99ce2f586cd4 show: config option to register aliases for views
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33046
diff changeset
   252
            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: 33046
diff changeset
   253
31765
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   254
# 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
   255
# 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
   256
# 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
   257
# to do this more robustly.
264baeef3588 show: new extension for displaying various repository data
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   258
# TODO make this more robust.
31943
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   259
def _updatedocstring():
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   260
    longest = max(map(len, showview._table.keys()))
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   261
    entries = []
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   262
    for key in sorted(showview._table.keys()):
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   263
        entries.append(pycompat.sysstr('    %s   %s' % (
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   264
            key.ljust(longest), showview._table[key]._origdoc)))
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   265
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   266
    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
   267
        cmdtable['show'][0].__doc__.rstrip(),
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   268
        pycompat.sysstr('\n\n').join(entries))
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   269
3e9f118cc834 show: fix formatting of multiple commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31859
diff changeset
   270
_updatedocstring()