Commit Graph

77 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
Jared Bosco
ae89e32851 cliparser: expose method to perform alias expansion on arguments
Summary:
Alias expansion originally occurs in mercurial through a chain of command handlers that point at their alias.

Now, aliases can be fully expanded early on into parsing to only resolve actual commands and not have to follow a chain of executions.

Reviewed By: quark-zju

Differential Revision: D16059122

fbshipit-source-id: cf28fba4a131ab29ceda87bc3e90d7a434e06625
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
Jun Wu
8278878d8a logging: log exthook name
Summary:
Inside `ui.system`, there is no context about exthook name. Change exthook log
to the `_exthook` function so we know the hook name.

Reviewed By: markbt

Differential Revision: D15755291

fbshipit-source-id: 88eb63dd1e06464b9a0ba291deba13a47adbd175
2019-07-06 02:46:19 -07:00
Jun Wu
66c2b83c09 logging: log pythonhook blocked time
Summary:
Note: MergeDriver is a special kind of Python hooks. Therefore the MergeDriver
enum was removed.

Reviewed By: markbt

Differential Revision: D15755282

fbshipit-source-id: a00c75a5c3b013eda189d50f6dae42653c0ed18b
2019-07-06 02:46:18 -07:00
Jun Wu
c5d1eadcb7 tests: stabilize test-blackbox.t
Summary:
The test was flaky because there are errors about time selection. Extending the
"end time" by 1 second to fix it.

Reviewed By: xavierd

Differential Revision: D16044383

fbshipit-source-id: ab929f5f212cec88aa9e9254dd58e696b20d75f8
2019-06-27 19:59:53 -07:00
Jun Wu
c754e0147b commands: provide in-core blackbox command
Summary:
The in-core blackbox command displays blackbox entries in the given time range.

The `blackbox` command provided by the blackbox extension was removed. They
can still be accessed via `.hg/blackbox.log`, though.

Tests are updated. Most `| grep` patterns were changed to use structured pattern
matching `--pattern` instead. Tests that are not interesting (ex. bundlebackup,
since we are moving away from bundle files slowly) are just removed.

Reviewed By: markbt

Differential Revision: D15640718

fbshipit-source-id: 7e5da60ca2b15ae9495d0242b340a066979d5a4f
2019-06-26 11:03:27 -07:00
Mark Thomas
57ed970fed blackbox: only log current commit if the changelog has been loaded
Summary:
When writing a blackbox log entry, only include the current commit if the repo
has already loaded the changelog.  Otherwise, finding out what the current
commit is will load the changelog, which is wasteful, and may cause a
re-entrant call back into blackbox logging.

Reviewed By: xavierd

Differential Revision: D15539413

fbshipit-source-id: 48c27b053b9db7ce5c2d4b1991020adaea720c21
2019-05-30 04:02:54 -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
Mark Thomas
cfe64a31f7 blackbox: add util.log for blackbox logging when no ui object is available
Summary:
If a ui object is not available, then callers can't make blackbox logs.  However,
the blackbox extension has `lastui()` which lets it find a ui object.

Add `util.log`, a hook point for blackbox that lets callers log to blackbox without
having a ui object to hand.

Reviewed By: quark-zju

Differential Revision: D15495215

fbshipit-source-id: b468647ccacc6992f71b9a8be2552db860d16ebe
2019-05-28 02:40:07 -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
Mark Thomas
66d79c86c8 pull: remove postincoming advice
Summary:
The postincoming checks prints out advice of the following forms:

* `(run 'hg heads' to see heads)`
* `(run 'hg heads' to see heads, 'hg merge' to merge)`
* `(run 'hg heads .' to see heads, 'hg merge' to merge)`
* `(run 'hg update' to get a working copy)`

This advice is no longer useful, so remove it.

Reviewed By: DurhamG, farnz

Differential Revision: D15317185

fbshipit-source-id: 50ba576406c96715fa058399da53462be9b7a3bf
2019-05-20 06:19:49 -07:00
Mark Thomas
94257a258b blackbox: clean up blackbox logging and log more during rage
Summary:
Clean up some of the calls to `ui.log` and how they appear in blackbox logging.

* Make the names of the events consistently use `snake_case`.
* For watchman, only log once for each watchman command.  Include whether or not it failed.
* Unify `fsmonitor` logging under the `fsmonitor` event.
* Omit the second argument when it is empty - it is optional and does nothing when empty.
* Increase the number of blackbox lines included in rage to 100.

Reviewed By: quark-zju

Differential Revision: D14949868

fbshipit-source-id: a9aa8251e71ae7ca556c08116f8f7c61ff472218
2019-04-23 02:48:50 -07:00
Jun Wu
31c8ecbdf4 dispatch: print shorter crash header
Summary:
Change the crash header to just a single line without blaming extensions or
Python. This makes the crash log shorter, and easier to read when there are
crashes in run-tests.py diffs.

