Commit Graph

66 Commits

Author SHA1 Message Date
Yuya Nishihara
8f3fa790c1 tests: alias syshg and syshgenv so they can be switched conditionally 2017-07-02 13:14:20 +09:00
Adam Simpkins
55a457de69 tests: use the system hg for examining the local repository
Most test scripts use "hg" to interact with a temporary test repository.
However a few tests also want to run hg commands to interact with the local
repository containing the mercurial source code.  Notably, many of the
test-check-* tests want to check local files and commit messages.

These tests were previously using the version of hg being tested to query the
source repository.  However, this will fail if the source repository requires
extensions or other settings not supported by the version of mercurial being
tested.  The source repository was typically initially cloned using the system
hg installation, so we should use the system hg installation to query it.

There was already a helpers-testrepo.sh script designed to help cope with
different requirements for the source repository versus the test repositories.
However, it only handled the evolve extension.  This new behavior works with
any extensions that are different between the system installation and the test
installation.
2017-06-27 17:24:31 -07:00
Gregory Szorc
6d8d6e3d41 perf: don't convert rev to node before calling revlog.revision() 2017-05-06 11:12:23 -07:00
Gregory Szorc
d84946776c perf: move gettimer() call
This is more consistent with other perf* functions.
2017-05-06 11:01:02 -07:00
Yuya Nishihara
d9d64e114f bdiff: proxy through mdiff module
See the previous commit for why.

mdiff seems a good place to host bdiff functions. bdiff.bdiff was already
aliased as textdiff, so we use it.
2017-04-26 22:03:37 +09:00
Yuya Nishihara
e4989d80e7 check-code: ignore re-exports of os.environ in encoding.py
These are valid uses of os.environ.
2017-05-01 17:23:48 +09:00
Yuya Nishihara
edbbe128cc check-code: exclude demandimport.py and policy.py from Python 3 checks
These modules can't depend on pycompat.py, which means we have to write Py3
hacks in them.
2017-04-26 21:51:19 +09:00
Phil Cohen
0c884d7a6a demandimport: add urwid.command_map to ignore list
The useful pudb debugger can be used with Mercurial, but its import of urwid
fails when demandimport is enabled. Add urwid.command_map to the ignore list so
pudb can be used with hg without disabling all of demandimport.
2017-05-03 18:26:57 -07:00
Gregory Szorc
9df2b10ec0 tests: add tests for poorly behaving HTTP server
I've spent several hours over the past few weeks investigating
networking failures involving hg.mozilla.org. As part of this, it
has become clear that the Mercurial client's error handling when
it encounters network failures is far from robust.

To prove this is true, I've devised a battery of tests simulating
various network failures, notably premature connection closes. To
achieve this, I've implemented an extension that monkeypatches the
built-in HTTP server and hooks in at the socket level and allows
various events to occur based on config options. For example, you
can refuse to accept() a client socket or you can close() the socket
after N bytes have been sent or received. The latter effectively
simulates an unexpected connection drop (and these occur all the
time in the real world).

The new test file launches servers exhibiting various "bad" behaviors
and points a client at them. As the many TODO comments in the test
call attention to, Mercurial often displays unhelpful errors when
network-related failures occur. This makes it difficult for users
to understand what's going on and difficult for server administrators
to pinpoint root causes without packet tracing.

Upcoming patches will attempt to fix these error handling
deficiencies.
2017-04-13 22:19:28 -07:00
Kostia Balytskyi
64a48b9fb1 windows: add win32com.shell to demandimport ignore list
Module 'appdirs' tries to import win32com.shell (and catch ImportError as an
indication of failure) to check whether some further functionality should
be implemented one or another way [1]. Of course, demandimport lets it down, so
if we want appdirs to work we have to add it to demandimport's ignore list.

The reason we want appdirs to work is becuase it is used by setuptools [2] to
determine egg cache location. Only fairly recent versions of setuptools depend
on this so people don't see this often.


