view tests/test-unionrepo.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 198b003a2263
children bf86e3e87123
line wrap: on
line source

Test unionrepo functionality

Create one repository

  $ hg init repo1
  $ cd repo1
  $ touch repo1-0
  $ echo repo1-0 > f
  $ hg ci -Aqmrepo1-0
  $ touch repo1-1
  $ echo repo1-1 >> f
  $ hg ci -Aqmrepo1-1
  $ touch repo1-2
  $ echo repo1-2 >> f
  $ hg ci -Aqmrepo1-2
  $ hg log --template '{rev}:{node|short}  {desc|firstline}\n'
  2:68c0685446a3  repo1-2
  1:8a58db72e69d  repo1-1
  0:f093fec0529b  repo1-0
  $ tip1=`hg id -q`
  $ cd ..

- and a clone with a not-completely-trivial history

  $ hg clone -q repo1 --rev 0 repo2
  $ cd repo2
  $ touch repo2-1
  $ sed '1i\
  > repo2-1 at top
  > ' f > f.tmp
  $ mv f.tmp f
  $ hg ci -Aqmrepo2-1
  $ touch repo2-2
  $ hg pull -q ../repo1 -r 1
  $ hg merge -q
  $ hg ci -Aqmrepo2-2-merge
  $ touch repo2-3
  $ echo repo2-3 >> f
  $ hg ci -mrepo2-3
  $ hg log --template '{rev}:{node|short}  {desc|firstline}\n'
  4:2f0d178c469c  repo2-3
  3:9e6fb3e0b9da  repo2-2-merge
  2:8a58db72e69d  repo1-1
  1:c337dba826e7  repo2-1
  0:f093fec0529b  repo1-0
  $ cd ..

revisions from repo2 appear as appended / pulled to repo1

  $ hg -R union:repo1+repo2 log --template '{rev}:{node|short}  {desc|firstline}\n'
  5:2f0d178c469c  repo2-3
  4:9e6fb3e0b9da  repo2-2-merge
  3:c337dba826e7  repo2-1
  2:68c0685446a3  repo1-2
  1:8a58db72e69d  repo1-1
  0:f093fec0529b  repo1-0

manifest can be retrieved for revisions in both repos

  $ hg -R union:repo1+repo2 mani -r $tip1
  f
  repo1-0
  repo1-1
  repo1-2
  $ hg -R union:repo1+repo2 mani -r 4
  f
  repo1-0
  repo1-1
  repo2-1
  repo2-2

files can be retrieved form both repos

  $ hg -R repo1 cat repo1/f -r2
  repo1-0
  repo1-1
  repo1-2

  $ hg -R union:repo1+repo2 cat -r$tip1 repo1/f
  repo1-0
  repo1-1
  repo1-2

  $ hg -R union:repo1+repo2 cat -r4 $TESTTMP/repo1/f
  repo2-1 at top
  repo1-0
  repo1-1

files can be compared across repos

  $ hg -R union:repo1+repo2 diff -r$tip1 -rtip
  diff -r 68c0685446a3 -r 2f0d178c469c f
  --- a/f	Thu Jan 01 00:00:00 1970 +0000
  +++ b/f	Thu Jan 01 00:00:00 1970 +0000
  @@ -1,3 +1,4 @@
  +repo2-1 at top
   repo1-0
   repo1-1
  -repo1-2
  +repo2-3

heads from both repos are found correctly

  $ hg -R union:repo1+repo2 heads --template '{rev}:{node|short}  {desc|firstline}\n'
  5:2f0d178c469c  repo2-3
  2:68c0685446a3  repo1-2

revsets works across repos

  $ hg -R union:repo1+repo2 id -r "ancestor($tip1, 5)"
  8a58db72e69d

annotate works - an indication that linkrevs works

  $ hg --cwd repo1 -Runion:../repo2 annotate $TESTTMP/repo1/f -r tip
  3: repo2-1 at top
  0: repo1-0
  1: repo1-1
  5: repo2-3

union repos can be cloned ... and clones works correctly

  $ hg clone -U union:repo1+repo2 repo3
  requesting all changes
  adding changesets
  adding manifests
  adding file changes
  added 6 changesets with 11 changes to 6 files (+1 heads)

  $ hg -R repo3 paths
  default = union:repo1+repo2

  $ hg -R repo3 verify
  checking changesets
  checking manifests
  crosschecking files in changesets and manifests
  checking files
  6 files, 6 changesets, 11 total revisions

  $ hg -R repo3 heads --template '{rev}:{node|short}  {desc|firstline}\n'
  5:2f0d178c469c  repo2-3
  2:68c0685446a3  repo1-2

  $ hg -R repo3 log --template '{rev}:{node|short}  {desc|firstline}\n'
  5:2f0d178c469c  repo2-3
  4:9e6fb3e0b9da  repo2-2-merge
  3:c337dba826e7  repo2-1
  2:68c0685446a3  repo1-2
  1:8a58db72e69d  repo1-1
  0:f093fec0529b  repo1-0