Mercurial > public > mercurial-scm > hg
diff tests/test-fileset.t @ 27464:c39ecb2b86b3
fileset: detect unintentional existing() invocation at runtime
A fileset predicate can invoke 'matchctx.existing()' successfully,
even if it isn't marked as "existing caller". It is aborted only in
some corner cases: e.g. there were one deleted file in the working
directory (see 8a0513bf030a for detail).
This patch makes 'matchctx.existing()' invocation abort if not
'_existingenabled', which is true only while "existing caller"
running.
After this changes, non-"existing caller" predicate function is
aborted immediately, whenever it invokes 'matchctx.existing()'. This
prevent developer from forgetting to mark a predicate as "existing
caller".
BTW, unintentional 'matchctx.status()' invocation can be detected
easily without any additional trick like this patch, because it
returns 'None' if a predicate isn't marked as "status caller", and
referring field (e.g. '.modified') of it is always aborted.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Mon, 21 Dec 2015 22:31:16 +0900 |
parents | 2f15253e415f |
children | 319d78cf787d |
line wrap: on
line diff
--- a/tests/test-fileset.t Mon Dec 21 22:31:16 2015 +0900 +++ b/tests/test-fileset.t Mon Dec 21 22:31:16 2015 +0900 @@ -328,3 +328,22 @@ b2link bin c1 + +Test detection of unintentional 'matchctx.existing()' invocation + + $ cat > $TESTTMP/existingcaller.py <<EOF + > from mercurial import fileset + > + > @fileset.predicate('existingcaller()', callexisting=False) + > def existingcaller(mctx, x): + > # this 'mctx.existing()' invocation is unintentional + > return [f for f in mctx.existing()] + > EOF + + $ cat >> .hg/hgrc <<EOF + > [extensions] + > existingcaller = $TESTTMP/existingcaller.py + > EOF + + $ fileset 'existingcaller()' 2>&1 | tail -1 + AssertionError: unexpected existing() invocation