Commit Graph

31206 Commits

Author SHA1 Message Date
Yuya Nishihara
99a868d61d py3: call strftime() with native str type
Since strftime() may contain non-ascii character if locale set, we use
strfrom/tolocal().

Now "hg tip" works.
2017-03-13 09:19:07 -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
Yuya Nishihara
ec012a1a69 py3: use next() to obtain next item from inner generator of generatorset
.next attribute does not exist on Python 3. As this function seems to really
care about the overhead of the Python interpreter, I follow the way of micro
optimization.
2017-03-13 08:53:31 -07:00
Yuya Nishihara
02b9a6d074 py3: rewrite itervalues() as values() by importer
I'm not a great fan of these importer magics, but this should be okay since
"itervalues" seems as unique name as "iteritems".
2017-03-13 08:44:57 -07:00
Yuya Nishihara
fad2547154 py3: use portable way to stringify cache key of repoview 2017-03-12 17:20:42 -07:00
Kostia Balytskyi
688382aced exewrapper: prefer HackableMercurial python if availbale
Currently hg.exe will only try to load python27.dll from hg-python
subdir if PYTHONHOME environment variable is not set. I think that
it is better to check whether 'hg-python' subdir exists and load
python from it in that case, regardless of environment. This allows
for reliable approach of distributing Mercurial with its own Python.
2017-03-13 12:44:13 -07:00
Pierre-Yves David
56371ac490 import-checkers: split tests of the tool from running it on the source
We did such splits for other tools already. The 'test-check-*.t' performs the
check of the source code while the regular tests verifies the tools works.

One of the benefit is that is provides a simple file to reuse in third party
extensions.
2017-03-14 23:07:08 -07:00
Yuya Nishihara
eea0ef4b6e py3: use bytestr wrapper in revsetlang.tokenize()
This backs out a2d8ce9531e1 and wraps program by bytestr() instead.
2017-03-16 21:36:21 +09:00
Yuya Nishihara
a665b1ac40 py3: use bytestr wrapper in revsetlang.formatspec()
This backs out e6d1d689544f and wraps expr by bytestr() instead.
2017-03-16 21:33:25 +09:00
Yuya Nishihara
791afb08eb pycompat: add bytestr wrapper which mostly acts as a Python 2 str
This allows us to handle bytes in mostly the same manner as Python 2 str,
so we can get rid of ugly s[i:i + 1] hacks:

  s = bytestr(s)
  while i < len(s):
      c = s[i]
      ...

This is the simpler version of the previous RFC patch which tried to preserve
the bytestr type if possible. New version simply drops the bytestr wrapping
so we aren't likely to pass a bytestr to a function that expects Python 3
bytes.
2017-03-08 22:48:26 +09:00
Yuya Nishihara
8b296e4cfa tests: allow running doctests selectively on Python 3
Currently most doctests fail on Python 3, but I want to add some.
2017-03-08 22:13:32 +09:00
Pierre-Yves David
b9d210d680 context: explicitly tests for None
Changeset c832083e5671 removed the mutable default value, but did not explicitly
tested for None. Such implicit testing can introduce semantic and performance
issue. We move to an explicit testing for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-03-15 15:33:24 -07:00
Pierre-Yves David
4fa55e8b7e filemerge: explicitly tests for None
Changeset 3495cae22a41 removed the mutable default value, but did not explicitly
tested for None. Such implicit testing can introduce semantic and performance
issue. We move to an explicit testing for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-03-15 15:11:52 -07:00
Pierre-Yves David
50e7f5d5fd hgweb: explicitly tests for None
Changeset 11e325d162fe removed the mutable default value, but did not explicitly
tested for None. Such implicit testing can introduce semantic and performance
issue. We move to an explicit testing for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-03-15 15:11:04 -07:00
Pierre-Yves David
c05c73d498 hgweb: explicitly tests for None in webutil
Changeset 45c7a22dbdc0 removed the mutable default value, but did not explicitly
tested for None. Such implicit testing can introduce semantic and performance
issue. We move to an explicit testing for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-03-15 15:10:09 -07:00
Pierre-Yves David
be968edfac match: explicitly tests for None
Changeset ba7f2a1cc2d2 removed the mutable default value, but did not explicitly
tested for None. Such implicit testing can introduce semantic and performance
issue. We move to an explicit testing for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-03-15 15:08:45 -07:00
Pierre-Yves David
0d3c7adc2c mq: explicitly tests for None
Changeset 97936471dc8d removed the mutable default value, but did not explicitly
tested for None. Such implicit testing can introduce semantic and performance
issue. We move to an explicit testing for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-03-15 15:05:54 -07:00
Pierre-Yves David
9f5b98723a rebase: explicitly tests for None
Changeset 33b71926122d removed the mutable default value, but did not explicitly
tested for None. Such implicit checking can introduce semantic and performance
issue. We move to an explicit check for None as recommended by PEP8:

