Commit Graph

91 Commits

Author SHA1 Message Date
Yuya Nishihara
7b77796abc extensions: show deprecation warning for the use of cmdutil.command
Since this is a fundamental API for extensions, we set 1-year period until
actually removing it.
2016-01-09 23:24:52 +09:00
Yuya Nishihara
029af11327 extensions: prohibit registration of command without using @command (API)
Detect the problem earlier for better error indication. I'm tired of teaching
users that the mq extension is not guilty but the third-party extension is.

https://bitbucket.org/tortoisehg/thg/issues?q=%27norepo%27
2017-05-13 15:41:50 +09:00
Yuya Nishihara
3e663dde68 registrar: move cmdutil.command to registrar module (API)
cmdutil.command wasn't a member of the registrar framework only for a
historical reason. Let's make that happen. This patch keeps cmdutil.command
as an alias for extension compatibility.
2016-01-09 23:07:20 +09:00
Yuya Nishihara
5fab4a9d55 patchbomb: add config knob to generate flags by template (issue5354)
This can be used to flag patches by branch or topic automatically. Flags
optionally given by --flag option are exported as {flags} template keyword,
so you can add --flag V2.
2017-02-25 18:41:00 +09:00
Pierre-Yves David
a29094b506 color: update main documentation
Now that the feature no longer lives in the extension, we document it in the
help of the core config. This include the new 'ui.color' option introduced in
the previous changesets.

As a result the color extensions can now be deprecated.

This is a documentation patch only; color is still disabled by default.
2017-02-21 20:04:55 +01:00
Pierre-Yves David
b29eb57306 color: add a 'ui.color' option to control color behavior
This new option control whether or not color will be used. It mirror the behavior
of '--color'. I usually avoid adding new option to '[ui]' as the section is
already filled with many option. However, I feel like 'color' is central enough
to deserves a spot in this '[ui]' section.

For now the option is not documented so it is still marked as experimental. Once
it get documented and official, we should be able to deprecate the color
extensions.

There is more cleanup to do before that documentation is written, but we need
this option early to made them. Having that option will allow for more cleanup
of the initialisation process and proper separation between color
configuration.
2017-02-25 19:44:23 +01:00
Pierre-Yves David
e5d5db7cf5 color: add the definition of '--color' in core
If we want to be able to move the initialisation in core, we need core to be
aware of that '--color' flag at all time. So we now have the definition in core. That flag
is currently unprocessed without the extensions (will be fixed soon). In
addition the default value for this flag in core is 'never'. Enabling the
extensions change that default value to 'auto'.
2017-02-21 18:09:21 +01:00
Augie Fackler
3967c4ed9b pager: move more behavior into core
This moves the global flag and the --pager=yes logic into core. Only
functionality change is that users now always get a --pager flag and
can enable the pager via the flag without the extension active.

Moving the flag into core exposes a defect in the ro localization,
which will have to be corrected later.
2017-02-15 17:47:57 -05:00
Martin von Zweigbergk
43fb09f0d0 help: explain that revsets can be used where 1 or 2 revs are wanted
We did not seem to document that one can do things like "hg up :@"
where the last revision of the revset ":@".
2017-01-11 23:13:00 -08:00
Martin von Zweigbergk
8f2ed099c1 help: make multirevs just an alias for revsets
The multirevs topis seems to be covered well by the revsets topic, so
just make it an alias and remove multirevs.txt.
2016-12-16 09:48:14 -08:00
Augie Fackler
d3b8e6d277 dispatch: stop supporting non-use of @command
We said we'd delete this after 3.8. It's time.
2016-11-21 21:51:23 -05:00
Mads Kiilerich
38cb771268 spelling: fixes of non-dictionary words 2016-10-17 23:16:55 +02:00
Pulkit Goyal
96b2983c6a help: show help for disabled extensions (issue5228)
This patch does not exactly solve issue5228 but it results in a better
condition on this issue. For disabled extensions, we used to parse the
module and get the first occurrences of docstring and then return the first
line of that as an introductory heading of extension. This is what we get
today.

This patch returns the whole docstring of the module as a help for extension,
which is more informative. There are some modules which don't have much
docstring at top level except the heading so those are unaffected by this
change. To follow the existing trend of showing commands either we have to
load the extension or have a very ugly parsing method which don't even assure
correctness.
2016-11-06 06:54:31 +05:30
Pierre-Yves David
d482e52866 help: backout 6f89f03ad369 (mark boolean flags with [no-] in help) for now
The ability to negate any boolean flags itself is great, but I think we are not
ready to expose the help side of it yet.

