Commit Graph

30386 Commits

Author SHA1 Message Date
Gregory Szorc
c066170094 dirs: port PyInt code to work on Python 3
PyIntObject no longer exists in Python 3. Instead, there is
PyLongObject.

Furthermore, PyInt_AS_LONG is a macro referencing a struct member.
PyInt_AS_LONG doesn't exist in Python 3 and PyLong_AS_LONG is a
#define for PyLong_AsLong, which is a function. So assigning to the
return value of PyLong_AS_LONG doesn't work.

This patch introduces a macro for obtaining the value of an
integer-like type that works on Python 2 and Python 3. On
Python 3, we access the struct field of the underlying
PyLongObjet directly, without overflow checking. This is
essentially the same as what Python 2 was doing except using a
PyLong instead of a PyInt.
2016-10-08 16:20:21 +02:00
Gregory Szorc
17698cdbdb dirs: convert PyString to PyBytes
PyStringObject was renamed to PyBytes in Python 3 along with the
corresponding PyString* functions and macros. PyString* doesn't
exist in Python 3. But PyBytes* is an alias to PyString in Python 2.
So rewrite PyString* to PyBytes* for Python 2/3 dual compatibility.
2016-10-08 14:31:59 +02:00
Gregory Szorc
e7e3331fdd dirs: inline string macros
The old code happened to work because of how the macro was defined.
This no longer works in Python 3. Furthermore, assigning to a macro
just feels weird. So just inline the macro.
2016-10-08 16:02:51 +02:00
Gregory Szorc
216178bf54 parsers: use PyVarObject_HEAD_INIT
The macro changed slightly in Python 3, introducing curly brackets
that somehow confuse Clang into issuing a ton of compiler warnings.
Using PyVarObject_HEAD_INIT makes these go away.

It's worth noting that the code is identical: the 2nd argument to
PyVarObject_HEAD_INIT is assigned to the ob_size field and is
inserted immediately after "PyObject_HEAD_INIT(type)" is generated.
Compilers are weird.
2016-10-08 22:44:02 +02:00
Gregory Szorc
c76037ee62 pathencode: use Py_SIZE directly
On Python 2, PyBytes_GET_SIZE is the same as PyString_GET_SIZE which
is the same as Py_SIZE which resolves to a struct member.

On Python 3, PyBytes_GET_SIZE is
"(assert(PyBytes_Check(op)),Py_SIZE(op))". The compiler barfs when
assigning to this version.

This patch simply changes PyBytes_GET_SIZE to Py_SIZE. On Python 2,
there is no effective change in behavior. On Python 3, we drop the
PyBytes_Check(). However, in all cases we have explicitly created
a PyBytesObject in the same function, so the PyBytes_Check() is
guaranteed to be true. Despite this, code changes over time, so
I've added added assert() in all callers so we can catch this in
debug builds.

With this patch, all mercurial.* C extensions now compile on Python 3
on my OS X machine. There are several compiler warnings and I'm sure
there are incompatibilities with Python 3, including possibly
segfaults. But it is a milestone.
2016-10-08 22:21:22 +02:00
Gregory Szorc
83437de093 util: remove PyString* aliases on Python 3
We no longer have any users of the legacy PyString* functions. We no
longer need these redefinitions.

After this change, the only reference to "PyString" in the repo is in
watchman's C extension. That isn't our code and porting Mercurial
extensions to Python 3 is not a high priority at the moment. watchman's
C extension will be dealt with later.
2016-10-08 22:04:56 +02:00
Gregory Szorc
bd245cb051 parsers: convert PyString* to PyBytes*
With this change, we no longer have any occurrences of "PyString" in
our C extensions.
2016-10-08 22:02:29 +02:00
Gregory Szorc
d59467145b pathencode: convert PyString* to PyBytes* 2016-10-08 22:01:07 +02:00
Gregory Szorc
fb1f96e995 osutil: convert PyString* to PyBytes*
Continuing the conversion from PyString* to PyBytes*.
2016-10-08 21:58:55 +02:00
Gregory Szorc
0c43bebd47 manifest: convert PyString* to PyBytes*
Python 2.6 introduced PyBytesObject and PyBytes* as aliases for
PyStringObject and PyString*. So on Python 2.6+, PyBytes* and PyString*
are identical and this patch should be a no-op.

