Commit Graph

91 Commits

Author SHA1 Message Date
Jun Wu
a55fe385eb dispatch: change 'no repository found' message
Summary:
Change the message so it looks more like a user error, not a crash in the
software. This is motivated by some people reporting `hg rage` crash with
`abort: no repository found` messages.

Reviewed By: sfilipco

Differential Revision: D17292658

fbshipit-source-id: 9988f54f2ff8fd48949bcd35c13309c117f3afc6
2019-09-10 18:29:50 -07:00
Jun Wu
adbe2b2b32 alias: ignore alias definitions with ":" in name
Summary:
Aliases with `:doc` in name are not real commands. Do not treat them as
commands.

The upstream patch https://phab.mercurial-scm.org/D5087 added other metadata
including `:help` and `:category`. We might end up having some in the future
so I blacklisted names with `:` in them, not just `:doc`.

Reviewed By: chadaustin

Differential Revision: D16955596

fbshipit-source-id: b6f3e1129b632e0ba43c800e7e6fdd2b52d3b40c
2019-08-21 21:13:38 -07:00
Jun Wu
b6101a12e0 clidispatch: rework error handling
Summary:
Change error type in clidispatch from `DispatchError` to `failure::Error`.

Pros:
- `failure` will attach a backtrace for free. (otherwise, backtrace handling is
  manual)
- Wrapping other errors (ex. `io::Error`, `cliparser::Error`) is optional.
  (otherwise, wrapping other errors is mandatory, and needs to be careful to
  not lose information)

Cons:
- No longer able to enumerate *all* possible error types. (but can still
  downcast to specific errors)

This seems to be a good tradeoff especially because of the backtrace handling - I
ran into a few issues where the location where the error happened really helped
debugging.

Since we can no longer enumerate all possible error types, the enum was changed
to individual structs to make the code shorter (ex. the struct can be downcasted
directly, instead of down-casting to the enum, then matching its variant).

The `HighLevelError` handling was simplified and moved to `hgmain`.

The new code path falls back to Python less aggressively, therefore some behaviors
were tweaked (ex. `-R` takes a bundle path).

Reviewed By: sfilipco

Differential Revision: D16796400

fbshipit-source-id: 1b17eb8d62503644b118c6b799778182bf222538
2019-08-21 12:59:28 -07:00
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
2f3cf9b23b dispatch: do not show help on UnknownCommand
Summary:
Similar to D14151200, instead of printing a long help that might flush out
important messages, make the error short but still point the user to `hg help`.

This makes the error message much shorter, and make the test change by the
upcoming diff smaller.

Besides, we no longer check disabled extensions, as we don't expect users to
tweak extension config by themselves.

Reviewed By: sfilipco

Differential Revision: D16733273

fbshipit-source-id: b39bd4b2af6f315273484ec582094609b8e331ae
2019-08-19 19:27:28 -07:00
Jun Wu
37b7928dc8 help: resolve aliases using Rust
Summary:
Resolve aliases directly in command help. This removes the dependency of the
Python alias handling.

There are some minor behavior changes. But they look reasonable.

Reviewed By: sfilipco

Differential Revision: D16733276

fbshipit-source-id: ad97def2c60828236bbd8784ffd8202abfdeeb15
2019-08-19 19:27:28 -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
Jun Wu
53e9fbd706 test-alias: make shell alias tests easier to read
Summary:
The shell alias tests are hard to read because:

- It uses `cat << EOF`, which will escape the heredoc block.
- It uses `sh -c`, which adds another layer.

Change `EOF` to `'EOF'` to prevent escaping heredoc, and remove `sh -c` to make
the test easier to read. The `escaped3` test now works as expected.

Reviewed By: sfilipco

Differential Revision: D16819451

fbshipit-source-id: 687e9ce78dfed7d76b53cf90e6d871dffd3ab84d
2019-08-19 19:27:28 -07:00
Jun Wu
bd75a8e099 cliparser: fix regression on error message
Summary:
Fix the regression caused by D16557266 on error message. The fix is not the
most efficient, though. But it should restore the behavior.

Reviewed By: singhsrb

Differential Revision: D16557654

