Commit Graph

39 Commits

Author SHA1 Message Date
Jun Wu
d0cf5aacfa dispatch: remove Python alias handling
Summary:
This removes Python alias handling so the alias handling is done entirely in
Rust.

There are some subtle changes - alias using prefix mathcing to ambiguous
commands will not show other aliases. Hopefully that won't be a big issue.
Users can always avoid prefix matching in alias to solve the issue.

Reviewed By: sfilipco

Differential Revision: D16733270

fbshipit-source-id: 54a4915d49c2b2f6e8664a225a9c0f25e1c38d17
2019-08-19 19:27:29 -07:00
Jun Wu
38a0a8ff95 dispatch: translate shell aliases to hg commands
Summary:
Translate alias like `echo = !echo foo` to `echo = debugrunshell '--cmd=echo
foo'`.  This enables the Rust shell alias handling code path. The Python
shell alias handling was removed.

The majority part of `test-alias.t` still passes. That includes some "weird"
shell alias features.

This has some test changes, through:

- `$HG_ARGS` is no longer supported. And tests depending on it are changed.
  `$@` will be the alternative for most cases.
  Practically, our `$HG_ARGS` users seem to come from
  https://stackoverflow.com/a/833387, which does not seem to use `$HG_ARGS`
  correctly (since `$HG_ARGS` includes the command name).
- Early-parse commands (ex. `hg log -b '--config=alias.log=!echo
  howdy'`) no longer works.
- The warning `--repository ignored` now shows up, since `debugrunshell`
  is a "no-repo" command.
- Global flags can no longer be used after shell aliases. Supporting them
  is a head-ache.
- `circular alias` error message changed because it's now reported by the Rust
  code, which does not report all alias names right now.

Reviewed By: sfilipco

Differential Revision: D16733266

fbshipit-source-id: b06bc7f8fc2f1c2701a17407d6a1656e17e4ba55
2019-08-19 19:27:28 -07:00
Jared Bosco
95b0be5bdc dispatch: remove strictflags and related tests
Reviewed By: quark-zju

Differential Revision: D15833690

fbshipit-source-id: 3469d8def660b116c0f82c674a19f06b18f29211
2019-07-20 01:06:32 -07:00
Aida Getoeva
f2a68e1174 selectivepull: show hint in hg log to fetch remotename
Summary: When selective pull will be enabled, `hg log` won't be able to show any information about the remote bookmarks that are not in subscriptions for particular user. So we need to hint the user that they may want to explicitly pull the remote bookmark first, if hg log fails to find it.

Reviewed By: quark-zju

Differential Revision: D15516462

fbshipit-source-id: 5be77b0048d8e175a737f76a8e89768f4c837f60
2019-06-10 09:31:15 -07:00
Durham Goode
ad813edcbd treemanifest: enable treemanifest by default in tests
Summary:
Now that all our repos are treemanifest, let's enable the extension by
default in tests. Once we're certain no one needs it in production we'll also
make it the default in core Mercurial.

This diff includes a minor fix in treemanifest to be aware of always-enabled
extensions. It won't matter until we actually add treemanifest to the list of
default enabled extensions, but I caught this while testing things.

Reviewed By: ikostia

Differential Revision: D15030253

fbshipit-source-id: d8361f915928b6ad90665e6ed330c1df5c8d8d86
2019-05-28 03:17:02 -07:00
Jun Wu
2dc2a3d2a2 dispatch: do not show help on CommandError
Summary:
CommandError happens if there is an unknown command flag, or a required
argument is missing. The old behavior is to print an error message to
stderr, then start the pager with the command help printed to stdout.

There are 2 problems with that approach:
1. When using mosh, a long help text might flush the actual error to out of the
   screen. The error message will be missed.
2. When captured in shell scripts, the help text printed to stdout would be
   captured, which is almost always undesirable.

The actual motivation of this change is for 2. Zsh themes like bullet-train [1]
uses `hg id -b 2>/dev/null` and we'd like to remove `id -b` support. After that,
the command should not polluate stdout with help text.

[1]: bd88ade263/bullet-train.zsh-theme (L102)

Differential Revision: D14151200

fbshipit-source-id: edd38e91115f96929438379aa2e40edfba560b41
2019-02-20 18:44:35 -08:00
Mark Thomas
c6c99b4777 configparser: update pest to 2.1.0
Summary:
Update pest to 2.1.0.

This version has a new behaviour for parser error messages: the line feed at
the end of the line is shown in the error output.