On Python 3, PyStringObject is effectively renamed to PyUnicodeObject
and PyBytesObject becomes the main type for byte strings.

This patch begins the process of mass converting PyString* to PyBytes*
so the C extensions use the correct type on Python 3.
2016-10-08 21:57:55 +02:00
Yuya Nishihara
512724e1f5 merge: update doc of manifestmerge() per ce7e15f82b44
p1 was renamed to wctx by ce7e15f82b44.
2016-10-02 17:31:32 +09:00
Yuya Nishihara
48807b626c py3: remove superfluous indent from check-py3-compat.py 2016-10-08 17:22:40 +02:00
Yuya Nishihara
6ed34c797c py3: make check-py3-compat.py load modules in standard manner
Otherwise no code transformation would be applied to the modules which are
imported only by imp.load_module().

This change means modules are imported from PYTHONPATH, not from the paths
given by command arguments. This isn't always correct, but seems acceptable.
2016-10-08 17:22:07 +02:00
Yuya Nishihara
635359be9c py3: include module filename in check-py3-compat.py output
This change is intended to reduce noises in the next patch.
2016-10-09 08:31:39 +02:00
Gregory Szorc
101896816d util: document we want Python type mapping to be temporary
I think remapping Python C API types and functions is not a great
approach. I'd prefer this whole #ifdef disappeared. Add a comment
so we don't forget about it.
2016-10-08 19:16:50 +02:00
Gregory Szorc
e28802538d util: define PyInt_Type on Python 3
util.h attempts to wallpaper over C API differences between Python 2
and 3. This is not the correct approach where performance is critical.
But it is good enough for the current state of the Python 3 port.
2016-10-08 19:02:44 +02:00
Gregory Szorc
8d34ccc102 parsers: return NULL from PyInit_parsers on Python 3
This function must return a PyObject* or the compiler complains.
2016-10-08 17:51:29 +02:00
Gábor Stefanik
9fbfde0b09 mail: take --encoding and HGENCODING into account
Fall back to our encoding strategy for sending MIME text
that's neither ASCII nor UTF-8.
2016-10-05 13:45:22 +02:00
Simon Farnsworth
c7fbc87ac7 template: provide a termwidth keyword (issue5395)
We want to provide terminal-sized output. As a starting point, expose the
terminal width to the templater for use in things like fill.
2016-10-08 02:26:48 -07:00
Augie Fackler
10de2c7e4f util: ensure forwarded attrs are set in globals() as sysstr
Custom module importer strikes again.
2016-10-08 08:36:39 -04:00
Augie Fackler
867b91b167 pycompat: when setting attrs, ensure we use sysstr
The custom module importer was making these bytes, so when we poked
values into self.__dict__ we had bytes instead of unicode on py3 and
it didn't work.
2016-10-08 08:35:43 -04:00
Augie Fackler
968375bf81 i18n: make the locale directory name the same string type as the datapath 2016-10-08 05:26:18 -04:00
Augie Fackler
5a5f1c4d36 contributing: add new file with a pointer to the wiki
This also includes what I consider to be the minimum set of steps
someone should be able to perform even if they can't run the
testsuite. Hopefully this will help new contributors know to at least
run the two checkers that find most things that (in my experience)
require manual cleanup.
2016-10-08 10:39:00 -04:00
Yuya Nishihara
5196f3da90 templater: add relpath() to convert repo path to relative path (issue5394)
File paths in template are repository-absolute paths. This function can be
used to convert them to filesystem paths relative to cwd. This also converts
'/' to '\\' on Windows.
2016-10-08 15:24:26 +02:00
Martijn Pieters
de1f10a894 hgweb: fix the MRO in Python 3
object should appear at the end, otherwise it tries to pre-empt the other
new-style classes in the MRO, resulting in an unresolvable MRO in Py3. We still
need to include object because otherwise in 2.7 we end up with an old-style
class if threading is not supported, new-style if it is.
2016-10-08 19:11:19 +02:00
Jun Wu
a68511813b hgweb: make fctx.annotate a separated function so it could be wrapped
This patch moves "fctx.annotate" used by the "annotate" webcommand, along
with the diffopts to a separated function which takes a ui and a fctx.
So it could be replaced by other implementations which don't want to replace
the core "fctx.annotate" directly.
2016-10-08 16:10:34 +01:00
Anton Shestakov
36cf1f5e53 zsh_completion: update some option usage flags ('+', '=' and ':')
Here are the relevant symbol descriptions from [0]