[1] https://github.com/ActiveState/appdirs/blob/master/appdirs.py#L560
[2] aae0a92811/pkg_resources/__init__.py (L1369)
2017-04-14 12:34:26 -07:00
Jun Wu
e62af0bff4 test-check-code: do not use xargs
We have too many files, and passing them via arguments could cause strange
errors on some platforms [1]. Since check-code.py can now take "-" and read
file names from stdin, use it instead of xargs to avoid the argv size limit.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-April/096346.html
2017-04-06 22:10:46 -07:00
Philippe Pepiot
e5957f96bd perf: add historical portability for util.timer
util.timer has been introduced in ae5d60bb and used in perf.py since 22fbca1d.
For historical portability, forcibly define util.timer in perf.py
2017-04-06 14:41:42 +02:00
Martin von Zweigbergk
6b2860bef0 check-code: fix "covert" typo 2017-04-03 11:30:51 -07:00
Jun Wu
e6e0b871f1 test-check-code: prevent files being added to the root directory
Adding new files in the root directory is probably a mistake, and is usually
discouraged [1]. The test catches it to avoid mistakes like [2].

Modify the test if files need to be added in the root.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-July/086442.html
[2]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-March/095836.html
2017-03-29 12:14:20 -07:00
Jun Wu
6ac1cb4157 unionrepo: avoid unnecessary node -> rev conversion 2017-03-29 16:28:51 -07:00
Jun Wu
9c45c07c8b bundlerepo: avoid unnecessary node -> rev conversion 2017-03-29 16:28:00 -07:00
Jun Wu
7f99b86dbd revlog: avoid unnecessary node -> rev conversion 2017-03-29 16:23:04 -07:00
Jun Wu
5dda7e9e48 check-code: detect r.revision(r.node(rev))
revlog.revision takes either node or rev, but taking a rev is more
efficient, because converting rev to node is just a seek and read.
That's cheaper than converting node to rev, which may require O(n) walk in
revlog index for the first times, and then triggering building the radix
tree index. Even with the radix tree built, rev -> node is still faster than
node -> rev because the radix tree requires more jumps in memory.

So r.revision(r.node(rev)) should be changed to r.revision(rev). This patch
adds a check-code rule to detect that.
2017-03-29 16:46:57 -07:00
Yuya Nishihara
af7f25fdb3 encoding: add converter between native str and byte string
This kind of encoding conversion is unavoidable on Python 3.
2017-03-13 09:12:56 -07:00
Yuya Nishihara
dcade16cf7 encoding: factor out unicode variants of from/tolocal()
Unfortunately, these functions will be commonly used on Python 3.
2017-03-13 09:11:08 -07:00
FUJIWARA Katsunori
9d450170ba py3: add "b" prefix to string literals related to module policy
String literals without explicit prefix in __init__.py and policy.py
are treated as unicode object on Python3, because these modules are
loaded before setup of our specific code transformation (the later
module is imported at the beginning of __init__.py).

BTW, "modulepolicy" in __init__.py is initialized by "policy.policy".

This causes issues below;

  - checking "policy" value in other modules causes unintentional result

    For example, "b'py' not in (u'c', u'py')" returns True
    unintentionally on Python3.

  - writing "policy" out fails at conversion from unicode to bytes

    db1ebf457295 fixed this issue for default code path, but "policy"
    can be overridden by HGMODULEPOLICY environment variable (it should
    be rare case for developer using Python3, though).

This patch does:

  - add "b" prefix to all string literals, which are related to module
    policy, in modules above.

  - check existence of HGMODULEPOLICY, and overwrite "policy" only if
    it exists

    For simplicity, this patch omits checking "supports_bytes_environ",
    switching os.environ/os.environb, and so on (Yuya agreed this in
    personal talking)
2017-03-13 04:06:36 +09:00
Augie Fackler
067ebafd12 merge with stable 2017-01-04 14:52:59 -05:00
Augie Fackler
6a644ad048 httpclient: update to 54868ef054d2 of httpplus
As of that revision, httpplus fully supports Python 3, including
mimicing all the subtle behavior changes around headers in Python 3's
http.client.
2016-06-27 11:53:50 -04:00
timeless
0c82fc02cd tests: silence test-repo obsolete warning
refactoring test-check-commit.t HGRCPATH bits as helpers-testrepo.sh
2016-05-11 04:49:27 +00:00
Pulkit Goyal
ff574e7b93 py3: use pycompat.getcwd instead of os.getcwd 2016-12-22 01:54:17 +05:30
Pulkit Goyal
589ad4d6b7 py3: use python 3 compatible variables in hgext/fsmontor/__init__.py
Earlier this was left thinking that its part of pywatchman package.
This patch replaces variables os.sep, sys.platform and os.envrion with their
py3 compatible ones.
2016-12-21 23:40:38 +05:30
Pulkit Goyal
2207f24f07 py3: add warnings in check-code related to py3
We have our own bytes versions of things like, getopt.getopt, os.sep, os.name,
sys.executable, os.environ and few more for python 3 portability. Its better
to come up with warnings if someone breaks the things which we have fixed.