Reviewed By: wez

Differential Revision: D13671099

fbshipit-source-id: b8d1142a44a56a0b21b3b72cf027f3f8a30f421e
2019-01-16 03:52:09 -08:00
Mark Thomas
36c697f8e0 help: new default help
Summary:
Replace the default help for Mercurial with a curated list of interesting
commands, categorized by their use case.

Reviewed By: phillco

Differential Revision: D10356916

fbshipit-source-id: 65e578a4bfde7b0ad04e7107f4e77d8ea882d78a
2018-10-15 09:37:18 -07:00
Jun Wu
a987ecb9b2 ui: use Rust config parser in Mercurial
Summary:
Switch `ui.load` and `ui.readconfig` to use the Rust config parser.
`ui` now no longer depends on `config.config` or `rcutil`.

Pest's error messages are fancier, thus most test changes.

For the fbsource repo, debugshell shows the new code is 10+x faster:

On laptop:

Before:

  In [1]: %timeit m.ui.ui.load()
  10 loops, best of 3: 27.8 ms per loop

After:

  In [1]: %timeit m.ui.ui.load()
  100 loops, best of 3: 1.85 ms per loop

On devserver:

Before:

  In [1]: %timeit m.ui.ui.load()
  100 loops, best of 3: 16.8 ms per loop

After:

  In [1]: %timeit m.ui.ui.load()
  1000 loops, best of 3: 1.28 ms per loop

Since `ui._rcfg` is no longer copy-on-write, there is concern about `ui.copy()`
performance. It is faster too (on devserver):

Before:

  In [1]: %timeit ui.copy()
  1000 loops, best of 3: 198 µs per loop

After:

  In [1]: %timeit ui.copy()
  10000 loops, best of 3: 157 µs per loop

The old `ui.py` was copied to `legacyui.py` and can replace the new `ui.py` if
a config file exists on the system.  This provides a way to switch back to the
old config parser in case of emergency.

Reviewed By: mitrandir77

Differential Revision: D8887375

fbshipit-source-id: 2951ca622c77bf41187ad5c5cab3445cda0dc519
2018-08-23 17:52:52 -07:00
Matt Harbison
7d8bebd9c1 tests: remove (glob) annotations that were only for '\' matches
# skip-blame because this was mechanically rewritten the following script.  I
ran it on both *.t and *.py, but none of the *.py changes were proper.  All *.t
ones appear to be, and they run without addition failures on both Windows and
Linux.

  import argparse
  import os
  import re

  ap = argparse.ArgumentParser()
  ap.add_argument('path', nargs='+')
  opts = ap.parse_args()

  globre = re.compile(r'^(.*) \(glob\)(.*)$')

  for p in opts.path:
      tmp = p + '.tmp'
      with open(p, 'rb') as src, open(tmp, 'wb') as dst:
          for line in src:
              m = globre.match(line)
              if not m or '$LOCALIP' in line or '*' in line:
                  dst.write(line)
                  continue
              if '?' in line[:-3] or ('?' in line[:-3] and line[-3:] != '(?)'):
                  dst.write(line)
                  continue
              dst.write(m.group(1) + m.group(2) + '\n')
      os.unlink(p)
      os.rename(tmp, p)
2017-12-10 22:50:57 -05:00
Matt Harbison
d2dab77cb0 tests: add a substitution for ENOENT/ERROR_FILE_NOT_FOUND messages
Automatic replacement seems better than trying to figure out a check-code rule.
I didn't bother looking to see why the error message and file name is reversed
in the annotate and histedit tests, based on Windows or not.

I originally had this as a list of tuples, conditional on the platform.  But
there are a couple of 'No such file or directory' messages emitted by Mercurial
itself, so unconditional is required for stability.  There are also several
variants of what I assume is 'connection refused' and 'unknown host' in
test-clone.t and test-clonebundles.t for Docker, FreeBSD jails, etc.  Yes, these
are handled by (re) tags, but maybe it would be better to capture those strings
in order to avoid whack-a-mole in future tests.  All of this points to using a
dictionary containing one or more strings-to-be-replaced values.
2017-12-02 19:33:34 -05:00
Yuya Nishihara
9bf6236a83 fancyopts: fix handling of "--" value in earlygetopt() 2017-11-25 17:30:50 +09:00
Yuya Nishihara
502549c773 fancyopts: use getopt.gnu_getopt()
The issue described in the docstring has been fixed since Python 20ab2260dc93,
which is in 2.7.