Remove `ui.supportcontact` since it's no longer used.

Reviewed By: sfilipco

Differential Revision: D14393982

fbshipit-source-id: 3ede8d3d3d8fd5d125944a9a750350d3ce356b14
2019-04-04 23:38:34 -07:00
Durham Goode
73683c048e tracing: add various tracing across the code base
Summary:
Now that we have perftracing infra, let's trace a bunch of likely
problem spots.

Reviewed By: sfilipco

Differential Revision: D14426367

fbshipit-source-id: 354a241aa9ac5d75d34062a9838d581b4f46746f
2019-03-25 19:31:13 -07:00
Mark Thomas
9a19e06fee strip: move extension to core and rename to debugstrip
Summary:
Move the strip extension to core.  Rename the command to `hg debugstrip` as it
is not intended for use by users.  Users should use `hg hide` instead.

Reviewed By: quark-zju

Differential Revision: D14185822

fbshipit-source-id: ef096488cb94b72a7bb79f5bf153c064e0555b34
2019-02-25 03:55:08 -08:00
Jun Wu
66f2e5f45e branch: disable branchcache and drop all branches other than "default"
Summary:
This hardcodes several perftweaks configs that have been enabled for major FB
repos for months:

  [perftweaks]
  disablebranchcache = True
  disablebranchcache2 = True
  disableresolvingbranches = True
  disableupdatebranchcacheoncommit = True

Practically, this means the branchmap is now just `{'default': heads}`. (i.e.
there are no named branches other than `default`), and branchcache is removed
(i.e. `.hg/cache` does not exist without clindex or in-repo tags).

This diff only makes easy-to-verify logic changes by assuming the configs and
removing dead code. Things can be further cleaned up. They will be done by
upcoming changes.

Most test changes are due to the fact that `.hg/cache` is no longer created.

Reviewed By: singhsrb

Differential Revision: D14179858

fbshipit-source-id: 479f7427168eb1d9614a973e273a229e50f5620a
2019-02-22 21:02:41 -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
4337aee636 mq: remove the extension
Summary:
mq is already somehow problematic at D8907646. Without bandwidth supporting
it, let's remove it.

Alternative to mq would be rebase, shelve, unshelve, histedit.

Maintain "--config extensions.mq=" compatibility by marking it builtin so hg4idea
won't break by this change.

Reviewed By: phillco

Differential Revision: D9039741

fbshipit-source-id: a3a1e48a2a982ff8e8b6a6ce659c906a4e2b2b36
2018-07-30 08:49:26 -07:00
Jun Wu
0cd76376ed tests: run watchman tests in CI
Summary: Run tests with watchman built from fbcode master. So we get signals about watchman/hg changes.

Reviewed By: DurhamG

Differential Revision: D8448187

fbshipit-source-id: 8643f139932057f326bc75b0b0c5cc616355eeed
2018-06-20 19:35:31 -07:00
Jun Wu
56246aa66c dispatch: add a config option to control exit code
Summary:
Previously, hg returns -1 (255) on "unknown errors". That could conflict with
other things. For example, http://tldp.org/LDP/abs/html/exitcodes.html suggests
1, 2, 126 ... 255 have special meanings defined by a common shell.  Namely,
`ssh` also returns 255.

Another long complaints about hg exit code is the use of 1 to indicate
"no changes". Although that's explained at [1], a lot of scripts still find it
surprising.

This diff adds a `ui.exitcodemask` config option, which makes it to alter the
exit code. Set it to 254 will change 1 to 0 for some script use-cases. Set it
to 63 or so will avoid conflicts with software like `ssh`.

Many existing scripts still expect 255 to be the return code. So we cannot
change the default value that easily. To avoid surprises (like, put the config
option in `/etc/mercurial/hgrc.d/exitcode.rc`), the config set by config
files is ignored if `HGPLAIN` is set and `HGPLAINEXCEPT` does not contain
`exitcode`.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2012-January/037711.html

Reviewed By: DurhamG

Differential Revision: D7921817

fbshipit-source-id: 764b0de030fc727aa5df7305c2b8bc92f576cd33
2018-06-13 16:14:01 -07:00
Jun Wu
a4c9b8d134 blackbox: be graceful when the log message cannot be formatted
Summary:
It's legit for a file name to contain `%s` or `%r` strings. Previously,
blackbox always expect the first argument to be the "format string". That's
inconvenient and it's easy to just pass a string containing the troublesome
`%s` to `ui.log`.

Let's just do not even try formatting strings if there is only one argument,
and if there are multiple arguments, fallback to concatenate them if they
cannot be formatted.

Reviewed By: DurhamG

Differential Revision: D8364130

