##// END OF EJS Templates
copies-rust: leverage the immutability for efficient update...
copies-rust: leverage the immutability for efficient update The immutable OrdMap has a diff function. That function yield items for each difference (missing in minor; missing in major; present in both, but different). We reorganise the manifest merging code to use this new function. We gather the data we would need to inject into the `minor` or `major` dict and eventually update one of them. The semantic of the merge itself is kept as is. Why are we doing this? Last year we contributed a patch making that diff function quickly detect some of the identical subsection when comparing two OrdMap cloned from a common ancestors (because they point to the very same node in memory). As a result: - That diff function is very fast in most of our cases, - It is important to maximize the "common" part by minimising the amount of unnecessary changes we do in theses Map. This is why we gather update for both and update the one with the smaller update. In practice, this yield a massive speed up on all our slow cases. Some examples below.: Repo Cases Source-Rev Dest-Rev Old-Time New-Time Difference Factor ------------------------------------------------------------------------------------------------------------------------------------ pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 33.527067 s, 2.780174 s, -30.746893 s, × 0.0829 netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : killed(>120), 1.231869 s mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : killed(>120), 3.478747 s mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 83.508590 s, 9.843481 s, -73.665109 s, × 0.1179 mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 55.079813 s, 1.465128 s, -53.614685 s, × 0.0266 The performance compared to the Python code are now comparable (worst case are a score percent slower)" You an check the full table below for details. The big new is that, with this change, we are now faster filelog in most case, . Below is an highlight of some pretty nice win: Repo Case Source-Rev Dest-Rev filelog sidedata Difference Factor --------------------------------------------------------------------------------------------------------------------------------------- pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 1.354211 s, 0.252125 s, -1.102086 s, × 0.186179 netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 0.939593 s, 0.112534 s, -0.827059 s, × 0.119769 netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 3.824967 s, 1.231869 s, -2.593098 s, × 0.322060 mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 1.142414 s, 0.102184 s, -1.040230 s, × 0.089446 mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 6.667504 s, 0.046220 s, -6.621284 s, × 0.006932 mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 3.267274 s, 0.315271 s, -2.952003 s, × 0.096494 mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 16.038104 s, 3.478747 s, -12.559357 s, × 0.216905 mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 20.639928 s, 4.766435 s, -15.873493 s, × 0.230933 They they are a handful of slower case where we perform less well. A good Share of them are really pathological "service" merge in mozilla-try, but not all of them. Repo Case Source-Rev Dest-Rev filelog sidedata Difference Factor --------------------------------------------------------------------------------------------------------------------------------------- pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 0.001055 s, 2.780174 s, +2.779119 s, × 2635.236019 mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 0.088715 s, 0.435381 s, +0.346666 s, × 4.907637 mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 0.080765 s, 0.415461 s, +0.334696 s, × 5.144072 mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 7.598509 s, 9.843481 s, +2.244972 s, × 1.295449 mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 0.092232 s, killed mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 0.093892 s, killed mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 0.227503 s, killed mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 21.145391 s, killed mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 25.304164 s, killed Below are two different tables for full performance comparison - this changeset against the previous one (spoiler: it is much better) - this changeset against the python code (spoiler: still slower, but it gets more comparable) - this changeset against the filelog code (spoiler: better in many case, but not all) Repo Cases Source-Rev Dest-Rev Old-Time New-Time Difference Factor ------------------------------------------------------------------------------------------------------------------------------------ mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 0.000049 s, 0.000049 s, +0.000000 s, × 1.0000 mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 0.000179 s, 0.000182 s, +0.000003 s, × 1.0168 mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 0.006494 s, 0.005872 s, -0.000622 s, × 0.9042 pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 0.000339 s, 0.000229 s, -0.000110 s, × 0.6755 pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 0.000057 s, 0.000058 s, +0.000001 s, × 1.0175 pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 0.000299 s, 0.000148 s, -0.000151 s, × 0.4950 pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 0.001200 s, 0.001205 s, +0.000005 s, × 1.0042 pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 0.025120 s, 0.025662 s, +0.000542 s, × 1.0216 pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 0.506921 s, 0.080113 s, -0.426808 s, × 0.1580 pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 1.272060 s, 0.153030 s, -1.119030 s, × 0.1203 pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 0.690941 s, 0.098774 s, -0.592167 s, × 0.1430 pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 33.527067 s, 2.780174 s, -30.746893 s, × 0.0829 pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 0.021970 s, 0.022218 s, +0.000248 s, × 1.0113 pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 1.772094 s, 0.252125 s, -1.519969 s, × 0.1423 netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 0.000185 s, 0.000186 s, +0.000001 s, × 1.0054 netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 0.000135 s, 0.000133 s, -0.000002 s, × 0.9852 netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 0.000329 s, 0.000320 s, -0.000009 s, × 0.9726 netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 0.001343 s, 0.001336 s, -0.000007 s, × 0.9948 netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 0.029396 s, 0.015573 s, -0.013823 s, × 0.5298 netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 0.040210 s, 0.018667 s, -0.021543 s, × 0.4642 netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 4.556794 s, 0.112534 s, -4.444260 s, × 0.0247 netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : killed , 1.231869 s mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 0.000199 s, 0.000197 s, -0.000002 s, × 0.9899 mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 0.000639 s, 0.000637 s, -0.000002 s, × 0.9969 mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 0.000542 s, 0.000303 s, -0.000239 s, × 0.5590 mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 0.001685 s, 0.001663 s, -0.000022 s, × 0.9869 mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 0.006954 s, 0.007008 s, +0.000054 s, × 1.0078 mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 0.132938 s, 0.127385 s, -0.005553 s, × 0.9582 mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.008683 s, 0.008740 s, +0.000057 s, × 1.0066 mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.005956 s, 0.005783 s, -0.000173 s, × 0.9710 mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 0.963905 s, 0.102184 s, -0.861721 s, × 0.1060 mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 0.049239 s, 0.046220 s, -0.003019 s, × 0.9387 mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 4.217003 s, 0.315271 s, -3.901732 s, × 0.0748 mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : killed , 3.478747 s mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : killed , 4.766435 s mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 0.001197 s, 0.001214 s, +0.000017 s, × 1.0142 mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 0.001213 s, 0.001221 s, +0.000008 s, × 1.0066 mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 0.000762 s, 0.000613 s, -0.000149 s, × 0.8045 mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 0.001909 s, 0.001904 s, -0.000005 s, × 0.9974 mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 0.093021 s, 0.093000 s, -0.000021 s, × 0.9998 mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 0.134536 s, 0.132194 s, -0.002342 s, × 0.9826 mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.009071 s, 0.009069 s, -0.000002 s, × 0.9998 mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.006206 s, 0.006169 s, -0.000037 s, × 0.9940 mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 1.150502 s, 0.115540 s, -1.034962 s, × 0.1004 mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 1.114864 s, 0.435381 s, -0.679483 s, × 0.3905 mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 1.042658 s, 0.415461 s, -0.627197 s, × 0.3985 mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 0.447402 s, 0.155946 s, -0.291456 s, × 0.3486 mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 0.051132 s, 0.048521 s, -0.002611 s, × 0.9489 mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 83.508590 s, 9.843481 s, -73.665109 s, × 0.1179 mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 55.079813 s, 1.465128 s, -53.614685 s, × 0.0266 mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 1.442793 s, 1.374283 s, -0.068510 s, × 0.9525 mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : killed , 5.255158 s Repo Cases Source-Rev Dest-Rev Py-time Rust-time Difference Factor ------------------------------------------------------------------------------------------------------------------------------------ mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 0.000044 s, 0.000049 s, +0.000005 s, × 1.1136 mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 0.000138 s, 0.000182 s, +0.000044 s, × 1.3188 mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 0.005052 s, 0.005872 s, +0.000820 s, × 1.1623 pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 0.000219 s, 0.000229 s, +0.000010 s, × 1.0457 pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 0.000055 s, 0.000058 s, +0.000003 s, × 1.0545 pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 0.000128 s, 0.000148 s, +0.000020 s, × 1.1562 pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 0.001089 s, 0.001205 s, +0.000116 s, × 1.1065 pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 0.017407 s, 0.025662 s, +0.008255 s, × 1.4742 pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 0.094175 s, 0.080113 s, -0.014062 s, × 0.8507 pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 0.238009 s, 0.153030 s, -0.084979 s, × 0.6430 pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 0.125876 s, 0.098774 s, -0.027102 s, × 0.7847 pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 3.581556 s, 2.780174 s, -0.801382 s, × 0.7762 pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 0.016721 s, 0.022218 s, +0.005497 s, × 1.3287 pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 0.242367 s, 0.252125 s, +0.009758 s, × 1.0403 netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 0.000165 s, 0.000186 s, +0.000021 s, × 1.1273 netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 0.000114 s, 0.000133 s, +0.000019 s, × 1.1667 netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 0.000296 s, 0.000320 s, +0.000024 s, × 1.0811 netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 0.001124 s, 0.001336 s, +0.000212 s, × 1.1886 netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 0.013060 s, 0.015573 s, +0.002513 s, × 1.1924 netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 0.017112 s, 0.018667 s, +0.001555 s, × 1.0909 netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 0.660350 s, 0.112534 s, -0.547816 s, × 0.1704 netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 10.032499 s, 1.231869 s, -8.800630 s, × 0.1228 mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 0.000189 s, 0.000197 s, +0.000008 s, × 1.0423 mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 0.000462 s, 0.000637 s, +0.000175 s, × 1.3788 mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 0.000270 s, 0.000303 s, +0.000033 s, × 1.1222 mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 0.001474 s, 0.001663 s, +0.000189 s, × 1.1282 mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 0.004806 s, 0.007008 s, +0.002202 s, × 1.4582 mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 0.085150 s, 0.127385 s, +0.042235 s, × 1.4960 mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.007064 s, 0.008740 s, +0.001676 s, × 1.2373 mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.004741 s, 0.005783 s, +0.001042 s, × 1.2198 mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 0.190133 s, 0.102184 s, -0.087949 s, × 0.5374 mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 0.035651 s, 0.046220 s, +0.010569 s, × 1.2965 mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 0.440694 s, 0.315271 s, -0.125423 s, × 0.7154 mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 18.454163 s, 3.478747 s, -14.975416 s, × 0.1885 mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 31.562719 s, 4.766435 s, -26.796284 s, × 0.1510 mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 0.001189 s, 0.001214 s, +0.000025 s, × 1.0210 mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 0.001204 s, 0.001221 s, +0.000017 s, × 1.0141 mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 0.000586 s, 0.000613 s, +0.000027 s, × 1.0461 mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 0.001845 s, 0.001904 s, +0.000059 s, × 1.0320 mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 0.063822 s, 0.093000 s, +0.029178 s, × 1.4572 mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 0.088038 s, 0.132194 s, +0.044156 s, × 1.5016 mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.007389 s, 0.009069 s, +0.001680 s, × 1.2274 mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.004868 s, 0.006169 s, +0.001301 s, × 1.2673 mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 0.222450 s, 0.115540 s, -0.106910 s, × 0.5194 mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 0.370675 s, 0.435381 s, +0.064706 s, × 1.1746 mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 0.358020 s, 0.415461 s, +0.057441 s, × 1.1604 mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 0.145235 s, 0.155946 s, +0.010711 s, × 1.0737 mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 0.037606 s, 0.048521 s, +0.010915 s, × 1.2902 mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 7.382439 s, 9.843481 s, +2.461042 s, × 1.3334 mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 7.273506 s, 1.465128 s, -5.808378 s, × 0.2014 mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 1.074593 s, 1.374283 s, +0.299690 s, × 1.2789 mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 27.746195 s, 5.255158 s, -22.491037 s, × 0.1894 Repo Case Source-Rev Dest-Rev filelog sidedata Difference Factor --------------------------------------------------------------------------------------------------------------------------------------- mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 0.000906 s, 0.000049 s, -0.000857 s, × 0.054084 mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 0.001832 s, 0.000182 s, -0.001650 s, × 0.099345 mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 0.018101 s, 0.005872 s, -0.012229 s, × 0.324402 pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 0.001508 s, 0.000229 s, -0.001279 s, × 0.151857 pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 0.207438 s, 0.000058 s, -0.207380 s, × 0.000280 pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 0.016956 s, 0.000148 s, -0.016808 s, × 0.008728 pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 0.019129 s, 0.001205 s, -0.017924 s, × 0.062993 pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 0.772050 s, 0.025662 s, -0.746388 s, × 0.033239 pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 1.181775 s, 0.080113 s, -1.101662 s, × 0.067790 pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 1.255717 s, 0.153030 s, -1.102687 s, × 0.121867 pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 1.628132 s, 0.098774 s, -1.529358 s, × 0.060667 pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 0.001055 s, 2.780174 s, +2.779119 s, × 2635.236019 pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 1.056756 s, 0.022218 s, -1.034538 s, × 0.021025 pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 1.354211 s, 0.252125 s, -1.102086 s, × 0.186179 netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 0.027759 s, 0.000186 s, -0.027573 s, × 0.006701 netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 0.133382 s, 0.000133 s, -0.133249 s, × 0.000997 netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 0.025353 s, 0.000320 s, -0.025033 s, × 0.012622 netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 0.052939 s, 0.001336 s, -0.051603 s, × 0.025237 netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 0.037532 s, 0.015573 s, -0.021959 s, × 0.414926 netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 0.195401 s, 0.018667 s, -0.176734 s, × 0.095532 netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 0.939593 s, 0.112534 s, -0.827059 s, × 0.119769 netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 3.824967 s, 1.231869 s, -2.593098 s, × 0.322060 mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 0.024626 s, 0.000197 s, -0.024429 s, × 0.008000 mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 0.141098 s, 0.000637 s, -0.140461 s, × 0.004515 mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 0.025973 s, 0.000303 s, -0.025670 s, × 0.011666 mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 0.085098 s, 0.001663 s, -0.083435 s, × 0.019542 mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 0.196623 s, 0.007008 s, -0.189615 s, × 0.035642 mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 2.182911 s, 0.127385 s, -2.055526 s, × 0.058356 mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.088865 s, 0.008740 s, -0.080125 s, × 0.098351 mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.731211 s, 0.005783 s, -0.725428 s, × 0.007909 mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 1.142414 s, 0.102184 s, -1.040230 s, × 0.089446 mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 6.667504 s, 0.046220 s, -6.621284 s, × 0.006932 mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 3.267274 s, 0.315271 s, -2.952003 s, × 0.096494 mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 16.038104 s, 3.478747 s, -12.559357 s, × 0.216905 mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 20.639928 s, 4.766435 s, -15.873493 s, × 0.230933 mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 0.080513 s, 0.001214 s, -0.079299 s, × 0.015078 mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 0.502965 s, 0.001221 s, -0.501744 s, × 0.002428 mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 0.021408 s, 0.000613 s, -0.020795 s, × 0.028634 mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 0.228498 s, 0.001904 s, -0.226594 s, × 0.008333 mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 1.118490 s, 0.093000 s, -1.025490 s, × 0.083148 mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 2.188390 s, 0.132194 s, -2.056196 s, × 0.060407 mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.089755 s, 0.009069 s, -0.080686 s, × 0.101042 mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.750223 s, 0.006169 s, -0.744054 s, × 0.008223 mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 1.189708 s, 0.115540 s, -1.074168 s, × 0.097116 mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 0.088715 s, 0.435381 s, +0.346666 s, × 4.907637 mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 0.080765 s, 0.415461 s, +0.334696 s, × 5.144072 mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 7.487310 s, 0.155946 s, -7.331364 s, × 0.020828 mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 6.676682 s, 0.048521 s, -6.628161 s, × 0.007267 mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 7.598509 s, 9.843481 s, +2.244972 s, × 1.295449 mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 9.871850 s, 1.465128 s, -8.406722 s, × 0.148415 mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 0.092232 s, killed mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 26.471560 s, 1.374283 s, -25.097277 s, × 0.051915 mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 0.093892 s, killed mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 0.227503 s, killed mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 19.064699 s, 5.255158 s, -13.809541 s, × 0.275649 mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 21.145391 s, killed mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 25.304164 s, killed Differential Revision: https://phab.mercurial-scm.org/D9302

