A Scalable, User-Friendly Source Control System.
Go to file
Chris Jerdonek 0a2a1314d9 parsers: fail fast if Python has wrong minor version (issue4110)
This change causes an informative ImportError to be raised when importing
the parsers extension module if the minor version of the currently-running
Python interpreter doesn't match that of the Python used when compiling
the extension module.

This change also exposes a parsers.versionerrortext constant in the
C implementation of the module.  Its presence can be used to determine
whether this behavior is present in a version of the module.  The value
of the constant is the leading text of the ImportError raised and is set
to "Python minor version mismatch".

Here is an example of what the new error looks like:

  Traceback (most recent call last):
    File "test.py", line 1, in <module>
      import mercurial.parsers
  ImportError: Python minor version mismatch: The Mercurial extension
  modules were compiled with Python 2.7.6, but Mercurial is currently using
  Python with sys.hexversion=33883888: Python 2.5.6
  (r256:88840, Nov 18 2012, 05:37:10)
  [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))]
   at: /opt/local/Library/Frameworks/Python.framework/Versions/2.5/Resources/
    Python.app/Contents/MacOS/Python

The reason for raising an error in this scenario is that Python's C API
is known not to be compatible from minor version to minor version, even
if sys.api_version is the same.  See for example this Python bug report
about incompatibilities between 2.5 and 2.6+:

  http://bugs.python.org/issue8118

These incompatibilities can cause Mercurial to break in mysterious,
unforeseen ways.  For example, when Mercurial compiled with Python 2.7 was
run with 2.5, the following crash occurred when running "hg status":

  http://bz.selenic.com/show_bug.cgi?id=4110

After this crash was fixed, running with Python 2.5 no longer crashes, but
the following puzzling behavior still occurs:

    $ hg status
      ...
      File ".../mercurial/changelog.py", line 123, in __init__
        revlog.revlog.__init__(self, opener, "00changelog.i")
      File ".../mercurial/revlog.py", line 251, in __init__
        d = self._io.parseindex(i, self._inline)
      File ".../mercurial/revlog.py", line 158, in parseindex
        index, cache = parsers.parse_index2(data, inline)
    TypeError: data is not a string

which can be reproduced more simply with:

    import mercurial.parsers as parsers
    parsers.parse_index2("", True)

Both the crash and the TypeError occurred because the Python C API's
PyString_Check() returns the wrong value when the C header files from
Python 2.7 are run with Python 2.5.  This is an example of an
incompatibility of the sort mentioned in the Python bug report above.

Failing fast with an informative error message results in a better user
experience in cases like the above.  The information in the ImportError
also simplifies troubleshooting for those on Mercurial mailing lists, the
bug tracker, etc.

This patch only adds the version check to parsers.c, which is sufficient
to affect command-line commands like "hg status" and "hg summary".
An idea for a future improvement is to move the version-checking C code
to a more central location, and have it run when importing all
Mercurial extension modules and not just parsers.c.
2013-12-04 20:38:27 -08:00
contrib check-code: disallow use of dict(key=value) construction 2014-03-12 13:31:27 -04:00
doc doc: show short description of each commands in generated documents 2014-03-11 14:36:40 +09:00
hgext templater: avoid recursive evaluation of string literals completely 2014-03-10 01:01:42 +09:00
i18n i18n-ja: synchronized with ab338a276a26 2014-02-23 18:03:47 +09:00
mercurial parsers: fail fast if Python has wrong minor version (issue4110) 2013-12-04 20:38:27 -08:00
tests parsers: fail fast if Python has wrong minor version (issue4110) 2013-12-04 20:38:27 -08:00
.hgignore Makefile: do update on a temporary copy of a po file 2013-11-05 09:43:36 +01:00
.hgsigs Added signature for changeset c6d901b5cf89 2014-03-01 15:22:49 -06:00
CONTRIBUTORS Add note to CONTRIBUTORS file 2007-11-07 21:10:30 -06:00
COPYING COPYING: refresh with current address from fsf.org 2011-06-02 11:17:02 -05:00
hg rename util.set_binary to setbinary 2011-05-06 15:25:35 +02:00
hgeditor Fixed a bashism with the use of $RANDOM in hgeditor. 2010-05-19 18:06:35 +02:00
hgweb.cgi mq: add a warning about uncommitted changes for qfinish 2011-11-10 15:40:34 -06:00
Makefile setup: specify --prefix="" for install-home-bin to avoid badness with defaults 2014-02-03 02:09:46 -05:00
README readme: mention how to run in-place 2012-03-02 21:43:55 +02:00
setup.py setup.py: fix 2.4 breakage in 77ab0abb 2014-03-12 18:28:57 -04:00

Mercurial
=========

Mercurial is a fast, easy to use, distributed revision control tool
for software developers.

Basic install:

 $ make            # see install targets
 $ make install    # do a system-wide install
 $ hg debuginstall # sanity-check setup
 $ hg              # see help

Running without installing:

 $ make local      # build for inplace usage
 $ ./hg --version  # should show the latest version

See http://mercurial.selenic.com/ for detailed installation
instructions, platform-specific notes, and Mercurial user information.