https://hg.python.org/cpython/rev/20ab2260dc93
https://bugs.python.org/issue4458

This fixes the handling of '--' value.
2017-11-24 01:09:00 +09:00
Yuya Nishihara
2e53122de6 dispatch: alias --repo to --repository while parsing early options
This prepares for replacing old _early*opt() functions. My initial attempt
was to extend options table to support 'repository|repo' syntax. It worked,
but seemed too invasive. So I decided to add an optional argument to
fancyopts() instead.

This also changes the nevernegate dict to be keyed by a canonical_name,
not by an option-name for clarity.
2017-11-25 17:03:52 +09:00
Matt Harbison
c0662d6461 tests: trivial fixes for Windows 2017-12-02 17:52:53 -05:00
Yuya Nishihara
5ff5d9b38c dispatch: add HGPLAIN=+strictflags to restrict early parsing of global options
If this feature is enabled, early options are parsed using the global options
table. As the parser stops processing options when non/unknown option is
encountered, it won't mistakenly take an option value as a new early option.
Still "--" can be injected to terminate the parsing (e.g. "hg -R -- log"), I
think it's unlikely to lead to an RCE.

To minimize a risk of this change, new fancyopts.earlygetopt() path is enabled
only when +strictflags is set. Also the strict parser doesn't support '--repo',
a short for '--repository' yet. This limitation will be removed later.

As this feature is backward incompatible, I decided to add a new opt-in
mechanism to HGPLAIN. I'm not pretty sure if this is the right choice, but
I'm thinking of adding +feature/-feature syntax to HGPLAIN. Alternatively,
we could add a new environment variable. Any bikeshedding is welcome.

Note that HGPLAIN=+strictflags doesn't work correctly in chg session since
command arguments are pre-processed in C. This wouldn't be easily fixed.
2017-11-23 22:17:03 +09:00
Yuya Nishihara
52b06fe73d dispatch: verify result of early command parsing
Before, early options were stripped from args, and because of this, some
kind of parsing errors weren't reported. For example,

  $ hg ci -m -Ra file

would execute "hg ci -m file" in repository "a".

This patch fixes the issue by parsing early options again by real getopt-based
parser, and verifying the results. If the early parsing appears wrong, hg just
aborts. The current error message seems not nice, and should be improved, maybe
in V2 or follow-up.

Note that this isn't a security feature because we can still do anything by
using shell aliases.
2017-11-11 12:40:13 +09:00
Yuya Nishihara
82ae4401fe dispatch: abort if early boolean options can't be parsed
Perhaps we'll need to restrict the parsing rules of --debugger and --profile,
where this patch will help us know why the --debugger option doesn't work.

I have another series to extend this feature to --config/--cwd/-R, but even
with that, shell aliases can be used to get around the restriction.
2017-11-11 14:02:41 +09:00
Yuya Nishihara
8f01395e02 dispatch: stop parsing of early boolean option at "--" 2017-11-10 22:27:26 +09:00
Yuya Nishihara
7137d3d976 dispatch: do not drop unpaired argument at _earlygetopt()
Before, "hg log -R" just worked.
2017-11-11 12:09:19 +09:00
Jun Wu
04a084983c test-dispatch: stabilize the test
When cwd is removed and `hg` is executed, some shells may run `getcwd`
before forking and executing, some may not do it, some may print a
different error message.

The test should be shell-independent so let's just avoid checking the error
message.

Differential Revision: https://phab.mercurial-scm.org/D1282
2017-11-01 14:22:26 -07:00
Saurabh Singh
246c9d85ba test-dispatch: make the test compatible with chg
The test is broken when run with chg because it prints a different
error message when chg is running. This commit fixes the test by special casing
for chg.

Test Plan:
Ran the test 'test-dispatch.t' with and without '--chg' option.