After this patch, check-code will warn us to use our bytes version.
These checks run on mercurial/ and hgext/ and pycompat.py is excluded.
2016-12-21 22:42:31 +05:30
David Soria Parra
66598c8ac2 tests: exclude bundled pywatchman from check-code test
pywatchman is imported from upstream and therefore fails to pass
linting. We have added 'no-check-code' manually to every file in the
past. This is cumbersome and modifies upstream sources.
2016-12-20 20:28:41 -08:00
Gregory Szorc
d5c4807106 debugcommands: sort command order
The diff is a bit large but it is straight code moving without any
logical modifications.
2016-11-25 09:59:39 -08:00
Gregory Szorc
7ab5315d89 tests: add test that @commands in debugcommands.py are sorted
I felt like inline Python in test-check-code.t was the most
appropriate place for this, as other linters in contrib/ seem to
be source file agnostic.

The test currently fails.
2016-11-25 09:55:05 -08:00
Gregory Szorc
2005375cdc zstd: vendor python-zstandard 0.5.0
As the commit message for the previous changeset says, we wish
for zstd to be a 1st class citizen in Mercurial. To make that
happen, we need to enable Python to talk to the zstd C API. And
that requires bindings.

This commit vendors a copy of existing Python bindings. Why do we
need to vendor? As the commit message of the previous commit says,
relying on systems in the wild to have the bindings or zstd present
is a losing proposition. By distributing the zstd and bindings with
Mercurial, we significantly increase our chances that zstd will
work. Since zstd will deliver a better end-user experience by
achieving better performance, this benefits our users. Another
reason is that the Python bindings still aren't stable and the
API is somewhat fluid. While Mercurial could be coded to target
multiple versions of the Python bindings, it is safer to bundle
an explicit, known working version.

The added Python bindings are mostly a fully-featured interface
to the zstd C API. They allow one-shot operations, streaming,
reading and writing from objects implements the file object
protocol, dictionary compression, control over low-level compression
parameters, and more. The Python bindings work on Python 2.6,
2.7, and 3.3+ and have been tested on Linux and Windows. There are
CFFI bindings, but they are lacking compared to the C extension.
Upstream work will be needed before we can support zstd with PyPy.
But it will be possible.

The files added in this commit come from Git commit
e637c1b214d5f869cf8116c550dcae23ec13b677 from
https://github.com/indygreg/python-zstandard and are added without
modifications. Some files from the upstream repository have been
omitted, namely files related to continuous integration.

In the spirit of full disclosure, I'm the maintainer of the
"python-zstandard" project and have authored 100% of the code
added in this commit. Unfortunately, the Python bindings have
not been formally code reviewed by anyone. While I've tested
much of the code thoroughly (I even have tests that fuzz APIs),
there's a good chance there are bugs, memory leaks, not well
thought out APIs, etc. If someone wants to review the code and
send feedback to the GitHub project, it would be greatly
appreciated.

Despite my involvement with both projects, my opinions of code
style differ from Mercurial's. The code in this commit introduces
numerous code style violations in Mercurial's linters. So, the code
is excluded from most lints. However, some violations I agree with.
These have been added to the known violations ignore list for now.
2016-11-10 22:15:58 -08:00
Gregory Szorc
e735a48987 statprof: vendor statprof.py
Vendored from https://bitbucket.org/facebook/hg-experimental
changeset 73f9db47ae5a1a9fa29a98dfe92d557ad51234c3 without
modification.

This introduces a number of code style violations. The file
already has the magic words to skip test-check-code.t. I'll
make additional changes to clean up the test-check-py3-compat.t
warnings and to change some behavior in the code that isn't
suitable for general use.

test-check-commit.t also complains about numerous things. But
there's nothing we can do if we're importing as-is.
2016-11-01 18:54:03 -07:00
Augie Fackler
b569044317 fsmonitor: flag msc_stdint as no-check-code
I'd rather not modify code that we're vendoring, so I'm just marking
it this way.
2016-03-14 21:15:59 -04:00
Martijn Pieters
64a4b2e8cf fsmonitor: dependencies for new experimental extension
In preparation for the filesystem monitor extension, include the pywatchman
library. The fbmonitor extension relies on this library to communicate with
the Watchman service. The library is BSD licensed and is taken from
https://github.com/facebook/watchman/tree/master/python.