https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-03-15 15:03:43 -07:00
Rishabh Madan
8a9d68951e py3: use iter() instead of iterkeys() 2017-03-16 04:53:23 +05:30
Pierre-Yves David
09a5f07adf localrepo: deprecated '_link'
That method had a total on 1 internal user...


G: changed mercurial/localrepo.py
2016-08-05 14:15:45 +02:00
Pierre-Yves David
2634c22ce0 localrepo: use self.wvfs.islink directly
We are about to deprecate the helper function.
2016-08-05 14:19:31 +02:00
Pulkit Goyal
fcc99d385f py3: convert opts back to bytes for status 2017-03-16 10:10:00 +05:30
Gregory Szorc
206cd3557e parsers: handle refcounting of "parents" consistently
Py_None can be refcounted like any other Python object. So
do that.
2017-03-13 17:49:13 -07:00
Martin von Zweigbergk
7b5dab5409 py3: make py3 compat.iterbytestr simpler and faster
With Python 3.4.3, timit says 11.9 usec-> 6.44 usec. With Python
3.6.0, timeit says 14.1 usec -> 9.55 usec.
2017-03-15 09:32:18 -07:00
Martin von Zweigbergk
cf1f0d3920 py3: optimize py3 compat.bytechr using Struct.pack
With Python 3.4.3, timeit says 0.437 usec -> 0.0685 usec. With Python
3.6, timeit says 0.157 usec -> 0.0907 usec. So it's faster on both
versions, but the speedup varies a lot.

Thanks to Gregory Szorc for the suggestion.
2017-03-15 09:30:50 -07:00
Ryan McElroy
5ffd6c8793 tests: properly drop back to root dir in test-status.t 2017-03-15 19:26:20 -07:00
Pulkit Goyal
f9b7821158 dirstate: use list comprehension to get a list of keys
We have used dict.keys() which returns a dict_keys() object instead
of list on Python 3. So this patch replaces that with list comprehension
which works both on Python 2 and 3.
2017-03-16 09:00:27 +05:30
Pulkit Goyal
5a7c5d918e match: slice over bytes to get the byteschr instead of ascii value 2017-03-16 08:03:51 +05:30
Pulkit Goyal
0bad6ee6aa match: make regular expression bytes to prevent TypeError 2017-03-16 07:52:47 +05:30
Pulkit Goyal
7ed6d8245e scmutil: make function name bytes in class filecache
func.__name__ returns unicodes and this leads to keyerror when we try
to do filecache[''] by passing bytes.
2017-03-16 06:32:33 +05:30
Pierre-Yves David
0923ede90f localrepo: deprecate 'wfile'
The method had very few users and the modern form is shorter. So let us
deprecates another method of the localrepo class.
2017-03-15 00:27:17 -07:00
Pierre-Yves David
c8ef80badf eol: use 'wvfs' instead of 'wfile'
Method is about to be deprecated and the modern form is shorter.
2017-03-15 00:31:59 -07:00
Pierre-Yves David
5fc4dd0997 localrepo: use 'wvfs' instead of 'wfile'
Method is about to be deprecated and the modern form is shorter.
2017-03-15 00:29:09 -07:00
Pierre-Yves David
3298e01804 tagmerge: use 'wvfs' instead of 'wfile'
Method is about to be deprecated and the modern form is shorter.
2017-03-15 00:28:58 -07:00
Pierre-Yves David
20c832d095 gpg: use 'wvfs' instead of 'wfile'
Method is about to be deprecated and the modern form is shorter.
2017-03-15 00:28:21 -07:00
Pierre-Yves David
a51384137e test: add a basic 'test-check-pylint.t'
We add a minimal check using pylint for one case we knows we care about:
"mutable default" argument.