First, while there exist a handful of such flags whose default value can be
changed (eg: git diff, patchwork confirmation), there is only a few of them. The
users who benefit the most from this change are alias users and large
installation that can deploy extension to change behavior (eg: facebook
tweakdefault).  So the majority of user who will be affected by a large change
to command help that is not yet relevant to them. (I expect this to become
relevant when ui.progressive start to exists).

Below is an example of the impact of the new help on 'hg help diff':

  -r --rev REV [+]              revision
  -c --change REV               change made by revision
  -a --[no-]text                treat all files as text
  -g --[no-]git                 use git extended diff format
     --[no-]nodates             omit dates from diff headers
     --[no-]noprefix            omit a/ and b/ prefixes from filenames
  -p --[no-]show-function       show which function each change is in
     --[no-]reverse             produce a diff that undoes the changes
  -w --[no-]ignore-all-space    ignore white space when comparing lines
  -b --[no-]ignore-space-change ignore changes in the amount of white space
  -B --[no-]ignore-blank-lines  ignore changes whose lines are all blank
  -U --unified NUM              number of lines of context to show
     --[no-]stat                output diffstat-style summary of changes
     --root DIR                 produce diffs relative to subdirectory
  -I --include PATTERN [+]      include names matching the given patterns
  -X --exclude PATTERN [+]      exclude names matching the given patterns
  -S --[no-]subrepos            recurse into subrepositories

Another issue with the current state of help, the default value for the
flag is not conveyed to the user. For example in the 'backout' help, there is
no real distinction between "--[no-]backup" (default to True) and "--[no-]keep"
(default) to False:

  --[no-]backup        no backups
  --[no-]keep          do not modify working directory during strip

In addition, I've discussed with Augie Fackler and the last batch of the work on
this have burned him out quite some. Therefore he is not intending to perform
any more work on this topic. Quoting him, he would rather see the help part
backed out than spending more time on it.

I do not think we are ready to expose this to users in 4.0 (freeze in a week),
especially because we cannot expect quick improvement on these aspect as this
topic no longer have an owner. We should be able to reintroduce that change in
the future when someone get back on it and the main issues are solves:

* Introduction of  ui.progressive makes it relevant for a majority of user,
* Current default value are efficiently conveyed to the user.

(In addition, the excerpt from diff help show that we still have some issue with
some negative option like '--nodates' so further improvement are probably
welcome there.)
2016-10-09 03:11:18 +02:00
Augie Fackler
8843ab4c98 help: mark boolean flags with [no-] to explain that they can be negated
That is, help gets tweaked thus:

  global options ([+] can be repeated):
   -v --[no-]verbose      enable additional output


Other proposals have included:

  global options ([+] can be repeated, options marked [?] are boolean flags):
   -v --verbose[?]        enable additional output

and

  global options ([+] can be repeated, options marked [^] are boolean flags):
   -v --verbose[^]        enable additional output

which avoid the unfortunate visual noise in this patch. In this
version's favor, it's consistent with what I'm used to seeing in man
pages and similar documentation venues.
2016-09-13 22:58:12 -04:00
timeless
5fd9e9e1b5 help: use single quotes in use warning 2016-09-20 23:47:46 +00:00
Yuya Nishihara
9695a817e8 version: change "place" field of extension to "bundled" flag
The name "place" sounds odd. We can simply expose raw boolean values instead
of switching external/internal literals.
2016-08-26 23:38:52 +09:00
timeless
1ad349cf3d tests: guard demandimport segment of test-extension.t 2016-08-25 23:13:36 +00:00
Yuya Nishihara
3e1f2a73cd version: add formatter support
The license message isn't exported, which I don't think is useful and I
couldn't find a way to restructure it for JSON or template outputs.
2016-08-25 01:00:26 -04:00
Yuya Nishihara
161bc66818 version: factor out mapping of internal/external labels
Prepares for formatter support, where translation should be disabled
conditionally.
2016-08-16 16:09:12 +09:00
Yuya Nishihara
e723a6d369 version: always build list of extension versions
This patch just moves "if ui.verbose:" to the inner loop, as preparation
for formatter support.
2016-08-16 16:03:09 +09:00
FUJIWARA Katsunori
21c1b2af7c demandimport: import sub-module relatively as expected (issue5208)
Before this patch, importing sub-module might (1) fail or (2) success
but import incorrect module, because demandimport tries to import
sub-module with level=-1 (on Python 2.x) or level=0 (on Python 3.x),
which is default value of "level" argument at construction of
"_demandmod" proxy object.

  (1) on Python 3.x, importing sub-module always fails to import
      existing sub-module

  (2) both on Python 2.x and 3.x, importing sub-module might import
      same name module on root level unintentionally

      On Python 2.x, existing sub-module is prior to this unexpected
      module. Therefore, this problem hasn't appeared.