fbshipit-source-id: 75b2d0e0a460b9a86d4ecd6ecfbb77c0c0fbe98c
2018-06-11 17:36:15 -07:00
Jun Wu
4c2fadcbba blackbox: add a way to label logs with a "request id"
Summary: This would help labeling interesting commands from callers.

Reviewed By: DurhamG

Differential Revision: D8057148

fbshipit-source-id: 647cc91be3baeaa0362799603a66dab0c6c570b8
2018-05-18 10:46:59 -07:00
Jun Wu
857e9aa714 blackbox: append "\n" automatically
Summary:
Some log messages might not end with "\n". Append it automatically so it
looks good in blackbox.log.

Reviewed By: singhsrb

Differential Revision: D7648930

fbshipit-source-id: f5262e0c77a3bde952c3963ac5298b850f38d9db
2018-04-16 20:53:58 -07:00
Jun Wu
40dd438fc8 blackbox: do not log if msg is empty
Summary:
There are certain code paths that passes an empty `msg` that would crash
blackbox code:

```
error in exit handlers:
Traceback (most recent call last):
  File "mercurial/dispatch.py", line 73, in _runexithandlers
    func(*args, **kwargs)
  File "hgext/sampling.py", line 118, in telemetry
    generaldelta=str('generaldelta' in repo.requirements).lower())
  File "hgext/blackbox.py", line 170, in log
    formattedmsg = msg[0] % msg[1:]
IndexError: tuple index out of range
```

Fix it by ignoring those messages.

Reviewed By: singhsrb

Differential Revision: D7648932

fbshipit-source-id: be9f8327fd476399e4b762c92ea5f31cb174e189
2018-04-16 20:53:58 -07:00
Jun Wu
7fa918cefd perftweaks: move commit head detection removal logic to core
Summary: Also change the internal API so it no longer accepts the "heads" argument.

Reviewed By: ryanmce

Differential Revision: D6745865

fbshipit-source-id: 368742be49b192f7630421003552d0a10eb0b76d
2018-04-13 21:50:52 -07:00
Phil Cohen
72085d2e96 testdir: fix test-extension.t for DEFAULT_EXTENSIONS
Differential Revision: https://phabricator.intern.facebook.com/D6718663
2018-01-14 14:53:52 -08: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
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
Denis Laxalde
9efc7f05e3 transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Upon pull or unbundle, we display a message with the range of new revisions
fetched. This revision range could readily be used after a pull to look out
what's new with 'hg log'. The algorithm takes care of filtering "obsolete"
revisions that might be present in transaction's "changes" but should not be
displayed to the end user.
2017-10-12 09:39:50 +02:00
Jun Wu
a18c4e0d85 blackbox: do not prevent 'chg init' from working
Previously, blackbox always appends to blackbox.log and creates the
directory for that file on demand. That could be an issue if:

  1. chg starts from `$REPO` directory, so `ui._bbrepo` is set.
  2. `rm -rf $REPO`.
  3. `chg init $REPO`, blackbox writes something and `init` will fail
     because `$REPO` directory is non-empty.

This patch fixes that by verifying whether vfs exists before re-using it.

Differential Revision: https://phab.mercurial-scm.org/D768
2017-09-21 11:03:37 -07:00
Augie Fackler
6fea4e0714 tests: add a test for blackbox with nested alias configurations
I've observed some weirdness around this, and needed to rule some
things out. There aren't any bugs in core around this, but it was nice
to have confirmation.
2017-09-11 20:07:41 -04:00
Augie Fackler
11bbe7db58 tests: clean up blackbox test around aliases a little bit 2017-09-11 20:06:52 -04:00
Jun Wu
042b7a7361 blackbox: set lastui even if ui.log is not called (issue5518)
`lastui` decides where (where is the `.hg`) to use if the current `ui`
object does not have a `_bbrepo` associated. Previously it only gets set in
`ui.log`, which means unless a `ui` with repo associated calls `log` with
tracked event, blackbox does not know where to write its log. This patch
makes `reposetup` set `lastui` so it so we could log some more events (see
test changes).

Differential Revision: https://phab.mercurial-scm.org/D655
2017-09-18 16:01:03 -07:00
Jun Wu
a97d2d42cb blackbox: fix rotation with chg
The added test will show:

  $ $PYTHON showsize.py .hg/blackbox*
  .hg/blackbox.log: < 500
  .hg/blackbox.log.1: < 500
  .hg/blackbox.log.2: < 500
  .hg/blackbox.log.3: < 500
  .hg/blackbox.log.4: < 500
  .hg/blackbox.log.5: >= 500

with previous code.

The issue is caused by blackbox caching file objects *by path*, and the
rotation size check could run on a wrong file object (i.e. it should check
"blackbox.log", but `filehandles["blackbox.log"]` contains a file object
that has been renamed to "blackbox.log.5").