This package has not been updated to mercurial code standards.
2016-03-02 16:25:12 +00:00
timeless
a2c7933e41 zeroconf: replace has_key with in 2016-03-01 10:22:10 +00:00
Pierre-Yves David
7cae660c88 tests: move the '-hg' postfix for all style tests
We had them on 'test-check-code-hg.t' to avoid collision with the test checking
'check-code' itself. Now that this one have been rename, we can safely remove
this suffix for all of them. This get them in line with 'check-pyflakes.t'.
2015-12-05 22:49:39 -08:00
Pierre-Yves David
22f4eed389 test: rename 'check-code' own test to 'test-contrib-check-code.t'
This test (making sure the 'check-code' script run as intended) have been
confused with the test making that the mercurial code base comply with our
coding still by multiple generations of contributors.

We are moving it out of the way so that all tests starting with
'test-check' are now doing compliance testing.
2015-12-05 22:47:26 -08:00
Pierre-Yves David
4a231c9668 check-code: entirely drop the 'non-py24.py' file from the test
There are no Python 2.4 related errors remaining.
2015-05-18 16:30:24 -05:00
Pierre-Yves David
624cc99b09 check-code: drop the 'format' built-in
I'm not clear what it is doing, but one who knows what it is about can now make
use of it.
2015-05-18 16:11:44 -05:00
Pierre-Yves David
2d3ab51ced check-code: drop the yield inside try/finally ban
This is now possible with Python 2.6.
2015-05-18 12:56:59 -05:00
Augie Fackler
82d20c6721 check-code: un-ban __builtins__.all now that we're on 2.6 2015-05-16 14:34:04 -04:00
Augie Fackler
8135f8f3bf check-code: un-ban any() now that we're on 2.6 2015-05-16 14:31:03 -04:00
Pierre-Yves David
5c28bef986 check-code: lift the ban on 'next()'
'next' is supported by Python2.6 the new lowest version supported by Mercurial.
2015-05-17 17:47:42 -07:00
Pierre-Yves David
b126ceafed check-code: fix the error message about 'class foo():'
Using 'classs foo():' result in old style object instead of new style object. We
do not want old style object so this check is unrelated to 2.4.
2015-05-17 17:40:26 -07:00
Matt Mackall
d4d62e93d0 check-code: drop try/except/finally check 2015-05-15 09:54:35 -05:00
Mads Kiilerich
523c87c1fe spelling: fixes from proofreading of spell checker issues 2014-04-17 22:47:38 +02:00
Steven Brown
b97c015cd5 check-code: check for consistent usage of the websub filter in hgweb templates
The check-code tool now expects the "desc" keyword to be followed by the
"websub" filter, with the following exceptions:
a) It has no filters at all, e.g. a changeset description in the raw style
   templates or the repository description in the summary page.
b) It is followed by the "firstline" filter, e.g. the first line of the
   changeset description is displayed as a summary or title.
2014-05-17 17:11:06 +08:00
FUJIWARA Katsunori
0ba1f1ddab check-code: detect "% inside _()" when there are leading whitespaces
Before this patch, "contrib/check-code.py" can't detect "% inside _()"
correctly, when there are leading whitespaces before the format
string, like below:

    _(
      "format string %s" % v)

This patch adds regexp pattern "[ \t\n]*" before the pattern matching
against the format string.

"[\s\n]" can't be used in this purpose, because "\s" is automatically
replaced with "[ \t]" by "_preparepats()" and "\s" in "[]" causes
nested "[]" unexpectedly.
2014-04-16 03:05:00 +09:00
Augie Fackler
ad0fddea79 check-code: disallow use of dict(key=value) construction
{} literals are faster and more consistent across Python 2 and 3.

Whitelisted the one use of dict() that is using a generator expresion.
2014-03-12 13:31:27 -04:00
Simon Heimberg
a4feb953c7 check-code: prepend warning prefix only once, but for each warning
The code adding the prefix is now run once per pattern. It was run once per
file (after the change 17484f4c54fb).
Demonstrate that it is working now by extending the test. Raise two different
warnings, one of them twice.
2013-11-09 10:21:20 +01:00