To import sub-module relatively as expected, this patch specifies "1"
as import level explicitly at construction of "_demandmod" proxy
object for sub-module.
2016-08-06 22:24:33 +09:00
FUJIWARA Katsunori
84bc1a274c demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.

For example:

  - it is assumed that extension X has "from P import M" for module M
    under package P with absolute_import feature

  - if importing module M is already delayed before loading extension
    X, loading module M in extension X is delayed until actually
    referring

    util, cmdutil, scmutil or so of Mercurial itself should be
    imported by "from . import M" style before loading extension X

  - otherwise, module M is loaded immediately at loading extension X,
    even if extension X itself isn't used at that "hg" command invocation

    Some minor modules (e.g. filemerge or so) of Mercurial itself
    aren't imported by "from . import M" style before loading
    extension X. And of course, external libraries aren't, too.

This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.

To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:

  1. import root module of "name" by system built-in __import__
     (referred as _origimport)

  2. recurse down the module chain for hierarchical "name"

     This logic can be shared with non absolute_import
     case. Therefore, this patch also centralizes it into chainmodules().

  3. and fall through to process elements in "fromlist" for the leaf
     module of "name"

     Processing elements in "fromlist" is executed in the code path
     after "if _pypy: .... else: ..." clause. Therefore, this patch
     replaces "if _pypy:" with "elif _pypy:" to share it.

At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.

IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.

This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-19 02:17:33 +09:00
timeless
93ae7771a2 tests: use debuginstall to retrieve hg version 2016-05-10 22:52:26 +00:00
Yuya Nishihara
73426f0951 dispatch: show deprecation warning if command has no attributes (issue5137)
norepo/optionalrepo/inferrepo were removed by e1563031f528, which would be
significant API change. This patch tries to avoid crash even if ancient
third-party extensions are enabled.
2016-01-09 22:46:26 +09:00
Jun Wu
ef33508a32 tests: explicitly flush output streams
Some tests fail while running with chg because they do not flush their output
streams. chgserver will make sure ui.flush is called after dispatch, but not
after {ui,repo}setup. For other non-ui streams, it should be explicitly
flushed since the request handler will use os._exit.
This patch adds explicit flushes in test-bundle2-format.t, test-extension.t
and test-obsolete.t. It will fix most test cases of them when running with chg.
2016-03-15 09:51:42 +00:00
liscju
64f1a9aa22 version: verbose list internal and external extension source (issue4731) 2016-02-05 13:20:23 +01:00
timeless
45b895c57d minirst: change hgrole to use single quotes
We decided to reserve double quotes for arguments to hg because cmd
does not like single quotes, so switch the outer quotes to single
2016-01-12 06:03:36 +00:00
Jun Wu
8663e10abb test-extension: do not depend on demandimport (issue5012)
When demandimport is disabled, the test will fail because extroot/foo.py uses
import outside PYTHONPATH. This is bad since we have a PyPy migration plan and
it does not support demandimport. Fix by setting PYTHONPATH.
2015-12-18 09:47:21 +00:00
timeless
fc1657cf34 help: make help deprecated mention the extension
before this, you got an empty list of extensions, which was unhelpful
2015-11-30 20:45:07 +00:00
Gregory Szorc
2afb6aff3e extensions: refuse to load extensions if minimum hg version not met
As the author of several 3rd party extensions, I frequently see bug
reports from users attempting to run my extension with an old version
of Mercurial that I no longer support in my extension. Oftentimes, the
extension will import just fine. But as soon as we run extsetup(),
reposetup(), or get into the guts of a wrapped function, we encounter
an exception and abort. Today, Mercurial will print a message about
extensions that don't have a "testedwith" declaring explicit
compatibility with the current version.