This patch removes the "filehandlers" global cache added by 39bd7b0c79fe to
solve the issue.

I think the original patch was trying to make different ui objects use a same
file object if their blackbox.log path is the same. In theory it could also
be problematic in the rotation case. Anyway, that should become unnecessary
after D650.

Differential Revision: https://phab.mercurial-scm.org/D648
2017-09-06 19:27:30 -07:00
Jun Wu
7d887b076a test-blackbox: make it compatible with chg
Differential Revision: https://phab.mercurial-scm.org/D647
2017-09-06 18:31:25 -07:00
FUJIWARA Katsunori
8f3aa7a7e3 tests: take extra care for fsmonitor at enabling incompatible extension
This is worthwhile, because these tests don't focus mainly on using
incompatible extensions itself.
2017-07-13 03:17:58 +09:00
Augie Fackler
e5d7bd82c5 cleanup: use $PYTHON to run python in many more tests
Spotted one of these, then wrote a check-code rule that caught them
all. It will be the next change.
2017-06-20 09:45:02 -04:00
Pulkit Goyal
f8b6f67b7a update: show the commit to which we updated in case of multiple heads (BC)
Currently when we have multiple heads on the same branch, update tells us that
there some more heads for the current branch but does not tells us the head to
which the repository has been updated to. It makes more sense showing the
head we updated to and then telling there are some more heads.
2017-06-06 22:17:39 +05:30
Pierre-Yves David
781ab337a0 caches: stop warming the cache after 'localrepo.commitctx'
Now that we garantee that branchmap cache are updated at the end of the
transaction we can drop that one. This removes a problematic case with nested
transaction where the new cache could be written on disk before the transaction
is finished.

The test change is harmless, since we update the cache at a later point, the
dirstate have been updated in between.
2017-05-02 18:56:07 +02:00
Matt Harbison
916bb7c1c1 test-blackbox: glob away quoting differences on Windows
Windows uses double quotes in these places.
2017-04-02 02:29:51 -04:00
Augie Fackler
f1710548b8 dispatch: replace mayberepr with shellquote
The quoting logic here was actually insufficient, and would have had
bogus b-prefixes on Python 3. shellquote seems more appropriate
anyway. Surprisingly, only two tests have output changes, and both of
them look reasonable to me (both are in blackbox logs).

Spotted by Yuya during review.
2017-03-19 14:23:30 -04:00
Augie Fackler
82bc5f196f blackbox: also log alias expansions
This should be extremely useful for helping users debug without having
to see their complete configuration.

Shell aliases do not get their expansion logged, because we don't look
and see if we're in a repo before we dive into the execution of a
shell alias. As a result, the ui object doesn't know where to log.
2016-08-23 16:40:08 -04:00
Matt Harbison
1d574a1dd2 test-blackbox: add missing glob for Windows
The test warns instead of completes without this.
2016-03-15 23:04:35 -04:00
timeless
57b0b61ecb blackbox: guard against recursion from dirty check 2016-03-08 20:34:59 +00:00
timeless
189e3f9aca tests: divorce blackbox test from test-dispatch.py
I used test-dispatch.py to demonstrate what would happen if
a log file changed from being readonly to writable, by
having it replace a directory (proxy for readonly/not-writable)
with a log file in between transactions of a running python
process (proxy for Mercurial).

This commit makes it easier for people to follow what the test
is doing, by creating a real file that people can read.
2016-03-08 20:52:57 +00:00
Danek Duvall
ea87ae32e5 tests: Solaris sed does not support "\n" meaning newline in the RHS of s///
The blackbox test rewrites a copy of test-dispatch.py on the fly, and adds
a couple of lines with the s/// command.  GNU sed supports the use of the
\n escape to represent a newline, but not Solaris sed.  Using a literal
newline, prefixed by a backslash, works with both versions of the utility.
2016-03-02 14:55:13 -08:00
timeless
8b93438cc2 blackbox: properly replace ui class
Without this, anyone creating a ui object using: uimod.ui()
skips the blackbox.

Also, anyone doing ui.copy() skipped the blackbox.

Unfortunately, the ui object lifestyle is a bit messy,
the first one that's created is never actually initialized
with subclasses, instead pieces of the subclass are adopted
into the primal ui object. In order to handle this, a
_partialinit method will be called to ensure that the
blackboxui is properly initialized.
2016-02-03 04:54:40 +00:00
timeless
ecdcbad06b blackbox: store the blackbox ui object instead of the log file
Without this, the last logged entry didn't have access to
the repository, and thus couldn't report its version
(and especially that an add or similar dirtied it).

A side-effect is that one repo leaks until process exit...
2016-02-03 17:05:04 +00:00
timeless
236079f621 blackbox: log dirty state
If blackbox.dirty = True, use `+` to indicate dirty repositories.
2016-02-09 15:44:13 +00:00