fbshipit-source-id: 2eb6956f99c931f94201b875c8bebb2219a794f0
2019-07-30 08:43:39 -07:00
Jun Wu
bf5047760d test-alias: update test showing a regression
Summary:
The last diff D16557266 caused a regression on the error message. Update the
test to show that.

Reviewed By: singhsrb

Differential Revision: D16557653

fbshipit-source-id: ce4a039f4c91a7bd61ea8e570de960880abae937
2019-07-30 01:10:33 -07:00
Jun Wu
72e3fc1d9a cliparser: simplify expand_aliases a bit
Summary:
The loop body can be changed to reduce some identation.

This changes the behavior a bit - an alias expanding to an emtpy string is now
an error. That's consistent with the original behavior.

Reviewed By: kulshrax

Differential Revision: D16530516

fbshipit-source-id: 3f5c2ebe9d8d1727cac706e4ff11f2678567c525
2019-07-29 19:35:28 -07:00
Jun Wu
5dd0629478 cliparser: add an error type about illegal alias
Summary:
When the alias cannot be split via shlex::split, raise an error directly
instead of silently ignoring it and fallback to Python error handling.

Reviewed By: kulshrax

Differential Revision: D16530519

fbshipit-source-id: d81534b198555b256f062dc4e6520fa40ace7700
2019-07-29 19:35:28 -07:00
Jared Bosco
93949f4629 dispatch: replace alias expansion and fancyopts parsing call with native rust
Summary:
Replace the second to last fancyopts call with pure rust code parsing and error handling.

Make slightly nicer help messages for ambiguous commands instead of just saying every possible command possible.

Reviewed By: quark-zju

Differential Revision: D16063049

fbshipit-source-id: bfd9e58649b1de2d3485069ce8d5646927bc77f4
2019-07-20 01:06:34 -07:00
Jared Bosco
5f02e5cd5c dispatch: replace _parse's call to fancyopts with native code
Summary: Replacing another fancyopts call to be parsed by native Rust code.  This diff introduces slightly hacky feeling behavior in order to handle cycles and resolving aliases, but will be fixed in a follow-up diff where Rust will fully expand the aliases completely removing the need for this confusing alias resolving, chaining, and execution.

Reviewed By: quark-zju

Differential Revision: D15902758

fbshipit-source-id: 11d9a479989a23de09bf96f8020d2fded6c06351
2019-07-20 01:06:33 -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
Durham Goode
69ebfd6bf7 template: remove manifest rev number from templates
Summary:
With treemanifest we no longer have manifest rev numbers, so let's drop
them from the templates. This let's us convert a few more tests to treeonly.

In theory automation may parse this, but I kinda doubt anyone parses the
manifest node from this.

Reviewed By: xavierd

Differential Revision: D15296141

fbshipit-source-id: a4d2194bd9604867cd9958509bcd2e6513a72494
2019-05-22 08:37:10 -07:00
Jun Wu
e188aff028 revset: make "branch(x)" equvilant to "all()"
Summary:
All commits belong to `default` branch. Therefore `branch(x)` can be seen as
just `all()`, assuming `x` is a valid name.

This removes the only user of `repo.revbranchcache`.

In a later step, branch related features will be moved to an extension so the
code becomes separate and features are optional.

Reviewed By: sfilipco

Differential Revision: D14180594

fbshipit-source-id: 9dc52743f1b69a1838114c8c0de5fc69383dc41e
2019-02-22 21:02:41 -08: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
Jun Wu
f752c4dd75 commands: deprecate "hg id -b"
Summary:
There are still users of "hg id -b", namely shell prompt scripts.
However, it seems fine to remove "branch" from the formatted (JSON or other
formats) output.

Reviewed By: ikostia

Differential Revision: D14076296

fbshipit-source-id: a77f4b9e73161d322da3f1bdec993082ac463939
2019-02-14 17:44:40 -08:00
Jun Wu
fbccd19ed7 patchbomb: remove the extension
Summary:
`test-patchbomb.t` uses named branches and does not look simple to fix.
We don't use email patches internally, and it's not hard to write scripts
around `hg export`. Therefore drop the extension and its tests.

Reviewed By: singhsrb