The existing mechanism is a good start. But it isn't as robust as I
would like. Specifically, Mercurial assumes compatibility by default.
This means extension authors must perform compatibility checking in
their extsetup() or we wait and see if we encounter an abort at
runtime. And, compatibility checking can involve a lot of code and
lots of error checking. It's a lot of effort for extension authors.

Oftentimes, extension authors know which versions of Mercurial there
extension works on and more importantly where it is broken.

This patch introduces a magic "minimumhgversion" attribute in
extensions. When found, the extension loading mechanism will compare
the declared version against the current Mercurial version. If the
extension explicitly states we require a newer Mercurial version, a
warning is printed and the extension isn't loaded beyond importing
the Python module. This causes a graceful failure while alerting
the user of the compatibility issue.

I would be receptive to the idea of making the failure more fatal.
However, care would need to be taken to not criple every hg command.
e.g. the user may use `hg config` to fix the hgrc and if we aborted
trying to run that, the user would effectively be locked out of `hg`!

A potential future improvement to this functionality would be to catch
ImportError for the extension/module and parse the source code for
"minimumhgversion = 'XXX'" and do similar checking. This way we could
give more information about why the extension failed to load.
2015-11-24 15:16:25 -08:00
Matt Mackall
5e1b4ad958 urls: bulk-change primary website URLs 2015-09-30 15:43:49 -05:00
liscju
c4c7beba44 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
information.

Extensions are printed sorted by extension name.
2015-09-10 16:53:07 +02:00
Pierre-Yves David
4595c06fb1 traceback: allow providing a local support contact point
The extensions blaming code is fine for casual users but pretty terrible for
corporate environments that can deploy a large amount of extensions to
unsuspecting users. Reports will likely blame a random "innocent" extension (in
our case crecord) and the hint in the message will triggers endless debug
attempts from the user.

We introduce a "ui.supportcontact" option that allow such big company to redirect
their users to their own support desk. This disables all extensions blaming and
just point people to the local support in all cases.
2015-09-11 12:45:19 -07:00
Matt Harbison
c3b634a166 extdiff: add a --patch argument for diffing changeset deltas
One of the things I missed the most when transitioning from versioned MQ to
evolve was the loss of being able to check that rebase conflicts were properly
resolved by:

  $ hg ci --mq -m "before"
  $ hg rebase -s qbase -d tip
  $ hg bcompare --mq

The old csets stay in the tree with evolve, but a straight diff includes all of
the other changes that were pulled in, obscuring the code that was rebased.
Diffing deltas can be confusing, but unless radical changes were made during the
resolve, it is very clear when individual hunks are added, dropped or modified.
Unlike the MQ technique, this can only compare a single pair of csets/patches at
a time.  Like the MQ method, this also highlights changes in the commit comment
and other metadata.

I originally tried monkey patching from the evolve extension, but that is too
complicated given that it depends on the order the two different extensions are
loaded.  This functionality is also useful when comparing grafts however, so
implementing it in the core is more than just convenience.

The --change argument doesn't make much sense for this, but it isn't harmful so
I didn't bother blocking it.  The -I/-X options are ignored because of a
limitation of cmdutil.export().  We'll fix that next.
2015-09-09 21:07:38 -04:00
Gregory Szorc
83818c1fca hg: establish a cache for localrepository instances
hgweb contained code for determining whether a cached localrepository
instance was up to date. This code was way too low-level to be in
hgweb.

This functionality has been moved to a new "cachedlocalrepo" class
in hg.py. The code has been changed slightly to facilitate use
inside a class. hgweb has been refactored to use the new API.

As part of this refactor, hgweb.repo no longer exists! We're very close
to using a distinct repo instance per thread.

The new cache records state when it is created. This intelligence
prevents an extra localrepository from being created on the first
hgweb request. This is why some redundant output from test-extension.t
has gone away.
2015-08-22 18:54:34 -07:00
Matt Harbison
400240f7c1 extdiff: add support for subrepos
Git and svn subrepo support is incomplete, because they don't support archiving
the working copy.
2012-07-15 12:43:10 -04:00
Pierre-Yves David
6ff877d809 test: make version based test-extensions failure more explanatory
A buggy __version__ content (usually from setup.py's hg being unable to read the
repo) can make this test fails in an obscure manner. We make the root of the
failure more explicit.
2015-03-10 11:01:10 -07:00
Ryan McElroy
54e6a6adbc extensions: allow extending command synopsis and docstring
Mercurial uses a synopsis string and the docstring of a command for the
command's help output. Today  there is no way for an extension that adds
functionality to a command to extend either of these help strings.