Differential Revision: https://phab.mercurial-scm.org/D1126
2017-10-16 17:14:21 -07:00
Jun Wu
d91707e2a4 hgweb: do not import uuid immediately to avoid its side effect
With hgdemandimport disabled (chg's case), `import uuid` has an immediate
side effect calling `ctypes.util.find_library` trying to locate the
`libuuid` library.  This happens at `import` time before `dispatch.run()`.
The call trace is like:

  File "hg/hg", line 54, in <module>
    from mercurial import (
  File "hg/mercurial/dispatch.py", line 24, in <module>
    from . import (
  File "hg/mercurial/commands.py", line 23, in <module>
    from . import (
  File "hg/mercurial/help.py", line 33, in <module>
    from .hgweb import (
  File "hg/mercurial/hgweb/__init__.py", line 20, in <module>
    from . import (
  File "hg/mercurial/hgweb/hgweb_mod.py", line 14, in <module>
    from .common import (
  File "hg/mercurial/hgweb/common.py", line 15, in <module>
    import uuid
  File "/usr/lib64/python2.7/uuid.py", line 404, in <module>
    lib = ctypes.CDLL(ctypes.util.find_library(libname))

The problem is, `ctypes.util.find_library` will execute
`sh -c '/sbin/ldconfig -p 2>/dev/null'` on Python <= 2.7.12. The output of
`sh` may pollute the terminal:

  shell-init: error retrieving current directory: getcwd: cannot access
  parent directories: No such file or directory

This patch moves `import uuid` so its side-effect can only happen after the
cwd check in `dispatch._getlocal`. Therefore the terminal won't be
polluted by importing `uuid`.

Differential Revision: https://phab.mercurial-scm.org/D1024
2017-10-11 21:24:32 -07:00
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
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
106c32f507 help: improve command summary hint
This adds our normal hint parentheses, corrects the command syntax
(consider config), and corrects the fullness of help you'll get.
2014-08-12 03:09:26 -05:00
Mads Kiilerich
4f2a779466 tests: fix for windows - slashes and no serve 2013-01-30 19:40:07 +01:00
Mads Kiilerich
5584e7ca16 dispatch: show empty filename in OSError aborts
Mercurial would sometimes exit with:
  abort: No such file or directory
where str of the actual OSError exception was the more helpful:
  [Errno 2] No such file or directory: ''

The exception will now always show the filename and quote it:
  abort: No such file or directory: ''
2013-01-07 02:00:29 +01:00
Mads Kiilerich
33fe5e6036 test-dispatch.t: remove incorrect "cd $dir"
A line that should have been removed in 8041254f9d0f.
2013-01-06 04:04:44 +01:00
Mads Kiilerich
db42f91a88 tests: convert some 'hghave no-outer-repo' to #if
In some places we instead use 'hg init' to create a well-known outer repo
without any special extensions or other config settings.
2012-06-20 23:41:21 +02:00
Matt Mackall
4204f3ffa5 help: use RST to format option lists 2011-09-21 13:00:48 -05:00
Nicolas Dumazet
561d5dd9fb tests: move test-issue436 in test-dispatch where fancyopts is tested 2011-04-30 17:38:06 +02:00
Matt Mackall
a33ce77f33 dispatch: improve repository not found message
This should help clarify what the problem is in various problematic
cases like ssh.
2011-04-20 14:28:40 -05:00
Adrian Buehlmann
3efb31d590 help: do not show full help text for command on option errors
Example

  $ hg clone --jump foo bar
  hg clone: option --jump not recognized
  hg clone [OPTION]... SOURCE [DEST]

  make a copy of an existing repository

  options:

   -U --noupdate           the clone will include an empty working copy (only a
                           repository)
   -u --updaterev REV      revision, tag or branch to check out
   -r --rev REV [+]        include the specified changeset
   -b --branch BRANCH [+]  clone only the specified branch
      --pull               use pull protocol to copy metadata
      --uncompressed       use uncompressed transfer (fast over LAN)
   -e --ssh CMD            specify ssh command to use
      --remotecmd CMD      specify hg command to run on the remote side
      --insecure           do not verify server certificate (ignoring
                           web.cacerts config)

  [+] marked option can be specified multiple times

  use "hg help clone" to show the full help text

Motivation for this change

  If the user already has specified the command, he probably already knows
  the command to some extent. Apparently, he has a problem with the options,
  so we show him just the synopsis with the short help and the details about
  the options, with a hint on the last line how to get the full help text.

Why is Mercurial better with this change?

  Experts who just forgot about the details of an option don't get that
  much text thrown at them, while the newbies still get a hint on the last
  line how to get the full help text.
2011-04-17 11:37:11 +02:00
Matt Mackall
bf9417da11 tests: exit 0 no longer needed on unified tests 2010-09-17 17:03:04 -05:00
Matt Mackall
08439e0f2d tests: add exit codes to unified tests 2010-09-16 17:51:32 -05:00
Adrian Buehlmann
9686dc8dba tests: unify test-dispatch 2010-09-02 17:13:23 +02:00