optspec:...
  The colon indicates handling for one or more arguments to the option; if it
  is not present, the option is assumed to take no arguments.

-optname+
  The first argument may appear immediately after optname in the same word,
  or may appear as a separate word after the option. For example, ‘-foo+:...’
  specifies that the completed option and argument will look like either
  ‘-fooarg’ or ‘-foo arg’.

-optname=
  The argument may appear as the next word, or in same word as the option
  name provided that it is separated from it by an equals sign, for example
  ‘-foo=arg’ or ‘-foo arg’.

There are 3 types of changes in this patch:

- addition of '=': means that '--repository ~/foo' can now also be spelled as
  '--reporitory=~/foo'

- addition of '+': means '-r 0' can now also be spelled as '-r0'

- removal of '+', '=' and ':': means that '-u|--untrusted' doesn't take any
  arguments, so '-uq' is definitely '-u -q' and not '--untrusted=q'

Occasionally, ':' had to be added together with '=' and '+'.

This patch is mostly just making zsh_completion file look more like zsh's own
hg completion file so that we can more easily take improvements from them or
send patches to them. Some context for this patch from zsh project: [2] [3].

[0]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html
[1]: https://sourceforge.net/p/zsh/code/ci/master/tree/Completion/Unix/Command/_hg
[2]: 92584634d3/
[3]: http://www.zsh.org/mla/workers/2015/msg02551.html
2016-10-04 20:49:59 +08:00
Gregory Szorc
552458f2ca manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
This flag disappeared in Python 3. It is only necessary in Python 2,
apparently.
2016-10-08 18:04:57 +02:00
Ryan McElroy
eabf9d1003 import: abort instead of crashing when copy source does not exist (issue5375)
Previously, when a patch contained a move or copy from a source that did not
exist, `hg import` would crash. This patch changes import to raise a PatchError
with an explanantion of what is wrong with the patch to avoid the stack trace
and bad user experience.
2016-10-08 05:26:58 -07:00
Mateusz Kwapich
c9434eddcf py3: make encodefun in store.py compatible with py3k
This ensures that the filename encoding functions always map bytestrings
to bytestrings regardless of python version.
2016-10-08 08:54:05 -07:00
Mateusz Kwapich
411ad51cc8 py3: make the string unicode so its iterable in py3k 2016-10-08 08:45:28 -07:00
Gábor Stefanik
8d5c0019c5 copies: don't record divergence for files needing no merge
This is left over from when _checkcopies was factored out from mergecopies.

The 2nd break has "of = None" before it, so it's a functionally equivalent
change. The 1st one, however, causes a divergence to be recorded when
a file has been renamed, but there is nothing to be merged to it.

This is currently harmless, since the extra divergence is simply ignored
later. However, the new _checkcopies introduced in the rest of this series
does more than just record a divergence after completing the main loop,
and it's important that the "post-processing" stage is really skipped
for no-merge-needed renames.
2016-10-03 13:29:59 +02:00
Tooru Fujisawa
2c9ec77e6d hgweb: avoid line wrap between revision and annotate-info (issue5398)
Add white-space: nowrap to td.annotate to avoid wrapping div.annotate-info
into next line if there is revision number in the same cell, as it is hard to
mouse over div.annotate-info if it's wrapped into next line.
2016-10-08 19:32:54 +09:00
Pulkit Goyal
e4b15b1b8c py3: make format strings unicodes and not bytes
Fixes issues on Python 3, wherein docstrings are unicodes.
Shouldn't break anything on Python 2.
2016-10-08 16:10:58 +02:00
Pulkit Goyal
5df46f7e20 mail: handle renamed email.Header
We are still using email.Header which was renamed to email.header back in
Python 2.5. References: https://hg.python.org/cpython/file/2.4/Lib/email
and https://hg.python.org/cpython/file/2.5/Lib/email
2016-10-07 17:30:11 +02:00
Augie Fackler
efaaf08415 revset: build _syminitletters from a saner source: the string module
For now, these sets will be unicode characters in Python 3, which is
probably wrong, but it un-blocks importing the module so we can get
further along. In the future we'll have to come up with a reasonable
encoding strategy for revsets in Python 3.

