annotate tests/test-module-imports.t @ 23702:c48924787eaa

filectx.parents: enforce changeid of parent to be in own changectx ancestors Because of the way filenodes are computed, you can have multiple changesets "introducing" the same file revision. For example, in the changeset graph below, changeset 2 and 3 both change a file -to- and -from- the same content. o 3: content = new | | o 2: content = new |/ o 1: content = old In such cases, the file revision is create once, when 2 is added, and just reused for 3. So the file change in '3' (from "old" to "new)" has no linkrev pointing to it). We'll call this situation "linkrev-shadowing". As the linkrev is used for optimization purposes when walking a file history, the linkrev-shadowing results in an unexpected jump to another branch during such a walk.. This leads to multiple bugs with log, annotate and rename detection. One element to fix such bugs is to ensure that walking the file history sticks on the same topology as the changeset's history. For this purpose, we extend the logic in 'basefilectx.parents' so that it always defines the proper changeset to associate the parent file revision with. This "proper" changeset has to be an ancestor of the changeset associated with the child file revision. This logic is performed in the '_adjustlinkrev' function. This function is given the starting changeset and all the information regarding the parent file revision. If the linkrev for the file revision is an ancestor of the starting changeset, the linkrev is valid and will be used. If it is not, we detected a topological jump caused by linkrev shadowing, we are going to walk the ancestors of the starting changeset until we find one setting the file to the revision we are trying to create. The performance impact appears acceptable: - We are walking the changelog once for each filelog traversal (as there should be no overlap between searches), - changelog traversal itself is fairly cheap, compared to what is likely going to be perform on the result on the filelog traversal, - We only touch the manifest for ancestors touching the file, And such changesets are likely to be the one introducing the file. (except in pathological cases involving merge), - We use manifest diff instead of full manifest unpacking to check manifest content, so it does not involve applying multiple diffs in most case. - linkrev shadowing is not the common case. Tests for fixed issues in log, annotate and rename detection have been added. But this changeset does not solve all problems. It fixes -ancestry- computation, but if the linkrev-shadowed changesets is the starting one, we'll still get things wrong. We'll have to fix the bootstrapping of such operations in a later changeset. Also, the usage of `hg log FILE` without --follow still has issues with linkrev pointing to hidden changesets, because it relies on the `filelog` revset which implement its own traversal logic that is still to be fixed. Thanks goes to: - Matt Mackall: for nudging me in the right direction - Julien Cristau and RĂ©mi Cardona: for keep telling me linkrev bug were an evolution show stopper for 3 years. - Durham Goode: for finding a new linkrev issue every few weeks - Mads Kiilerich: for that last rename bug who raise this topic over my anoyance limit.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 23 Dec 2014 15:30:38 -0800
parents c63a09b6b337
children f388ceae2250
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20059
385e209377a6 test-module-imports: skip on Python < 2.6, since ast is new in 2.6
Augie Fackler <raf@durin42.com>
parents: 20039
diff changeset
1 This code uses the ast module, which was new in 2.6, so we'll skip
385e209377a6 test-module-imports: skip on Python < 2.6, since ast is new in 2.6
Augie Fackler <raf@durin42.com>
parents: 20039
diff changeset
2 this test on anything earlier.
22947
c63a09b6b337 tests: use $PYTHON instead of hardcoding python
Augie Fackler <raf@durin42.com>
parents: 20519
diff changeset
3 $ $PYTHON -c 'import sys ; assert sys.version_info >= (2, 6)' || exit 80
20059
385e209377a6 test-module-imports: skip on Python < 2.6, since ast is new in 2.6
Augie Fackler <raf@durin42.com>
parents: 20039
diff changeset
4
20039
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
5 $ import_checker="$TESTDIR"/../contrib/import-checker.py
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
6 Run the doctests from the import checker, and make sure
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7 it's working correctly.
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
8 $ TERM=dumb
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9 $ export TERM
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
10 $ python -m doctest $import_checker
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12 $ cd "$TESTDIR"/..
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 $ if hg identify -q > /dev/null 2>&1; then :
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14 > else
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
15 > echo "skipped: not a Mercurial working dir" >&2
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16 > exit 80
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 > fi
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
18
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
19 There are a handful of cases here that require renaming a module so it
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
20 doesn't overlap with a stdlib module name. There are also some cycles
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
21 here that we should still endeavor to fix, and some cycles will be
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22 hidden by deduplication algorithm in the cycle detector, so fixing
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
23 these may expose other cycles.
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24
20395
ab71fb058ebf tests: test-module-imports.t works on windows (with backslash path sep)
Simon Heimberg <simohe@besonet.ch>
parents: 20392
diff changeset
25 $ hg locate 'mercurial/**.py' | sed 's-\\-/-g' | xargs python "$import_checker"
20386
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
26 mercurial/dispatch.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
27 stdlib: commands
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
28 relative: error, extensions, fancyopts, hg, hook, util
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
29 mercurial/fileset.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
30 stdlib: parser
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
31 relative: error, merge, util
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
32 mercurial/revset.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
33 stdlib: parser
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
34 relative: discovery, error, hbisect, phases, util
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
35 mercurial/templater.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
36 stdlib: parser
20519
cda9d2b6beab template: add revset() template function
Durham Goode <durham@fb.com>
parents: 20405
diff changeset
37 relative: config, error, templatefilters, templatekw, util
20386
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
38 mercurial/ui.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
39 stdlib: formatter
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
40 relative: config, error, scmutil, util
20392
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20386
diff changeset
41 Import cycle: mercurial.cmdutil -> mercurial.context -> mercurial.subrepo -> mercurial.cmdutil -> mercurial.cmdutil