Commit Graph

31167 Commits

Author SHA1 Message Date
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
Gregory Szorc
db258a9802 pycompat: alias urllib symbols directly
urllib.request imports a bunch of symbols from other urllib
modules. We should map to the original symbols not the
re-exported ones because this is more correct. Also, it
will prevent an import of urllib.request if only one of
the lower-level symbols/modules is needed.
2017-03-13 12:14:17 -07:00
Gregory Szorc
c90e121239 tests: clean up bad extension
The presence of the "babar" extension breaks subsequent tests.
So delete the file and create an empty one to return the config
to sanity.
2017-03-13 13:08:11 -07:00
Gregory Szorc
ddf0e60af7 perf: perform a garbage collection before each iteration
Currently, no explicit garbage collection is performed when running
the microbenchmarks in `hg perf`. I think this is wrong because
garbage collection can have a significant impact on execution times.
And, if gc is triggered via the default heuristics, it will
fire effectively randomly during subsequent benchmark iterations
due to variable amount of garbage left over from previous runs.

Running a gc before invoking the measured function will help ensure
state is more consistent across all iterations.
2017-03-13 18:16:42 -07:00
Gregory Szorc
dc53c9ca1b formatter: support json formatting of long type
By luck, we appear to not pass any long instances into
the JSON formatter. I suspect this will change with all the
Python 3 porting work. Plus I have another series that will
convert some ints to longs that triggers this.
2017-03-13 18:31:29 -07:00
Gregory Szorc
547d4e1ec5 rebase: don't use mutable default argument value 2017-03-12 21:56:39 -07:00
Gregory Szorc
ad67019046 mq: don't use mutable default argument value 2017-03-12 21:55:46 -07:00
Gregory Szorc
fbefc30c75 util: don't use mutable default argument value
I don't think this is any tight loops and we'd need to worry about
PyObject creation overhead. Also, I'm pretty sure strptime()
will be much slower than PyObject creation (date parsing is
surprisingly slow).
2017-03-12 21:54:32 -07:00
Gregory Szorc
98c99b99fa match: don't use mutable default argument value
There shouldn't be a big perf hit creating a new object because
this function is complicated and does things that dwarf the cost
of creating a new PyObject.
2017-03-12 21:53:03 -07:00
Gregory Szorc
d2e9e46760 hgweb: don't use mutable default argument value 2017-03-12 21:52:17 -07:00
Gregory Szorc
5cc9a634fe hgweb: don't use mutable default argument value 2016-12-26 16:55:47 -07:00
Gregory Szorc
9bc6055676 filemerge: don't use mutable default argument value 2016-12-26 16:54:33 -07:00
Gregory Szorc
b1f8fb51cd context: don't use mutable default argument value
Mutable default argument values are a Python gotcha and can
represent subtle, hard-to-find bugs. Lets rid our code base
of them.
2017-03-12 21:50:42 -07:00
Martin von Zweigbergk
b7d134a4b3 heads: enable pager 2017-03-13 11:19:24 -07:00
Martin von Zweigbergk
d6f2ec5990 branches: enable pager 2017-03-13 11:03:59 -07:00
Yuya Nishihara
0b54547397 py3: fix slicing of bytes in revset.formatspec() 2017-03-12 17:16:43 -07:00
Yuya Nishihara
ce52228976 py3: make set of revset operators and quotes in bytes 2017-03-12 17:13:54 -07:00
Yuya Nishihara
b72ea4927a py3: convert set of revset initial symbols back to bytes
Otherwise tokenize() would fail due to comparison between unicode and bytes.
2017-03-12 17:10:14 -07:00
Yuya Nishihara
a1b53adeff pycompat: add helper to iterate each char in bytes 2017-03-12 17:04:45 -07:00
Augie Fackler
38e6574e36 branchmap: fix python 2.6 by using util.buffer() instead of passing bytearray 2017-03-12 19:47:51 -04:00
Mads Kiilerich
b41f3f4681 rebase: allow rebasing children of wd to wd if a new branch has been set (BC)
The named branch of the leaf changeset can be changed by updating to it,
setting the branch, and amending.

But previously, there was no good way to *just* change the branch of several
linear changes. If rebasing changes with another parent to '.', it would pick
up a pending branch change up. But when rebasing changes that have the same
parent, it would fail with 'nothing to rebase', even when the branch name was
set differently.

