Mercurial > hg
view tests/test-mq-merge.t @ 29642:8960fcb76ca4 stable
demandimport: avoid infinite recursion at actual module importing (issue5304)
Before this patch, importing C module on Windows environment causes
infinite recursion call, if py2exe is used with -b2 option.
At importing C module "a.b", extra hooking by zipextimporter of py2exe
causes:
0. assumption before accessing "b" of "a":
- built-in module object is created for "a",
(= "a" is actually imported)
- _demandmod is created for "a.b" as a proxy object, and
(= "a.b" is not yet imported)
- an attribute "b" of "a" is initialized by the latter
1. invocation of __import__ via _hgextimport() in _demandmod._load()
for "a.b" implies _demandimport() for "a.b"
This is unintentional, because _demandmod might be returned by
_hgextimport() instead of built-in module object.
2. _demandimport() at (1) is invoked with not context of "a", but
context of zipextimporter
Just after invocation of _hgextimport() in _demandimport(), an
attribute "b" of the built-in module object for "a" is still
bound to the proxy object for "a.b", because context of "a" isn't
updated by actual importing "a.b". even though the built-in
module object for "a.b" already appears in sys.modules.
Therefore, chainmodules() returns _demandmod for "a.b", which is
gotten from the attribute "b" of "a".
3. processfromitem() on "a.b" causes _demandmod._load() for "a.b"
again
_demandimport() takes context of "a" in this case.
Therefore, attributes below are bound to built-in module object
for "a.b", as expected:
- "b" of built-in module object for "a"
- _module of _demandmod for "a.b"
4. but _demandimport() invoked at (1) returns _demandmod object
because _demandimport() just returns the object returned by
chainmodules() at (3) above.
5. then, _demandmod._load() causes infinite recursion call
_demandimport() returns _demandmod for "a.b", and it is "self" at
_demandmod._load().
To avoid infinite recursion at actual module importing, this patch
uses self._module, if _hgextimport() returns _demandmod itself. If
_demandmod._module isn't yet bound at this point, execution should be
aborted, because actual importing failed.
In this patch, _demandmod._module is examined not on _demandimport()
side, but on _demandmod._load() side, because:
- the former has some exit points
- only the latter uses _hgextimport(), except for _demandimport()
BTW, this issue occurs only in the code path for non .py/.pyc files in
zipextimporter (strictly speaking, in _memimporter) of py2exe.
Even if zipextimporter is enabled, .py/.pyc files are handled by
zipimporter, and it doesn't imply unintentional _demandimport() at
invocation of __import__ via _hgextimport().
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sun, 31 Jul 2016 05:39:59 +0900 |
parents | e955549cd045 |
children | 4441705b7111 |
line wrap: on
line source
Setup extension: $ cat <<EOF >> $HGRCPATH > [extensions] > mq = > [mq] > git = keep > EOF Test merge with mq changeset as the second parent: $ hg init m $ cd m $ touch a b c $ hg add a $ hg commit -m a $ hg add b $ hg qnew -d "0 0" b $ hg update 0 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg add c $ hg commit -m c created new head $ hg merge 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg commit -m merge abort: cannot commit over an applied mq patch [255] $ cd .. Issue529: mq aborts when merging patch deleting files $ checkundo() > { > if [ -f .hg/store/undo ]; then > echo ".hg/store/undo still exists" > fi > } Commit two dummy files in "init" changeset: $ hg init t $ cd t $ echo a > a $ echo b > b $ hg ci -Am init adding a adding b $ hg tag -l init Create a patch removing a: $ hg qnew rm_a $ hg rm a $ hg qrefresh -m "rm a" Save the patch queue so we can merge it later: $ hg qsave -c -e copy $TESTTMP/t/.hg/patches to $TESTTMP/t/.hg/patches.1 (glob) $ checkundo Update b and commit in an "update" changeset: $ hg up -C init 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ echo b >> b $ hg st M b $ hg ci -m update created new head # Here, qpush used to abort with : # The system cannot find the file specified => a $ hg manifest a b $ hg qpush -a -m merging with queue at: $TESTTMP/t/.hg/patches.1 (glob) applying rm_a now at: rm_a $ checkundo $ hg manifest b Ensure status is correct after merge: $ hg qpop -a popping rm_a popping .hg.patches.merge.marker patch queue now empty $ cd .. Classic MQ merge sequence *with an explicit named queue*: $ hg init t2 $ cd t2 $ echo '[diff]' > .hg/hgrc $ echo 'nodates = 1' >> .hg/hgrc $ echo a > a $ hg ci -Am init adding a $ echo b > a $ hg ci -m changea $ hg up -C 0 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg cp a aa $ echo c >> a $ hg qnew --git -f -e patcha $ echo d >> a $ hg qnew -d '0 0' -f -e patcha2 Create the reference queue: $ hg qsave -c -e -n refqueue copy $TESTTMP/t2/.hg/patches to $TESTTMP/t2/.hg/refqueue (glob) $ hg up -C 1 1 files updated, 0 files merged, 1 files removed, 0 files unresolved Merge: $ HGMERGE=internal:other hg qpush -a -m -n refqueue merging with queue at: $TESTTMP/t2/.hg/refqueue (glob) applying patcha patching file a Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines). fuzz found when applying patch, stopping patch didn't work out, merging patcha 1 files updated, 0 files merged, 1 files removed, 0 files unresolved 0 files updated, 2 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) applying patcha2 now at: patcha2 Check patcha is still a git patch: $ cat .hg/patches/patcha # HG changeset patch # Parent d3873e73d99ef67873dac33fbcc66268d5d2b6f4 diff --git a/a b/a --- a/a +++ b/a @@ -1,1 +1,2 @@ -b +a +c diff --git a/a b/aa copy from a copy to aa --- a/a +++ b/aa @@ -1,1 +1,1 @@ -b +a Check patcha2 is still a regular patch: $ cat .hg/patches/patcha2 # HG changeset patch # Date 0 0 # Parent ???????????????????????????????????????? (glob) diff -r ???????????? -r ???????????? a (glob) --- a/a +++ b/a @@ -1,2 +1,3 @@ a c +d $ cd ..