Mercurial > hg
annotate tests/test-pull.t @ 20742:3681de20b0a7
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.
author | Chris Jerdonek <chris.jerdonek@gmail.com> |
---|---|
date | Wed, 04 Dec 2013 20:38:27 -0800 |
parents | 73e3e368bd42 |
children | 7a9cbb315d84 |
rev | line source |
---|---|
15446
c5c9ca3719f9
tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents:
13956
diff
changeset
|
1 $ "$TESTDIR/hghave" serve || exit 80 |
c5c9ca3719f9
tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents:
13956
diff
changeset
|
2 |
13956
ffb5c09ba822
tests: remove redundant mkdir
Martin Geisler <mg@lazybytes.net>
parents:
13826
diff
changeset
|
3 $ hg init test |
12279 | 4 $ cd test |
5 | |
6 $ echo foo>foo | |
7 $ hg addremove | |
8 adding foo | |
9 $ hg commit -m 1 | |
10 | |
11 $ hg verify | |
12 checking changesets | |
13 checking manifests | |
14 crosschecking files in changesets and manifests | |
15 checking files | |
16 1 files, 1 changesets, 1 total revisions | |
336 | 17 |
12279 | 18 $ hg serve -p $HGPORT -d --pid-file=hg.pid |
19 $ cat hg.pid >> $DAEMON_PIDS | |
20 $ cd .. | |
21 | |
12366
c01dc9087d9a
tests: drop a bunch of sed calls from unified tests
Matt Mackall <mpm@selenic.com>
parents:
12328
diff
changeset
|
22 $ hg clone --pull http://foo:bar@localhost:$HGPORT/ copy |
12279 | 23 requesting all changes |
24 adding changesets | |
25 adding manifests | |
26 adding file changes | |
27 added 1 changesets with 1 changes to 1 files | |
28 updating to branch default | |
29 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
30 | |
31 $ cd copy | |
32 $ hg verify | |
33 checking changesets | |
34 checking manifests | |
35 crosschecking files in changesets and manifests | |
36 checking files | |
37 1 files, 1 changesets, 1 total revisions | |
336 | 38 |
12279 | 39 $ hg co |
40 0 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
41 $ cat foo | |
42 foo | |
43 | |
44 $ hg manifest --debug | |
45 2ed2a3912a0b24502043eae84ee4b279c18b90dd 644 foo | |
46 | |
12366
c01dc9087d9a
tests: drop a bunch of sed calls from unified tests
Matt Mackall <mpm@selenic.com>
parents:
12328
diff
changeset
|
47 $ hg pull |
15552
62c9183a0bbb
clone: don't save user's password in .hg/hgrc (Issue3122)
Augie Fackler <durin42@gmail.com>
parents:
13956
diff
changeset
|
48 pulling from http://foo@localhost:$HGPORT/ |
12279 | 49 searching for changes |
50 no changes found | |
51 | |
12366
c01dc9087d9a
tests: drop a bunch of sed calls from unified tests
Matt Mackall <mpm@selenic.com>
parents:
12328
diff
changeset
|
52 $ hg rollback --dry-run --verbose |
13446
1e497df514e2
rollback: clarifies the message about the reverted state (issue2628)
Gilles Moris <gilles.moris@free.fr>
parents:
12643
diff
changeset
|
53 repository tip rolled back to revision -1 (undo pull: http://foo:***@localhost:$HGPORT/) |
12279 | 54 |
12399
4fee1fd3de9a
tests: added a short description to issue numbers
Martin Geisler <mg@aragost.com>
parents:
12377
diff
changeset
|
55 Issue622: hg init && hg pull -u URL doesn't checkout default branch |
4891
2d545b98a7bc
issue 622: pull/unbundle -u updates to default branch if repo was empty
Bryan O'Sullivan <bos@serpentine.com>
parents:
3736
diff
changeset
|
56 |
12279 | 57 $ cd .. |
58 $ hg init empty | |
59 $ cd empty | |
60 $ hg pull -u ../test | |
61 pulling from ../test | |
62 requesting all changes | |
63 adding changesets | |
64 adding manifests | |
65 adding file changes | |
66 added 1 changesets with 1 changes to 1 files | |
67 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
9996
2770d03ae49f
handle file URIs correctly, according to RFC 2396 (issue1153)
Sune Foldager <cryo@cyanite.org>
parents:
5384
diff
changeset
|
68 |
12279 | 69 Test 'file:' uri handling: |
70 | |
17486 | 71 $ hg pull -q file://../test-does-not-exist |
13823
ad179644750f
hg: look up schemes using url.url
Brodie Rao <brodie@bitheap.org>
parents:
13817
diff
changeset
|
72 abort: file:// URLs can only refer to localhost |
12316
4134686b83e1
tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents:
12279
diff
changeset
|
73 [255] |
12279 | 74 |
13826
e574207e3bcd
url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents:
13823
diff
changeset
|
75 $ hg pull -q file://../test |
e574207e3bcd
url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents:
13823
diff
changeset
|
76 abort: file:// URLs can only refer to localhost |
e574207e3bcd
url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents:
13823
diff
changeset
|
77 [255] |
e574207e3bcd
url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents:
13823
diff
changeset
|
78 |
12279 | 79 $ hg pull -q file:../test |
80 | |
12328
b63f6422d2a7
tests: fix a bunch of pointless #s in unified tests
Matt Mackall <mpm@selenic.com>
parents:
12316
diff
changeset
|
81 It's tricky to make file:// URLs working on every platform with |
b63f6422d2a7
tests: fix a bunch of pointless #s in unified tests
Matt Mackall <mpm@selenic.com>
parents:
12316
diff
changeset
|
82 regular shell commands. |
12279 | 83 |
84 $ URL=`python -c "import os; print 'file://foobar' + ('/' + os.getcwd().replace(os.sep, '/')).replace('//', '/') + '/../test'"` | |
85 $ hg pull -q "$URL" | |
13817
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13446
diff
changeset
|
86 abort: file:// URLs can only refer to localhost |
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13446
diff
changeset
|
87 [255] |
12279 | 88 |
13817
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13446
diff
changeset
|
89 $ URL=`python -c "import os; print 'file://localhost' + ('/' + os.getcwd().replace(os.sep, '/')).replace('//', '/') + '/../test'"` |
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13446
diff
changeset
|
90 $ hg pull -q "$URL" |
16913
f2719b387380
tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents:
16107
diff
changeset
|
91 |
f2719b387380
tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents:
16107
diff
changeset
|
92 $ cd .. |