To fix this, allow rebasing to same parent when a branch has been set.
2017-03-12 16:44:01 -07:00
Mads Kiilerich
ea3cfbc6fb merge: check current wc branch for 'nothing to merge', not its p1
The working directory will usually be clean or very clean, and wc will usually
have the same branch as its parent. This change will thus usually not make any
difference and is done as a separate change to show that. It will be used in a
later change.
2017-03-12 16:41:46 -07:00
Yuya Nishihara
1aa2b14401 lock: do not encode result of gethostname on Python 2
If a hostname contained non-ascii character, str.encode() would first try
to decode it to a unicode and raise UnicodeDecodeError.
2017-03-12 16:26:34 -07:00
Augie Fackler
be3d23b263 py3: prove hg files --rev works 2017-03-12 03:33:38 -04:00
Augie Fackler
cf064d4eef tests: make a variable for hg binary location in test-check-py3-commands
The number of which calls in here is starting to get silly.
2017-03-12 03:37:45 -04:00
Augie Fackler
3c69b88530 lock: encode result of gethostname into a bytestring 2017-03-12 03:28:50 -04:00
Martijn Pieters
458cf59837 config: avoid using a mutable default
Nothing *currently* mutates this list, but the moment something does it'll be
shared between all config instances. Avoid this eventuality.
2017-03-12 12:56:12 -07:00
Pierre-Yves David
c6f71ed49c localrepo: deprecate 'repo.join' in favor of 'repo.vfs.join'
localrepo have an insane amount of method. Accessing the feature through the
vfs is not really harder and allow us to schedule that method for removal.
2016-08-05 14:09:04 +02:00
Yuya Nishihara
7daa87b335 pycompat: move imports of cStringIO/io to where they are used
There's no point to import cStringIO as io since we have to select StringIO
or BytesIO conditionally.
2017-03-12 12:54:11 -07:00
Mads Kiilerich
d97e14e32b rbc: empty (and invalid) rbc-names file should give an empty name list
An empty file (if it somehow should exist) used to give a list with an empty
name. That didn't do any harm, but it was "wrong". Fix that.
2017-03-12 12:17:30 -07:00
Mads Kiilerich
d6292de3bd rbc: use struct unpack_from and pack_into instead of unpack and pack
These functions were introduced in Python 2.5 and are faster and simpler than
the old ones ...  mainly because we can avoid intermediate buffers:

  $ python -m timeit -s "_rbcrecfmt='>4sI'" -s 's = "x"*10000' -s 'from struct import unpack' 'unpack(_rbcrecfmt, buffer(s, 16, 8))'
  1000000 loops, best of 3: 0.543 usec per loop
  $ python -m timeit -s "_rbcrecfmt='>4sI'" -s 's = "x"*10000' -s 'from struct import unpack_from' 'unpack_from(_rbcrecfmt, s, 16)'
  1000000 loops, best of 3: 0.323 usec per loop

  $ python -m timeit -s "from array import array" -s "_rbcrecfmt='>4sI'" -s "s = array('c')" -s 's.fromstring("x"*10000)' -s 'from struct import pack' -s "rec = array('c')" 'rec.fromstring(pack(_rbcrecfmt, "asdf", 7))'
  1000000 loops, best of 3: 0.364 usec per loop
  $ python -m timeit -s "from array import array" -s "_rbcrecfmt='>4sI'" -s "s = array('c')" -s 's.fromstring("x"*10000)' -s 'from struct import pack_into' -s "rec = array('c')" -s 'rec.fromstring("x"*100)' 'pack_into(_rbcrecfmt, rec, 0, "asdf", 7)'
  1000000 loops, best of 3: 0.229 usec per loop
2016-10-19 02:46:35 +02:00
Augie Fackler
bc09440907 revlog: use bytes() instead of str() to get data from memoryview
Fixes `files -v` on Python 3.
2017-03-12 15:27:02 -04:00
Augie Fackler
d5d09dfdf4 util: teach url object about __bytes__
__str__ tries to do something reasonable, but someone else more
familiar with encoding bugs should check my work.
2017-03-12 03:33:22 -04:00
Augie Fackler
408bc8a668 manifest: ensure paths are bytes (not str) in pure parser 2017-03-12 03:31:54 -04:00
Augie Fackler
518fdf5357 manifest: now that node.bin is available, use it directly
Previously we were getting it through revlog, which is a little unusual.
2017-03-12 03:30:15 -04:00
Augie Fackler
c6a7c91d01 manifest: use node.bin instead of .decode('hex')
The latter doesn't work in Python 3.
2017-03-12 03:29:48 -04:00
Augie Fackler
93c6a91a94 manifest: add __next__ methods for Python 3
Python 3 renamed .next() in the iterator protocol to __next__().
2017-03-12 00:43:20 -05:00
Augie Fackler
f010a9d8ef files: use native string type to load rev opt from dict 2017-03-12 00:51:00 -05:00
Augie Fackler
8c2dacbd98 store: fix many single-byte ops to use slicing in _auxencode 2017-03-12 00:50:44 -05: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