This patch enables appending to both the doctring and the synopsis, and adds
a test for this functionality. Example usage is shown in the test and is also
described in the docstring of extensions.wrapcommand().
2015-02-09 11:02:45 -08:00
Gregory Szorc
28755d2e9a dispatch: only check compatibility against major and minor versions (BC)
Extensions can declare compatibility with Mercurial versions. If an
error occurs, Mercurial will attempt to pin blame on an extension that
isn't marked as compatible.

While all bets are off when it comes to the internal API, my experience
has shown that a monthly/patch release of Mercurial has never broken any
of the extensions I've written. I think that expecting extensions to
declare compatibility with every patch release of Mercurial is asking a
bit much and adds little to no value.

This patch changes the blame logic from exact version matching to only
match on the major and minor Mercurial versions. This means that
extensions only need to mark themselves as compatible with the major,
quarterly releases and not the monthly ones in order to stay current and
avoid what is almost certainly unfair blame. This will mean less work
for extension authors and almost certainly fewer false positives in the
blame attribution.
2015-01-15 20:36:03 -08:00
Gregory Szorc
bd697301fe test-extension: use a realistic Mercurial version
Mercurial doesn't define the 3rd "patch" version field for major
releases. Don't use it in tests.
2015-01-15 20:03:48 -08:00
Gregory Szorc
db026aaaab test-extension: improve test readability
There was a mountain of text in this file that made reading the tests
difficult. Inserting some line breaks greatly improves the situation.
2015-01-15 19:47:06 -08:00
Chingis Dugarzhapov
3f0e231547 help: suggest '-v -e' to get built-in aliases for extensions (issue4461)
If extension name matches one of command names, suggest user to type
'hg help -v -e <extension>' to get full list of built-in aliases
2014-12-22 03:20:50 +01:00
Yuya Nishihara
ed7051c6c7 tests: write hgrc of more than two lines by using shell heredoc
Here document should be readable than repeating echo commands.
2014-11-04 23:41:46 +09:00
Matt Harbison
13f1cdf941 extdiff: drop the command alias without options example in the help text
In the dropped example, the extension would look for 'vdiff.diffargs' in the
configuration, and not finding it, would run kdiff3 without the configured
options.  That's not obvious to a new user who sees a kdiff3 configuration in
the prepackaged mergetools.rc file, and sees that kdiff3 still runs.  While it
is conceivable that the user wants a kdiff3 command that runs without the
preconfigured options, it is more likely what they want is this, which uses the
canned options:

    [alias]
    vdiff = kdiff3

    [extdiff]
    kdiff3 =

We could mention alias here, but that seems like it belongs elswhere.
2014-11-02 15:27:15 -05:00
Matt Harbison
41a84ec470 extdiff: allow a preconfigured merge-tool to be invoked
There are three ways to configure an extdiff tool:

    1) cmd.tool = (/path/to/exe optional)
    2) tool = (path/to/exe optional)
    3) tool = sometool someargs

Previously, if no executable is specified in the first two forms, the named tool
must be in $PATH, or the invocation fails.  Since the [merge-tools] section
already has the path to the diff executable, and/or the registry keys to find
the executable on Windows, reuse that configuration for forms 1 and 2 instead of
failing.  We already fallback to [diff-tools] and then [merge-tools] for program
arguments if they aren't specified in the [extdiff] section.

Since this additional lookup only occurs if an executable is not on the $PATH
for the named tool, this is backwards compatible.  For now, we assume the user
knows what he is doing if a path is provided.

This change allows a configuration file like this (assuming beyondcompare3 is
configured in merge-tools), instead of hardcoding system specific a path:

    [extdiff]
    beyondcompare3 =
2014-10-31 21:34:55 -04:00
Augie Fackler
a5ddb1dcfe tests: use $PYTHON instead of hardcoding python
This makes running the testsuite with pypy possible.
2014-10-15 15:35:59 -04:00
Matt Mackall
d2e240d48e help: normalize helplist hints 2014-08-12 04:11:32 -05:00
Matt Mackall
68762ac0d2 help: fold repeatable option message into option table header
This will hopefully conserve some limited user attention.
2014-08-12 04:00:42 -05:00
Matt Mackall
e6f86f6aa5 help: normalize hint about enabling extensions 2014-08-12 03:18:50 -05:00