This patch was originally pair-programmed with Martijn.
2016-10-07 08:32:40 -04:00
Gregory Szorc
275bf7db29 debugcommands: move 'debugdeltachain' in the new module 2016-08-17 21:01:02 -07:00
Gregory Szorc
df02df41b0 debugcommands: move 'debugindex' and 'debugindexdot' in the new module 2016-08-17 21:00:11 -07:00
Gregory Szorc
56f5ef7ff5 debugcommands: move 'debugignore' in the new module 2016-08-17 20:59:13 -07:00
Gregory Szorc
1ec64ddf29 debugcommands: move 'debuggetbundle' in the new module 2016-11-10 09:44:47 -08:00
Gregory Szorc
a47dd1170a debugcommands: move 'debugfsinfo' in the new module 2016-08-17 20:58:16 -07:00
Gregory Szorc
c3736a6fe2 debugcommands: move 'debugfileset' in the new module 2016-08-17 20:57:57 -07:00
Remi Chaintron
25e30cf1ed censor: flag internal documentation 2016-11-23 17:36:35 +00:00
Kostia Balytskyi
c89c84d317 shelve: make --keep option survive user intervention (issue5431)
Currently if user runs 'hg unshelve --keep' and merge conflicts
occur, the information about --keep provided by user is lost and
shelf is deleted after 'hg unshelve --continue'. This is obviously
not desired, so this patch fixes it.
2016-11-23 14:58:52 -08:00
Jun Wu
cdd5ade3da worker: use os._exit for posix worker in all cases
Like commandserver, the worker should never run other resource cleanup logic.

Previously this is not true for workers if they have exceptions other than
KeyboardInterrupt.

This actually caused a real-world deadlock with remotefilelog:

1. remotefilelog/fileserverclient creates a sshpeer. pipei/o/e get created.
2. worker inherits that sshpeer's pipei/o/e.
3. worker runs sshpeer.cleanup (only happens without os._exit)
4. worker closes pipeo/i, which will normally make the sshpeer read EOF from
   its stdin and exit. But the master process still have pipeo, so no EOF.
5. worker reads pipee (stderr of sshpeer), which never completes because
   the ssh process does not exit, does not close its stderr.
6. master waits for all workers, which never completes because they never
   complete sshpeer.cleanup.

This could also be addressed by closing these fds after fork, which is not
easy because Python 2.x does not have an official "afterfork" hook. Hacking
os.fork is also ugly. Besides, sshpeer is probably not the only troublemarker.

The patch changes _posixworker so all its code paths will use os._exit to
avoid running unwanted resource clean-ups.
2016-11-24 01:15:34 +00:00
Jun Wu
115ee04855 dispatch: move part of callcatch to scmutil
Per discussion at 7d927e65eaf2 [1], we need "callcatch" in worker.py. Move
it to scmutil.py to avoid cycles.

Note that dispatch's callcatch handles some additional high-level exceptions
related to config parsing, and commands. Moving them to scmutil will make
scmutil depend on "commands" or require "_formatparse" and "_getsimilar"
(and "difflib") to be moved as well. In the worker use-case, it is forked
when config and commands are fully loaded. So it should not care about those
exceptions.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-August/087116.html
2016-11-24 00:48:40 +00:00
Pulkit Goyal
97f340e354 py3: use pycompat.getcwd() instead of os.getcwd()
We have pycompat.getcwd() which returns bytes path on Python 3. This patch
changes most of the occurences of the os.getcwd() with pycompat one.
2016-11-23 00:03:11 +05:30
Gregory Szorc
06abee55d2 debugcommands: move 'debugextensions' to the new module 2016-08-17 20:57:15 -07:00
Gregory Szorc
ba40ffc6e2 debugcommands: move 'debugdiscovery' in the module
And a lot of imports with it.
2016-08-17 20:56:11 -07:00
Gregory Szorc
7264f083ae debugcommands: move 'debugdate' in the new module 2016-08-17 20:43:31 -07:00