Differential Revision: D13978577

fbshipit-source-id: 19867ae68c19c996bfce064eb2234705939db9ea
2019-02-12 21:45:10 -08:00
Jun Wu
9dc21f8d0b codemod: import from the edenscm package
Summary:
D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`.
That has nasty problems if both `import mercurial` and
`import edenscm.mercurial` are used, because Python would think `mercurial.foo`
and `edenscm.mercurial.foo` are different modules so code like
`try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)`
would fail to handle the `edenscm.mercurial` version. There are also some
module-level states (ex. `extensions._extensions`) that would cause trouble if
they have multiple versions in a single process.

Change imports to use the `edenscm` so ideally the `mercurial` is no longer
imported at all. Add checks in extensions.py to catch unexpected extensions
importing modules from the old (wrong) locations when running tests.

Reviewed By: phillco

Differential Revision: D13868981

fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
2019-01-29 17:25:32 -08:00
Jun Wu
ee754d941a hgext: drop support for thirdparty default extensions
Summary:
Our codebase is already unfriendly to 3rd-party extensions and we will likely
break the compatibility as part of revisising / replacing components in Rust
anyway. So just stop supporting `--config extensions.3rdpartyfoo=`.

Note `--config extensions.3rdpartyfoo=foo.py` still works.

This also makes `ImportError` more meaningful. Previously, when `hgext.foo`
imports `bar` which does not exist, the error is "cannot import foo", while
it should really be "cannot import bar". That is because extensions.py falls
back to import `hgext3rd.foo`, and `foo`. Now extensions.py only tries
`hgext.foo` and will suface the right error.

Reviewed By: DurhamG

Differential Revision: D13440400

fbshipit-source-id: c659f6d05abbc0d09f2811f36c0dc31e49491f19
2018-12-12 18:54:22 -08:00
Marla Azriel
96cb1050bc commands: update help summary text
Summary: Updated the global help summaries that are displayed for each command when you run 'hg help' and fixed corresponding tests

Reviewed By: markbt, kulshrax

Differential Revision: D12832280

fbshipit-source-id: 950dad1c805feab573d7d0182da523ae12299d3b
2018-11-07 19:59:47 -08:00
Aida Getoeva
8940a7c464 uncommit: move to core
Summary: Moving extension `uncommit` to the core.

Reviewed By: quark-zju

Differential Revision: D10447651

fbshipit-source-id: 2ccf7db858b78e0811ffef742c82237259492719
2018-10-30 08:00:05 -07:00
Phil Cohen
f2a3798dfa commands: rename hg grep to hg histgrep
Summary:
tweakdefaults renamed core hg's `grep` to `histgrep`, and added a `hg grep` that behaves more like `git grep`, searching the working copy. This diff folds those changes into core.

The config changes from

```
[tweakdefaults]
allowfullrepohistgrep = False
```

to

```
[histgrep]
allowfullrepogrep = False
```

Reviewed By: quark-zju

Differential Revision: D10435279

fbshipit-source-id: ad3d1da5824511a612111715e46119d70066050f
2018-10-25 14:54:22 -07:00
Marla Azriel
6e0cece004 commands: update help text for pull and rebase
Summary: Updated help text for hg pull and hg rebase

Reviewed By: markbt

Differential Revision: D10446929

fbshipit-source-id: a81e186398cda02f58df95e6f2613b3f7457d9ed
2018-10-23 11:41:07 -07:00
Durham Goode
8e20e191b5 tests: fix alias test to deal with long hgrc paths
Summary:
On OSX the path to the hgrc can be so long it word wraps. Let's update
the test to accomodate the extra line.

Reviewed By: quark-zju

Differential Revision: D10453508

fbshipit-source-id: 5ba9db86f8475ab31ddb4b0e32da4feeeb8b5ce8
2018-10-18 14:43:56 -07:00
Mark Thomas
1bf045df79 help: implement configurable documentation for aliases
Summary:
Aliases can be additionally configured with documentation by adding an entry of
the form:

```
[alias]
aliasname:doc = help text
```

The help text for the alias will be displayed if the user runs `hg help
aliasname`, and in the list of commands when the user runs `hg help commands`.

Reviewed By: phillco

Differential Revision: D10428399

fbshipit-source-id: 14338902fce6efab4c8d3b2541cdcf5b15385784
2018-10-17 12:22:53 -07:00
Mark Thomas
1cc0fedc1c help: reorganise help commands
Summary:
Reorganise the top-level help commands to more useful categories, allowing them
to be listed in a custom order.

Reviewed By: phillco

Differential Revision: D10423184

fbshipit-source-id: 17f02ae201493397a448d108e781eca28a7b1d44
2018-10-17 09:58:06 -07:00
Mark Thomas
f18bd9714d help: improve some help messages
Summary: Make a few help messages clearer.

Reviewed By: phillco

Differential Revision: D10356915

fbshipit-source-id: 277d4cecbd17b647d6dd01209ff6f93a926d37d4
2018-10-15 09:37:19 -07: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
Saurabh Singh
3d88ec0346 record: move extension into core
Summary:
This extension exposes only the `record` command which can be easily
moved to core. This commit achieves the same.

Reviewed By: ikostia

Differential Revision: D10360759

fbshipit-source-id: 25f0c46aa3fa9b19ab8ba03a6b4e8598bc003c7a
2018-10-12 11:16:46 -07:00
Saurabh Singh
cd49463e2c show: move the extension into core
Summary:
The extension only offers one command i.e. `show` which can move into
core.

Reviewed By: ikostia

Differential Revision: D10302192

fbshipit-source-id: 9473ec8c80e52506e1b7de62b2c90a51c29419c1
2018-10-12 07:03:11 -07:00
Phil Cohen
917604f2f5 tests: fold tglog into tinit; standardize
Summary:
Like D9323267, hg tests commonly reinvent common aliases to render the DAG, and they often differ very slightly. This makes adding a test require more boilerplate, and reading a test in a foreign new area slightly more overhead.

Let's standardize these to reduce the copypasta.

It's necessary to define this as a shell function instead of an hgrc alias to prevent tests that list aliases from printing it. Plus that enforces a nice separation of test/stdlib logic.

Bookmarks and branches are easy enough to add since they're empty if not used. A good number added `{phase}` -- I renamed this to `tglogp`.

Reviewed By: quark-zju

Differential Revision: D9347072

fbshipit-source-id: 6aac7de3e65d2295a7ebecd2ab30901709af3ff1
2018-08-16 10:53:43 -07:00
Phil Cohen
ed708bc77f tests: fix for D6717635 2018-01-12 16:58:28 -08:00
Yuya Nishihara
86043c7487 dispatch: replace _earlygetopt(strip=True) with new parser
The execution order in cmdalias.__init__() is adjusted to set stripped args
to self.givenargs, which is no longer updated in place.
2017-11-23 23:18:56 +09:00
Jun Wu
0802429abd test-alias: make it compatible with chg
ad1bdea (dispatch: defer environment variable resolution in alias commands
(BC), 2016-05-06) made environment variables lazily resolved. But after
D805 (alias: make alias command lazily resolved 2017-09-23), alias
resolution happened after uisetup, which breaks the test for chg.

`uisetup` is known to behave different in chg. Let's verify the feature
without using `*setup`.

Differential Revision: https://phab.mercurial-scm.org/D912
2017-10-02 16:48:58 -07:00
timeless
5fd9e9e1b5 help: use single quotes in use warning 2016-09-20 23:47:46 +00:00
Jun Wu
318fb5a998 dispatch: defer environment variable resolution in alias commands (BC)
Before this patch, if there are environment variables in an alias command,
they will be expanded immediately when we first see the alias.

This will cause issues with chg, because environment variable updates will
not propagate to expanded arguments.

This patch makes "args" of "cmdalias" a property that will be calculated
every time when accessed.
2016-05-07 00:16:58 +01:00
Yuya Nishihara
27d625a5ea dispatch: copy inferrepo attribute to alias commands
The other attributes are copied. Let's do the same for the inferrepo.
2016-01-04 21:40:05 +09:00
Bryan O'Sullivan
ca96e23cd1 dispatch: report similar names consistently 2016-01-04 21:52:44 -08:00
Augie Fackler
dbd43329ce dispatch: offer suggestions of similar-named commands
When suggestions are available, we show those suggestions instead of
showing some help output.
2015-02-10 15:59:12 -05:00
FUJIWARA Katsunori
6fd4318051 hg.bat: return exit code explicitly for indirect invocation
When "hg.bat" is invoked via interactive shell "cmd.exe" on Windows,
it can store own exit code into ERRORLEVEL correctly, regardless of
explicit "exit" statement in it: "cmd.exe" seems to hold ERRORLEVEL
updated by the last command in the batch file (= "python hg", in
"hg.bat" case).

On the other hand, "hg.bat" is invoked indirectly via
"subprocess.Popen" (e.g. shell alias, hooks, hgclient and so on), the
parent process always receives exit code 0 from spawned "hg.bat":
batch files on Windows seem not to be really spawned like as shell
scripts on UNIX, but to be executed in the "cmd.exe" process.

This patch returns exit code explicitly for indirect invocation.

"/b" should be specified for "exit" to prevent "cmd.exe" from being
terminated when "hg.bat" is invoked interactively from it.
2015-01-22 00:07:06 +09:00
anatoly techtonik
6abd5e7bc0 merge: be precise about what merged into what in short desc 2014-11-26 17:22:09 +03:00
FUJIWARA Katsunori
503f499347 tests: use "%HG_ARGS%" in shell alias on Windows instead of "$HG_ARGS"
Before this patch, a part of "test-alias.t" fails unexpectedly on
Windows environment, because "cmd.exe" can't evaluate "$HG_ARGS"
expression in shell alias correctly.

This patch uses "%HG_ARGS%" in shell alias on Windows instead of
"$HG_ARGS" to expand it correctly.
2014-10-28 00:19:18 +09:00
Jordi Gutiérrez Hermoso
a7cc108c20 log: do not hide the public phase in debug mode (BC)
When 62900f2373fa introduced phases to the `hg log --debug` output, it
also disabled outputting public phase. At the same time, it always
shows phases in the default template, `hg log --debug -T default`.
Those two should produce the same output, but they don't.

I think it makes a lot more sense to always show all phases. There's
already loss of backwards compatibility in this case when using a
newer hg on an old hg repo, since draft commits will show up in the
output of `hg log --debug`.

Finally, I just don't think that any sort of information should be
hidden with --debug. This flag should be about showing as much
information as possible.
2014-10-04 16:28:28 -04:00
Augie Fackler
a0fd83333c merge with stable 2014-09-09 13:47:50 -04:00
FUJIWARA Katsunori
0d1dc1fcfa dispatch: check shell alias again after loading extensions (issue4355)
Before this patch, the shell alias causes failure when it takes its
specific (= unknown for "hg") options in the command line, because
"_parse()" can't accept them.

This is the regression introduced by 7849ac1dbc57.

It fixed the issue that ambiguity between shell aliases and commands
defined by extensions was ignored. But it also caused that ambiguous
shell alias is handled in "_parse()" even if it takes specific options
in the command line.

To avoid such failure, this patch checks shell alias again after
loading extensions.

All aliases and commands (including ones defined by extensions) are
completely defined before the 2nd (= newly added in this patch)
"_checkshellalias()" invocation, and "cmdutil.findcmd(strict=False)"
can detect ambiguity between them correctly.

For efficiency, this patch does:

  - omit the 2nd "_checkshellalias()" invocation if "[ui] strict= True"

    it causes "cmdutil.findcmd(strict=True)", of which result should
    be equal to one of the 1st invocation before adding aliases

  - avoid removing the 1st "_checkshellalias()" invocation

    it causes "cmdutil.findcmd(strict=True)" invocation preventing
    shell alias execution from loading extensions uselessly
2014-09-10 00:41:44 +09:00
Yuya Nishihara
ea70238e6f alias: exit from bad definition by Abort 2014-08-13 22:22:24 +09:00
Yuya Nishihara
2d19d347a0 alias: show one-line hint for command provided by disabled extension
It will be a hint of Abort exception.  "hg help <alias>" provides the detailed
version as before.
2014-08-13 22:18:28 +09:00