We'll likely extend this over time to cover other useful checks but this is a
good starting point.
2016-12-28 23:42:50 +01:00
Pierre-Yves David
2a46795ed1 localrepo: don't use mutable default argument value
Caught by pylint.
2017-03-14 23:50:07 -07:00
Pierre-Yves David
c4d32111df httpclient: don't use mutable default argument value
Caught by pylint.
2017-03-14 23:49:25 -07:00
Pierre-Yves David
654e9bcf93 largefiles: don't use mutable default argument value
Caught by pylint.
2017-03-14 23:49:10 -07:00
Pierre-Yves David
5e3487503b hgk: don't use mutable default argument value
Caught by pylint.
2017-03-14 23:48:25 -07:00
Pierre-Yves David
76c3fb0c64 convert: don't use mutable default argument value
Caught by pylint.
2017-03-14 23:48:08 -07:00
Pierre-Yves David
1df4bd9f0c mq: don't use mutable default argument value
Caught by pylint.
2017-03-14 23:46:48 -07:00
Martin von Zweigbergk
d32ca3644f pager: if old pager extensions is enabled, respect pager.attend
This patch makes us respect pager.attend again if the extension is
enabled. It also brings back the default attend list, so e.g. summary
is not paged by default, just like it used to be before pager was
moved into core.
2017-03-13 21:43:17 -07:00
Martin von Zweigbergk
ee1e520bcd tests: duplicate test for pager for old extension and for in-core pager
When the old pager extension is enabled, I think we should try to be
as BC as reasonable. To help with that, this patch brings back
test-pager.t as of 45ff5bf9e9c2 (pager: add a test of --pager=no
functionality, 2017-02-06), but under the name test-pager-legacy.t
However, since the behavior has changed in a few cases (notably by no
longer respecting pager.attend), the file is modified to work with the
current version. We will recover some lost BC in coming patches.

Also, to make sure the in-core pager does not depend on the pager
extension being enabled, this patch disables the extension in
test-pager.t. It turns out that pager.attend-$cmd was only supported
when the pager extension was enabled, so the tests are updated to
reflect that. We will need to decide what to do with these.
2017-03-13 21:42:59 -07:00
Gregory Szorc
1c399d6b97 util: make strdate's defaults default value a dict
It was specified to be an empty list in 3d8abfdaa08a in 2007.
It was correct at the time. But when the function was
refactored in 7bca0f2718ab (2010), it started expecting a dict.
I guess this code path is untested?

Thanks to Yuya for spotting this.
2017-03-14 08:51:35 -07:00
Rishabh Madan
6a6d5ec05c py3: open file in rb mode 2017-03-15 14:51:18 +05:30
Kyle Lippincott
a0eab21ffc debuglabelcomplete: fix to call debugnamecomplete in new location
debugnamecomplete was moved in a9aa67ba from commands to debugcommands, but
debuglabelcomplete was not modified to call it in its new location.
2017-03-14 13:10:30 -07:00
Gregory Szorc
1deeab0dbf tests: prove that hg init works with Python 3
The previous patch made `hg init` work!
2017-03-13 13:06:37 -07:00
Gregory Szorc
75a74f883f pycompat: custom implementation of urllib.parse.quote()
urllib.parse.quote() accepts either str or bytes and returns str.

There exists a urllib.parse.quote_from_bytes() which only accepts
bytes. We should probably use that to retain strong typing and
avoid surprises.

In addition, since nearly all strings in Mercurial are bytes, we
probably don't want quote() returning unicode.

So, this patch implements a custom quote() that only accepts bytes
and returns bytes. The quoted URL should only contain URL safe
characters which is a strict subset of ASCII. So
`.encode('ascii', 'strict')` should be safe.
2017-03-13 12:16:47 -07:00