annotate rust/hg-core/src/copy_tracing.rs @ 46585:60b2b7ecf9cb

copies-rust: use imrs::OrdSet instead of imrs::HashSet This yield small speedup all over the board, and a large one for our slower cases: Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 2.034596 s, 1.465264 s, -0.569332 s, × 0.7202, 15 µs/rev mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 52031 revs, 0.694030 s, 0.690376 s, -0.003654 s, × 0.9947, 13 µs/rev mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 363753 revs, 4.407723 s, 4.011322 s, -0.396401 s, × 0.9101, 11 µs/rev mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 34414 revs, 0.574355 s, 0.573541 s, -0.000814 s, × 0.9986, 16 µs/rev mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 362229 revs, 4.457827 s, 3.981133 s, -0.476694 s, × 0.8931, 10 µs/rev mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 359344 revs, 4.351696 s, 3.996647 s, -0.355049 s, × 0.9184, 11 µs/rev mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 80.828689 s, 50.244975 s, -30.583714 s, × 0.6216, 219 µs/rev mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 382065 revs, 34.094064 s, 20.030023 s, -14.064041 s, × 0.5875, 52 µs/rev private : 459513 revs, 27.435529 s, 24.490825 s, -2.944704 s, × 0.8927, 53 µs/rev We also got significantly faster than the implementation using is_ancestors except for one of our reference case: Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 363753 revs, 5.138169 s, 4.011322 s, -1.126847 s, × 0.7807, 11 µs/rev mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 362229 revs, 5.127809 s, 3.981133 s, -1.146676 s, × 0.7764, 10 µs/rev mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 359344 revs, 4.971136 s, 3.996647 s, -0.974489 s, × 0.8040, 11 µs/rev mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 192665 revs, 1.741678 s, 1.520607 s, -0.221071 s, × 0.8731, 7 µs/rev private : 459513 revs, 37.179470 s, 24.490825 s, -12.688645 s, × 0.6587, 53 µs/rev mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 40.314822 s, 50.244975 s, +9.930153 s, × 1.2463, 219 µs/rev Below are three different benchmark comparing this changeset to: * the previous one, * the implementation based on `is_anscestors`, * the filelog copy tracing. ### Compared to the previous ones Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 1 revs, 0.000043 s, 0.000041 s, -0.000002 s, × 0.9535, 41 µs/rev mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 6 revs, 0.000114 s, 0.000116 s, +0.000002 s, × 1.0175, 19 µs/rev mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 1032 revs, 0.004899 s, 0.004933 s, +0.000034 s, × 1.0069, 4 µs/rev pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 9 revs, 0.000196 s, 0.000193 s, -0.000003 s, × 0.9847, 21 µs/rev pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 1 revs, 0.000049 s, 0.000048 s, -0.000001 s, × 0.9796, 48 µs/rev pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 7 revs, 0.000117 s, 0.000114 s, -0.000003 s, × 0.9744, 16 µs/rev pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 1 revs, 0.6f1f4a s, 0.000319 s, -0.000003 s, × 0.9907, 319 µs/rev pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 6 revs, 0.011856 s, 0.012025 s, +0.000169 s, × 1.0143, 2004 µs/rev pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 4785 revs, 0.050992 s, 0.050525 s, -0.000467 s, × 0.9908, 10 µs/rev pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 6780 revs, 0.087444 s, 0.085713 s, -0.001731 s, × 0.9802, 12 µs/rev pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 5441 revs, 0.062487 s, 0.061825 s, -0.000662 s, × 0.9894, 11 µs/rev pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.634909 s, 0.543998 s, -0.090911 s, × 0.8568, 12 µs/rev pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 2 revs, 0.013360 s, 0.013455 s, +0.000095 s, × 1.0071, 6727 µs/rev pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 11316 revs, 0.120775 s, 0.117479 s, -0.003296 s, × 0.9727, 10 µs/rev netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 2 revs, 0.000085 s, 0.000084 s, -0.000001 s, × 0.9882, 42 µs/rev netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 2 revs, 0.000108 s, 0.000111 s, +0.000003 s, × 1.0278, 55 µs/rev netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 3 revs, 0.000176 s, 0.000175 s, -0.000001 s, × 0.9943, 58 µs/rev netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 9 revs, 0.000747 s, 0.000732 s, -0.000015 s, × 0.9799, 81 µs/rev netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 1421 revs, 0.010128 s, 0.010062 s, -0.000066 s, × 0.9935, 7 µs/rev netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 1533 revs, 0.015899 s, 0.015659 s, -0.000240 s, × 0.9849, 10 µs/rev netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 5750 revs, 0.062215 s, 0.062744 s, +0.000529 s, × 1.0085, 10 µs/rev netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 66949 revs, 0.521004 s, 0.499449 s, -0.021555 s, × 0.9586, 7 µs/rev mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 2 revs, 0.000090 s, 0.000088 s, -0.000002 s, × 0.9778, 44 µs/rev mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 8 revs, 0.000264 s, 0.000266 s, +0.000002 s, × 1.0076, 33 µs/rev mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 9 revs, 0.000186 s, 0.000182 s, -0.000004 s, × 0.9785, 20 µs/rev mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 7 revs, 0.000660 s, 0.000656 s, -0.000004 s, × 0.9939, 93 µs/rev mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 3 revs, 0.003542 s, 0.003389 s, -0.000153 s, × 0.9568, 1129 µs/rev mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.071574 s, 0.075882 s, +0.004308 s, × 1.0602, 12647 µs/rev mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.006498 s, 0.006479 s, -0.000019 s, × 0.9971, 4 µs/rev mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.005206 s, 0.004889 s, -0.000317 s, × 0.9391, 119 µs/rev mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 7839 revs, 0.065535 s, 0.064394 s, -0.001141 s, × 0.9826, 8 µs/rev mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.027139 s, 0.026815 s, -0.000324 s, × 0.9881, 43 µs/rev mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 30263 revs, 0.201924 s, 0.cc85eb s, +0.000940 s, × 1.0047, 6 µs/rev mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 153721 revs, 1.257201 s, 1.219445 s, -0.037756 s, × 0.9700, 7 µs/rev mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 204976 revs, 1.663045 s, 1.613857 s, -0.049188 s, × 0.9704, 7 µs/rev mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 2 revs, 0.000866 s, 0.000873 s, +0.000007 s, × 1.0081, 436 µs/rev mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 2 revs, 0.000883 s, 0.000885 s, +0.000002 s, × 1.0023, 442 µs/rev mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 4 revs, 0.000163 s, 0.000161 s, -0.000002 s, × 0.9877, 40 µs/rev mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 2 revs, 0.001139 s, 0.001138 s, -0.000001 s, × 0.9991, 569 µs/rev mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 1 revs, 0.032753 s, 0.033399 s, +0.000646 s, × 1.0197, 33399 µs/rev mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.073266 s, 0.075445 s, +0.002179 s, × 1.0297, 12574 µs/rev mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.006567 s, 0.006456 s, -0.000111 s, × 0.9831, 4 µs/rev mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.005427 s, 0.005462 s, +0.000035 s, × 1.0064, 133 µs/rev mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 6657 revs, 0.064058 s, 0.064117 s, +0.000059 s, × 1.0009, 9 µs/rev mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 40314 revs, 0.303320 s, 0.297563 s, -0.005757 s, × 0.9810, 7 µs/rev mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 38690 revs, 0.288456 s, 0.282463 s, -0.005993 s, × 0.9792, 7 µs/rev mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 8598 revs, 0.085925 s, 0.084038 s, -0.001887 s, × 0.9780, 9 µs/rev mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.027302 s, 0.027306 s, +0.000004 s, × 1.0001, 44 µs/rev mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 2.034596 s, 1.465264 s, -0.569332 s, × 0.7202, 15 µs/rev mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 52031 revs, 0.694030 s, 0.690376 s, -0.003654 s, × 0.9947, 13 µs/rev mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 363753 revs, 4.407723 s, 4.011322 s, -0.396401 s, × 0.9101, 11 µs/rev mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 34414 revs, 0.574355 s, 0.573541 s, -0.000814 s, × 0.9986, 16 µs/rev mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 362229 revs, 4.457827 s, 3.981133 s, -0.476694 s, × 0.8931, 10 µs/rev mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 359344 revs, 4.351696 s, 3.996647 s, -0.355049 s, × 0.9184, 11 µs/rev mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 192665 revs, 1.570065 s, 1.520607 s, -0.049458 s, × 0.9685, 7 µs/rev mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 80.828689 s, 50.244975 s, -30.583714 s, × 0.6216, 219 µs/rev mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 382065 revs, 34.094064 s, 20.030023 s, -14.064041 s, × 0.5875, 52 µs/rev private : 459513 revs, 27.435529 s, 24.490825 s, -2.944704 s, × 0.8927, 53 µs/rev ### Compared to the implementation using `is_anscestor` Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 1 revs, 0.000042 s, 0.000041 s, -0.000001 s, × 0.9762, 41 µs/rev mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 6 revs, 0.000110 s, 0.000116 s, +0.000006 s, × 1.0545, 19 µs/rev mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 1032 revs, 0.004945 s, 0.004933 s, -0.000012 s, × 0.9976, 4 µs/rev pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 9 revs, 0.000192 s, 0.000193 s, +0.000001 s, × 1.0052, 21 µs/rev pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 1 revs, 0.000049 s, 0.000048 s, -0.000001 s, × 0.9796, 48 µs/rev pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 7 revs, 0.000112 s, 0.000114 s, +0.000002 s, × 1.0179, 16 µs/rev pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 1 revs, 0.000323 s, 0.000319 s, -0.000004 s, × 0.9876, 319 µs/rev pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 6 revs, 0.010042 s, 0.012025 s, +0.001983 s, × 1.1975, 2004 µs/rev pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 4785 revs, 0.049813 s, 0.050525 s, +0.000712 s, × 1.0143, 10 µs/rev pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 6780 revs, 0.079937 s, 0.085713 s, +0.005776 s, × 1.0723, 12 µs/rev pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 5441 revs, 0.059412 s, 0.061825 s, +0.002413 s, × 1.0406, 11 µs/rev pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.533769 s, 0.543998 s, +0.010229 s, × 1.0192, 12 µs/rev pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 2 revs, 0.013147 s, 0.013455 s, +0.000308 s, × 1.0234, 6727 µs/rev pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 11316 revs, 0.110680 s, 0.117479 s, +0.006799 s, × 1.0614, 10 µs/rev netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 2 revs, 0.000085 s, 0.000084 s, -0.000001 s, × 0.9882, 42 µs/rev netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 2 revs, 0.000107 s, 0.000111 s, +0.000004 s, × 1.0374, 55 µs/rev netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 3 revs, 0.000175 s, 0.000175 s, +0.000000 s, × 1.0000, 58 µs/rev netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 9 revs, 0.000720 s, 0.000732 s, +0.000012 s, × 1.0167, 81 µs/rev netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 1421 revs, 0.010019 s, 0.010062 s, +0.000043 s, × 1.0043, 7 µs/rev netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 1533 revs, 0.015602 s, 0.015659 s, +0.000057 s, × 1.0037, 10 µs/rev netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 5750 revs, 0.058759 s, 0.062744 s, +0.003985 s, × 1.0678, 10 µs/rev netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 66949 revs, 0.491550 s, 0.499449 s, +0.007899 s, × 1.0161, 7 µs/rev mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 2 revs, 0.000087 s, 0.000088 s, +0.000001 s, × 1.0115, 44 µs/rev mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 8 revs, 0.000268 s, 0.000266 s, -0.000002 s, × 0.9925, 33 µs/rev mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 9 revs, 0.000181 s, 0.000182 s, +0.000001 s, × 1.0055, 20 µs/rev mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 7 revs, 0.000661 s, 0.000656 s, -0.000005 s, × 0.9924, 93 µs/rev mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 3 revs, 0.003256 s, 0.003389 s, +0.000133 s, × 1.0408, 1129 µs/rev mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.066749 s, 0.075882 s, +0.009133 s, × 1.1368, 12647 µs/rev mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.006462 s, 0.006479 s, +0.000017 s, × 1.0026, 4 µs/rev mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.004919 s, 0.004889 s, -0.000030 s, × 0.9939, 119 µs/rev mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 7839 revs, 0.062421 s, 0.064394 s, +0.001973 s, × 1.0316, 8 µs/rev mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.026633 s, 0.026815 s, +0.000182 s, × 1.0068, 43 µs/rev mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 30263 revs, 0.197792 s, 0.cc85eb s, +0.005072 s, × 1.0256, 6 µs/rev mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 153721 revs, 1.259970 s, 1.219445 s, -0.040525 s, × 0.9678, 7 µs/rev mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 204976 revs, 1.689184 s, 1.613857 s, -0.075327 s, × 0.9554, 7 µs/rev mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 2 revs, 0.000865 s, 0.000873 s, +0.000008 s, × 1.0092, 436 µs/rev mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 2 revs, 0.000893 s, 0.000885 s, -0.000008 s, × 0.9910, 442 µs/rev mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 4 revs, 0.000172 s, 0.000161 s, -0.000011 s, × 0.9360, 40 µs/rev mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 2 revs, 0.001159 s, 0.001138 s, -0.000021 s, × 0.9819, 569 µs/rev mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 1 revs, 0.031621 s, 0.033399 s, +0.001778 s, × 1.0562, 33399 µs/rev mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.068571 s, 0.075445 s, +0.006874 s, × 1.1002, 12574 µs/rev mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.006452 s, 0.006456 s, +0.000004 s, × 1.0006, 4 µs/rev mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.005443 s, 0.005462 s, +0.000019 s, × 1.0035, 133 µs/rev mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 6657 revs, 0.063180 s, 0.064117 s, +0.000937 s, × 1.0148, 9 µs/rev mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 40314 revs, 0.293564 s, 0.297563 s, +0.003999 s, × 1.0136, 7 µs/rev mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 38690 revs, 0.286595 s, 0.282463 s, -0.004132 s, × 0.9856, 7 µs/rev mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 8598 revs, 0.083256 s, 0.084038 s, +0.000782 s, × 1.0094, 9 µs/rev mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.027282 s, 0.027306 s, +0.000024 s, × 1.0009, 44 µs/rev mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 1.343373 s, 1.465264 s, +0.121891 s, × 1.0907, 15 µs/rev mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 52031 revs, 0.665737 s, 0.690376 s, +0.024639 s, × 1.0370, 13 µs/rev mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 363753 revs, 5.138169 s, 4.011322 s, -1.126847 s, × 0.7807, 11 µs/rev mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 34414 revs, 0.573276 s, 0.573541 s, +0.000265 s, × 1.0005, 16 µs/rev mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 362229 revs, 5.127809 s, 3.981133 s, -1.146676 s, × 0.7764, 10 µs/rev mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 359344 revs, 4.971136 s, 3.996647 s, -0.974489 s, × 0.8040, 11 µs/rev mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 192665 revs, 1.741678 s, 1.520607 s, -0.221071 s, × 0.8731, 7 µs/rev mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 40.314822 s, 50.244975 s, +9.930153 s, × 1.2463, 219 µs/rev mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 382065 revs, 20.048029 s, 20.030023 s, -0.018006 s, × 0.9991, 52 µs/rev private : 459513 revs, 37.179470 s, 24.490825 s, -12.688645 s, × 0.6587, 53 µs/rev ### Compared to the filelog based copy tracing Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 1 revs, 0.000918 s, 0.000041 s, -0.000877 s, × 0.044662, 40 µs/rev mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 6 revs, 0.001853 s, 0.000116 s, -0.001737 s, × 0.062601, 19 µs/rev mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 1032 revs, 0.018994 s, 0.004933 s, -0.014061 s, × 0.259714, 4 µs/rev pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 9 revs, 0.001532 s, 0.000193 s, -0.001339 s, × 0.125979, 21 µs/rev pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 1 revs, 0.210633 s, 0.000048 s, -0.210585 s, × 0.000228, 47 µs/rev pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 7 revs, 0.017041 s, 0.000114 s, -0.016927 s, × 0.006690, 16 µs/rev pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 1 revs, 0.019474 s, 0.000319 s, -0.019155 s, × 0.016381, 318 µs/rev pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 6 revs, 0.763136 s, 0.012025 s, -0.751111 s, × 0.015757, 2003 µs/rev pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 4785 revs, 1.226569 s, 0.050525 s, -1.176044 s, × 0.041192, 10 µs/rev pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 6780 revs, 1.314572 s, 0.085713 s, -1.228859 s, × 0.065202, 12 µs/rev pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 5441 revs, 1.686022 s, 0.061825 s, -1.624197 s, × 0.036669, 11 µs/rev pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.001110 s, 0.543998 s, +0.542888 s, × 490.0882, 12 µs/rev pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 2 revs, 1.106265 s, 0.013455 s, -1.092810 s, × 0.012163, 6724 µs/rev pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 11316 revs, 1.377398 s, 0.117479 s, -1.259919 s, × 0.085291, 10 µs/rev netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 2 revs, 0.028579 s, 0.000084 s, -0.028495 s, × 0.002939, 41 µs/rev netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 2 revs, 0.133644 s, 0.000111 s, -0.133533 s, × 0.000831, 55 µs/rev netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 3 revs, 0.025988 s, 0.000175 s, -0.025813 s, × 0.006734, 58 µs/rev netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 9 revs, 0.053011 s, 0.000732 s, -0.052279 s, × 0.013808, 81 µs/rev netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 1421 revs, 0.037858 s, 0.010062 s, -0.027796 s, × 0.265783, 7 µs/rev netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 1533 revs, 0.200517 s, 0.015659 s, -0.184858 s, × 0.078093, 10 µs/rev netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 5750 revs, 0.964542 s, 0.062744 s, -0.901798 s, × 0.065051, 10 µs/rev netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 66949 revs, 3.976210 s, 0.499449 s, -3.476761 s, × 0.125609, 7 µs/rev mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 2 revs, 0.025172 s, 0.000088 s, -0.025084 s, × 0.003496, 43 µs/rev mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 8 revs, 0.145144 s, 0.000266 s, -0.144878 s, × 0.001833, 33 µs/rev mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 9 revs, 0.026139 s, 0.000182 s, -0.025957 s, × 0.006963, 20 µs/rev mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 7 revs, 0.086184 s, 0.000656 s, -0.085528 s, × 0.007612, 93 µs/rev mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 3 revs, 0.203187 s, 0.003389 s, -0.199798 s, × 0.016679, 1129 µs/rev mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 2.255675 s, 0.075882 s, -2.179793 s, × 0.033640, 12644 µs/rev mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.091147 s, 0.006479 s, -0.084668 s, × 0.071083, 4 µs/rev mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.767530 s, 0.004889 s, -0.762641 s, × 0.006370, 119 µs/rev mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 7839 revs, 1.185330 s, 0.064394 s, -1.120936 s, × 0.054326, 8 µs/rev mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 6.831179 s, 0.026815 s, -6.804364 s, × 0.003925, 43 µs/rev mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 30263 revs, 3.373551 s, 0.cc85eb s, -3.170687 s, × 0.060134, 6 µs/rev mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 153721 revs, 16.540604 s, 1.219445 s, -15.321159 s, × 0.073724, 7 µs/rev mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 204976 revs, 21.527155 s, 1.613857 s, -19.913298 s, × 0.074968, 7 µs/rev mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 2 revs, 0.084540 s, 0.000873 s, -0.083667 s, × 0.010326, 436 µs/rev mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 2 revs, 0.507151 s, 0.000885 s, -0.506266 s, × 0.001745, 442 µs/rev mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 4 revs, 0.021748 s, 0.000161 s, -0.021587 s, × 0.007403, 40 µs/rev mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 2 revs, 0.236786 s, 0.001138 s, -0.235648 s, × 0.004806, 568 µs/rev mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 1 revs, 1.111735 s, 0.033399 s, -1.078336 s, × 0.030042, 33365 µs/rev mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 2.228030 s, 0.075445 s, -2.152585 s, × 0.033862, 12572 µs/rev mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.091289 s, 0.006456 s, -0.084833 s, × 0.070720, 4 µs/rev mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.771361 s, 0.005462 s, -0.765899 s, × 0.007081, 133 µs/rev mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 6657 revs, 1.189483 s, 0.064117 s, -1.125366 s, × 0.053903, 9 µs/rev mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 40314 revs, 0.089756 s, 0.297563 s, +0.207807 s, × 3.315244, 7 µs/rev mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 38690 revs, 0.084888 s, 0.282463 s, +0.197575 s, × 3.327479, 7 µs/rev mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 8598 revs, 7.682665 s, 0.084038 s, -7.598627 s, × 0.010939, 9 µs/rev mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 6.894680 s, 0.027306 s, -6.867374 s, × 0.003960, 44 µs/rev mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 7.650907 s, 1.465264 s, -6.185643 s, × 0.191515, 15 µs/rev mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 52031 revs, 9.898788 s, 0.690376 s, -9.208412 s, × 0.069743, 13 µs/rev mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 363753 revs, 0.092208 s, 4.011322 s, +3.919114 s, × 43.50297, 11 µs/rev mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 34414 revs, 28.130003 s, 0.573541 s, -27.556462 s, × 0.020389, 16 µs/rev mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 362229 revs, 0.093366 s, 3.981133 s, +3.887767 s, × 42.64007, 10 µs/rev mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 359344 revs, 0.229368 s, 3.996647 s, +3.767279 s, × 17.42460, 11 µs/rev mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 192665 revs, 19.624851 s, 1.520607 s, -18.104244 s, × 0.077484, 7 µs/rev mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 22.070126 s, 50.244975 s, +28.174849 s, × 2.276606, 219 µs/rev mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 382065 revs, 26.006524 s, 20.030023 s, -5.976501 s, × 0.770192, 52 µs/rev private : 459513 revs, 18.704612 s, 24.490825 s, +5.786213 s, × 1.309347, 53 µs/rev Differential Revision: https://phab.mercurial-scm.org/D9656
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 21 Dec 2020 12:34:59 +0100
parents aa19d60ac974
children 435d9fc72646
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45973
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
1 use crate::utils::hg_path::HgPath;
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 use crate::utils::hg_path::HgPathBuf;
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3 use crate::Revision;
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
4 use crate::NULL_REVISION;
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5
45971
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45964
diff changeset
6 use im_rc::ordmap::DiffItem;
46153
0a721fc457bf copies-rust: use the `entry` API for copy information too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46152
diff changeset
7 use im_rc::ordmap::Entry;
45963
0d99778af68a copies-rust: use immutable "OrdMap" to store copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45944
diff changeset
8 use im_rc::ordmap::OrdMap;
46585
60b2b7ecf9cb copies-rust: use imrs::OrdSet instead of imrs::HashSet
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46584
diff changeset
9 use im_rc::OrdSet;
45963
0d99778af68a copies-rust: use immutable "OrdMap" to store copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45944
diff changeset
10
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
11 use std::cmp::Ordering;
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
12 use std::collections::HashMap;
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
13 use std::convert::TryInto;
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
14
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
15 pub type PathCopies = HashMap<HgPathBuf, HgPathBuf>;
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
16
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
17 type PathToken = usize;
46129
818502d2f5e3 copies-rust: pre-introduce a PathToken type and use it where applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46128
diff changeset
18
46582
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
19 #[derive(Clone, Debug)]
46565
2bd069788367 copies-rust: rename TimeStampedPathCopy to CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46564
diff changeset
20 struct CopySource {
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
21 /// revision at which the copy information was added
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
22 rev: Revision,
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
23 /// the copy source, (Set to None in case of deletion of the associated
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
24 /// key)
46129
818502d2f5e3 copies-rust: pre-introduce a PathToken type and use it where applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46128
diff changeset
25 path: Option<PathToken>,
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
26 /// a set of previous `CopySource.rev` value directly or indirectly
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
27 /// overwritten by this one.
46585
60b2b7ecf9cb copies-rust: use imrs::OrdSet instead of imrs::HashSet
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46584
diff changeset
28 overwritten: OrdSet<Revision>,
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
29 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
30
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
31 impl CopySource {
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
32 /// create a new CopySource
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
33 ///
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
34 /// Use this when no previous copy source existed.
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
35 fn new(rev: Revision, path: Option<PathToken>) -> Self {
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
36 Self {
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
37 rev,
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
38 path,
46585
60b2b7ecf9cb copies-rust: use imrs::OrdSet instead of imrs::HashSet
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46584
diff changeset
39 overwritten: OrdSet::new(),
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
40 }
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
41 }
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
42
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
43 /// create a new CopySource from merging two others
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
44 ///
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
45 /// Use this when merging two InternalPathCopies requires active merging of
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
46 /// some entries.
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
47 fn new_from_merge(rev: Revision, winner: &Self, loser: &Self) -> Self {
46585
60b2b7ecf9cb copies-rust: use imrs::OrdSet instead of imrs::HashSet
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46584
diff changeset
48 let mut overwritten = OrdSet::new();
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
49 overwritten.extend(winner.overwritten.iter().copied());
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
50 overwritten.extend(loser.overwritten.iter().copied());
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
51 overwritten.insert(winner.rev);
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
52 overwritten.insert(loser.rev);
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
53 Self {
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
54 rev,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
55 path: winner.path,
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
56 overwritten: overwritten,
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
57 }
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
58 }
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
59
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
60 /// Update the value of a pre-existing CopySource
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
61 ///
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
62 /// Use this when recording copy information from parent → child edges
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
63 fn overwrite(&mut self, rev: Revision, path: Option<PathToken>) {
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
64 self.overwritten.insert(self.rev);
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
65 self.rev = rev;
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
66 self.path = path;
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
67 }
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
68
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
69 /// Mark pre-existing copy information as "dropped" by a file deletion
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
70 ///
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
71 /// Use this when recording copy information from parent → child edges
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
72 fn mark_delete(&mut self, rev: Revision) {
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
73 self.overwritten.insert(self.rev);
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
74 self.rev = rev;
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
75 self.path = None;
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
76 }
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
77
46581
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
78 /// Mark pre-existing copy information as "dropped" by a file deletion
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
79 ///
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
80 /// Use this when recording copy information from parent → child edges
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
81 fn mark_delete_with_pair(&mut self, rev: Revision, other: &Self) {
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
82 self.overwritten.insert(self.rev);
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
83 if other.rev != rev {
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
84 self.overwritten.insert(other.rev);
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
85 }
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
86 self.overwritten.extend(other.overwritten.iter().copied());
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
87 self.rev = rev;
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
88 self.path = None;
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
89 }
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
90
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
91 fn is_overwritten_by(&self, other: &Self) -> bool {
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
92 other.overwritten.contains(&self.rev)
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
93 }
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
94 }
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
95
46582
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
96 // For the same "dest", content generated for a given revision will always be
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
97 // the same.
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
98 impl PartialEq for CopySource {
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
99 fn eq(&self, other: &Self) -> bool {
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
100 #[cfg(debug_assertions)]
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
101 {
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
102 if self.rev == other.rev {
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
103 debug_assert!(self.path == other.path);
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
104 debug_assert!(self.overwritten == other.overwritten);
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
105 }
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
106 }
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
107 self.rev == other.rev
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
108 }
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
109 }
b0a3ca02d17a copies-rust: implement PartialEqual manually
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46581
diff changeset
110
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
111 /// maps CopyDestination to Copy Source (+ a "timestamp" for the operation)
46565
2bd069788367 copies-rust: rename TimeStampedPathCopy to CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46564
diff changeset
112 type InternalPathCopies = OrdMap<PathToken, CopySource>;
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
113
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
114 /// hold parent 1, parent 2 and relevant files actions.
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
115 pub type RevInfo<'a> = (Revision, Revision, ChangedFiles<'a>);
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
116
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
117 /// represent the files affected by a changesets
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
118 ///
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
119 /// This hold a subset of mercurial.metadata.ChangingFiles as we do not need
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
120 /// all the data categories tracked by it.
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
121 /// This hold a subset of mercurial.metadata.ChangingFiles as we do not need
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
122 /// all the data categories tracked by it.
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
123 pub struct ChangedFiles<'a> {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
124 nb_items: u32,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
125 index: &'a [u8],
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
126 data: &'a [u8],
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
127 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
128
45973
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
129 /// Represent active changes that affect the copy tracing.
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
130 enum Action<'a> {
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
131 /// The parent ? children edge is removing a file
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
132 ///
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
133 /// (actually, this could be the edge from the other parent, but it does
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
134 /// not matters)
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
135 Removed(&'a HgPath),
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
136 /// The parent ? children edge introduce copy information between (dest,
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
137 /// source)
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
138 CopiedFromP1(&'a HgPath, &'a HgPath),
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
139 CopiedFromP2(&'a HgPath, &'a HgPath),
45973
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
140 }
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
141
45975
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
142 /// This express the possible "special" case we can get in a merge
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
143 ///
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
144 /// See mercurial/metadata.py for details on these values.
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
145 #[derive(PartialEq)]
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
146 enum MergeCase {
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
147 /// Merged: file had history on both side that needed to be merged
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
148 Merged,
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
149 /// Salvaged: file was candidate for deletion, but survived the merge
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
150 Salvaged,
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
151 /// Normal: Not one of the two cases above
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
152 Normal,
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
153 }
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
154
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
155 type FileChange<'a> = (u8, &'a HgPath, &'a HgPath);
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
156
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
157 const EMPTY: &[u8] = b"";
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
158 const COPY_MASK: u8 = 3;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
159 const P1_COPY: u8 = 2;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
160 const P2_COPY: u8 = 3;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
161 const ACTION_MASK: u8 = 28;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
162 const REMOVED: u8 = 12;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
163 const MERGED: u8 = 8;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
164 const SALVAGED: u8 = 16;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
165
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
166 impl<'a> ChangedFiles<'a> {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
167 const INDEX_START: usize = 4;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
168 const ENTRY_SIZE: u32 = 9;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
169 const FILENAME_START: u32 = 1;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
170 const COPY_SOURCE_START: u32 = 5;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
171
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
172 pub fn new(data: &'a [u8]) -> Self {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
173 assert!(
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
174 data.len() >= 4,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
175 "data size ({}) is too small to contain the header (4)",
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
176 data.len()
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
177 );
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
178 let nb_items_raw: [u8; 4] = (&data[0..=3])
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
179 .try_into()
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
180 .expect("failed to turn 4 bytes into 4 bytes");
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
181 let nb_items = u32::from_be_bytes(nb_items_raw);
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
182
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
183 let index_size = (nb_items * Self::ENTRY_SIZE) as usize;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
184 let index_end = Self::INDEX_START + index_size;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
185
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
186 assert!(
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
187 data.len() >= index_end,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
188 "data size ({}) is too small to fit the index_data ({})",
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
189 data.len(),
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
190 index_end
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
191 );
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
192
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
193 let ret = ChangedFiles {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
194 nb_items,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
195 index: &data[Self::INDEX_START..index_end],
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
196 data: &data[index_end..],
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
197 };
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
198 let max_data = ret.filename_end(nb_items - 1) as usize;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
199 assert!(
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
200 ret.data.len() >= max_data,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
201 "data size ({}) is too small to fit all data ({})",
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
202 data.len(),
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
203 index_end + max_data
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
204 );
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
205 ret
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
206 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
207
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
208 pub fn new_empty() -> Self {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
209 ChangedFiles {
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
210 nb_items: 0,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
211 index: EMPTY,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
212 data: EMPTY,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
213 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
214 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
215
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
216 /// internal function to return an individual entry at a given index
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
217 fn entry(&'a self, idx: u32) -> FileChange<'a> {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
218 if idx >= self.nb_items {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
219 panic!(
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
220 "index for entry is higher that the number of file {} >= {}",
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
221 idx, self.nb_items
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
222 )
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
223 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
224 let flags = self.flags(idx);
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
225 let filename = self.filename(idx);
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
226 let copy_idx = self.copy_idx(idx);
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
227 let copy_source = self.filename(copy_idx);
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
228 (flags, filename, copy_source)
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
229 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
230
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
231 /// internal function to return the filename of the entry at a given index
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
232 fn filename(&self, idx: u32) -> &HgPath {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
233 let filename_start;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
234 if idx == 0 {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
235 filename_start = 0;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
236 } else {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
237 filename_start = self.filename_end(idx - 1)
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
238 }
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
239 let filename_end = self.filename_end(idx);
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
240 let filename_start = filename_start as usize;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
241 let filename_end = filename_end as usize;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
242 HgPath::new(&self.data[filename_start..filename_end])
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
243 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
244
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
245 /// internal function to return the flag field of the entry at a given
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
246 /// index
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
247 fn flags(&self, idx: u32) -> u8 {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
248 let idx = idx as usize;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
249 self.index[idx * (Self::ENTRY_SIZE as usize)]
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
250 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
251
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
252 /// internal function to return the end of a filename part at a given index
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
253 fn filename_end(&self, idx: u32) -> u32 {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
254 let start = (idx * Self::ENTRY_SIZE) + Self::FILENAME_START;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
255 let end = (idx * Self::ENTRY_SIZE) + Self::COPY_SOURCE_START;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
256 let start = start as usize;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
257 let end = end as usize;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
258 let raw = (&self.index[start..end])
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
259 .try_into()
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
260 .expect("failed to turn 4 bytes into 4 bytes");
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
261 u32::from_be_bytes(raw)
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
262 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
263
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
264 /// internal function to return index of the copy source of the entry at a
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
265 /// given index
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
266 fn copy_idx(&self, idx: u32) -> u32 {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
267 let start = (idx * Self::ENTRY_SIZE) + Self::COPY_SOURCE_START;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
268 let end = (idx + 1) * Self::ENTRY_SIZE;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
269 let start = start as usize;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
270 let end = end as usize;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
271 let raw = (&self.index[start..end])
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
272 .try_into()
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
273 .expect("failed to turn 4 bytes into 4 bytes");
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
274 u32::from_be_bytes(raw)
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
275 }
45973
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
276
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
277 /// Return an iterator over all the `Action` in this instance.
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
278 fn iter_actions(&self) -> ActionsIterator {
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
279 ActionsIterator {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
280 changes: &self,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
281 current: 0,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
282 }
45973
ed0e1339e4a8 copies-rust: combine the iteration over remove and copies into one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45972
diff changeset
283 }
45975
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
284
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
285 /// return the MergeCase value associated with a filename
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
286 fn get_merge_case(&self, path: &HgPath) -> MergeCase {
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
287 if self.nb_items == 0 {
45975
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
288 return MergeCase::Normal;
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
289 }
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
290 let mut low_part = 0;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
291 let mut high_part = self.nb_items;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
292
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
293 while low_part < high_part {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
294 let cursor = (low_part + high_part - 1) / 2;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
295 let (flags, filename, _source) = self.entry(cursor);
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
296 match path.cmp(filename) {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
297 Ordering::Less => low_part = cursor + 1,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
298 Ordering::Greater => high_part = cursor,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
299 Ordering::Equal => {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
300 return match flags & ACTION_MASK {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
301 MERGED => MergeCase::Merged,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
302 SALVAGED => MergeCase::Salvaged,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
303 _ => MergeCase::Normal,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
304 };
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
305 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
306 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
307 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
308 MergeCase::Normal
45975
2367937982ba copies-rust: encapsulate internal sets on `changes`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45974
diff changeset
309 }
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
310 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
311
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
312 struct ActionsIterator<'a> {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
313 changes: &'a ChangedFiles<'a>,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
314 current: u32,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
315 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
316
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
317 impl<'a> Iterator for ActionsIterator<'a> {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
318 type Item = Action<'a>;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
319
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
320 fn next(&mut self) -> Option<Action<'a>> {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
321 while self.current < self.changes.nb_items {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
322 let (flags, file, source) = self.changes.entry(self.current);
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
323 self.current += 1;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
324 if (flags & ACTION_MASK) == REMOVED {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
325 return Some(Action::Removed(file));
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
326 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
327 let copy = flags & COPY_MASK;
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
328 if copy == P1_COPY {
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
329 return Some(Action::CopiedFromP1(file, source));
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
330 } else if copy == P2_COPY {
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
331 return Some(Action::CopiedFromP2(file, source));
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
332 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
333 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
334 return None;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
335 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
336 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
337
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
338 /// A small struct whose purpose is to ensure lifetime of bytes referenced in
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
339 /// ChangedFiles
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
340 ///
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
341 /// It is passed to the RevInfoMaker callback who can assign any necessary
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
342 /// content to the `data` attribute. The copy tracing code is responsible for
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
343 /// keeping the DataHolder alive at least as long as the ChangedFiles object.
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
344 pub struct DataHolder<D> {
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
345 /// RevInfoMaker callback should assign data referenced by the
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
346 /// ChangedFiles struct it return to this attribute. The DataHolder
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
347 /// lifetime will be at least as long as the ChangedFiles one.
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
348 pub data: Option<D>,
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
349 }
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
350
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
351 pub type RevInfoMaker<'a, D> =
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
352 Box<dyn for<'r> Fn(Revision, &'r mut DataHolder<D>) -> RevInfo<'r> + 'a>;
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
353
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
354 /// A small "tokenizer" responsible of turning full HgPath into lighter
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
355 /// PathToken
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
356 ///
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
357 /// Dealing with small object, like integer is much faster, so HgPath input are
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
358 /// turned into integer "PathToken" and converted back in the end.
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
359 #[derive(Clone, Debug, Default)]
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
360 struct TwoWayPathMap {
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
361 token: HashMap<HgPathBuf, PathToken>,
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
362 path: Vec<HgPathBuf>,
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
363 }
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
364
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
365 impl TwoWayPathMap {
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
366 fn tokenize(&mut self, path: &HgPath) -> PathToken {
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
367 match self.token.get(path) {
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
368 Some(a) => *a,
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
369 None => {
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
370 let a = self.token.len();
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
371 let buf = path.to_owned();
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
372 self.path.push(buf.clone());
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
373 self.token.insert(buf, a);
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
374 a
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
375 }
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
376 }
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
377 }
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
378
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
379 fn untokenize(&self, token: PathToken) -> &HgPathBuf {
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
380 assert!(token < self.path.len(), format!("Unknown token: {}", token));
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
381 &self.path[token]
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
382 }
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
383 }
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
384
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
385 /// Same as mercurial.copies._combine_changeset_copies, but in Rust.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
386 ///
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
387 /// Arguments are:
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
388 ///
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
389 /// revs: all revisions to be considered
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
390 /// children: a {parent ? [childrens]} mapping
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
391 /// target_rev: the final revision we are combining copies to
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
392 /// rev_info(rev): callback to get revision information:
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
393 /// * first parent
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
394 /// * second parent
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
395 /// * ChangedFiles
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
396 /// isancestors(low_rev, high_rev): callback to check if a revision is an
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
397 /// ancestor of another
46569
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
398 pub fn combine_changeset_copies<D>(
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
399 revs: Vec<Revision>,
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
400 mut children_count: HashMap<Revision, usize>,
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
401 target_rev: Revision,
46057
e0313b0a6f7e copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45975
diff changeset
402 rev_info: RevInfoMaker<D>,
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
403 ) -> PathCopies {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
404 let mut all_copies = HashMap::new();
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
405
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
406 let mut path_map = TwoWayPathMap::default();
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
407
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
408 for rev in revs {
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
409 let mut d: DataHolder<D> = DataHolder { data: None };
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
410 let (p1, p2, changes) = rev_info(rev, &mut d);
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
411
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
412 // We will chain the copies information accumulated for the parent with
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
413 // the individual copies information the curent revision. Creating a
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
414 // new TimeStampedPath for each `rev` → `children` vertex.
46575
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
415 // Retrieve data computed in a previous iteration
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
416 let p1_copies = match p1 {
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
417 NULL_REVISION => None,
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
418 _ => get_and_clean_parent_copies(
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
419 &mut all_copies,
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
420 &mut children_count,
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
421 p1,
46575
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
422 ), // will be None if the vertex is not to be traversed
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
423 };
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
424 let p2_copies = match p2 {
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
425 NULL_REVISION => None,
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
426 _ => get_and_clean_parent_copies(
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
427 &mut all_copies,
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
428 &mut children_count,
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
429 p2,
46575
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
430 ), // will be None if the vertex is not to be traversed
389b0328b789 copies-rust: get the parents' copies earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46569
diff changeset
431 };
46576
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
432 // combine it with data for that revision
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
433 let (p1_copies, p2_copies) =
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
434 chain_changes(&mut path_map, p1_copies, p2_copies, &changes, rev);
46576
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
435 let copies = match (p1_copies, p2_copies) {
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
436 (None, None) => None,
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
437 (c, None) => c,
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
438 (None, c) => c,
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
439 (Some(p1_copies), Some(p2_copies)) => Some(merge_copies_dict(
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
440 &path_map, rev, p2_copies, p1_copies, &changes,
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
441 )),
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
442 };
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
443 if let Some(c) = copies {
f8bdc8329d77 copies-rust: use matching to select the final copies information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46575
diff changeset
444 all_copies.insert(rev, c);
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
445 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
446 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
447
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
448 // Drop internal information (like the timestamp) and return the final
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
449 // mapping.
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
450 let tt_result = all_copies
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
451 .remove(&target_rev)
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
452 .expect("target revision was not processed");
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
453 let mut result = PathCopies::default();
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
454 for (dest, tt_source) in tt_result {
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
455 if let Some(path) = tt_source.path {
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
456 let path_dest = path_map.untokenize(dest).to_owned();
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
457 let path_path = path_map.untokenize(path).to_owned();
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
458 result.insert(path_dest, path_path);
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
459 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
460 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
461 result
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
462 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
463
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
464 /// fetch previous computed information
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
465 ///
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
466 /// If no other children are expected to need this information, we drop it from
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
467 /// the cache.
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
468 ///
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
469 /// If parent is not part of the set we are expected to walk, return None.
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
470 fn get_and_clean_parent_copies(
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
471 all_copies: &mut HashMap<Revision, InternalPathCopies>,
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
472 children_count: &mut HashMap<Revision, usize>,
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
473 parent_rev: Revision,
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
474 ) -> Option<InternalPathCopies> {
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
475 let count = children_count.get_mut(&parent_rev)?;
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
476 *count -= 1;
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
477 if *count == 0 {
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
478 match all_copies.remove(&parent_rev) {
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
479 Some(c) => Some(c),
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
480 None => Some(InternalPathCopies::default()),
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
481 }
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
482 } else {
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
483 match all_copies.get(&parent_rev) {
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
484 Some(c) => Some(c.clone()),
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
485 None => Some(InternalPathCopies::default()),
46149
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
486 }
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
487 }
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
488 }
294d5aca4ff5 copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46129
diff changeset
489
46059
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
490 /// Combine ChangedFiles with some existing PathCopies information and return
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
491 /// the result
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
492 fn chain_changes(
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
493 path_map: &mut TwoWayPathMap,
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
494 base_p1_copies: Option<InternalPathCopies>,
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
495 base_p2_copies: Option<InternalPathCopies>,
46059
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
496 changes: &ChangedFiles,
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
497 current_rev: Revision,
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
498 ) -> (Option<InternalPathCopies>, Option<InternalPathCopies>) {
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
499 // Fast path the "nothing to do" case.
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
500 if let (None, None) = (&base_p1_copies, &base_p2_copies) {
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
501 return (None, None);
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
502 }
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
503
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
504 let mut p1_copies = base_p1_copies.clone();
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
505 let mut p2_copies = base_p2_copies.clone();
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
506 for action in changes.iter_actions() {
46059
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
507 match action {
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
508 Action::CopiedFromP1(path_dest, path_source) => {
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
509 match &mut p1_copies {
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
510 None => (), // This is not a vertex we should proceed.
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
511 Some(copies) => add_one_copy(
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
512 current_rev,
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
513 path_map,
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
514 copies,
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
515 base_p1_copies.as_ref().unwrap(),
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
516 path_dest,
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
517 path_source,
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
518 ),
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
519 }
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
520 }
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
521 Action::CopiedFromP2(path_dest, path_source) => {
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
522 match &mut p2_copies {
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
523 None => (), // This is not a vertex we should proceed.
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
524 Some(copies) => add_one_copy(
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
525 current_rev,
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
526 path_map,
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
527 copies,
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
528 base_p2_copies.as_ref().unwrap(),
46578
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
529 path_dest,
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
530 path_source,
a34cd9aa3323 copies-rust: yield both p1 and p2 copies in `ChangedFiles.actions()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46577
diff changeset
531 ),
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
532 }
46059
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
533 }
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
534 Action::Removed(deleted_path) => {
46059
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
535 // We must drop copy information for removed file.
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
536 //
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
537 // We need to explicitly record them as dropped to
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
538 // propagate this information when merging two
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
539 // InternalPathCopies object.
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
540 let deleted = path_map.tokenize(deleted_path);
46580
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
541
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
542 let p1_entry = match &mut p1_copies {
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
543 None => None,
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
544 Some(copies) => match copies.entry(deleted) {
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
545 Entry::Occupied(e) => Some(e),
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
546 Entry::Vacant(_) => None,
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
547 },
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
548 };
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
549 let p2_entry = match &mut p2_copies {
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
550 None => None,
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
551 Some(copies) => match copies.entry(deleted) {
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
552 Entry::Occupied(e) => Some(e),
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
553 Entry::Vacant(_) => None,
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
554 },
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
555 };
46580
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
556
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
557 match (p1_entry, p2_entry) {
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
558 (None, None) => (),
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
559 (Some(mut e), None) => {
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
560 e.get_mut().mark_delete(current_rev)
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
561 }
46580
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
562 (None, Some(mut e)) => {
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
563 e.get_mut().mark_delete(current_rev)
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
564 }
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
565 (Some(mut e1), Some(mut e2)) => {
46581
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
566 let cs1 = e1.get_mut();
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
567 let cs2 = e2.get();
46584
aa19d60ac974 copies-rust: use simpler overwrite when value on both side are identical
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46583
diff changeset
568 if cs1 == cs2 {
aa19d60ac974 copies-rust: use simpler overwrite when value on both side are identical
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46583
diff changeset
569 cs1.mark_delete(current_rev);
aa19d60ac974 copies-rust: use simpler overwrite when value on both side are identical
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46583
diff changeset
570 } else {
aa19d60ac974 copies-rust: use simpler overwrite when value on both side are identical
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46583
diff changeset
571 cs1.mark_delete_with_pair(current_rev, &cs2);
aa19d60ac974 copies-rust: use simpler overwrite when value on both side are identical
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46583
diff changeset
572 }
46581
d6d57bfc1a1b copies-rust: record "overwritten" information from both side on delete
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46580
diff changeset
573 e2.insert(cs1.clone());
46580
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
574 }
2076df13d00f copies-rust: refactor the "deletion" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46579
diff changeset
575 }
46059
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
576 }
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
577 }
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
578 }
46579
600f8d510ab6 copies-rust: process copy information of both parent at the same time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46578
diff changeset
579 (p1_copies, p2_copies)
46059
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
580 }
dacb771f6dd2 copies-rust: extract the processing of a ChangedFiles in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46058
diff changeset
581
46577
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
582 // insert one new copy information in an InternalPathCopies
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
583 //
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
584 // This deal with chaining and overwrite.
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
585 fn add_one_copy(
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
586 current_rev: Revision,
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
587 path_map: &mut TwoWayPathMap,
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
588 copies: &mut InternalPathCopies,
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
589 base_copies: &InternalPathCopies,
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
590 path_dest: &HgPath,
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
591 path_source: &HgPath,
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
592 ) {
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
593 let dest = path_map.tokenize(path_dest);
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
594 let source = path_map.tokenize(path_source);
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
595 let entry;
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
596 if let Some(v) = base_copies.get(&source) {
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
597 entry = match &v.path {
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
598 Some(path) => Some((*(path)).to_owned()),
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
599 None => Some(source.to_owned()),
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
600 }
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
601 } else {
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
602 entry = Some(source.to_owned());
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
603 }
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
604 // Each new entry is introduced by the children, we
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
605 // record this information as we will need it to take
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
606 // the right decision when merging conflicting copy
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
607 // information. See merge_copies_dict for details.
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
608 match copies.entry(dest) {
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
609 Entry::Vacant(slot) => {
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
610 let ttpc = CopySource::new(current_rev, entry);
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
611 slot.insert(ttpc);
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
612 }
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
613 Entry::Occupied(mut slot) => {
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
614 let ttpc = slot.get_mut();
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
615 ttpc.overwrite(current_rev, entry);
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
616 }
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
617 }
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
618 }
d2ad44b8ef6a copies-rust: extract the processing of a single copy information
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46576
diff changeset
619
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
620 /// merge two copies-mapping together, minor and major
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
621 ///
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
622 /// In case of conflict, value from "major" will be picked, unless in some
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
623 /// cases. See inline documentation for details.
46569
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
624 fn merge_copies_dict(
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
625 path_map: &TwoWayPathMap,
46156
7d99614b7b77 copies-rust: make the comparison aware of the revision being current merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46155
diff changeset
626 current_merge: Revision,
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
627 mut minor: InternalPathCopies,
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
628 mut major: InternalPathCopies,
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
629 changes: &ChangedFiles,
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
630 ) -> InternalPathCopies {
46127
c58c8f1d63b1 copies-rust: hide most of the comparison details inside a closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46126
diff changeset
631 // This closure exist as temporary help while multiple developper are
c58c8f1d63b1 copies-rust: hide most of the comparison details inside a closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46126
diff changeset
632 // actively working on this code. Feel free to re-inline it once this
c58c8f1d63b1 copies-rust: hide most of the comparison details inside a closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46126
diff changeset
633 // code is more settled.
46569
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
634 let cmp_value =
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
635 |dest: &PathToken, src_minor: &CopySource, src_major: &CopySource| {
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
636 compare_value(
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
637 path_map,
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
638 current_merge,
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
639 changes,
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
640 dest,
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
641 src_minor,
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
642 src_major,
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
643 )
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
644 };
45971
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45964
diff changeset
645 if minor.is_empty() {
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
646 major
45971
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45964
diff changeset
647 } else if major.is_empty() {
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
648 minor
46128
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
649 } else if minor.len() * 2 < major.len() {
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
650 // Lets says we are merging two InternalPathCopies instance A and B.
46128
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
651 //
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
652 // If A contains N items, the merge result will never contains more
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
653 // than N values differents than the one in A
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
654 //
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
655 // If B contains M items, with M > N, the merge result will always
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
656 // result in a minimum of M - N value differents than the on in
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
657 // A
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
658 //
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
659 // As a result, if N < (M-N), we know that simply iterating over A will
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
660 // yield less difference than iterating over the difference
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
661 // between A and B.
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
662 //
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
663 // This help performance a lot in case were a tiny
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
664 // InternalPathCopies is merged with a much larger one.
46128
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
665 for (dest, src_minor) in minor {
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
666 let src_major = major.get(&dest);
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
667 match src_major {
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
668 None => {
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
669 major.insert(dest, src_minor);
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
670 }
46128
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
671 Some(src_major) => {
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
672 let (pick, overwrite) =
46569
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
673 cmp_value(&dest, &src_minor, src_major);
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
674 if overwrite {
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
675 let src = match pick {
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
676 MergePick::Major => CopySource::new_from_merge(
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
677 current_merge,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
678 src_major,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
679 &src_minor,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
680 ),
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
681 MergePick::Minor => CopySource::new_from_merge(
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
682 current_merge,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
683 &src_minor,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
684 src_major,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
685 ),
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
686 MergePick::Any => CopySource::new_from_merge(
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
687 current_merge,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
688 src_major,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
689 &src_minor,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
690 ),
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
691 };
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
692 major.insert(dest, src);
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
693 } else {
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
694 match pick {
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
695 MergePick::Any | MergePick::Major => None,
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
696 MergePick::Minor => major.insert(dest, src_minor),
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
697 };
46128
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
698 }
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
699 }
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
700 };
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
701 }
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
702 major
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
703 } else if major.len() * 2 < minor.len() {
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
704 // This use the same rational than the previous block.
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
705 // (Check previous block documentation for details.)
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
706 for (dest, src_major) in major {
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
707 let src_minor = minor.get(&dest);
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
708 match src_minor {
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
709 None => {
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
710 minor.insert(dest, src_major);
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
711 }
46128
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
712 Some(src_minor) => {
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
713 let (pick, overwrite) =
46569
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
714 cmp_value(&dest, src_minor, &src_major);
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
715 if overwrite {
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
716 let src = match pick {
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
717 MergePick::Major => CopySource::new_from_merge(
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
718 current_merge,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
719 &src_major,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
720 src_minor,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
721 ),
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
722 MergePick::Minor => CopySource::new_from_merge(
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
723 current_merge,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
724 src_minor,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
725 &src_major,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
726 ),
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
727 MergePick::Any => CopySource::new_from_merge(
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
728 current_merge,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
729 &src_major,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
730 src_minor,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
731 ),
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
732 };
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
733 minor.insert(dest, src);
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
734 } else {
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
735 match pick {
46566
3c5a8b13206a copies-rust: fix reverted argument when merging tiny minor or major
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46565
diff changeset
736 MergePick::Any | MergePick::Minor => None,
3c5a8b13206a copies-rust: fix reverted argument when merging tiny minor or major
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46565
diff changeset
737 MergePick::Major => minor.insert(dest, src_major),
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
738 };
46128
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
739 }
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
740 }
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
741 };
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
742 }
c94d013e2299 copies-rust: add smarter approach for merging small mapping with large mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46127
diff changeset
743 minor
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
744 } else {
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
745 let mut override_minor = Vec::new();
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
746 let mut override_major = Vec::new();
45971
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45964
diff changeset
747
46565
2bd069788367 copies-rust: rename TimeStampedPathCopy to CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46564
diff changeset
748 let mut to_major = |k: &PathToken, v: &CopySource| {
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
749 override_major.push((k.clone(), v.clone()))
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
750 };
46565
2bd069788367 copies-rust: rename TimeStampedPathCopy to CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46564
diff changeset
751 let mut to_minor = |k: &PathToken, v: &CopySource| {
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
752 override_minor.push((k.clone(), v.clone()))
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
753 };
45971
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45964
diff changeset
754
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
755 // The diff function leverage detection of the identical subpart if
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
756 // minor and major has some common ancestors. This make it very
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
757 // fast is most case.
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
758 //
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
759 // In case where the two map are vastly different in size, the current
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
760 // approach is still slowish because the iteration will iterate over
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
761 // all the "exclusive" content of the larger on. This situation can be
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
762 // frequent when the subgraph of revision we are processing has a lot
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
763 // of roots. Each roots adding they own fully new map to the mix (and
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
764 // likely a small map, if the path from the root to the "main path" is
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
765 // small.
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
766 //
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
767 // We could do better by detecting such situation and processing them
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
768 // differently.
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
769 for d in minor.diff(&major) {
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
770 match d {
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
771 DiffItem::Add(k, v) => to_minor(k, v),
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
772 DiffItem::Remove(k, v) => to_major(k, v),
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
773 DiffItem::Update { old, new } => {
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
774 let (dest, src_major) = new;
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
775 let (_, src_minor) = old;
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
776 let (pick, overwrite) =
46569
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
777 cmp_value(dest, src_minor, src_major);
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
778 if overwrite {
46567
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
779 let src = match pick {
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
780 MergePick::Major => CopySource::new_from_merge(
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
781 current_merge,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
782 src_major,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
783 src_minor,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
784 ),
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
785 MergePick::Minor => CopySource::new_from_merge(
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
786 current_merge,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
787 src_minor,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
788 src_major,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
789 ),
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
790 MergePick::Any => CopySource::new_from_merge(
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
791 current_merge,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
792 src_major,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
793 src_minor,
b6f65d90e8af copies-rust: add methods to build and update CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46566
diff changeset
794 ),
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
795 };
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
796 to_minor(dest, &src);
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
797 to_major(dest, &src);
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
798 } else {
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
799 match pick {
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
800 MergePick::Major => to_minor(dest, src_major),
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
801 MergePick::Minor => to_major(dest, src_minor),
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
802 // If the two entry are identical, no need to do
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
803 // anything (but diff should not have yield them)
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
804 MergePick::Any => unreachable!(),
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
805 }
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
806 }
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
807 }
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
808 };
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
809 }
45971
cc759d3db1e8 copies-rust: leverage the immutability for efficient update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45964
diff changeset
810
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
811 let updates;
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
812 let mut result;
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
813 if override_major.is_empty() {
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
814 result = major
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
815 } else if override_minor.is_empty() {
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
816 result = minor
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
817 } else {
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
818 if override_minor.len() < override_major.len() {
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
819 updates = override_minor;
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
820 result = minor;
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
821 } else {
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
822 updates = override_major;
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
823 result = major;
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
824 }
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
825 for (k, v) in updates {
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
826 result.insert(k, v);
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
827 }
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
828 }
46126
94300498491e copies-rust: move the mapping merging into a else clause
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46125
diff changeset
829 result
45944
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
830 }
595979dc924e copies: introduce a basic Rust function for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
831 }
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
832
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
833 /// represent the side that should prevail when merging two
46564
313610be4147 copies-rust: rename TimeStampedPathCopies to InternalPathCopies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46563
diff changeset
834 /// InternalPathCopies
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
835 enum MergePick {
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
836 /// The "major" (p1) side prevails
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
837 Major,
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
838 /// The "minor" (p2) side prevails
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
839 Minor,
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
840 /// Any side could be used (because they are the same)
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
841 Any,
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
842 }
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
843
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
844 /// decide which side prevails in case of conflicting values
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
845 #[allow(clippy::if_same_then_else)]
46569
34827c95092c copies-rust: remove the ancestor Oracle logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46568
diff changeset
846 fn compare_value(
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
847 path_map: &TwoWayPathMap,
46156
7d99614b7b77 copies-rust: make the comparison aware of the revision being current merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46155
diff changeset
848 current_merge: Revision,
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
849 changes: &ChangedFiles,
46129
818502d2f5e3 copies-rust: pre-introduce a PathToken type and use it where applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46128
diff changeset
850 dest: &PathToken,
46565
2bd069788367 copies-rust: rename TimeStampedPathCopy to CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46564
diff changeset
851 src_minor: &CopySource,
2bd069788367 copies-rust: rename TimeStampedPathCopy to CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46564
diff changeset
852 src_major: &CopySource,
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
853 ) -> (MergePick, bool) {
46583
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
854 if src_major == src_minor {
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
855 (MergePick::Any, false)
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
856 } else if src_major.rev == current_merge {
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
857 // minor is different according to per minor == major check earlier
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
858 debug_assert!(src_minor.rev != current_merge);
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
859
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
860 // The last value comes the current merge, this value -will- win
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
861 // eventually.
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
862 (MergePick::Major, true)
46156
7d99614b7b77 copies-rust: make the comparison aware of the revision being current merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46155
diff changeset
863 } else if src_minor.rev == current_merge {
7d99614b7b77 copies-rust: make the comparison aware of the revision being current merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46155
diff changeset
864 // The last value comes the current merge, this value -will- win
7d99614b7b77 copies-rust: make the comparison aware of the revision being current merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46155
diff changeset
865 // eventually.
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
866 (MergePick::Minor, true)
46156
7d99614b7b77 copies-rust: make the comparison aware of the revision being current merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46155
diff changeset
867 } else if src_major.path == src_minor.path {
46583
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
868 debug_assert!(src_major.rev != src_major.rev);
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
869 // we have the same value, but from other source;
46583
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
870 if src_major.is_overwritten_by(src_minor) {
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
871 (MergePick::Minor, false)
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
872 } else if src_minor.is_overwritten_by(src_major) {
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
873 (MergePick::Major, false)
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
874 } else {
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
875 (MergePick::Any, true)
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
876 }
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
877 } else {
46583
8fcf07e6bbb4 copies-rust: make more use of the new comparison property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46582
diff changeset
878 debug_assert!(src_major.rev != src_major.rev);
46151
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
879 let dest_path = path_map.untokenize(*dest);
c6bc77f7e593 copies-rust: tokenize all paths into integer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46149
diff changeset
880 let action = changes.get_merge_case(dest_path);
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
881 if src_minor.path.is_some()
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
882 && src_major.path.is_none()
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
883 && action == MergeCase::Salvaged
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
884 {
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
885 // If the file is "deleted" in the major side but was
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
886 // salvaged by the merge, we keep the minor side alive
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
887 (MergePick::Minor, true)
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
888 } else if src_major.path.is_some()
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
889 && src_minor.path.is_none()
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
890 && action == MergeCase::Salvaged
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
891 {
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
892 // If the file is "deleted" in the minor side but was
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
893 // salvaged by the merge, unconditionnaly preserve the
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
894 // major side.
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
895 (MergePick::Major, true)
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
896 } else if src_minor.is_overwritten_by(src_major) {
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
897 // The information from the minor version are strictly older than
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
898 // the major version
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
899 if action == MergeCase::Merged {
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
900 // If the file was actively merged, its means some non-copy
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
901 // activity happened on the other branch. It
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
902 // mean the older copy information are still relevant.
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
903 //
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
904 // The major side wins such conflict.
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
905 (MergePick::Major, true)
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
906 } else {
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
907 // No activity on the minor branch, pick the newer one.
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
908 (MergePick::Major, false)
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
909 }
46568
0d840b9d200d copies-rust: track "overwrites" directly within CopySource
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46567
diff changeset
910 } else if src_major.is_overwritten_by(src_minor) {
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
911 if action == MergeCase::Merged {
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
912 // If the file was actively merged, its means some non-copy
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
913 // activity happened on the other branch. It
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
914 // mean the older copy information are still relevant.
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
915 //
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
916 // The major side wins such conflict.
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
917 (MergePick::Major, true)
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
918 } else {
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
919 // No activity on the minor branch, pick the newer one.
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
920 (MergePick::Minor, false)
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
921 }
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
922 } else if src_minor.path.is_none() {
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
923 // the minor side has no relevant information, pick the alive one
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
924 (MergePick::Major, true)
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
925 } else if src_major.path.is_none() {
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
926 // the major side has no relevant information, pick the alive one
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
927 (MergePick::Minor, true)
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
928 } else {
46562
c692384bb559 copies: rearrange all value comparison conditional
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46157
diff changeset
929 // by default the major side wins
46563
c19c662097e1 copies: detect case when a merge decision overwrite previous data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46562
diff changeset
930 (MergePick::Major, true)
46125
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
931 }
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
932 }
61afe6215aef copies-rust: extract conflicting value comparison in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46059
diff changeset
933 }