copies-rust: tokenize all paths into integer
Copy information for each changesets tend to affect a small new number of path.
However, each of these path might be handled a large number of time. Handling
HgPathBuf (aka `Vec<u8>`) is expensive. Handling integer is cheap.
With this patch we:
- turn any input path into an integer "token" early,
- do all the internal logic using such "token",
- turn "token" back into path right before returning a result.
This gives use a quite significant performance boost in our slower cases.
Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev
---------------------------------------------------------------------------------------------------------------------------------------------------------------
pypy x000_revs_x000_added_x_copies
8a3b5bfd266e 2c68e87c3efe : 6780 revs, 0.092828 s, 0.081225 s, -0.011603 s, × 0.8750, 11 µs/rev
pypy x0000_revs_x_added_0_copies
d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.711975 s, 0.586011 s, -0.125964 s, × 0.8231, 13 µs/rev
pypy x0000_revs_xx000_added_x000_copies
08ea3258278e d9fa043f30c0 : 11316 revs, 0.124505 s, 0.114173 s, -0.010332 s, × 0.9170, 10 µs/rev
netbeans x000_revs_x000_added_x000_copies
ff453e9fee32 411350406ec2 : 5750 revs, 0.072072 s, 0.061004 s, -0.011068 s, × 0.8464, 10 µs/rev
netbeans x0000_revs_xx000_added_x000_copies
588c2d1ced70 1aad62e59ddd : 66949 revs, 0.682732 s, 0.535874 s, -0.146858 s, × 0.7849, 8 µs/rev
mozilla-central x00000_revs_x0000_added_x0000_copies
6832ae71433c 4c222a1d9a00 : 153721 revs, 1.935918 s, 1.781383 s, -0.154535 s, × 0.9202, 11 µs/rev
mozilla-central x00000_revs_x00000_added_x000_copies
76caed42cf7c 1daa622bbe42 : 204976 revs, 2.827320 s, 2.603867 s, -0.223453 s, × 0.9210, 12 µs/rev
mozilla-try x0000_revs_xx000_added_x000_copies
89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 3.243010 s, 1.529120 s, -1.713890 s, × 0.4715, 15 µs/rev
mozilla-try x00000_revs_x_added_0_copies
6a320851d377 1ebb79acd503 : 363753 revs, 5.693818 s, 4.842699 s, -0.851119 s, × 0.8505, 13 µs/rev
mozilla-try x00000_revs_x_added_x_copies
5173c4b6f97c 95d83ee7242d : 362229 revs, 5.677655 s, 4.761732 s, -0.915923 s, × 0.8387, 13 µs/rev
mozilla-try x00000_revs_x000_added_x_copies
9126823d0e9c ca82787bb23c : 359344 revs, 5.563370 s, 4.733912 s, -0.829458 s, × 0.8509, 13 µs/rev
mozilla-try x00000_revs_x0000_added_x0000_copies
8d3fafa80d4b eb884023b810 : 192665 revs, 2.864099 s, 2.593410 s, -0.270689 s, × 0.9055, 13 µs/rev
mozilla-try x00000_revs_x00000_added_x0000_copies
1b661134e2ca 1ae03d022d6d : 228985 revs, 113.297287 s, 41.041198 s, -72.256089 s, × 0.3622, 179 µs/rev
mozilla-try x00000_revs_x00000_added_x000_copies
9b2a99adc05e 8e29777b48e6 : 382065 revs, 59.498652 s, 27.915689 s, -31.582963 s, × 0.4692, 73 µs/rev
Full timing comparison between this revision and the previous one:
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.000042 s, +0.000000 s, × 1.0000, 42 µs/rev
mercurial x_revs_x_added_x_copies
2b1c78674230 0c1d10351869 : 6 revs, 0.000104 s, 0.000110 s, +0.000006 s, × 1.0577, 18 µs/rev
mercurial x000_revs_x000_added_x_copies
81f8ff2a9bf2 dd3267698d84 : 1032 revs, 0.004913 s, 0.004918 s, +0.000005 s, × 1.0010, 4 µs/rev
pypy x_revs_x_added_0_copies
aed021ee8ae8 099ed31b181b : 9 revs, 0.000191 s, 0.000195 s, +0.000004 s, × 1.0209, 21 µs/rev
pypy x_revs_x000_added_0_copies
4aa4e1f8e19a 359343b9ac0e : 1 revs, 0.000050 s, 0.000049 s, -0.000001 s, × 0.9800, 49 µs/rev
pypy x_revs_x_added_x_copies
ac52eb7bbbb0 72e022663155 : 7 revs, 0.000112 s, 0.000112 s, +0.000000 s, × 1.0000, 16 µs/rev
pypy x_revs_x00_added_x_copies
c3b14617fbd7 ace7255d9a26 : 1 revs, 0.000288 s, 0.000324 s, +0.000036 s, × 1.1250, 324 µs/rev
pypy x_revs_x000_added_x000_copies
df6f7a526b60 a83dc6a2d56f : 6 revs, 0.010411 s, 0.010611 s, +0.000200 s, × 1.0192, 1768 µs/rev
pypy x000_revs_xx00_added_0_copies
89a76aede314 2f22446ff07e : 4785 revs, 0.052852 s, 0.050835 s, -0.002017 s, × 0.9618, 10 µs/rev
pypy x000_revs_x000_added_x_copies
8a3b5bfd266e 2c68e87c3efe : 6780 revs, 0.092828 s, 0.081225 s, -0.011603 s, × 0.8750, 11 µs/rev
pypy x000_revs_x000_added_x000_copies
89a76aede314 7b3dda341c84 : 5441 revs, 0.063269 s, 0.061291 s, -0.001978 s, × 0.9687, 11 µs/rev
pypy x0000_revs_x_added_0_copies
d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.711975 s, 0.586011 s, -0.125964 s, × 0.8231, 13 µs/rev
pypy x0000_revs_xx000_added_0_copies
bf2c629d0071 4ffed77c095c : 2 revs, 0.012771 s, 0.012824 s, +0.000053 s, × 1.0042, 6412 µs/rev
pypy x0000_revs_xx000_added_x000_copies
08ea3258278e d9fa043f30c0 : 11316 revs, 0.124505 s, 0.114173 s, -0.010332 s, × 0.9170, 10 µs/rev
netbeans x_revs_x_added_0_copies
fb0955ffcbcd a01e9239f9e7 : 2 revs, 0.000082 s, 0.000085 s, +0.000003 s, × 1.0366, 42 µs/rev
netbeans x_revs_x000_added_0_copies
6f360122949f 20eb231cc7d0 : 2 revs, 0.000111 s, 0.000108 s, -0.000003 s, × 0.9730, 54 µs/rev
netbeans x_revs_x_added_x_copies
1ada3faf6fb6 5a39d12eecf4 : 3 revs, 0.000171 s, 0.000175 s, +0.000004 s, × 1.0234, 58 µs/rev
netbeans x_revs_x00_added_x_copies
35be93ba1e2c 9eec5e90c05f : 9 revs, 0.000708 s, 0.000719 s, +0.000011 s, × 1.0155, 79 µs/rev
netbeans x000_revs_xx00_added_0_copies
eac3045b4fdd 51d4ae7f1290 : 1421 revs, 0.010608 s, 0.010175 s, -0.000433 s, × 0.9592, 7 µs/rev
netbeans x000_revs_x000_added_x_copies
e2063d266acd 6081d72689dc : 1533 revs, 0.015635 s, 0.015569 s, -0.000066 s, × 0.9958, 10 µs/rev
netbeans x000_revs_x000_added_x000_copies
ff453e9fee32 411350406ec2 : 5750 revs, 0.072072 s, 0.061004 s, -0.011068 s, × 0.8464, 10 µs/rev
netbeans x0000_revs_xx000_added_x000_copies
588c2d1ced70 1aad62e59ddd : 66949 revs, 0.682732 s, 0.535874 s, -0.146858 s, × 0.7849, 8 µs/rev
mozilla-central x_revs_x_added_0_copies
3697f962bb7b 7015fcdd43a2 : 2 revs, 0.000090 s, 0.000090 s, +0.000000 s, × 1.0000, 45 µs/rev
mozilla-central x_revs_x000_added_0_copies
dd390860c6c9 40d0c5bed75d : 8 revs, 0.000210 s, 0.000281 s, +0.000071 s, × 1.3381, 35 µs/rev
mozilla-central x_revs_x_added_x_copies
8d198483ae3b 14207ffc2b2f : 9 revs, 0.000182 s, 0.000187 s, +0.000005 s, × 1.0275, 20 µs/rev
mozilla-central x_revs_x00_added_x_copies
98cbc58cc6bc 446a150332c3 : 7 revs, 0.000594 s, 0.000660 s, +0.000066 s, × 1.1111, 94 µs/rev
mozilla-central x_revs_x000_added_x000_copies
3c684b4b8f68 0a5e72d1b479 : 3 revs, 0.003102 s, 0.003385 s, +0.000283 s, × 1.0912, 1128 µs/rev
mozilla-central x_revs_x0000_added_x0000_copies
effb563bb7e5 c07a39dc4e80 : 6 revs, 0.060234 s, 0.069812 s, +0.009578 s, × 1.1590, 11635 µs/rev
mozilla-central x000_revs_xx00_added_0_copies
6100d773079a 04a55431795e : 1593 revs, 0.006300 s, 0.006503 s, +0.000203 s, × 1.0322, 4 µs/rev
mozilla-central x000_revs_x000_added_x_copies
9f17a6fc04f9 2d37b966abed : 41 revs, 0.004817 s, 0.004988 s, +0.000171 s, × 1.0355, 121 µs/rev
mozilla-central x000_revs_x000_added_x000_copies
7c97034feb78 4407bd0c6330 : 7839 revs, 0.065451 s, 0.063963 s, -0.001488 s, × 0.9773, 8 µs/rev
mozilla-central x0000_revs_xx000_added_0_copies
9eec5917337d 67118cc6dcad : 615 revs, 0.026282 s, 0.026225 s, -0.000057 s, × 0.9978, 42 µs/rev
mozilla-central x0000_revs_xx000_added_x000_copies
f78c615a656c 96a38b690156 : 30263 revs, 0.206873 s, 0.201377 s, -0.005496 s, × 0.9734, 6 µs/rev
mozilla-central x00000_revs_x0000_added_x0000_copies
6832ae71433c 4c222a1d9a00 : 153721 revs, 1.935918 s, 1.781383 s, -0.154535 s, × 0.9202, 11 µs/rev
mozilla-central x00000_revs_x00000_added_x000_copies
76caed42cf7c 1daa622bbe42 : 204976 revs, 2.827320 s, 2.603867 s, -0.223453 s, × 0.9210, 12 µs/rev
mozilla-try x_revs_x_added_0_copies
aaf6dde0deb8 9790f499805a : 2 revs, 0.000842 s, 0.000845 s, +0.000003 s, × 1.0036, 422 µs/rev
mozilla-try x_revs_x000_added_0_copies
d8d0222927b4 5bb8ce8c7450 : 2 revs, 0.000870 s, 0.000862 s, -0.000008 s, × 0.9908, 431 µs/rev
mozilla-try x_revs_x_added_x_copies
092fcca11bdb 936255a0384a : 4 revs, 0.000165 s, 0.000161 s, -0.000004 s, × 0.9758, 40 µs/rev
mozilla-try x_revs_x00_added_x_copies
b53d2fadbdb5 017afae788ec : 2 revs, 0.001145 s, 0.001163 s, +0.000018 s, × 1.0157, 581 µs/rev
mozilla-try x_revs_x000_added_x000_copies
20408ad61ce5 6f0ee96e21ad : 1 revs, 0.026500 s, 0.032414 s, +0.005914 s, × 1.2232, 32414 µs/rev
mozilla-try x_revs_x0000_added_x0000_copies
effb563bb7e5 c07a39dc4e80 : 6 revs, 0.059407 s, 0.070149 s, +0.010742 s, × 1.1808, 11691 µs/rev
mozilla-try x000_revs_xx00_added_0_copies
6100d773079a 04a55431795e : 1593 revs, 0.006325 s, 0.006526 s, +0.000201 s, × 1.0318, 4 µs/rev
mozilla-try x000_revs_x000_added_x_copies
9f17a6fc04f9 2d37b966abed : 41 revs, 0.005171 s, 0.005187 s, +0.000016 s, × 1.0031, 126 µs/rev
mozilla-try x000_revs_x000_added_x000_copies
1346fd0130e4 4c65cbdabc1f : 6657 revs, 0.066837 s, 0.065047 s, -0.001790 s, × 0.9732, 9 µs/rev
mozilla-try x0000_revs_x_added_0_copies
63519bfd42ee a36a2a865d92 : 40314 revs, 0.314252 s, 0.301129 s, -0.013123 s, × 0.9582, 7 µs/rev
mozilla-try x0000_revs_x_added_x_copies
9fe69ff0762d bcabf2a78927 : 38690 revs, 0.304160 s, 0.280683 s, -0.023477 s, × 0.9228, 7 µs/rev
mozilla-try x0000_revs_xx000_added_x_copies
156f6e2674f2 4d0f2c178e66 : 8598 revs, 0.089223 s, 0.084897 s, -0.004326 s, × 0.9515, 9 µs/rev
mozilla-try x0000_revs_xx000_added_0_copies
9eec5917337d 67118cc6dcad : 615 revs, 0.026711 s, 0.026620 s, -0.000091 s, × 0.9966, 43 µs/rev
mozilla-try x0000_revs_xx000_added_x000_copies
89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 3.243010 s, 1.529120 s, -1.713890 s, × 0.4715, 15 µs/rev
mozilla-try x0000_revs_x0000_added_x0000_copies
e928c65095ed e951f4ad123a : 52031 revs, 0.756500 s, 0.738709 s, -0.017791 s, × 0.9765, 14 µs/rev
mozilla-try x00000_revs_x_added_0_copies
6a320851d377 1ebb79acd503 : 363753 revs, 5.693818 s, 4.842699 s, -0.851119 s, × 0.8505, 13 µs/rev
mozilla-try x00000_revs_x00000_added_0_copies
dc8a3ca7010e d16fde900c9c : 34414 revs, 0.590904 s, 0.596946 s, +0.006042 s, × 1.0102, 17 µs/rev
mozilla-try x00000_revs_x_added_x_copies
5173c4b6f97c 95d83ee7242d : 362229 revs, 5.677655 s, 4.761732 s, -0.915923 s, × 0.8387, 13 µs/rev
mozilla-try x00000_revs_x000_added_x_copies
9126823d0e9c ca82787bb23c : 359344 revs, 5.563370 s, 4.733912 s, -0.829458 s, × 0.8509, 13 µs/rev
mozilla-try x00000_revs_x0000_added_x0000_copies
8d3fafa80d4b eb884023b810 : 192665 revs, 2.864099 s, 2.593410 s, -0.270689 s, × 0.9055, 13 µs/rev
mozilla-try x00000_revs_x00000_added_x0000_copies
1b661134e2ca 1ae03d022d6d : 228985 revs, 113.297287 s, 41.041198 s, -72.256089 s, × 0.3622, 179 µs/rev
mozilla-try x00000_revs_x00000_added_x000_copies
9b2a99adc05e 8e29777b48e6 : 382065 revs, 59.498652 s, 27.915689 s, -31.582963 s, × 0.4692, 73 µs/rev
Full timing comparison between this revision and the filelog copy tracing.
Repo Case Source-Rev Dest-Rev # of revisions filelog sidedata Difference Factor time per rev
---------------------------------------------------------------------------------------------------------------------------------------------------------------
mercurial x_revs_x_added_0_copies
ad6b123de1c7 39cfcef4f463 : 1 revs, 0.000903 s, 0.000042 s, -0.000861 s, × 0.0465, 41 µs/rev
mercurial x_revs_x_added_x_copies
2b1c78674230 0c1d10351869 : 6 revs, 0.001861 s, 0.000110 s, -0.001751 s, × 0.0591, 18 µs/rev
mercurial x000_revs_x000_added_x_copies
81f8ff2a9bf2 dd3267698d84 : 1032 revs, 0.018577 s, 0.004918 s, -0.013659 s, × 0.2647, 4 µs/rev
pypy x_revs_x_added_0_copies
aed021ee8ae8 099ed31b181b : 9 revs, 0.001519 s, 0.000195 s, -0.001324 s, × 0.1283, 21 µs/rev
pypy x_revs_x000_added_0_copies
4aa4e1f8e19a 359343b9ac0e : 1 revs, 0.213855 s, 0.000049 s, -0.350d73 s, × 0.0002, 48 µs/rev
pypy x_revs_x_added_x_copies
ac52eb7bbbb0 72e022663155 : 7 revs, 0.017022 s, 0.000112 s, -0.016910 s, × 0.0065, 15 µs/rev
pypy x_revs_x00_added_x_copies
c3b14617fbd7 ace7255d9a26 : 1 revs, 0.019398 s, 0.000324 s, -0.019074 s, × 0.0167, 323 µs/rev
pypy x_revs_x000_added_x000_copies
df6f7a526b60 a83dc6a2d56f : 6 revs, 0.769467 s, 0.010611 s, -0.758856 s, × 0.0137, 1768 µs/rev
pypy x000_revs_xx00_added_0_copies
89a76aede314 2f22446ff07e : 4785 revs, 1.221952 s, 0.050835 s, -1.171117 s, × 0.0416, 10 µs/rev
pypy x000_revs_x000_added_x_copies
8a3b5bfd266e 2c68e87c3efe : 6780 revs, 1.304007 s, 0.081225 s, -1.222782 s, × 0.0622, 11 µs/rev
pypy x000_revs_x000_added_x000_copies
89a76aede314 7b3dda341c84 : 5441 revs, 1.686610 s, 0.061291 s, -1.625319 s, × 0.0363, 11 µs/rev
pypy x0000_revs_x_added_0_copies
d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.001107 s, 0.586011 s, +0.584904 s, × 529.36, 13 µs/rev
pypy x0000_revs_xx000_added_0_copies
bf2c629d0071 4ffed77c095c : 2 revs, 1.100760 s, 0.012824 s, -1.087936 s, × 0.0116, 6408 µs/rev
pypy x0000_revs_xx000_added_x000_copies
08ea3258278e d9fa043f30c0 : 11316 revs, 1.350547 s, 0.114173 s, -1.236374 s, × 0.0845, 10 µs/rev
netbeans x_revs_x_added_0_copies
fb0955ffcbcd a01e9239f9e7 : 2 revs, 0.027864 s, 0.000085 s, -0.027779 s, × 0.0030, 42 µs/rev
netbeans x_revs_x000_added_0_copies
6f360122949f 20eb231cc7d0 : 2 revs, 0.132479 s, 0.000108 s, -0.132371 s, × 0.0008, 53 µs/rev
netbeans x_revs_x_added_x_copies
1ada3faf6fb6 5a39d12eecf4 : 3 revs, 0.025405 s, 0.000175 s, -0.025230 s, × 0.0068, 58 µs/rev
netbeans x_revs_x00_added_x_copies
35be93ba1e2c 9eec5e90c05f : 9 revs, 0.053244 s, 0.000719 s, -0.052525 s, × 0.0135, 79 µs/rev
netbeans x000_revs_xx00_added_0_copies
eac3045b4fdd 51d4ae7f1290 : 1421 revs, 0.038017 s, 0.010175 s, -0.027842 s, × 0.2676, 7 µs/rev
netbeans x000_revs_x000_added_x_copies
e2063d266acd 6081d72689dc : 1533 revs, 0.198308 s, 0.015569 s, -0.182739 s, × 0.0785, 10 µs/rev
netbeans x000_revs_x000_added_x000_copies
ff453e9fee32 411350406ec2 : 5750 revs, 0.949749 s, 0.061004 s, -0.888745 s, × 0.0642, 10 µs/rev
netbeans x0000_revs_xx000_added_x000_copies
588c2d1ced70 1aad62e59ddd : 66949 revs, 3.932262 s, 0.535874 s, -3.396388 s, × 0.1362, 8 µs/rev
mozilla-central x_revs_x_added_0_copies
3697f962bb7b 7015fcdd43a2 : 2 revs, 0.024490 s, 0.000090 s, -0.024400 s, × 0.0036, 44 µs/rev
mozilla-central x_revs_x000_added_0_copies
dd390860c6c9 40d0c5bed75d : 8 revs, 0.143885 s, 0.000281 s, -0.143604 s, × 0.0019, 35 µs/rev
mozilla-central x_revs_x_added_x_copies
8d198483ae3b 14207ffc2b2f : 9 revs, 0.025471 s, 0.000187 s, -0.025284 s, × 0.0073, 20 µs/rev
mozilla-central x_revs_x00_added_x_copies
98cbc58cc6bc 446a150332c3 : 7 revs, 0.086013 s, 0.000660 s, -0.085353 s, × 0.0076, 94 µs/rev
mozilla-central x_revs_x000_added_x000_copies
3c684b4b8f68 0a5e72d1b479 : 3 revs, 0.200726 s, 0.003385 s, -0.197341 s, × 0.0168, 1127 µs/rev
mozilla-central x_revs_x0000_added_x0000_copies
effb563bb7e5 c07a39dc4e80 : 6 revs, 2.224171 s, 0.069812 s, -2.154359 s, × 0.0313, 11633 µs/rev
mozilla-central x000_revs_xx00_added_0_copies
6100d773079a 04a55431795e : 1593 revs, 0.090780 s, 0.006503 s, -0.084277 s, × 0.0716, 4 µs/rev
mozilla-central x000_revs_x000_added_x_copies
9f17a6fc04f9 2d37b966abed : 41 revs, 0.764805 s, 0.004988 s, -0.759817 s, × 0.0065, 121 µs/rev
mozilla-central x000_revs_x000_added_x000_copies
7c97034feb78 4407bd0c6330 : 7839 revs, 1.161405 s, 0.063963 s, -1.097442 s, × 0.0550, 8 µs/rev
mozilla-central x0000_revs_xx000_added_0_copies
9eec5917337d 67118cc6dcad : 615 revs, 6.816186 s, 0.026225 s, -6.789961 s, × 0.0038, 42 µs/rev
mozilla-central x0000_revs_xx000_added_x000_copies
f78c615a656c 96a38b690156 : 30263 revs, 3.374819 s, 0.201377 s, -3.173442 s, × 0.0596, 6 µs/rev
mozilla-central x00000_revs_x0000_added_x0000_copies
6832ae71433c 4c222a1d9a00 : 153721 revs, 16.285469 s, 1.781383 s, -14.504086 s, × 0.1093, 11 µs/rev
mozilla-central x00000_revs_x00000_added_x000_copies
76caed42cf7c 1daa622bbe42 : 204976 revs, 21.207733 s, 2.603867 s, -18.603866 s, × 0.1227, 12 µs/rev
mozilla-try x_revs_x_added_0_copies
aaf6dde0deb8 9790f499805a : 2 revs, 0.080843 s, 0.000845 s, -0.079998 s, × 0.0104, 422 µs/rev
mozilla-try x_revs_x000_added_0_copies
d8d0222927b4 5bb8ce8c7450 : 2 revs, 0.511068 s, 0.000862 s, -0.510206 s, × 0.0016, 430 µs/rev
mozilla-try x_revs_x_added_x_copies
092fcca11bdb 936255a0384a : 4 revs, 0.021573 s, 0.000161 s, -0.021412 s, × 0.0074, 40 µs/rev
mozilla-try x_revs_x00_added_x_copies
b53d2fadbdb5 017afae788ec : 2 revs, 0.227726 s, 0.001163 s, -0.226563 s, × 0.0051, 581 µs/rev
mozilla-try x_revs_x000_added_x000_copies
20408ad61ce5 6f0ee96e21ad : 1 revs, 1.120448 s, 0.032414 s, -1.088034 s, × 0.0289, 32381 µs/rev
mozilla-try x_revs_x0000_added_x0000_copies
effb563bb7e5 c07a39dc4e80 : 6 revs, 2.241713 s, 0.070149 s, -2.171564 s, × 0.0312, 11689 µs/rev
mozilla-try x000_revs_xx00_added_0_copies
6100d773079a 04a55431795e : 1593 revs, 0.090633 s, 0.006526 s, -0.084107 s, × 0.0720, 4 µs/rev
mozilla-try x000_revs_x000_added_x_copies
9f17a6fc04f9 2d37b966abed : 41 revs, 0.770403 s, 0.005187 s, -0.765216 s, × 0.0067, 126 µs/rev
mozilla-try x000_revs_x000_added_x000_copies
1346fd0130e4 4c65cbdabc1f : 6657 revs, 1.184557 s, 0.065047 s, -1.119510 s, × 0.0549, 9 µs/rev
mozilla-try x0000_revs_x_added_0_copies
63519bfd42ee a36a2a865d92 : 40314 revs, 0.085790 s, 0.301129 s, +0.215339 s, × 3.5100, 7 µs/rev
mozilla-try x0000_revs_x_added_x_copies
9fe69ff0762d bcabf2a78927 : 38690 revs, 0.080616 s, 0.280683 s, +0.200067 s, × 3.4817, 7 µs/rev
mozilla-try x0000_revs_xx000_added_x_copies
156f6e2674f2 4d0f2c178e66 : 8598 revs, 7.712554 s, 0.084897 s, -7.627657 s, × 0.0110, 9 µs/rev
mozilla-try x0000_revs_xx000_added_0_copies
9eec5917337d 67118cc6dcad : 615 revs, 6.937294 s, 0.026620 s, -6.910674 s, × 0.0038, 43 µs/rev
mozilla-try x0000_revs_xx000_added_x000_copies
89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 7.712313 s, 1.529120 s, -6.183193 s, × 0.1982, 15 µs/rev
mozilla-try x0000_revs_x0000_added_x0000_copies
e928c65095ed e951f4ad123a : 52031 revs, 9.966910 s, 0.738709 s, -9.228201 s, × 0.0741, 14 µs/rev
mozilla-try x00000_revs_x_added_0_copies
6a320851d377 1ebb79acd503 : 363753 revs, 0.090397 s, 4.842699 s, +4.752302 s, × 53.571, 13 µs/rev
mozilla-try x00000_revs_x00000_added_0_copies
dc8a3ca7010e d16fde900c9c : 34414 revs, 27.817167 s, 0.596946 s, -27.220221 s, × 0.0214, 17 µs/rev
mozilla-try x00000_revs_x_added_x_copies
5173c4b6f97c 95d83ee7242d : 362229 revs, 0.091305 s, 4.761732 s, +4.670427 s, × 52.151, 13 µs/rev
mozilla-try x00000_revs_x000_added_x_copies
9126823d0e9c ca82787bb23c : 359344 revs, 0.231183 s, 4.733912 s, +4.502729 s, × 20.476, 13 µs/rev
mozilla-try x00000_revs_x0000_added_x0000_copies
8d3fafa80d4b eb884023b810 : 192665 revs, 19.830617 s, 2.593410 s, -17.237207 s, × 0.1307, 13 µs/rev
mozilla-try x00000_revs_x00000_added_x0000_copies
1b661134e2ca 1ae03d022d6d : 228985 revs, 21.743873 s, 41.041198 s, +19.297325 s, × 1.8874, 179 µs/rev
mozilla-try x00000_revs_x00000_added_x000_copies
9b2a99adc05e 8e29777b48e6 : 382065 revs, 25.935037 s, 27.915689 s, +1.980652 s, × 1.0763, 73 µs/rev
Differential Revision: https://phab.mercurial-scm.org/D9493
# templatekw.py - common changeset template keywords
#
# Copyright 2005-2009 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
from .i18n import _
from .node import (
hex,
nullid,
wdirid,
wdirrev,
)
from . import (
diffutil,
encoding,
error,
hbisect,
i18n,
obsutil,
patch,
pycompat,
registrar,
scmutil,
templateutil,
util,
)
from .utils import stringutil
_hybrid = templateutil.hybrid
hybriddict = templateutil.hybriddict
hybridlist = templateutil.hybridlist
compatdict = templateutil.compatdict
compatlist = templateutil.compatlist
_showcompatlist = templateutil._showcompatlist
def getlatesttags(context, mapping, pattern=None):
'''return date, distance and name for the latest tag of rev'''
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
cache = context.resource(mapping, b'cache')
cachename = b'latesttags'
if pattern is not None:
cachename += b'-' + pattern
match = stringutil.stringmatcher(pattern)[2]
else:
match = util.always
if cachename not in cache:
# Cache mapping from rev to a tuple with tag date, tag
# distance and tag name
cache[cachename] = {-1: (0, 0, [b'null'])}
latesttags = cache[cachename]
rev = ctx.rev()
todo = [rev]
while todo:
rev = todo.pop()
if rev in latesttags:
continue
ctx = repo[rev]
tags = [
t
for t in ctx.tags()
if (repo.tagtype(t) and repo.tagtype(t) != b'local' and match(t))
]
if tags:
latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
continue
try:
ptags = [latesttags[p.rev()] for p in ctx.parents()]
if len(ptags) > 1:
if ptags[0][2] == ptags[1][2]:
# The tuples are laid out so the right one can be found by
# comparison in this case.
pdate, pdist, ptag = max(ptags)
else:
def key(x):
tag = x[2][0]
if ctx.rev() is None:
# only() doesn't support wdir
prevs = [c.rev() for c in ctx.parents()]
changes = repo.revs(b'only(%ld, %s)', prevs, tag)
changessincetag = len(changes) + 1
else:
changes = repo.revs(b'only(%d, %s)', ctx.rev(), tag)
changessincetag = len(changes)
# Smallest number of changes since tag wins. Date is
# used as tiebreaker.
return [-changessincetag, x[0]]
pdate, pdist, ptag = max(ptags, key=key)
else:
pdate, pdist, ptag = ptags[0]
except KeyError:
# Cache miss - recurse
todo.append(rev)
todo.extend(p.rev() for p in ctx.parents())
continue
latesttags[rev] = pdate, pdist + 1, ptag
return latesttags[rev]
def getlogcolumns():
"""Return a dict of log column labels"""
_ = pycompat.identity # temporarily disable gettext
# i18n: column positioning for "hg log"
columns = _(
b'bookmark: %s\n'
b'branch: %s\n'
b'changeset: %s\n'
b'copies: %s\n'
b'date: %s\n'
b'extra: %s=%s\n'
b'files+: %s\n'
b'files-: %s\n'
b'files: %s\n'
b'instability: %s\n'
b'manifest: %s\n'
b'obsolete: %s\n'
b'parent: %s\n'
b'phase: %s\n'
b'summary: %s\n'
b'tag: %s\n'
b'user: %s\n'
)
return dict(
zip(
[s.split(b':', 1)[0] for s in columns.splitlines()],
i18n._(columns).splitlines(True),
)
)
# basic internal templates
_changeidtmpl = b'{rev}:{node|formatnode}'
# default templates internally used for rendering of lists
defaulttempl = {
b'parent': _changeidtmpl + b' ',
b'manifest': _changeidtmpl,
b'file_copy': b'{name} ({source})',
b'envvar': b'{key}={value}',
b'extra': b'{key}={value|stringescape}',
}
# filecopy is preserved for compatibility reasons
defaulttempl[b'filecopy'] = defaulttempl[b'file_copy']
# keywords are callables (see registrar.templatekeyword for details)
keywords = {}
templatekeyword = registrar.templatekeyword(keywords)
@templatekeyword(b'author', requires={b'ctx'})
def showauthor(context, mapping):
"""Alias for ``{user}``"""
return showuser(context, mapping)
@templatekeyword(b'bisect', requires={b'repo', b'ctx'})
def showbisect(context, mapping):
"""String. The changeset bisection status."""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
return hbisect.label(repo, ctx.node())
@templatekeyword(b'branch', requires={b'ctx'})
def showbranch(context, mapping):
"""String. The name of the branch on which the changeset was
committed.
"""
ctx = context.resource(mapping, b'ctx')
return ctx.branch()
@templatekeyword(b'branches', requires={b'ctx'})
def showbranches(context, mapping):
"""List of strings. The name of the branch on which the
changeset was committed. Will be empty if the branch name was
default. (DEPRECATED)
"""
ctx = context.resource(mapping, b'ctx')
branch = ctx.branch()
if branch != b'default':
return compatlist(
context, mapping, b'branch', [branch], plural=b'branches'
)
return compatlist(context, mapping, b'branch', [], plural=b'branches')
@templatekeyword(b'bookmarks', requires={b'repo', b'ctx'})
def showbookmarks(context, mapping):
"""List of strings. Any bookmarks associated with the
changeset. Also sets 'active', the name of the active bookmark.
"""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
bookmarks = ctx.bookmarks()
active = repo._activebookmark
makemap = lambda v: {b'bookmark': v, b'active': active, b'current': active}
f = _showcompatlist(context, mapping, b'bookmark', bookmarks)
return _hybrid(f, bookmarks, makemap, pycompat.identity)
@templatekeyword(b'children', requires={b'ctx'})
def showchildren(context, mapping):
"""List of strings. The children of the changeset."""
ctx = context.resource(mapping, b'ctx')
childrevs = [b'%d:%s' % (cctx.rev(), cctx) for cctx in ctx.children()]
return compatlist(
context, mapping, b'children', childrevs, element=b'child'
)
# Deprecated, but kept alive for help generation a purpose.
@templatekeyword(b'currentbookmark', requires={b'repo', b'ctx'})
def showcurrentbookmark(context, mapping):
"""String. The active bookmark, if it is associated with the changeset.
(DEPRECATED)"""
return showactivebookmark(context, mapping)
@templatekeyword(b'activebookmark', requires={b'repo', b'ctx'})
def showactivebookmark(context, mapping):
"""String. The active bookmark, if it is associated with the changeset."""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
active = repo._activebookmark
if active and active in ctx.bookmarks():
return active
return b''
@templatekeyword(b'date', requires={b'ctx'})
def showdate(context, mapping):
"""Date information. The date when the changeset was committed."""
ctx = context.resource(mapping, b'ctx')
# the default string format is '<float(unixtime)><tzoffset>' because
# python-hglib splits date at decimal separator.
return templateutil.date(ctx.date(), showfmt=b'%d.0%d')
@templatekeyword(b'desc', requires={b'ctx'})
def showdescription(context, mapping):
"""String. The text of the changeset description."""
ctx = context.resource(mapping, b'ctx')
s = ctx.description()
if isinstance(s, encoding.localstr):
# try hard to preserve utf-8 bytes
return encoding.tolocal(encoding.fromlocal(s).strip())
elif isinstance(s, encoding.safelocalstr):
return encoding.safelocalstr(s.strip())
else:
return s.strip()
@templatekeyword(b'diffstat', requires={b'ui', b'ctx'})
def showdiffstat(context, mapping):
"""String. Statistics of changes with the following format:
"modified files: +added/-removed lines"
"""
ui = context.resource(mapping, b'ui')
ctx = context.resource(mapping, b'ctx')
diffopts = diffutil.diffallopts(ui, {b'noprefix': False})
diff = ctx.diff(opts=diffopts)
stats = patch.diffstatdata(util.iterlines(diff))
maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
return b'%d: +%d/-%d' % (len(stats), adds, removes)
@templatekeyword(b'envvars', requires={b'ui'})
def showenvvars(context, mapping):
"""A dictionary of environment variables. (EXPERIMENTAL)"""
ui = context.resource(mapping, b'ui')
env = ui.exportableenviron()
env = util.sortdict((k, env[k]) for k in sorted(env))
return compatdict(context, mapping, b'envvar', env, plural=b'envvars')
@templatekeyword(b'extras', requires={b'ctx'})
def showextras(context, mapping):
"""List of dicts with key, value entries of the 'extras'
field of this changeset."""
ctx = context.resource(mapping, b'ctx')
extras = ctx.extra()
extras = util.sortdict((k, extras[k]) for k in sorted(extras))
makemap = lambda k: {b'key': k, b'value': extras[k]}
c = [makemap(k) for k in extras]
f = _showcompatlist(context, mapping, b'extra', c, plural=b'extras')
return _hybrid(
f,
extras,
makemap,
lambda k: b'%s=%s' % (k, stringutil.escapestr(extras[k])),
)
def _getfilestatus(context, mapping, listall=False):
ctx = context.resource(mapping, b'ctx')
revcache = context.resource(mapping, b'revcache')
if b'filestatus' not in revcache or revcache[b'filestatusall'] < listall:
stat = ctx.p1().status(
ctx, listignored=listall, listclean=listall, listunknown=listall
)
revcache[b'filestatus'] = stat
revcache[b'filestatusall'] = listall
return revcache[b'filestatus']
def _getfilestatusmap(context, mapping, listall=False):
revcache = context.resource(mapping, b'revcache')
if b'filestatusmap' not in revcache or revcache[b'filestatusall'] < listall:
stat = _getfilestatus(context, mapping, listall=listall)
revcache[b'filestatusmap'] = statmap = {}
for char, files in zip(pycompat.iterbytestr(b'MAR!?IC'), stat):
statmap.update((f, char) for f in files)
return revcache[b'filestatusmap'] # {path: statchar}
@templatekeyword(
b'file_copies', requires={b'repo', b'ctx', b'cache', b'revcache'}
)
def showfilecopies(context, mapping):
"""List of strings. Files copied in this changeset with
their sources.
"""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
cache = context.resource(mapping, b'cache')
copies = context.resource(mapping, b'revcache').get(b'copies')
if copies is None:
if b'getcopies' not in cache:
cache[b'getcopies'] = scmutil.getcopiesfn(repo)
getcopies = cache[b'getcopies']
copies = getcopies(ctx)
return templateutil.compatfilecopiesdict(
context, mapping, b'file_copy', copies
)
# showfilecopiesswitch() displays file copies only if copy records are
# provided before calling the templater, usually with a --copies
# command line switch.
@templatekeyword(b'file_copies_switch', requires={b'revcache'})
def showfilecopiesswitch(context, mapping):
"""List of strings. Like "file_copies" but displayed
only if the --copied switch is set.
"""
copies = context.resource(mapping, b'revcache').get(b'copies') or []
return templateutil.compatfilecopiesdict(
context, mapping, b'file_copy', copies
)
@templatekeyword(b'file_adds', requires={b'ctx', b'revcache'})
def showfileadds(context, mapping):
"""List of strings. Files added by this changeset."""
ctx = context.resource(mapping, b'ctx')
return templateutil.compatfileslist(
context, mapping, b'file_add', ctx.filesadded()
)
@templatekeyword(b'file_dels', requires={b'ctx', b'revcache'})
def showfiledels(context, mapping):
"""List of strings. Files removed by this changeset."""
ctx = context.resource(mapping, b'ctx')
return templateutil.compatfileslist(
context, mapping, b'file_del', ctx.filesremoved()
)
@templatekeyword(b'file_mods', requires={b'ctx', b'revcache'})
def showfilemods(context, mapping):
"""List of strings. Files modified by this changeset."""
ctx = context.resource(mapping, b'ctx')
return templateutil.compatfileslist(
context, mapping, b'file_mod', ctx.filesmodified()
)
@templatekeyword(b'files', requires={b'ctx'})
def showfiles(context, mapping):
"""List of strings. All files modified, added, or removed by this
changeset.
"""
ctx = context.resource(mapping, b'ctx')
return templateutil.compatfileslist(context, mapping, b'file', ctx.files())
@templatekeyword(b'graphnode', requires={b'repo', b'ctx', b'cache'})
def showgraphnode(context, mapping):
"""String. The character representing the changeset node in an ASCII
revision graph."""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
cache = context.resource(mapping, b'cache')
return getgraphnode(repo, ctx, cache)
def getgraphnode(repo, ctx, cache):
return getgraphnodecurrent(repo, ctx, cache) or getgraphnodesymbol(ctx)
def getgraphnodecurrent(repo, ctx, cache):
wpnodes = repo.dirstate.parents()
if wpnodes[1] == nullid:
wpnodes = wpnodes[:1]
if ctx.node() in wpnodes:
return b'@'
else:
merge_nodes = cache.get(b'merge_nodes')
if merge_nodes is None:
from . import mergestate as mergestatemod
mergestate = mergestatemod.mergestate.read(repo)
if mergestate.unresolvedcount():
merge_nodes = (mergestate.local, mergestate.other)
else:
merge_nodes = ()
cache[b'merge_nodes'] = merge_nodes
if ctx.node() in merge_nodes:
return b'%'
return b''
def getgraphnodesymbol(ctx):
if ctx.obsolete():
return b'x'
elif ctx.isunstable():
return b'*'
elif ctx.closesbranch():
return b'_'
else:
return b'o'
@templatekeyword(b'graphwidth', requires=())
def showgraphwidth(context, mapping):
"""Integer. The width of the graph drawn by 'log --graph' or zero."""
# just hosts documentation; should be overridden by template mapping
return 0
@templatekeyword(b'index', requires=())
def showindex(context, mapping):
"""Integer. The current iteration of the loop. (0 indexed)"""
# just hosts documentation; should be overridden by template mapping
raise error.Abort(_(b"can't use index in this context"))
@templatekeyword(b'latesttag', requires={b'repo', b'ctx', b'cache'})
def showlatesttag(context, mapping):
"""List of strings. The global tags on the most recent globally
tagged ancestor of this changeset. If no such tags exist, the list
consists of the single string "null".
"""
return showlatesttags(context, mapping, None)
def showlatesttags(context, mapping, pattern):
"""helper method for the latesttag keyword and function"""
latesttags = getlatesttags(context, mapping, pattern)
# latesttag[0] is an implementation detail for sorting csets on different
# branches in a stable manner- it is the date the tagged cset was created,
# not the date the tag was created. Therefore it isn't made visible here.
makemap = lambda v: {
b'changes': _showchangessincetag,
b'distance': latesttags[1],
b'latesttag': v, # BC with {latesttag % '{latesttag}'}
b'tag': v,
}
tags = latesttags[2]
f = _showcompatlist(context, mapping, b'latesttag', tags, separator=b':')
return _hybrid(f, tags, makemap, pycompat.identity)
@templatekeyword(b'latesttagdistance', requires={b'repo', b'ctx', b'cache'})
def showlatesttagdistance(context, mapping):
"""Integer. Longest path to the latest tag."""
return getlatesttags(context, mapping)[1]
@templatekeyword(b'changessincelatesttag', requires={b'repo', b'ctx', b'cache'})
def showchangessincelatesttag(context, mapping):
"""Integer. All ancestors not in the latest tag."""
tag = getlatesttags(context, mapping)[2][0]
mapping = context.overlaymap(mapping, {b'tag': tag})
return _showchangessincetag(context, mapping)
def _showchangessincetag(context, mapping):
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
offset = 0
revs = [ctx.rev()]
tag = context.symbol(mapping, b'tag')
# The only() revset doesn't currently support wdir()
if ctx.rev() is None:
offset = 1
revs = [p.rev() for p in ctx.parents()]
return len(repo.revs(b'only(%ld, %s)', revs, tag)) + offset
# teach templater latesttags.changes is switched to (context, mapping) API
_showchangessincetag._requires = {b'repo', b'ctx'}
@templatekeyword(b'manifest', requires={b'repo', b'ctx'})
def showmanifest(context, mapping):
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
mnode = ctx.manifestnode()
if mnode is None:
mnode = wdirid
mrev = wdirrev
else:
mrev = repo.manifestlog.rev(mnode)
mhex = hex(mnode)
mapping = context.overlaymap(mapping, {b'rev': mrev, b'node': mhex})
f = context.process(b'manifest', mapping)
return templateutil.hybriditem(
f, None, f, lambda x: {b'rev': mrev, b'node': mhex}
)
@templatekeyword(b'obsfate', requires={b'ui', b'repo', b'ctx'})
def showobsfate(context, mapping):
# this function returns a list containing pre-formatted obsfate strings.
#
# This function will be replaced by templates fragments when we will have
# the verbosity templatekw available.
succsandmarkers = showsuccsandmarkers(context, mapping)
ui = context.resource(mapping, b'ui')
repo = context.resource(mapping, b'repo')
values = []
for x in succsandmarkers.tovalue(context, mapping):
v = obsutil.obsfateprinter(
ui, repo, x[b'successors'], x[b'markers'], scmutil.formatchangeid
)
values.append(v)
return compatlist(context, mapping, b"fate", values)
def shownames(context, mapping, namespace):
"""helper method to generate a template keyword for a namespace"""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
ns = repo.names.get(namespace)
if ns is None:
# namespaces.addnamespace() registers new template keyword, but
# the registered namespace might not exist in the current repo.
return
names = ns.names(repo, ctx.node())
return compatlist(
context, mapping, ns.templatename, names, plural=namespace
)
@templatekeyword(b'namespaces', requires={b'repo', b'ctx'})
def shownamespaces(context, mapping):
"""Dict of lists. Names attached to this changeset per
namespace."""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
namespaces = util.sortdict()
def makensmapfn(ns):
# 'name' for iterating over namespaces, templatename for local reference
return lambda v: {b'name': v, ns.templatename: v}
for k, ns in pycompat.iteritems(repo.names):
names = ns.names(repo, ctx.node())
f = _showcompatlist(context, mapping, b'name', names)
namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity)
f = _showcompatlist(context, mapping, b'namespace', list(namespaces))
def makemap(ns):
return {
b'namespace': ns,
b'names': namespaces[ns],
b'builtin': repo.names[ns].builtin,
b'colorname': repo.names[ns].colorname,
}
return _hybrid(f, namespaces, makemap, pycompat.identity)
@templatekeyword(b'negrev', requires={b'repo', b'ctx'})
def shownegrev(context, mapping):
"""Integer. The repository-local changeset negative revision number,
which counts in the opposite direction."""
ctx = context.resource(mapping, b'ctx')
rev = ctx.rev()
if rev is None or rev < 0: # wdir() or nullrev?
return None
repo = context.resource(mapping, b'repo')
return rev - len(repo)
@templatekeyword(b'node', requires={b'ctx'})
def shownode(context, mapping):
"""String. The changeset identification hash, as a 40 hexadecimal
digit string.
"""
ctx = context.resource(mapping, b'ctx')
return ctx.hex()
@templatekeyword(b'obsolete', requires={b'ctx'})
def showobsolete(context, mapping):
"""String. Whether the changeset is obsolete. (EXPERIMENTAL)"""
ctx = context.resource(mapping, b'ctx')
if ctx.obsolete():
return b'obsolete'
return b''
@templatekeyword(b'onelinesummary', requires={b'ui', b'ctx'})
def showonelinesummary(context, mapping):
"""String. A one-line summary for the ctx (not including trailing newline).
The default template be overridden in command-templates.oneline-summary."""
# Avoid cycle:
# mercurial.cmdutil -> mercurial.templatekw -> mercurial.cmdutil
from . import cmdutil
ui = context.resource(mapping, b'ui')
ctx = context.resource(mapping, b'ctx')
return cmdutil.format_changeset_summary(ui, ctx)
@templatekeyword(b'path', requires={b'fctx'})
def showpath(context, mapping):
"""String. Repository-absolute path of the current file. (EXPERIMENTAL)"""
fctx = context.resource(mapping, b'fctx')
return fctx.path()
@templatekeyword(b'peerurls', requires={b'repo'})
def showpeerurls(context, mapping):
"""A dictionary of repository locations defined in the [paths] section
of your configuration file."""
repo = context.resource(mapping, b'repo')
# see commands.paths() for naming of dictionary keys
paths = repo.ui.paths
urls = util.sortdict(
(k, p.rawloc) for k, p in sorted(pycompat.iteritems(paths))
)
def makemap(k):
p = paths[k]
d = {b'name': k, b'url': p.rawloc}
d.update((o, v) for o, v in sorted(pycompat.iteritems(p.suboptions)))
return d
return _hybrid(None, urls, makemap, lambda k: b'%s=%s' % (k, urls[k]))
@templatekeyword(b"predecessors", requires={b'repo', b'ctx'})
def showpredecessors(context, mapping):
"""Returns the list of the closest visible predecessors. (EXPERIMENTAL)"""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node()))
predecessors = pycompat.maplist(hex, predecessors)
return _hybrid(
None,
predecessors,
lambda x: {b'ctx': repo[x]},
lambda x: scmutil.formatchangeid(repo[x]),
)
@templatekeyword(b'reporoot', requires={b'repo'})
def showreporoot(context, mapping):
"""String. The root directory of the current repository."""
repo = context.resource(mapping, b'repo')
return repo.root
@templatekeyword(b'size', requires={b'fctx'})
def showsize(context, mapping):
"""Integer. Size of the current file in bytes. (EXPERIMENTAL)"""
fctx = context.resource(mapping, b'fctx')
return fctx.size()
# requires 'fctx' to denote {status} depends on (ctx, path) pair
@templatekeyword(b'status', requires={b'ctx', b'fctx', b'revcache'})
def showstatus(context, mapping):
"""String. Status code of the current file. (EXPERIMENTAL)"""
path = templateutil.runsymbol(context, mapping, b'path')
path = templateutil.stringify(context, mapping, path)
if not path:
return
statmap = _getfilestatusmap(context, mapping)
if path not in statmap:
statmap = _getfilestatusmap(context, mapping, listall=True)
return statmap.get(path)
@templatekeyword(b"successorssets", requires={b'repo', b'ctx'})
def showsuccessorssets(context, mapping):
"""Returns a string of sets of successors for a changectx. Format used
is: [ctx1, ctx2], [ctx3] if ctx has been split into ctx1 and ctx2
while also diverged into ctx3. (EXPERIMENTAL)"""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
data = []
if ctx.obsolete():
ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
ssets = [[hex(n) for n in ss] for ss in ssets]
for ss in ssets:
h = _hybrid(
None,
ss,
lambda x: {b'ctx': repo[x]},
lambda x: scmutil.formatchangeid(repo[x]),
)
data.append(h)
# Format the successorssets
def render(d):
return templateutil.stringify(context, mapping, d)
def gen(data):
yield b"; ".join(render(d) for d in data)
return _hybrid(
gen(data), data, lambda x: {b'successorset': x}, pycompat.identity
)
@templatekeyword(b"succsandmarkers", requires={b'repo', b'ctx'})
def showsuccsandmarkers(context, mapping):
"""Returns a list of dict for each final successor of ctx. The dict
contains successors node id in "successors" keys and the list of
obs-markers from ctx to the set of successors in "markers".
(EXPERIMENTAL)
"""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
values = obsutil.successorsandmarkers(repo, ctx)
if values is None:
values = []
# Format successors and markers to avoid exposing binary to templates
data = []
for i in values:
# Format successors
successors = i[b'successors']
successors = [hex(n) for n in successors]
successors = _hybrid(
None,
successors,
lambda x: {b'ctx': repo[x]},
lambda x: scmutil.formatchangeid(repo[x]),
)
# Format markers
finalmarkers = []
for m in i[b'markers']:
hexprec = hex(m[0])
hexsucs = tuple(hex(n) for n in m[1])
hexparents = None
if m[5] is not None:
hexparents = tuple(hex(n) for n in m[5])
newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:]
finalmarkers.append(newmarker)
data.append({b'successors': successors, b'markers': finalmarkers})
return templateutil.mappinglist(data)
@templatekeyword(b'p1', requires={b'ctx'})
def showp1(context, mapping):
"""Changeset. The changeset's first parent. ``{p1.rev}`` for the revision
number, and ``{p1.node}`` for the identification hash."""
ctx = context.resource(mapping, b'ctx')
return templateutil.mappingdict({b'ctx': ctx.p1()}, tmpl=_changeidtmpl)
@templatekeyword(b'p2', requires={b'ctx'})
def showp2(context, mapping):
"""Changeset. The changeset's second parent. ``{p2.rev}`` for the revision
number, and ``{p2.node}`` for the identification hash."""
ctx = context.resource(mapping, b'ctx')
return templateutil.mappingdict({b'ctx': ctx.p2()}, tmpl=_changeidtmpl)
@templatekeyword(b'p1rev', requires={b'ctx'})
def showp1rev(context, mapping):
"""Integer. The repository-local revision number of the changeset's
first parent, or -1 if the changeset has no parents. (DEPRECATED)"""
ctx = context.resource(mapping, b'ctx')
return ctx.p1().rev()
@templatekeyword(b'p2rev', requires={b'ctx'})
def showp2rev(context, mapping):
"""Integer. The repository-local revision number of the changeset's
second parent, or -1 if the changeset has no second parent. (DEPRECATED)"""
ctx = context.resource(mapping, b'ctx')
return ctx.p2().rev()
@templatekeyword(b'p1node', requires={b'ctx'})
def showp1node(context, mapping):
"""String. The identification hash of the changeset's first parent,
as a 40 digit hexadecimal string. If the changeset has no parents, all
digits are 0. (DEPRECATED)"""
ctx = context.resource(mapping, b'ctx')
return ctx.p1().hex()
@templatekeyword(b'p2node', requires={b'ctx'})
def showp2node(context, mapping):
"""String. The identification hash of the changeset's second
parent, as a 40 digit hexadecimal string. If the changeset has no second
parent, all digits are 0. (DEPRECATED)"""
ctx = context.resource(mapping, b'ctx')
return ctx.p2().hex()
@templatekeyword(b'parents', requires={b'repo', b'ctx'})
def showparents(context, mapping):
"""List of strings. The parents of the changeset in "rev:node"
format. If the changeset has only one "natural" parent (the predecessor
revision) nothing is shown."""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
pctxs = scmutil.meaningfulparents(repo, ctx)
prevs = [p.rev() for p in pctxs]
parents = [
[(b'rev', p.rev()), (b'node', p.hex()), (b'phase', p.phasestr())]
for p in pctxs
]
f = _showcompatlist(context, mapping, b'parent', parents)
return _hybrid(
f,
prevs,
lambda x: {b'ctx': repo[x]},
lambda x: scmutil.formatchangeid(repo[x]),
keytype=int,
)
@templatekeyword(b'phase', requires={b'ctx'})
def showphase(context, mapping):
"""String. The changeset phase name."""
ctx = context.resource(mapping, b'ctx')
return ctx.phasestr()
@templatekeyword(b'phaseidx', requires={b'ctx'})
def showphaseidx(context, mapping):
"""Integer. The changeset phase index. (ADVANCED)"""
ctx = context.resource(mapping, b'ctx')
return ctx.phase()
@templatekeyword(b'rev', requires={b'ctx'})
def showrev(context, mapping):
"""Integer. The repository-local changeset revision number."""
ctx = context.resource(mapping, b'ctx')
return scmutil.intrev(ctx)
@templatekeyword(b'subrepos', requires={b'ctx'})
def showsubrepos(context, mapping):
"""List of strings. Updated subrepositories in the changeset."""
ctx = context.resource(mapping, b'ctx')
substate = ctx.substate
if not substate:
return compatlist(context, mapping, b'subrepo', [])
psubstate = ctx.p1().substate or {}
subrepos = []
for sub in substate:
if sub not in psubstate or substate[sub] != psubstate[sub]:
subrepos.append(sub) # modified or newly added in ctx
for sub in psubstate:
if sub not in substate:
subrepos.append(sub) # removed in ctx
return compatlist(context, mapping, b'subrepo', sorted(subrepos))
# don't remove "showtags" definition, even though namespaces will put
# a helper function for "tags" keyword into "keywords" map automatically,
# because online help text is built without namespaces initialization
@templatekeyword(b'tags', requires={b'repo', b'ctx'})
def showtags(context, mapping):
"""List of strings. Any tags associated with the changeset."""
return shownames(context, mapping, b'tags')
@templatekeyword(b'termwidth', requires={b'ui'})
def showtermwidth(context, mapping):
"""Integer. The width of the current terminal."""
ui = context.resource(mapping, b'ui')
return ui.termwidth()
@templatekeyword(b'user', requires={b'ctx'})
def showuser(context, mapping):
"""String. The unmodified author of the changeset."""
ctx = context.resource(mapping, b'ctx')
return ctx.user()
@templatekeyword(b'instabilities', requires={b'ctx'})
def showinstabilities(context, mapping):
"""List of strings. Evolution instabilities affecting the changeset.
(EXPERIMENTAL)
"""
ctx = context.resource(mapping, b'ctx')
return compatlist(
context,
mapping,
b'instability',
ctx.instabilities(),
plural=b'instabilities',
)
@templatekeyword(b'verbosity', requires={b'ui'})
def showverbosity(context, mapping):
"""String. The current output verbosity in 'debug', 'quiet', 'verbose',
or ''."""
ui = context.resource(mapping, b'ui')
# see logcmdutil.changesettemplater for priority of these flags
if ui.debugflag:
return b'debug'
elif ui.quiet:
return b'quiet'
elif ui.verbose:
return b'verbose'
return b''
@templatekeyword(b'whyunstable', requires={b'repo', b'ctx'})
def showwhyunstable(context, mapping):
"""List of dicts explaining all instabilities of a changeset.
(EXPERIMENTAL)
"""
repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
def formatnode(ctx):
return b'%s (%s)' % (scmutil.formatchangeid(ctx), ctx.phasestr())
entries = obsutil.whyunstable(repo, ctx)
for entry in entries:
if entry.get(b'divergentnodes'):
dnodes = entry[b'divergentnodes']
dnhybrid = _hybrid(
None,
[dnode.hex() for dnode in dnodes],
lambda x: {b'ctx': repo[x]},
lambda x: formatnode(repo[x]),
)
entry[b'divergentnodes'] = dnhybrid
tmpl = (
b'{instability}:{if(divergentnodes, " ")}{divergentnodes} '
b'{reason} {node|short}'
)
return templateutil.mappinglist(entries, tmpl=tmpl, sep=b'\n')
def loadkeyword(ui, extname, registrarobj):
"""Load template keyword from specified registrarobj"""
for name, func in pycompat.iteritems(registrarobj._table):
keywords[name] = func
# tell hggettext to extract docstrings from these functions:
i18nfunctions = keywords.values()