Mercurial > hg
view tests/test-revert.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 | bd19587a3347 |
children | 4af19d39706e |
line wrap: on
line source
$ hg init repo $ cd repo $ echo 123 > a $ echo 123 > c $ echo 123 > e $ hg add a c e $ hg commit -m "first" a c e nothing changed $ hg revert abort: no files or directories specified (use --all to revert all files) [255] $ hg revert --all $ echo 123 > b should show b unknown $ hg status ? b $ echo 12 > c should show b unknown and c modified $ hg status M c ? b $ hg add b should show b added and c modified $ hg status M c A b $ hg rm a should show a removed, b added and c modified $ hg status M c A b R a $ hg revert a should show b added, copy saved, and c modified $ hg status M c A b $ hg revert b should show b unknown, and c modified $ hg status M c ? b $ hg revert --no-backup c should show unknown: b $ hg status ? b $ hg add b should show b added $ hg status b A b $ rm b should show b deleted $ hg status b ! b $ hg revert -v b forgetting b should not find b $ hg status b b: * (glob) should show a c e $ ls a c e should verbosely save backup to e.orig $ echo z > e $ hg revert --all -v saving current version of e as e.orig reverting e should say no changes needed $ hg revert a no changes needed to a should say file not managed $ echo q > q $ hg revert q file not managed: q $ rm q should say file not found $ hg revert notfound notfound: no such file in rev 334a9e57682c $ touch d $ hg add d $ hg rm a $ hg commit -m "second" $ echo z > z $ hg add z $ hg st A z ? e.orig should add a, remove d, forget z $ hg revert --all -r0 adding a removing d forgetting z should forget a, undelete d $ hg revert --all -rtip forgetting a undeleting d $ rm a *.orig should silently add a $ hg revert -r0 a $ hg st a A a $ hg rm d $ hg st d R d should silently keep d removed $ hg revert -r0 d $ hg st d R d $ hg update -C 1 files updated, 0 files merged, 0 files removed, 0 files unresolved #if execbit $ chmod +x c $ hg revert --all reverting c should print non-executable $ test -x c || echo non-executable non-executable $ chmod +x c $ hg commit -m exe $ chmod -x c $ hg revert --all reverting c should print executable $ test -x c && echo executable executable #endif $ cd .. Issue241: update and revert produces inconsistent repositories $ hg init a $ cd a $ echo a >> a $ hg commit -A -d '1 0' -m a adding a $ echo a >> a $ hg commit -d '2 0' -m a $ hg update 0 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ mkdir b $ echo b > b/b should fail - no arguments $ hg revert -rtip abort: no files or directories specified (use --all to revert all files, or 'hg update 1' to update) [255] should succeed $ hg revert --all -rtip reverting a Issue332: confusing message when reverting directory $ hg ci -A -m b adding b/b created new head $ echo foobar > b/b $ mkdir newdir $ echo foo > newdir/newfile $ hg add newdir/newfile $ hg revert b newdir reverting b/b (glob) forgetting newdir/newfile (glob) $ echo foobar > b/b $ hg revert . reverting b/b (glob) reverting a rename target should revert the source $ hg mv a newa $ hg revert newa $ hg st a newa ? newa $ cd .. $ hg init ignored $ cd ignored $ echo '^ignored$' > .hgignore $ echo '^ignoreddir$' >> .hgignore $ echo '^removed$' >> .hgignore $ mkdir ignoreddir $ touch ignoreddir/file $ touch ignoreddir/removed $ touch ignored $ touch removed 4 ignored files (we will add/commit everything) $ hg st -A -X .hgignore I ignored I ignoreddir/file I ignoreddir/removed I removed $ hg ci -qAm 'add files' ignored ignoreddir/file ignoreddir/removed removed $ echo >> ignored $ echo >> ignoreddir/file $ hg rm removed ignoreddir/removed should revert ignored* and undelete *removed $ hg revert -a --no-backup reverting ignored reverting ignoreddir/file (glob) undeleting ignoreddir/removed (glob) undeleting removed $ hg st -mardi $ hg up -qC $ echo >> ignored $ hg rm removed should silently revert the named files $ hg revert --no-backup ignored removed $ hg st -mardi someone set up us the copies $ rm .hgignore $ hg update -C 0 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg mv ignored allyour $ hg copy removed base $ hg commit -m rename copies and renames, you have no chance to survive make your time (issue3920) $ hg update '.^' 1 files updated, 0 files merged, 2 files removed, 0 files unresolved $ hg revert -rtip -a adding allyour adding base removing ignored $ hg status -C A allyour ignored A base removed R ignored $ cd ..