File last commit:

r46466:5c736ba5 default
r46585:cc759d3d default
Show More
status.rs
996 lines | 34.5 KiB | application/rls-services+xml | RustLexer
// status.rs
//
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
//! Rust implementation of dirstate.status (dirstate.py).
//! It is currently missing a lot of functionality compared to the Python one
//! and will only be triggered in narrow cases.
#[cfg(feature = "dirstate-tree")]
use crate::dirstate::dirstate_tree::iter::StatusShortcut;
#[cfg(not(feature = "dirstate-tree"))]
use crate::utils::path_auditor::PathAuditor;
use crate::{
dirstate::SIZE_FROM_OTHER_PARENT,
filepatterns::PatternFileWarning,
matchers::{get_ignore_function, Matcher, VisitChildrenSet},
utils::{
files::{find_dirs, HgMetadata},
hg_path::{
hg_path_to_path_buf, os_string_to_hg_path_buf, HgPath, HgPathBuf,
HgPathError,
},
},
CopyMap, DirstateEntry, DirstateMap, EntryState, FastHashMap,
PatternError,
};
use lazy_static::lazy_static;
use micro_timer::timed;
use rayon::prelude::*;
use std::{
borrow::Cow,
collections::HashSet,
fs::{read_dir, DirEntry},
io::ErrorKind,
ops::Deref,
path::{Path, PathBuf},
};
/// Wrong type of file from a `BadMatch`
/// Note: a lot of those don't exist on all platforms.
#[derive(Debug, Copy, Clone)]
pub enum BadType {
CharacterDevice,
BlockDevice,
FIFO,
Socket,
Directory,
Unknown,
}
impl ToString for BadType {
fn to_string(&self) -> String {
match self {
BadType::CharacterDevice => "character device",
BadType::BlockDevice => "block device",
BadType::FIFO => "fifo",
BadType::Socket => "socket",
BadType::Directory => "directory",
BadType::Unknown => "unknown",
}
.to_string()
}
}
/// Was explicitly matched but cannot be found/accessed
#[derive(Debug, Copy, Clone)]
pub enum BadMatch {
OsError(i32),
BadType(BadType),
}
/// Enum used to dispatch new status entries into the right collections.
/// Is similar to `crate::EntryState`, but represents the transient state of
/// entries during the lifetime of a command.
#[derive(Debug, Copy, Clone)]
pub enum Dispatch {
Unsure,
Modified,
Added,
Removed,
Deleted,
Clean,
Unknown,
Ignored,
/// Empty dispatch, the file is not worth listing
None,
/// Was explicitly matched but cannot be found/accessed
Bad(BadMatch),
Directory {
/// True if the directory used to be a file in the dmap so we can say
/// that it's been removed.
was_file: bool,
},
}
type IoResult<T> = std::io::Result<T>;
/// `Box<dyn Trait>` is syntactic sugar for `Box<dyn Trait, 'static>`, so add
/// an explicit lifetime here to not fight `'static` bounds "out of nowhere".
type IgnoreFnType<'a> = Box<dyn for<'r> Fn(&'r HgPath) -> bool + Sync + 'a>;
/// We have a good mix of owned (from directory traversal) and borrowed (from
/// the dirstate/explicit) paths, this comes up a lot.
pub type HgPathCow<'a> = Cow<'a, HgPath>;
/// A path with its computed ``Dispatch`` information
type DispatchedPath<'a> = (HgPathCow<'a>, Dispatch);
/// The conversion from `HgPath` to a real fs path failed.
/// `22` is the error code for "Invalid argument"
const INVALID_PATH_DISPATCH: Dispatch = Dispatch::Bad(BadMatch::OsError(22));
/// Dates and times that are outside the 31-bit signed range are compared
/// modulo 2^31. This should prevent hg from behaving badly with very large
/// files or corrupt dates while still having a high probability of detecting
/// changes. (issue2608)
/// TODO I haven't found a way of having `b` be `Into<i32>`, since `From<u64>`
/// is not defined for `i32`, and there is no `As` trait. This forces the
/// caller to cast `b` as `i32`.
fn mod_compare(a: i32, b: i32) -> bool {
a & i32::max_value() != b & i32::max_value()
}
/// Return a sorted list containing information about the entries
/// in the directory.
///
/// * `skip_dot_hg` - Return an empty vec if `path` contains a `.hg` directory
fn list_directory(
path: impl AsRef<Path>,
skip_dot_hg: bool,
) -> std::io::Result<Vec<(HgPathBuf, DirEntry)>> {
let mut results = vec![];
let entries = read_dir(path.as_ref())?;
for entry in entries {
let entry = entry?;
let filename = os_string_to_hg_path_buf(entry.file_name())?;
let file_type = entry.file_type()?;
if skip_dot_hg && filename.as_bytes() == b".hg" && file_type.is_dir() {
return Ok(vec![]);
} else {
results.push((filename, entry))
}
}
results.sort_unstable_by_key(|e| e.0.clone());
Ok(results)
}
/// The file corresponding to the dirstate entry was found on the filesystem.
fn dispatch_found(
filename: impl AsRef<HgPath>,
entry: DirstateEntry,
metadata: HgMetadata,
copy_map: &CopyMap,
options: StatusOptions,
) -> Dispatch {
let DirstateEntry {
state,
mode,
mtime,
size,
} = entry;
let HgMetadata {
st_mode,
st_size,
st_mtime,
..
} = metadata;
match state {
EntryState::Normal => {
let size_changed = mod_compare(size, st_size as i32);
let mode_changed =
(mode ^ st_mode as i32) & 0o100 != 0o000 && options.check_exec;
let metadata_changed = size >= 0 && (size_changed || mode_changed);
let other_parent = size == SIZE_FROM_OTHER_PARENT;
if metadata_changed
|| other_parent
|| copy_map.contains_key(filename.as_ref())
{
Dispatch::Modified
} else if mod_compare(mtime, st_mtime as i32)
|| st_mtime == options.last_normal_time
{
// the file may have just been marked as normal and
// it may have changed in the same second without
// changing its size. This can happen if we quickly
// do multiple commits. Force lookup, so we don't
// miss such a racy file change.
Dispatch::Unsure
} else if options.list_clean {
Dispatch::Clean
} else {
Dispatch::None
}
}
EntryState::Merged => Dispatch::Modified,
EntryState::Added => Dispatch::Added,
EntryState::Removed => Dispatch::Removed,
EntryState::Unknown => Dispatch::Unknown,
}
}
/// The file corresponding to this Dirstate entry is missing.
fn dispatch_missing(state: EntryState) -> Dispatch {
match state {
// File was removed from the filesystem during commands
EntryState::Normal | EntryState::Merged | EntryState::Added => {
Dispatch::Deleted
}
// File was removed, everything is normal
EntryState::Removed => Dispatch::Removed,
// File is unknown to Mercurial, everything is normal
EntryState::Unknown => Dispatch::Unknown,
}
}
fn dispatch_os_error(e: &std::io::Error) -> Dispatch {
Dispatch::Bad(BadMatch::OsError(
e.raw_os_error().expect("expected real OS error"),
))
}
lazy_static! {
static ref DEFAULT_WORK: HashSet<&'static HgPath> = {
let mut h = HashSet::new();
h.insert(HgPath::new(b""));
h
};
}
#[derive(Debug, Copy, Clone)]
pub struct StatusOptions {
/// Remember the most recent modification timeslot for status, to make
/// sure we won't miss future size-preserving file content modifications
/// that happen within the same timeslot.
pub last_normal_time: i64,
/// Whether we are on a filesystem with UNIX-like exec flags
pub check_exec: bool,
pub list_clean: bool,
pub list_unknown: bool,
pub list_ignored: bool,
/// Whether to collect traversed dirs for applying a callback later.
/// Used by `hg purge` for example.
pub collect_traversed_dirs: bool,
}
#[derive(Debug)]
pub struct DirstateStatus<'a> {
pub modified: Vec<HgPathCow<'a>>,
pub added: Vec<HgPathCow<'a>>,
pub removed: Vec<HgPathCow<'a>>,
pub deleted: Vec<HgPathCow<'a>>,
pub clean: Vec<HgPathCow<'a>>,
pub ignored: Vec<HgPathCow<'a>>,
pub unknown: Vec<HgPathCow<'a>>,
pub bad: Vec<(HgPathCow<'a>, BadMatch)>,
/// Only filled if `collect_traversed_dirs` is `true`
pub traversed: Vec<HgPathBuf>,
}
#[derive(Debug)]
pub enum StatusError {
/// Generic IO error
IO(std::io::Error),
/// An invalid path that cannot be represented in Mercurial was found
Path(HgPathError),
/// An invalid "ignore" pattern was found
Pattern(PatternError),
}
pub type StatusResult<T> = Result<T, StatusError>;
impl From<PatternError> for StatusError {
fn from(e: PatternError) -> Self {
StatusError::Pattern(e)
}
}
impl From<HgPathError> for StatusError {
fn from(e: HgPathError) -> Self {
StatusError::Path(e)
}
}
impl From<std::io::Error> for StatusError {
fn from(e: std::io::Error) -> Self {
StatusError::IO(e)
}
}
impl ToString for StatusError {
fn to_string(&self) -> String {
match self {
StatusError::IO(e) => e.to_string(),
StatusError::Path(e) => e.to_string(),
StatusError::Pattern(e) => e.to_string(),
}
}
}
/// Gives information about which files are changed in the working directory
/// and how, compared to the revision we're based on
pub struct Status<'a, M: Matcher + Sync> {
dmap: &'a DirstateMap,
pub(crate) matcher: &'a M,
root_dir: PathBuf,
pub(crate) options: StatusOptions,
ignore_fn: IgnoreFnType<'a>,
}
impl<'a, M> Status<'a, M>
where
M: Matcher + Sync,
{
pub fn new(
dmap: &'a DirstateMap,
matcher: &'a M,
root_dir: PathBuf,
ignore_files: Vec<PathBuf>,
options: StatusOptions,
) -> StatusResult<(Self, Vec<PatternFileWarning>)> {
// Needs to outlive `dir_ignore_fn` since it's captured.
let (ignore_fn, warnings): (IgnoreFnType, _) =
if options.list_ignored || options.list_unknown {
get_ignore_function(ignore_files, &root_dir)?
} else {
(Box::new(|&_| true), vec![])
};
Ok((
Self {
dmap,
matcher,
root_dir,
options,
ignore_fn,
},
warnings,
))
}
/// Is the path ignored?
pub fn is_ignored(&self, path: impl AsRef<HgPath>) -> bool {
(self.ignore_fn)(path.as_ref())
}
/// Is the path or one of its ancestors ignored?
pub fn dir_ignore(&self, dir: impl AsRef<HgPath>) -> bool {
// Only involve ignore mechanism if we're listing unknowns or ignored.
if self.options.list_ignored || self.options.list_unknown {
if self.is_ignored(&dir) {
true
} else {
for p in find_dirs(dir.as_ref()) {
if self.is_ignored(p) {
return true;
}
}
false
}
} else {
true
}
}
/// Get stat data about the files explicitly specified by the matcher.
/// Returns a tuple of the directories that need to be traversed and the
/// files with their corresponding `Dispatch`.
/// TODO subrepos
#[timed]
pub fn walk_explicit(
&self,
traversed_sender: crossbeam::Sender<HgPathBuf>,
) -> (Vec<DispatchedPath<'a>>, Vec<DispatchedPath<'a>>) {
self.matcher
.file_set()
.unwrap_or(&DEFAULT_WORK)
.par_iter()
.flat_map(|&filename| -> Option<_> {
// TODO normalization
let normalized = filename;
let buf = match hg_path_to_path_buf(normalized) {
Ok(x) => x,
Err(_) => {
return Some((
Cow::Borrowed(normalized),
INVALID_PATH_DISPATCH,
))
}
};
let target = self.root_dir.join(buf);
let st = target.symlink_metadata();
let in_dmap = self.dmap.get(normalized);
match st {
Ok(meta) => {
let file_type = meta.file_type();
return if file_type.is_file() || file_type.is_symlink()
{
if let Some(entry) = in_dmap {
return Some((
Cow::Borrowed(normalized),
dispatch_found(
&normalized,
*entry,
HgMetadata::from_metadata(meta),
&self.dmap.copy_map,
self.options,
),
));
}
Some((
Cow::Borrowed(normalized),
Dispatch::Unknown,
))
} else if file_type.is_dir() {
if self.options.collect_traversed_dirs {
traversed_sender
.send(normalized.to_owned())
.expect("receiver should outlive sender");
}
Some((
Cow::Borrowed(normalized),
Dispatch::Directory {
was_file: in_dmap.is_some(),
},
))
} else {
Some((
Cow::Borrowed(normalized),
Dispatch::Bad(BadMatch::BadType(
// TODO do more than unknown
// Support for all `BadType` variant
// varies greatly between platforms.
// So far, no tests check the type and
// this should be good enough for most
// users.
BadType::Unknown,
)),
))
};
}
Err(_) => {
if let Some(entry) = in_dmap {
return Some((
Cow::Borrowed(normalized),
dispatch_missing(entry.state),
));
}
}
};
None
})
.partition(|(_, dispatch)| match dispatch {
Dispatch::Directory { .. } => true,
_ => false,
})
}
/// Walk the working directory recursively to look for changes compared to
/// the current `DirstateMap`.
///
/// This takes a mutable reference to the results to account for the
/// `extend` in timings
#[timed]
pub fn traverse(
&self,
path: impl AsRef<HgPath>,
old_results: &FastHashMap<HgPathCow<'a>, Dispatch>,
results: &mut Vec<DispatchedPath<'a>>,
traversed_sender: crossbeam::Sender<HgPathBuf>,
) {
// The traversal is done in parallel, so use a channel to gather
// entries. `crossbeam::Sender` is `Sync`, while `mpsc::Sender`
// is not.
let (files_transmitter, files_receiver) =
crossbeam::channel::unbounded();
self.traverse_dir(
&files_transmitter,
path,
&old_results,
traversed_sender,
);
// Disconnect the channel so the receiver stops waiting
drop(files_transmitter);
let new_results = files_receiver
.into_iter()
.par_bridge()
.map(|(f, d)| (Cow::Owned(f), d));
results.par_extend(new_results);
}
/// Dispatch a single entry (file, folder, symlink...) found during
/// `traverse`. If the entry is a folder that needs to be traversed, it
/// will be handled in a separate thread.
fn handle_traversed_entry<'b>(
&'a self,
scope: &rayon::Scope<'b>,
files_sender: &'b crossbeam::Sender<(HgPathBuf, Dispatch)>,
old_results: &'a FastHashMap<Cow<HgPath>, Dispatch>,
filename: HgPathBuf,
dir_entry: DirEntry,
traversed_sender: crossbeam::Sender<HgPathBuf>,
) -> IoResult<()>
where
'a: 'b,
{
let file_type = dir_entry.file_type()?;
let entry_option = self.dmap.get(&filename);
if filename.as_bytes() == b".hg" {
// Could be a directory or a symlink
return Ok(());
}
if file_type.is_dir() {
self.handle_traversed_dir(
scope,
files_sender,
old_results,
entry_option,
filename,
traversed_sender,
);
} else if file_type.is_file() || file_type.is_symlink() {
if let Some(entry) = entry_option {
if self.matcher.matches_everything()
|| self.matcher.matches(&filename)
{
let metadata = dir_entry.metadata()?;
files_sender
.send((
filename.to_owned(),
dispatch_found(
&filename,
*entry,
HgMetadata::from_metadata(metadata),
&self.dmap.copy_map,
self.options,
),
))
.unwrap();
}
} else if (self.matcher.matches_everything()
|| self.matcher.matches(&filename))
&& !self.is_ignored(&filename)
{
if (self.options.list_ignored
|| self.matcher.exact_match(&filename))
&& self.dir_ignore(&filename)
{
if self.options.list_ignored {
files_sender
.send((filename.to_owned(), Dispatch::Ignored))
.unwrap();
}
} else if self.options.list_unknown {
files_sender
.send((filename.to_owned(), Dispatch::Unknown))
.unwrap();
}
} else if self.is_ignored(&filename) && self.options.list_ignored {
files_sender
.send((filename.to_owned(), Dispatch::Ignored))
.unwrap();
}
} else if let Some(entry) = entry_option {
// Used to be a file or a folder, now something else.
if self.matcher.matches_everything()
|| self.matcher.matches(&filename)
{
files_sender
.send((filename.to_owned(), dispatch_missing(entry.state)))
.unwrap();
}
}
Ok(())
}
/// A directory was found in the filesystem and needs to be traversed
fn handle_traversed_dir<'b>(
&'a self,
scope: &rayon::Scope<'b>,
files_sender: &'b crossbeam::Sender<(HgPathBuf, Dispatch)>,
old_results: &'a FastHashMap<Cow<HgPath>, Dispatch>,
entry_option: Option<&'a DirstateEntry>,
directory: HgPathBuf,
traversed_sender: crossbeam::Sender<HgPathBuf>,
) where
'a: 'b,
{
scope.spawn(move |_| {
// Nested `if` until `rust-lang/rust#53668` is stable
if let Some(entry) = entry_option {
// Used to be a file, is now a folder
if self.matcher.matches_everything()
|| self.matcher.matches(&directory)
{
files_sender
.send((
directory.to_owned(),
dispatch_missing(entry.state),
))
.unwrap();
}
}
// Do we need to traverse it?
if !self.is_ignored(&directory) || self.options.list_ignored {
self.traverse_dir(
files_sender,
directory,
&old_results,
traversed_sender,
)
}
});
}
/// Decides whether the directory needs to be listed, and if so handles the
/// entries in a separate thread.
fn traverse_dir(
&self,
files_sender: &crossbeam::Sender<(HgPathBuf, Dispatch)>,
directory: impl AsRef<HgPath>,
old_results: &FastHashMap<Cow<HgPath>, Dispatch>,
traversed_sender: crossbeam::Sender<HgPathBuf>,
) {
let directory = directory.as_ref();
if self.options.collect_traversed_dirs {
traversed_sender
.send(directory.to_owned())
.expect("receiver should outlive sender");
}
let visit_entries = match self.matcher.visit_children_set(directory) {
VisitChildrenSet::Empty => return,
VisitChildrenSet::This | VisitChildrenSet::Recursive => None,
VisitChildrenSet::Set(set) => Some(set),
};
let buf = match hg_path_to_path_buf(directory) {
Ok(b) => b,
Err(_) => {
files_sender
.send((directory.to_owned(), INVALID_PATH_DISPATCH))
.expect("receiver should outlive sender");
return;
}
};
let dir_path = self.root_dir.join(buf);
let skip_dot_hg = !directory.as_bytes().is_empty();
let entries = match list_directory(dir_path, skip_dot_hg) {
Err(e) => {
files_sender
.send((directory.to_owned(), dispatch_os_error(&e)))
.expect("receiver should outlive sender");
return;
}
Ok(entries) => entries,
};
rayon::scope(|scope| {
for (filename, dir_entry) in entries {
if let Some(ref set) = visit_entries {
if !set.contains(filename.deref()) {
continue;
}
}
// TODO normalize
let filename = if directory.is_empty() {
filename.to_owned()
} else {
directory.join(&filename)
};
if !old_results.contains_key(filename.deref()) {
match self.handle_traversed_entry(
scope,
files_sender,
old_results,
filename,
dir_entry,
traversed_sender.clone(),
) {
Err(e) => {
files_sender
.send((
directory.to_owned(),
dispatch_os_error(&e),
))
.expect("receiver should outlive sender");
}
Ok(_) => {}
}
}
}
})
}
/// Add the files in the dirstate to the results.
///
/// This takes a mutable reference to the results to account for the
/// `extend` in timings
#[cfg(feature = "dirstate-tree")]
#[timed]
pub fn extend_from_dmap(&self, results: &mut Vec<DispatchedPath<'a>>) {
results.par_extend(
self.dmap
.fs_iter(self.root_dir.clone())
.par_bridge()
.filter(|(path, _)| self.matcher.matches(path))
.map(move |(filename, shortcut)| {
let entry = match shortcut {
StatusShortcut::Entry(e) => e,
StatusShortcut::Dispatch(d) => {
return (Cow::Owned(filename), d)
}
};
let filename_as_path = match hg_path_to_path_buf(&filename)
{
Ok(f) => f,
Err(_) => {
return (
Cow::Owned(filename),
INVALID_PATH_DISPATCH,
)
}
};
let meta = self
.root_dir
.join(filename_as_path)
.symlink_metadata();
match meta {
Ok(m)
if !(m.file_type().is_file()
|| m.file_type().is_symlink()) =>
{
(
Cow::Owned(filename),
dispatch_missing(entry.state),
)
}
Ok(m) => {
let dispatch = dispatch_found(
&filename,
entry,
HgMetadata::from_metadata(m),
&self.dmap.copy_map,
self.options,
);
(Cow::Owned(filename), dispatch)
}
Err(e)
if e.kind() == ErrorKind::NotFound
|| e.raw_os_error() == Some(20) =>
{
// Rust does not yet have an `ErrorKind` for
// `NotADirectory` (errno 20)
// It happens if the dirstate contains `foo/bar`
// and foo is not a
// directory
(
Cow::Owned(filename),
dispatch_missing(entry.state),
)
}
Err(e) => {
(Cow::Owned(filename), dispatch_os_error(&e))
}
}
}),
);
}
/// Add the files in the dirstate to the results.
///
/// This takes a mutable reference to the results to account for the
/// `extend` in timings
#[cfg(not(feature = "dirstate-tree"))]
#[timed]
pub fn extend_from_dmap(&self, results: &mut Vec<DispatchedPath<'a>>) {
results.par_extend(self.dmap.par_iter().map(
move |(filename, entry)| {
let filename: &HgPath = filename;
let filename_as_path = match hg_path_to_path_buf(filename) {
Ok(f) => f,
Err(_) => {
return (
Cow::Borrowed(filename),
INVALID_PATH_DISPATCH,
)
}
};
let meta =
self.root_dir.join(filename_as_path).symlink_metadata();
match meta {
Ok(m)
if !(m.file_type().is_file()
|| m.file_type().is_symlink()) =>
{
(
Cow::Borrowed(filename),
dispatch_missing(entry.state),
)
}
Ok(m) => (
Cow::Borrowed(filename),
dispatch_found(
filename,
*entry,
HgMetadata::from_metadata(m),
&self.dmap.copy_map,
self.options,
),
),
Err(e)
if e.kind() == ErrorKind::NotFound
|| e.raw_os_error() == Some(20) =>
{
// Rust does not yet have an `ErrorKind` for
// `NotADirectory` (errno 20)
// It happens if the dirstate contains `foo/bar`
// and foo is not a
// directory
(
Cow::Borrowed(filename),
dispatch_missing(entry.state),
)
}
Err(e) => (Cow::Borrowed(filename), dispatch_os_error(&e)),
}
},
));
}
/// Checks all files that are in the dirstate but were not found during the
/// working directory traversal. This means that the rest must
/// be either ignored, under a symlink or under a new nested repo.
///
/// This takes a mutable reference to the results to account for the
/// `extend` in timings
#[cfg(not(feature = "dirstate-tree"))]
#[timed]
pub fn handle_unknowns(&self, results: &mut Vec<DispatchedPath<'a>>) {
let to_visit: Vec<(&HgPath, &DirstateEntry)> =
if results.is_empty() && self.matcher.matches_everything() {
self.dmap.iter().map(|(f, e)| (f.deref(), e)).collect()
} else {
// Only convert to a hashmap if needed.
let old_results: FastHashMap<_, _> =
results.iter().cloned().collect();
self.dmap
.iter()
.filter_map(move |(f, e)| {
if !old_results.contains_key(f.deref())
&& self.matcher.matches(f)
{
Some((f.deref(), e))
} else {
None
}
})
.collect()
};
let path_auditor = PathAuditor::new(&self.root_dir);
let new_results = to_visit.into_par_iter().filter_map(
|(filename, entry)| -> Option<_> {
// Report ignored items in the dmap as long as they are not
// under a symlink directory.
if path_auditor.check(filename) {
// TODO normalize for case-insensitive filesystems
let buf = match hg_path_to_path_buf(filename) {
Ok(x) => x,
Err(_) => {
return Some((
Cow::Owned(filename.to_owned()),
INVALID_PATH_DISPATCH,
));
}
};
Some((
Cow::Owned(filename.to_owned()),
match self.root_dir.join(&buf).symlink_metadata() {
// File was just ignored, no links, and exists
Ok(meta) => {
let metadata = HgMetadata::from_metadata(meta);
dispatch_found(
filename,
*entry,
metadata,
&self.dmap.copy_map,
self.options,
)
}
// File doesn't exist
Err(_) => dispatch_missing(entry.state),
},
))
} else {
// It's either missing or under a symlink directory which
// we, in this case, report as missing.
Some((
Cow::Owned(filename.to_owned()),
dispatch_missing(entry.state),
))
}
},
);
results.par_extend(new_results);
}
}
#[timed]
pub fn build_response<'a>(
results: impl IntoIterator<Item = DispatchedPath<'a>>,
traversed: Vec<HgPathBuf>,
) -> (Vec<HgPathCow<'a>>, DirstateStatus<'a>) {
let mut lookup = vec![];
let mut modified = vec![];
let mut added = vec![];
let mut removed = vec![];
let mut deleted = vec![];
let mut clean = vec![];
let mut ignored = vec![];
let mut unknown = vec![];
let mut bad = vec![];
for (filename, dispatch) in results.into_iter() {
match dispatch {
Dispatch::Unknown => unknown.push(filename),
Dispatch::Unsure => lookup.push(filename),
Dispatch::Modified => modified.push(filename),
Dispatch::Added => added.push(filename),
Dispatch::Removed => removed.push(filename),
Dispatch::Deleted => deleted.push(filename),
Dispatch::Clean => clean.push(filename),
Dispatch::Ignored => ignored.push(filename),
Dispatch::None => {}
Dispatch::Bad(reason) => bad.push((filename, reason)),
Dispatch::Directory { .. } => {}
}
}
(
lookup,
DirstateStatus {
modified,
added,
removed,
deleted,
clean,
ignored,
unknown,
bad,
traversed,
},
)
}
/// Get the status of files in the working directory.
///
/// This is the current entry-point for `hg-core` and is realistically unusable
/// outside of a Python context because its arguments need to provide a lot of
/// information that will not be necessary in the future.
#[timed]
pub fn status<'a>(
dmap: &'a DirstateMap,
matcher: &'a (impl Matcher + Sync),
root_dir: PathBuf,
ignore_files: Vec<PathBuf>,
options: StatusOptions,
) -> StatusResult<(
(Vec<HgPathCow<'a>>, DirstateStatus<'a>),
Vec<PatternFileWarning>,
)> {
let (status, warnings) =
Status::new(dmap, matcher, root_dir, ignore_files, options)?;
Ok((status.run()?, warnings))
}