[PATCH V2] mercurial: add debugextensions command (issue4676)

Piotr Listkiewicz piotr.listkiewicz at gmail.com
Tue Sep 22 03:55:11 CDT 2015


>
> This can be written as
>   extbuglink = getattr(extmod, 'buglink', None)


Good point, i didnt even know about this. Use it in PATCH V2

formatter should be created even if exts_infos is empty. For example,
> "hg status -Tjson" prints [] if nothing changed.
>

Changed it, it now creates formatter even when there are no extensions.

So we don't need prebuild exts_infos list, and we can use extname,
> extsource,
> etc. instead of less-readable ext_info[i].


Right, in newest patch it uses it making code far more readable.

 Perhaps this should be fm.condwrite(ui.verbose, ...). Machine-readable
> format
> contains all variables in general.


Changed as requested

2015-09-22 10:50 GMT+02:00 Piotr Listkiewicz <piotr.listkiewicz at gmail.com>:

> $ hg debugextensions
>> color
>> dbsh(untested!)
>> Missing space
>
>
> Added in PATCH V2
>
> No need to tell us about 3.3.3 when we know about 3.4-rc and are running
>> 3.5.
>
>
> In newest patch shows only last version mentioned in testedwith - it looks
> like it always contains versions from oldest to newest.
>
> Also, you used the generic formatter but didn't enable the formatter
>> options:
>
>
> Added
>
> We probably want lowercase on the keys here and the versions should be a
>> list.
>
>
> Keys changed to lowercase. Version wasnt specified in json because i used
> IF statement to add this information in case verbose was specified. After
> changing IF statement to formatter.condwrite it shows this( because for
> jsonformatter condwrite is the same as write)
>
>
>
> 2015-09-22 10:39 GMT+02:00 liscju <piotr.listkiewicz at gmail.com>:
>
>> # HG changeset patch
>> # User liscju <piotr.listkiewicz at gmail.com>
>> # Date 1441896787 -7200
>> #      Thu Sep 10 16:53:07 2015 +0200
>> # Node ID 5282acdf2c3628065581169c89a233f9da001655
>> # Parent  ea489d94e1dc1fc3dc1dcbef1c86c18c49605ed1
>> mercurial: add debugextensions command (issue4676)
>>
>> Add debugextensions command to help users debug their extension
>> problems. If there are no extensions command prints nothing,
>> otherwise it prints names of extension modules. If quiet or
>> verbose option is not specified it prints(after extensions name)
>> last version of mercurial in which given module was tested for
>> non internal modules or not tested with user mercurial version.
>>
>> If verbose is specified it prints following information for every
>> extension: extension name, import source, testedwith and buglink
>> informations.
>>
>> Extensions are printed sorted by extension name.
>>
>> diff -r ea489d94e1dc -r 5282acdf2c36 mercurial/commands.py
>> --- a/mercurial/commands.py     Sat Aug 22 17:08:37 2015 -0700
>> +++ b/mercurial/commands.py     Thu Sep 10 16:53:07 2015 +0200
>> @@ -19,7 +19,7 @@
>>  import merge as mergemod
>>  import minirst, revset, fileset
>>  import dagparser, context, simplemerge, graphmod, copies
>> -import random
>> +import random, operator
>>  import setdiscovery, treediscovery, dagutil, pvec, localrepo
>>  import phases, obsolete, exchange, bundle2, repair, lock as lockmod
>>  import ui as uimod
>> @@ -2171,6 +2171,46 @@
>>          localrevs = opts.get('local_head')
>>          doit(localrevs, remoterevs)
>>
>> + at command('debugextensions', formatteropts, [], norepo=True)
>> +def debugextensions(ui, **opts):
>> +    '''show informations about active extensions'''
>> +    exts = extensions.extensions(ui)
>> +    fm = ui.formatter('debugextensions', opts)
>> +    for extname, extmod in sorted(exts, key=operator.itemgetter(0)):
>> +        extsource = extmod.__file__
>> +        exttestedwith = getattr(extmod, 'testedwith', None)
>> +        if exttestedwith is not None:
>> +            exttestedwith = exttestedwith.split()
>> +        extbuglink = getattr(extmod, 'buglink', None)
>> +
>> +        fm.startitem()
>> +
>> +        if ui.quiet or ui.verbose:
>> +            fm.write('extension name', '%s\n', extname)
>> +        else:
>> +            fm.write('extension name', '%s', extname)
>> +            if not exttestedwith:
>> +                fm.write('tested with', ' (untested!)\n')
>> +            else:
>> +                if exttestedwith == ['internal'] or \
>> +                                util.version() in exttestedwith:
>> +                    fm.write('tested with', '\n')
>> +                else:
>> +                    lasttestedversion = exttestedwith[-1]
>> +                    fm.write('tested with', ' (%s!)\n',
>> +                             lasttestedversion)
>> +
>> +        fm.condwrite(ui.verbose, 'import source',
>> +                 '  location: %s\n', extsource)
>> +
>> +        fm.condwrite(ui.verbose, 'tested with',
>> +                 '  tested with: %s\n', exttestedwith)
>> +
>> +        fm.condwrite(ui.verbose, 'bug link',
>> +                 '  bug reporting: %s\n', extbuglink)
>> +
>> +    fm.end()
>> +
>>  @command('debugfileset',
>>      [('r', 'rev', '', _('apply the filespec on this revision'),
>> _('REV'))],
>>      _('[-r REV] FILESPEC'))
>> diff -r ea489d94e1dc -r 5282acdf2c36 mercurial/formatter.py
>> --- a/mercurial/formatter.py    Sat Aug 22 17:08:37 2015 -0700
>> +++ b/mercurial/formatter.py    Thu Sep 10 16:53:07 2015 +0200
>> @@ -108,7 +108,7 @@
>>          self._ui.write(cPickle.dumps(self._data))
>>
>>  def _jsonifyobj(v):
>> -    if isinstance(v, tuple):
>> +    if isinstance(v, tuple) or isinstance(v, list):
>>          return '[' + ', '.join(_jsonifyobj(e) for e in v) + ']'
>>      elif v is None:
>>          return 'null'
>> diff -r ea489d94e1dc -r 5282acdf2c36 tests/test-completion.t
>> --- a/tests/test-completion.t   Sat Aug 22 17:08:37 2015 -0700
>> +++ b/tests/test-completion.t   Thu Sep 10 16:53:07 2015 +0200
>> @@ -80,6 +80,7 @@
>>    debugdate
>>    debugdirstate
>>    debugdiscovery
>> +  debugextensions
>>    debugfileset
>>    debugfsinfo
>>    debuggetbundle
>> @@ -239,6 +240,7 @@
>>    debugdate: extended
>>    debugdirstate: nodates, datesort
>>    debugdiscovery: old, nonheads, ssh, remotecmd, insecure
>> +  debugextensions: template
>>    debugfileset: rev
>>    debugfsinfo:
>>    debuggetbundle: head, common, type
>> diff -r ea489d94e1dc -r 5282acdf2c36 tests/test-debugextensions.t
>> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
>> +++ b/tests/test-debugextensions.t      Thu Sep 10 16:53:07 2015 +0200
>> @@ -0,0 +1,39 @@
>> +  $ hg debugextensions
>> +
>> +  $ cat >> $HGRCPATH <<EOF
>> +  > [extensions]
>> +  > color=
>> +  > histedit=
>> +  > patchbomb=
>> +  > rebase=
>> +  > mq=
>> +  > EOF
>> +
>> +  $ hg debugextensions
>> +  color
>> +  histedit
>> +  mq
>> +  patchbomb
>> +  rebase
>> +
>> +  $ hg debugextensions -v
>> +  color
>> +    location: */hgext/color.pyc (glob)
>> +    tested with: ['internal']
>> +    bug reporting: None
>> +  histedit
>> +    location: */hgext/histedit.pyc (glob)
>> +    tested with: ['internal']
>> +    bug reporting: None
>> +  mq
>> +    location: */hgext/mq.pyc (glob)
>> +    tested with: ['internal']
>> +    bug reporting: None
>> +  patchbomb
>> +    location: */hgext/patchbomb.pyc (glob)
>> +    tested with: ['internal']
>> +    bug reporting: None
>> +  rebase
>> +    location: */hgext/rebase.pyc (glob)
>> +    tested with: ['internal']
>> +    bug reporting: None
>> diff -r ea489d94e1dc -r 5282acdf2c36 tests/test-extension.t
>> --- a/tests/test-extension.t    Sat Aug 22 17:08:37 2015 -0700
>> +++ b/tests/test-extension.t    Thu Sep 10 16:53:07 2015 +0200
>> @@ -289,17 +289,23 @@
>>    $ echo "debugextension = $debugpath" >> $HGRCPATH
>>
>>    $ hg help debugextension
>> -  debugextension extension - only debugcommands
>> +  hg debugextensions
>>
>> -  no commands defined
>> +  show informations about active extensions
>> +
>> +  options:
>> +
>> +  (some details hidden, use --verbose to show complete help)
>>
>>
>>    $ hg --verbose help debugextension
>> -  debugextension extension - only debugcommands
>> +  hg debugextensions
>>
>> -  list of commands:
>> +  show informations about active extensions
>>
>> -   foo           yet another foo command
>> +  options:
>> +
>> +   -T --template TEMPLATE display with template (EXPERIMENTAL)
>>
>>    global options ([+] can be repeated):
>>
>> @@ -328,12 +334,13 @@
>>
>>
>>    $ hg --debug help debugextension
>> -  debugextension extension - only debugcommands
>> +  hg debugextensions
>>
>> -  list of commands:
>> +  show informations about active extensions
>>
>> -   debugfoobar   yet another debug command
>> -   foo           yet another foo command
>> +  options:
>> +
>> +   -T --template TEMPLATE display with template (EXPERIMENTAL)
>>
>>    global options ([+] can be repeated):
>>
>> @@ -546,20 +553,7 @@
>>
>>  Issue811: Problem loading extensions twice (by site and by user)
>>
>> -  $ debugpath=`pwd`/debugissue811.py
>> -  $ cat > debugissue811.py <<EOF
>> -  > '''show all loaded extensions
>> -  > '''
>> -  > from mercurial import cmdutil, commands, extensions
>> -  > cmdtable = {}
>> -  > command = cmdutil.command(cmdtable)
>> -  > @command('debugextensions', [], 'hg debugextensions', norepo=True)
>> -  > def debugextensions(ui):
>> -  >     "yet another debug command"
>> -  >     ui.write("%s\n" % '\n'.join([x for x, y in
>> extensions.extensions()]))
>> -  > EOF
>>    $ cat <<EOF >> $HGRCPATH
>> -  > debugissue811 = $debugpath
>>    > mq =
>>    > strip =
>>    > hgext.mq =
>> @@ -570,9 +564,8 @@
>>  (note that mq force load strip, also checking it's not loaded twice)
>>
>>    $ hg debugextensions
>> -  debugissue811
>> +  mq
>>    strip
>> -  mq
>>
>>  For extensions, which name matches one of its commands, help
>>  message should ask '-v -e' to get list of built-in aliases
>> diff -r ea489d94e1dc -r 5282acdf2c36 tests/test-help.t
>> --- a/tests/test-help.t Sat Aug 22 17:08:37 2015 -0700
>> +++ b/tests/test-help.t Thu Sep 10 16:53:07 2015 +0200
>> @@ -775,6 +775,8 @@
>>                   show the contents of the current dirstate
>>     debugdiscovery
>>                   runs the changeset discovery protocol in isolation
>> +   debugextensions
>> +                 show informations about active extensions
>>     debugfileset  parse and apply a fileset specification
>>     debugfsinfo   show information detected about current filesystem
>>     debuggetbundle
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20150922/43ec414c/attachment.html>


More information about the Mercurial-devel mailing list