hgext/extdiff.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Mon, 02 Nov 2020 11:03:56 +0100
changeset 45892 06b64fabf91c
parent 45410 2d08dcf8fd9e
child 45942 89a2afe31e82
permissions -rw-r--r--
copies: cache the ancestor checking call when tracing copy A good share of the time spent in this function is spent doing ancestors checking. To avoid spending time in duplicated call, we cache the result of calls. In the slower case, this provide a quite significant performance boost. Below are the result for a set of selected pairs (many of them pathological): (And further down is another table that summarize the current state of filelog based vs changeset base copy tracing) The benchmark have been configured to be killed after 6 minutes of runtime, which mean that any detect slower than 2 minutes will be marked as "killed". This drop some useful information about how much slower these case are… but also prevent 99% of the benchmark time to be spent on case that can be labelled "very slow" anyway. Repo Case Source-Rev Dest-Rev Old-Time New-Time Difference Factor ------------------------------------------------------------------------------------------------------------------------------------ mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 0.000044 s, 0.000044 s, +0.000000 s, × 1.0000 mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 0.000138 s, 0.000138 s, +0.000000 s, × 1.0000 mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 0.005067 s, 0.005052 s, -0.000015 s, × 0.9970 pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 0.000218 s, 0.000219 s, +0.000001 s, × 1.0046 pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 0.000053 s, 0.000055 s, +0.000002 s, × 1.0377 pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 0.000125 s, 0.000128 s, +0.000003 s, × 1.0240 pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 0.001098 s, 0.001089 s, -0.000009 s, × 0.9918 pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 0.017546 s, 0.017407 s, -0.000139 s, × 0.9921 pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 0.096723 s, 0.094175 s, -0.002548 s, × 0.9737 pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 0.271796 s, 0.238009 s, -0.033787 s, × 0.8757 pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 0.128602 s, 0.125876 s, -0.002726 s, × 0.9788 pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 7.086742 s, 3.581556 s, -3.505186 s, × 0.5054 pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 0.016634 s, 0.016721 s, +0.000087 s, × 1.0052 pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 0.254225 s, 0.242367 s, -0.011858 s, × 0.9534 netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 0.000166 s, 0.000165 s, -0.000001 s, × 0.9940 netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 0.000118 s, 0.000114 s, -0.000004 s, × 0.9661 netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 0.000296 s, 0.000296 s, +0.000000 s, × 1.0000 netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 0.001137 s, 0.001124 s, -0.000013 s, × 0.9886 netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 0.014133 s, 0.013060 s, -0.001073 s, × 0.9241 netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 0.016988 s, 0.017112 s, +0.000124 s, × 1.0073 netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 0.676361 s, 0.660350 s, -0.016011 s, × 0.9763 netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 12.515149 s, 10.032499 s, -2.482650 s, × 0.8016 mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 0.000186 s, 0.000189 s, +0.000003 s, × 1.0161 mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 0.000459 s, 0.000462 s, +0.000003 s, × 1.0065 mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 0.000273 s, 0.000270 s, -0.000003 s, × 0.9890 mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 0.001503 s, 0.001474 s, -0.000029 s, × 0.9807 mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 0.004862 s, 0.004806 s, -0.000056 s, × 0.9885 mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 0.088291 s, 0.085150 s, -0.003141 s, × 0.9644 mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.007113 s, 0.007064 s, -0.000049 s, × 0.9931 mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.004687 s, 0.004741 s, +0.000054 s, × 1.0115 mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 0.198710 s, 0.190133 s, -0.008577 s, × 0.9568 mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 0.036068 s, 0.035651 s, -0.000417 s, × 0.9884 mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 0.465362 s, 0.440694 s, -0.024668 s, × 0.9470 mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 24.519684 s, 18.454163 s, -6.065521 s, × 0.7526 mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 42.711897 s, 31.562719 s, -11.149178 s, × 0.7390 mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 0.001201 s, 0.001189 s, -0.000012 s, × 0.9900 mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 0.001216 s, 0.001204 s, -0.000012 s, × 0.9901 mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 0.000595 s, 0.000586 s, -0.000009 s, × 0.9849 mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 0.001856 s, 0.001845 s, -0.000011 s, × 0.9941 mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 0.064936 s, 0.063822 s, -0.001114 s, × 0.9828 mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 0.090601 s, 0.088038 s, -0.002563 s, × 0.9717 mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.007510 s, 0.007389 s, -0.000121 s, × 0.9839 mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.004911 s, 0.004868 s, -0.000043 s, × 0.9912 mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 0.233231 s, 0.222450 s, -0.010781 s, × 0.9538 mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 0.419989 s, 0.370675 s, -0.049314 s, × 0.8826 mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 0.401521 s, 0.358020 s, -0.043501 s, × 0.8917 mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 0.179555 s, 0.145235 s, -0.034320 s, × 0.8089 mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 0.038004 s, 0.037606 s, -0.000398 s, × 0.9895 mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 52.838482 s, 7.382439 s, -45.456043 s, × 0.1397 mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 8.705874 s, 7.273506 s, -1.432368 s, × 0.8355 mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 1.126708 s, 1.074593 s, -0.052115 s, × 0.9537 mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 83.854020 s, 27.746195 s, -56.107825 s, × 0.3309 Below is a table comparing the runtime of the current "filelog centric" algorithm, with the "changeset centric" one, we just modified. The changeset centric algorithm is a significant win in many scenario, but they are still various cases where it is quite slower. When many revision has to be considered the cost of retrieving the copy information, creating new dictionaries, merging dictionaries and checking if revision are ancestors of each other can slow things down. The rest of this series, will introduce a rust version of the copy tracing code to deal with most of theses issues. Repo Case Source-Rev Dest-Rev filelog sidedata Difference Factor --------------------------------------------------------------------------------------------------------------------------------------- mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 0.000914 s, 0.000044 s, - 0.000870 s, × 0.048140 mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 0.001812 s, 0.000138 s, - 0.001674 s, × 0.076159 mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 0.017954 s, 0.005052 s, - 0.012902 s, × 0.281386 pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 0.001509 s, 0.000219 s, - 0.001290 s, × 0.145129 pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 0.206881 s, 0.000055 s, - 0.206826 s, × 0.000266 pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 0.016951 s, 0.000128 s, - 0.016823 s, × 0.007551 pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 0.019096 s, 0.001089 s, - 0.018007 s, × 0.057028 pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 0.762506 s, 0.017407 s, - 0.745099 s, × 0.022829 pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 1.179211 s, 0.094175 s, - 1.085036 s, × 0.079863 pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 1.249058 s, 0.238009 s, - 1.011049 s, × 0.190551 pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 1.614107 s, 0.125876 s, - 1.488231 s, × 0.077985 pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 0.001064 s, 3.581556 s, + 3.580492 s, × 3366.124060 pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 1.061275 s, 0.016721 s, - 1.044554 s, × 0.015756 pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 1.341119 s, 0.242367 s, - 1.098752 s, × 0.180720 netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 0.027803 s, 0.000165 s, - 0.027638 s, × 0.005935 netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 0.130014 s, 0.000114 s, - 0.129900 s, × 0.000877 netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 0.024990 s, 0.000296 s, - 0.024694 s, × 0.011845 netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 0.052201 s, 0.001124 s, - 0.051077 s, × 0.021532 netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 0.037642 s, 0.013060 s, - 0.024582 s, × 0.346953 netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 0.197086 s, 0.017112 s, - 0.179974 s, × 0.086825 netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 0.935148 s, 0.660350 s, - 0.274798 s, × 0.706145 netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 3.920674 s, 10.032499 s, + 6.111825 s, × 2.558871 mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 0.024232 s, 0.000189 s, - 0.024043 s, × 0.007800 mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 0.141483 s, 0.000462 s, - 0.141021 s, × 0.003265 mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 0.025775 s, 0.000270 s, - 0.025505 s, × 0.010475 mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 0.084922 s, 0.001474 s, - 0.083448 s, × 0.017357 mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 0.194784 s, 0.004806 s, - 0.189978 s, × 0.024673 mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 2.161103 s, 0.085150 s, - 2.075953 s, × 0.039401 mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.089347 s, 0.007064 s, - 0.082283 s, × 0.079063 mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.732171 s, 0.004741 s, - 0.727430 s, × 0.006475 mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 1.157287 s, 0.190133 s, - 0.967154 s, × 0.164292 mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 6.726568 s, 0.035651 s, - 6.690917 s, × 0.005300 mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 3.266229 s, 0.440694 s, - 2.825535 s, × 0.134924 mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 15.860534 s, 18.454163 s, + 2.593629 s, × 1.163527 mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 20.450475 s, 31.562719 s, +11.112244 s, × 1.543373 mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 0.080442 s, 0.001189 s, - 0.079253 s, × 0.014781 mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 0.497672 s, 0.001204 s, - 0.496468 s, × 0.002419 mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 0.021183 s, 0.000586 s, - 0.020597 s, × 0.027664 mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 0.230991 s, 0.001845 s, - 0.229146 s, × 0.007987 mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 1.118461 s, 0.063822 s, - 1.054639 s, × 0.057062 mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 2.206083 s, 0.088038 s, - 2.118045 s, × 0.039907 mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 0.089404 s, 0.007389 s, - 0.082015 s, × 0.082647 mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 0.733043 s, 0.004868 s, - 0.728175 s, × 0.006641 mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 1.163367 s, 0.222450 s, - 0.940917 s, × 0.191212 mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 0.085456 s, 0.370675 s, + 0.285219 s, × 4.337612 mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 0.083601 s, 0.358020 s, + 0.274419 s, × 4.282485 mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 7.366614 s, 0.145235 s, - 7.221379 s, × 0.019715 mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 6.664464 s, 0.037606 s, - 6.626858 s, × 0.005643 mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 7.467836 s, 7.382439 s, - 0.085397 s, × 0.988565 mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 9.801294 s, 7.273506 s, - 2.527788 s, × 0.742097 mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 0.091886 s, killed mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 26.491140 s, 1.074593 s, -25.416547 s, × 0.040564 mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 0.092863 s, killed mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 0.226823 s, killed mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 18.914630 s, 27.746195 s, + 8.831565 s, × 1.466917 mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 21.198903 s, killed mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 24.952268 s, killed Differential Revision: https://phab.mercurial-scm.org/D9296
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     1
# extdiff.py - external diff program support for mercurial
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     2
#
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     3
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8076
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9956
diff changeset
     6
# GNU General Public License version 2 or any later version.
5245
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
     7
8934
9dda4c73fc3b extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8873
diff changeset
     8
'''command to allow external programs to compare revisions
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8866
diff changeset
     9
9286
a8fdcec4ab34 doc: fix quotes mismatches affecting rst
Cédric Duval <cedricduval@free.fr>
parents: 9257
diff changeset
    10
The extdiff Mercurial extension allows you to use external programs
9257
50ebe8845a1b extdiff: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9207
diff changeset
    11
to compare revisions, or revision with working directory. The external
50ebe8845a1b extdiff: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9207
diff changeset
    12
diff programs are called with a configurable set of options and two
5245
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    13
non-option arguments: paths to directories containing snapshots of
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    14
files to compare.
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    15
37209
2208149c4b8e extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents: 37120
diff changeset
    16
If there is more than one file being compared and the "child" revision
2208149c4b8e extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents: 37120
diff changeset
    17
is the working directory, any modifications made in the external diff
2208149c4b8e extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents: 37120
diff changeset
    18
program will be copied back to the working directory from the temporary
2208149c4b8e extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents: 37120
diff changeset
    19
directory.
2208149c4b8e extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents: 37120
diff changeset
    20
14327
d943412e2fba extdiff: grammar "allows to" -> "allows one to"
Javi Merino <cibervicho@gmail.com>
parents: 14322
diff changeset
    21
The extdiff extension also allows you to configure new diff commands, so
11191
c45a47bc4114 extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 11184
diff changeset
    22
you do not need to type :hg:`extdiff -p kdiff3` always. ::
3127
8e8deb8035a4 Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents: 3090
diff changeset
    23
5245
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    24
  [extdiff]
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    25
  # add new command that runs GNU diff(1) in 'context diff' mode
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    26
  cdiff = gdiff -Nprc5
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    27
  ## or the old way:
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    28
  #cmd.cdiff = gdiff
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    29
  #opts.cdiff = -Nprc5
3127
8e8deb8035a4 Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents: 3090
diff changeset
    30
23150
aff73c777b0b extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents: 23149
diff changeset
    31
  # add new command called meld, runs meld (no need to name twice).  If
aff73c777b0b extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents: 23149
diff changeset
    32
  # the meld executable is not available, the meld tool in [merge-tools]
aff73c777b0b extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents: 23149
diff changeset
    33
  # will be used, if available
5245
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    34
  meld =
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    35
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    36
  # add new command called vimdiff, runs gvimdiff with DirDiff plugin
9257
50ebe8845a1b extdiff: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9207
diff changeset
    37
  # (see http://www.vim.org/scripts/script.php?script_id=102) Non
50ebe8845a1b extdiff: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9207
diff changeset
    38
  # English user, be sure to put "let g:DirDiffDynamicDiffText = 1" in
5245
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    39
  # your .vimrc
16242
55174ab81973 extdiff: escape filenames with vim/DirDiff and make quoting work with Windows
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14739
diff changeset
    40
  vimdiff = gvim -f "+next" \\
55174ab81973 extdiff: escape filenames with vim/DirDiff and make quoting work with Windows
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14739
diff changeset
    41
            "+execute 'DirDiff' fnameescape(argv(0)) fnameescape(argv(1))"
5245
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    42
11191
c45a47bc4114 extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 11184
diff changeset
    43
Tool arguments can include variables that are expanded at runtime::
11184
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    44
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    45
  $parent1, $plabel1 - filename, descriptive label of first parent
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    46
  $child,   $clabel  - filename, descriptive label of child revision
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    47
  $parent2, $plabel2 - filename, descriptive label of second parent
14045
1c38777f7b8a extdiff: add repository root as a variable
Steven Stallion <sstallion@gmail.com>
parents: 14024
diff changeset
    48
  $root              - repository root
11184
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    49
  $parent is an alias for $parent1.
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    50
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    51
The extdiff extension will look in your [diff-tools] and [merge-tools]
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    52
sections for diff tool arguments, when none are specified in [extdiff].
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    53
11191
c45a47bc4114 extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 11184
diff changeset
    54
::
c45a47bc4114 extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 11184
diff changeset
    55
11184
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    56
  [extdiff]
11191
c45a47bc4114 extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 11184
diff changeset
    57
  kdiff3 =
11184
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    58
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    59
  [diff-tools]
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    60
  kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child
7d99edddbaea extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents: 10394
diff changeset
    61
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    62
If a program has a graphical interface, it might be interesting to tell
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    63
Mercurial about it. It will prevent the program from being mistakenly
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    64
used in a terminal-only environment (such as an SSH terminal session),
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    65
and will make :hg:`extdiff --per-file` open multiple file diffs at once
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    66
instead of one by one (if you still want to open file diffs one by one,
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    67
you can use the --confirm option).
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    68
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    69
Declaring that a tool has a graphical interface can be done with the
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    70
``gui`` flag next to where ``diffargs`` are specified:
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    71
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    72
::
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    73
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    74
  [diff-tools]
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    75
  kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    76
  kdiff3.gui = true
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    77
11191
c45a47bc4114 extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 11184
diff changeset
    78
You can use -I/-X and list of file or directory names like normal
c45a47bc4114 extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 11184
diff changeset
    79
:hg:`diff` command. The extdiff extension makes snapshots of only
c45a47bc4114 extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 11184
diff changeset
    80
needed files, so running the external diff program will actually be
c45a47bc4114 extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 11184
diff changeset
    81
pretty fast (at least faster than having to compare the entire tree).
5245
a1efa71f3ece Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents: 5147
diff changeset
    82
'''
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    83
28970
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    84
from __future__ import absolute_import
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    85
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    86
import os
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    87
import re
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    88
import shutil
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36268
diff changeset
    89
import stat
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
    90
import subprocess
38165
2ce60954b1b7 py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 37604
diff changeset
    91
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
    92
from mercurial.i18n import _
28970
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    93
from mercurial.node import (
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    94
    nullid,
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    95
    short,
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    96
)
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    97
from mercurial import (
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    98
    archival,
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
    99
    cmdutil,
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   100
    encoding,
28970
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
   101
    error,
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
   102
    filemerge,
37604
daafaff4e5be export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents: 37253
diff changeset
   103
    formatter,
30678
caf7e1c5efe4 py3: have a bytes version of shlex.split()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29841
diff changeset
   104
    pycompat,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32283
diff changeset
   105
    registrar,
28970
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
   106
    scmutil,
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
   107
    util,
4f86c3bed63b py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27681
diff changeset
   108
)
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
   109
from mercurial.utils import (
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
   110
    procutil,
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
   111
    stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
   112
)
5135
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
   113
21246
29eeaa6d662f extdiff: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 20674
diff changeset
   114
cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32283
diff changeset
   115
command = registrar.command(cmdtable)
34777
bb2525871d95 configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents: 32431
diff changeset
   116
bb2525871d95 configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents: 32431
diff changeset
   117
configtable = {}
bb2525871d95 configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents: 32431
diff changeset
   118
configitem = registrar.configitem(configtable)
bb2525871d95 configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents: 32431
diff changeset
   119
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   120
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   121
    b'extdiff', br'opts\..*', default=b'', generic=True,
34777
bb2525871d95 configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents: 32431
diff changeset
   122
)
bb2525871d95 configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents: 32431
diff changeset
   123
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   124
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   125
    b'extdiff', br'gui\..*', generic=True,
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   126
)
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   127
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   128
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   129
    b'diff-tools', br'.*\.diffargs$', default=None, generic=True,
34778
bf138446ac2f configitems: register the 'extdata.*.diffargs' config
Boris Feld <boris.feld@octobus.net>
parents: 34777
diff changeset
   130
)
bf138446ac2f configitems: register the 'extdata.*.diffargs' config
Boris Feld <boris.feld@octobus.net>
parents: 34777
diff changeset
   131
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   132
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   133
    b'diff-tools', br'.*\.gui$', generic=True,
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   134
)
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   135
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29723
diff changeset
   136
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24193
diff changeset
   137
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24193
diff changeset
   138
# be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24193
diff changeset
   139
# leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   140
testedwith = b'ships-with-hg-core'
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16686
diff changeset
   141
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   142
25813
18bae5eb58c5 extdiff: add support for subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 25812
diff changeset
   143
def snapshot(ui, repo, files, node, tmproot, listsubrepos):
8064
5c7bc1aece9e extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents: 7758
diff changeset
   144
    '''snapshot files as of some revision
5c7bc1aece9e extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents: 7758
diff changeset
   145
    if not using snapshot, -I/-X does not work and recursive diff
5c7bc1aece9e extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents: 7758
diff changeset
   146
    in tools like kdiff3 and meld displays too many files.'''
5135
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
   147
    dirname = os.path.basename(repo.root)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   148
    if dirname == b"":
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   149
        dirname = b"root"
8064
5c7bc1aece9e extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents: 7758
diff changeset
   150
    if node is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   151
        dirname = b'%s.%s' % (dirname, short(node))
5135
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
   152
    base = os.path.join(tmproot, dirname)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
   153
    os.mkdir(base)
32217
affd753ddaf1 extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents: 31451
diff changeset
   154
    fnsandstat = []
25812
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   155
8064
5c7bc1aece9e extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents: 7758
diff changeset
   156
    if node is not None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   157
        ui.note(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   158
            _(b'making snapshot of %d files from rev %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   159
            % (len(files), short(node))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   160
        )
8064
5c7bc1aece9e extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents: 7758
diff changeset
   161
    else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   162
        ui.note(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   163
            _(b'making snapshot of %d files from working directory\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   164
            % (len(files))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   165
        )
25812
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   166
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   167
    if files:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   168
        repo.ui.setconfig(b"ui", b"archivemeta", False)
25812
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   169
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   170
        archival.archive(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   171
            repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   172
            base,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   173
            node,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   174
            b'files',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   175
            match=scmutil.matchfiles(repo, files),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   176
            subrepos=listsubrepos,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   177
        )
25812
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   178
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   179
        for fn in sorted(files):
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   180
            wfn = util.pconvert(fn)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   181
            ui.note(b'  %s\n' % wfn)
25812
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   182
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   183
            if node is None:
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   184
                dest = os.path.join(base, wfn)
68822b7cdd01 extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 25186
diff changeset
   185
32217
affd753ddaf1 extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents: 31451
diff changeset
   186
                fnsandstat.append((dest, repo.wjoin(fn), os.lstat(dest)))
affd753ddaf1 extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents: 31451
diff changeset
   187
    return dirname, fnsandstat
5143
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5137
diff changeset
   188
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   189
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   190
def formatcmdline(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   191
    cmdline,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   192
    repo_root,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   193
    do3way,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   194
    parent1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   195
    plabel1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   196
    parent2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   197
    plabel2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   198
    child,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   199
    clabel,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   200
):
41196
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   201
    # Function to quote file/dir names in the argument string.
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   202
    # When not operating in 3-way mode, an empty string is
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   203
    # returned for parent2
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   204
    replace = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   205
        b'parent': parent1,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   206
        b'parent1': parent1,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   207
        b'parent2': parent2,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   208
        b'plabel1': plabel1,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   209
        b'plabel2': plabel2,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   210
        b'child': child,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   211
        b'clabel': clabel,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   212
        b'root': repo_root,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   213
    }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   214
41196
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   215
    def quote(match):
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   216
        pre = match.group(2)
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   217
        key = match.group(3)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   218
        if not do3way and key == b'parent2':
41196
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   219
            return pre
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   220
        return pre + procutil.shellquote(replace[key])
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   221
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   222
    # Match parent2 first, so 'parent1?' will match both parent1 and parent
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   223
    regex = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   224
        br'''(['"]?)([^\s'"$]*)'''
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   225
        br'\$(parent2|parent1?|child|plabel1|plabel2|clabel|root)\1'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   226
    )
41196
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   227
    if not do3way and not re.search(regex, cmdline):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   228
        cmdline += b' $parent1 $child'
41196
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   229
    return re.sub(regex, quote, cmdline)
4f675c12d083 extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents: 40819
diff changeset
   230
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   231
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   232
def _systembackground(cmd, environ=None, cwd=None):
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   233
    ''' like 'procutil.system', but returns the Popen object directly
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   234
        so we don't have to wait on it.
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   235
    '''
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   236
    env = procutil.shellenviron(environ)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   237
    proc = subprocess.Popen(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   238
        procutil.tonativestr(cmd),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   239
        shell=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   240
        close_fds=procutil.closefds,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   241
        env=procutil.tonativeenv(env),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   242
        cwd=pycompat.rapply(procutil.tonativestr, cwd),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   243
    )
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   244
    return proc
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   245
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   246
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   247
def _runperfilediff(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   248
    cmdline,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   249
    repo_root,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   250
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   251
    guitool,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   252
    do3way,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   253
    confirm,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   254
    commonfiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   255
    tmproot,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   256
    dir1a,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   257
    dir1b,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   258
    dir2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   259
    rev1a,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   260
    rev1b,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   261
    rev2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   262
):
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   263
    # Note that we need to sort the list of files because it was
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   264
    # built in an "unstable" way and it's annoying to get files in a
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   265
    # random order, especially when "confirm" mode is enabled.
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   266
    waitprocs = []
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   267
    totalfiles = len(commonfiles)
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   268
    for idx, commonfile in enumerate(sorted(commonfiles)):
45399
e7c5735433ac extdiff: pass full paths of `dir1a` and `dir1b` to `_runperfilediff()`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45130
diff changeset
   269
        path1a = os.path.join(dir1a, commonfile)
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   270
        label1a = commonfile + rev1a
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   271
        if not os.path.isfile(path1a):
43790
765a9c299c44 py3: make a pycompat.osdevnull, use it in extdiff
Kyle Lippincott <spectral@google.com>
parents: 43638
diff changeset
   272
            path1a = pycompat.osdevnull
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   273
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   274
        path1b = b''
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   275
        label1b = b''
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   276
        if do3way:
45399
e7c5735433ac extdiff: pass full paths of `dir1a` and `dir1b` to `_runperfilediff()`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45130
diff changeset
   277
            path1b = os.path.join(dir1b, commonfile)
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   278
            label1b = commonfile + rev1b
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   279
            if not os.path.isfile(path1b):
43790
765a9c299c44 py3: make a pycompat.osdevnull, use it in extdiff
Kyle Lippincott <spectral@google.com>
parents: 43638
diff changeset
   280
                path1b = pycompat.osdevnull
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   281
45400
1bed1b00b18d extdiff: remove dir2root and pass full path as dir2 in _runperfilediff()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45399
diff changeset
   282
        path2 = os.path.join(dir2, commonfile)
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   283
        label2 = commonfile + rev2
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   284
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   285
        if confirm:
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   286
            # Prompt before showing this diff
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   287
            difffiles = _(b'diff %s (%d of %d)') % (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   288
                commonfile,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   289
                idx + 1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   290
                totalfiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   291
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   292
            responses = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   293
                b'[Yns?]'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   294
                b'$$ &Yes, show diff'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   295
                b'$$ &No, skip this diff'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   296
                b'$$ &Skip remaining diffs'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   297
                b'$$ &? (display help)'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   298
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   299
            r = ui.promptchoice(b'%s %s' % (difffiles, responses))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   300
            if r == 3:  # ?
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   301
                while r == 3:
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   302
                    for c, t in ui.extractchoices(responses)[1]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   303
                        ui.write(b'%s - %s\n' % (c, encoding.lower(t)))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   304
                    r = ui.promptchoice(b'%s %s' % (difffiles, responses))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   305
            if r == 0:  # yes
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   306
                pass
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   307
            elif r == 1:  # no
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   308
                continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   309
            elif r == 2:  # skip
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   310
                break
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   311
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   312
        curcmdline = formatcmdline(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   313
            cmdline,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   314
            repo_root,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   315
            do3way=do3way,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   316
            parent1=path1a,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   317
            plabel1=label1a,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   318
            parent2=path1b,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   319
            plabel2=label1b,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   320
            child=path2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   321
            clabel=label2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   322
        )
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   323
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   324
        if confirm or not guitool:
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   325
            # Run the comparison program and wait for it to exit
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   326
            # before we show the next file.
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   327
            # This is because either we need to wait for confirmation
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   328
            # from the user between each invocation, or because, as far
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   329
            # as we know, the tool doesn't have a GUI, in which case
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   330
            # we can't run multiple CLI programs at the same time.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   331
            ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   332
                b'running %r in %s\n' % (pycompat.bytestr(curcmdline), tmproot)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   333
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   334
            ui.system(curcmdline, cwd=tmproot, blockedtag=b'extdiff')
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   335
        else:
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   336
            # Run the comparison program but don't wait, as we're
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   337
            # going to rapid-fire each file diff and then wait on
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   338
            # the whole group.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   339
            ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   340
                b'running %r in %s (backgrounded)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   341
                % (pycompat.bytestr(curcmdline), tmproot)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   342
            )
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   343
            proc = _systembackground(curcmdline, cwd=tmproot)
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   344
            waitprocs.append(proc)
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   345
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   346
    if waitprocs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   347
        with ui.timeblockedsection(b'extdiff'):
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   348
            for proc in waitprocs:
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   349
                proc.wait()
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   350
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   351
45129
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   352
def diffpatch(ui, repo, node1, node2, tmproot, matcher, cmdline):
45126
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   353
    template = b'hg-%h.patch'
45129
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   354
    # write patches to temporary files
45126
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   355
    with formatter.nullformatter(ui, b'extdiff', {}) as fm:
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   356
        cmdutil.export(
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   357
            repo,
45129
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   358
            [repo[node1].rev(), repo[node2].rev()],
45126
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   359
            fm,
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   360
            fntemplate=repo.vfs.reljoin(tmproot, template),
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   361
            match=matcher,
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   362
        )
45129
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   363
    label1 = cmdutil.makefilename(repo[node1], template)
45126
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   364
    label2 = cmdutil.makefilename(repo[node2], template)
45129
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   365
    file1 = repo.vfs.reljoin(tmproot, label1)
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   366
    file2 = repo.vfs.reljoin(tmproot, label2)
45126
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   367
    cmdline = formatcmdline(
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   368
        cmdline,
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   369
        repo.root,
45128
d23881b17388 extdiff: remove unrequired do3way argument to diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45127
diff changeset
   370
        # no 3way while comparing patches
d23881b17388 extdiff: remove unrequired do3way argument to diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45127
diff changeset
   371
        do3way=False,
45129
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   372
        parent1=file1,
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   373
        plabel1=label1,
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   374
        # while comparing patches, there is no second parent
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   375
        parent2=None,
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   376
        plabel2=None,
30c31de4d1db extdiff: add comments and minor variable renames diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45128
diff changeset
   377
        child=file2,
45126
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   378
        clabel=label2,
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   379
    )
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   380
    ui.debug(b'running %r in %s\n' % (pycompat.bytestr(cmdline), tmproot))
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   381
    ui.system(cmdline, cwd=tmproot, blockedtag=b'extdiff')
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   382
    return 1
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   383
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   384
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   385
def diffrevs(
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   386
    ui,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   387
    repo,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   388
    node1a,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   389
    node1b,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   390
    node2,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   391
    matcher,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   392
    tmproot,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   393
    cmdline,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   394
    do3way,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   395
    guitool,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   396
    opts,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   397
):
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   398
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   399
    subrepos = opts.get(b'subrepos')
45130
33524b6bef53 extdiff: add some comments in diffrevs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45129
diff changeset
   400
33524b6bef53 extdiff: add some comments in diffrevs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45129
diff changeset
   401
    # calculate list of files changed between both revs
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   402
    st = repo.status(node1a, node2, matcher, listsubrepos=subrepos)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   403
    mod_a, add_a, rem_a = set(st.modified), set(st.added), set(st.removed)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   404
    if do3way:
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   405
        stb = repo.status(node1b, node2, matcher, listsubrepos=subrepos)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   406
        mod_b, add_b, rem_b = (
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   407
            set(stb.modified),
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   408
            set(stb.added),
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   409
            set(stb.removed),
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   410
        )
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   411
    else:
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   412
        mod_b, add_b, rem_b = set(), set(), set()
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   413
    modadd = mod_a | add_a | mod_b | add_b
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   414
    common = modadd | rem_a | rem_b
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   415
    if not common:
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   416
        return 0
45130
33524b6bef53 extdiff: add some comments in diffrevs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45129
diff changeset
   417
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   418
    # Always make a copy of node1a (and node1b, if applicable)
45130
33524b6bef53 extdiff: add some comments in diffrevs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45129
diff changeset
   419
    # dir1a should contain files which are:
33524b6bef53 extdiff: add some comments in diffrevs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45129
diff changeset
   420
    #   * modified or removed from node1a to node2
33524b6bef53 extdiff: add some comments in diffrevs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45129
diff changeset
   421
    #   * modified or added from node1b to node2
33524b6bef53 extdiff: add some comments in diffrevs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45129
diff changeset
   422
    #     (except file added from node1a to node2 as they were not present in
33524b6bef53 extdiff: add some comments in diffrevs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45129
diff changeset
   423
    #     node1a)
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   424
    dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   425
    dir1a = snapshot(ui, repo, dir1a_files, node1a, tmproot, subrepos)[0]
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   426
    rev1a = b'@%d' % repo[node1a].rev()
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   427
    if do3way:
45130
33524b6bef53 extdiff: add some comments in diffrevs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45129
diff changeset
   428
        # file calculation criteria same as dir1a
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   429
        dir1b_files = mod_b | rem_b | ((mod_a | add_a) - add_b)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   430
        dir1b = snapshot(ui, repo, dir1b_files, node1b, tmproot, subrepos)[0]
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   431
        rev1b = b'@%d' % repo[node1b].rev()
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   432
    else:
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   433
        dir1b = None
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   434
        rev1b = b''
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   435
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   436
    fnsandstat = []
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   437
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   438
    # If node2 in not the wc or there is >1 change, copy it
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   439
    dir2root = b''
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   440
    rev2 = b''
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   441
    if node2:
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   442
        dir2 = snapshot(ui, repo, modadd, node2, tmproot, subrepos)[0]
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   443
        rev2 = b'@%d' % repo[node2].rev()
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   444
    elif len(common) > 1:
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   445
        # we only actually need to get the files to copy back to
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   446
        # the working dir in this case (because the other cases
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   447
        # are: diffing 2 revisions or single file -- in which case
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   448
        # the file is already directly passed to the diff tool).
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   449
        dir2, fnsandstat = snapshot(ui, repo, modadd, None, tmproot, subrepos)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   450
    else:
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   451
        # This lets the diff tool open the changed file directly
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   452
        dir2 = b''
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   453
        dir2root = repo.root
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   454
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   455
    label1a = rev1a
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   456
    label1b = rev1b
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   457
    label2 = rev2
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   458
45401
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   459
    if not opts.get(b'per_file'):
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   460
        # If only one change, diff the files instead of the directories
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   461
        # Handle bogus modifies correctly by checking if the files exist
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   462
        if len(common) == 1:
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   463
            common_file = util.localpath(common.pop())
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   464
            dir1a = os.path.join(tmproot, dir1a, common_file)
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   465
            label1a = common_file + rev1a
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   466
            if not os.path.isfile(dir1a):
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   467
                dir1a = pycompat.osdevnull
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   468
            if do3way:
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   469
                dir1b = os.path.join(tmproot, dir1b, common_file)
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   470
                label1b = common_file + rev1b
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   471
                if not os.path.isfile(dir1b):
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   472
                    dir1b = pycompat.osdevnull
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   473
            dir2 = os.path.join(dir2root, dir2, common_file)
451e13cc6d85 extdiff: move single file handling inside `not per-file` conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45400
diff changeset
   474
            label2 = common_file + rev2
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   475
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   476
        # Run the external tool on the 2 temp directories or the patches
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   477
        cmdline = formatcmdline(
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   478
            cmdline,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   479
            repo.root,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   480
            do3way=do3way,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   481
            parent1=dir1a,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   482
            plabel1=label1a,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   483
            parent2=dir1b,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   484
            plabel2=label1b,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   485
            child=dir2,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   486
            clabel=label2,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   487
        )
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   488
        ui.debug(b'running %r in %s\n' % (pycompat.bytestr(cmdline), tmproot))
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   489
        ui.system(cmdline, cwd=tmproot, blockedtag=b'extdiff')
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   490
    else:
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   491
        # Run the external tool once for each pair of files
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   492
        _runperfilediff(
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   493
            cmdline,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   494
            repo.root,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   495
            ui,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   496
            guitool=guitool,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   497
            do3way=do3way,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   498
            confirm=opts.get(b'confirm'),
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   499
            commonfiles=common,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   500
            tmproot=tmproot,
45399
e7c5735433ac extdiff: pass full paths of `dir1a` and `dir1b` to `_runperfilediff()`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45130
diff changeset
   501
            dir1a=os.path.join(tmproot, dir1a),
e7c5735433ac extdiff: pass full paths of `dir1a` and `dir1b` to `_runperfilediff()`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45130
diff changeset
   502
            dir1b=os.path.join(tmproot, dir1b) if do3way else None,
45400
1bed1b00b18d extdiff: remove dir2root and pass full path as dir2 in _runperfilediff()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45399
diff changeset
   503
            dir2=os.path.join(dir2root, dir2),
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   504
            rev1a=rev1a,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   505
            rev1b=rev1b,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   506
            rev2=rev2,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   507
        )
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   508
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   509
    for copy_fn, working_fn, st in fnsandstat:
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   510
        cpstat = os.lstat(copy_fn)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   511
        # Some tools copy the file and attributes, so mtime may not detect
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   512
        # all changes.  A size check will detect more cases, but not all.
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   513
        # The only certain way to detect every case is to diff all files,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   514
        # which could be expensive.
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   515
        # copyfile() carries over the permission, so the mode check could
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   516
        # be in an 'elif' branch, but for the case where the file has
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   517
        # changed without affecting mtime or size.
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   518
        if (
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   519
            cpstat[stat.ST_MTIME] != st[stat.ST_MTIME]
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   520
            or cpstat.st_size != st.st_size
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   521
            or (cpstat.st_mode & 0o100) != (st.st_mode & 0o100)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   522
        ):
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   523
            ui.debug(
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   524
                b'file changed while diffing. '
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   525
                b'Overwriting: %s (src: %s)\n' % (working_fn, copy_fn)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   526
            )
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   527
            util.copyfile(copy_fn, working_fn)
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   528
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   529
    return 1
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   530
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   531
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   532
def dodiff(ui, repo, cmdline, pats, opts, guitool=False):
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 16743
diff changeset
   533
    '''Do the actual diff:
6103
e668fd796b8b Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents: 5293
diff changeset
   534
e668fd796b8b Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents: 5293
diff changeset
   535
    - copy to a temp structure if diffing 2 internal revisions
e668fd796b8b Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents: 5293
diff changeset
   536
    - copy to a temp structure if diffing working revision with
e668fd796b8b Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents: 5293
diff changeset
   537
      another one and more than 1 file is changed
e668fd796b8b Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents: 5293
diff changeset
   538
    - just invoke the diff for a single file in the working dir
e668fd796b8b Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents: 5293
diff changeset
   539
    '''
7758
e81e6c996e99 extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents: 7599
diff changeset
   540
44808
aac816f584ad diff: use cmdutil.check_at_most_one_arg() for checking --rev/--change
Martin von Zweigbergk <martinvonz@google.com>
parents: 43790
diff changeset
   541
    cmdutil.check_at_most_one_arg(opts, b'rev', b'change')
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   542
    revs = opts.get(b'rev')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   543
    change = opts.get(b'change')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   544
    do3way = b'$parent2' in cmdline
7758
e81e6c996e99 extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents: 7599
diff changeset
   545
44808
aac816f584ad diff: use cmdutil.check_at_most_one_arg() for checking --rev/--change
Martin von Zweigbergk <martinvonz@google.com>
parents: 43790
diff changeset
   546
    if change:
37253
6089ef933ab5 extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
   547
        ctx2 = scmutil.revsingle(repo, change, None)
6089ef933ab5 extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
   548
        ctx1a, ctx1b = ctx2.p1(), ctx2.p2()
7758
e81e6c996e99 extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents: 7599
diff changeset
   549
    else:
37253
6089ef933ab5 extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
   550
        ctx1a, ctx2 = scmutil.revpair(repo, revs)
9512
e7bde4680eec extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents: 9467
diff changeset
   551
        if not revs:
37253
6089ef933ab5 extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
   552
            ctx1b = repo[None].p2()
9512
e7bde4680eec extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents: 9467
diff changeset
   553
        else:
37253
6089ef933ab5 extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
   554
            ctx1b = repo[nullid]
6089ef933ab5 extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
   555
6089ef933ab5 extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
   556
    node1a = ctx1a.node()
6089ef933ab5 extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
   557
    node1b = ctx1b.node()
6089ef933ab5 extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
   558
    node2 = ctx2.node()
9512
e7bde4680eec extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents: 9467
diff changeset
   559
e7bde4680eec extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents: 9467
diff changeset
   560
    # Disable 3-way merge if there is only one parent
e7bde4680eec extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents: 9467
diff changeset
   561
    if do3way:
e7bde4680eec extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents: 9467
diff changeset
   562
        if node1b == nullid:
e7bde4680eec extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents: 9467
diff changeset
   563
            do3way = False
7758
e81e6c996e99 extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents: 7599
diff changeset
   564
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14327
diff changeset
   565
    matcher = scmutil.match(repo[node2], pats, opts)
26227
611ba118ebfc extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents: 25876
diff changeset
   566
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   567
    if opts.get(b'patch'):
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   568
        if opts.get(b'subrepos'):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   569
            raise error.Abort(_(b'--patch cannot be used with --subrepos'))
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   570
        if opts.get(b'per_file'):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   571
            raise error.Abort(_(b'--patch cannot be used with --per-file'))
26228
0fd20a71abdb extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents: 26227
diff changeset
   572
        if node2 is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   573
            raise error.Abort(_(b'--patch requires two revisions'))
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   574
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   575
    tmproot = pycompat.mkdtemp(prefix=b'extdiff.')
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   576
    try:
45126
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   577
        if opts.get(b'patch'):
45128
d23881b17388 extdiff: remove unrequired do3way argument to diffpatch()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45127
diff changeset
   578
            return diffpatch(ui, repo, node1a, node2, tmproot, matcher, cmdline)
45126
48c38018bd77 extdiff: refactor logic which does diff of patches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44867
diff changeset
   579
45127
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   580
        return diffrevs(
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   581
            ui,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   582
            repo,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   583
            node1a,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   584
            node1b,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   585
            node2,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   586
            matcher,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   587
            tmproot,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   588
            cmdline,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   589
            do3way,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   590
            guitool,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   591
            opts,
da2e69a278df extdiff: refactor logic to diff revs of versions of files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45126
diff changeset
   592
        )
5143
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5137
diff changeset
   593
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   594
    finally:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   595
        ui.note(_(b'cleaning up temp directory\n'))
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   596
        shutil.rmtree(tmproot)
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   597
27680
c750245c6b85 extdiff: factor out list of common options
Yuya Nishihara <yuya@tcha.org>
parents: 26587
diff changeset
   598
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   599
extdiffopts = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   600
    [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   601
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   602
            b'o',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   603
            b'option',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   604
            [],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   605
            _(b'pass option to comparison program'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   606
            _(b'OPT'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   607
        ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   608
        (b'r', b'rev', [], _(b'revision'), _(b'REV')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   609
        (b'c', b'change', b'', _(b'change made by revision'), _(b'REV')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   610
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   611
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   612
            b'per-file',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   613
            False,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   614
            _(b'compare each file instead of revision snapshots'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   615
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   616
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   617
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   618
            b'confirm',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   619
            False,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   620
            _(b'prompt user before each external program invocation'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   621
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   622
        (b'', b'patch', None, _(b'compare patches for two revisions')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   623
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   624
    + cmdutil.walkopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   625
    + cmdutil.subrepoopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   626
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   627
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   628
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   629
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   630
    b'extdiff',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   631
    [(b'p', b'program', b'', _(b'comparison program to run'), _(b'CMD')),]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   632
    + extdiffopts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   633
    _(b'hg extdiff [OPT]... [FILE]...'),
40293
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38165
diff changeset
   634
    helpcategory=command.CATEGORY_FILE_CONTENTS,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   635
    inferrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   636
)
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   637
def extdiff(ui, repo, *pats, **opts):
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   638
    '''use external program to diff repository (or selected files)
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   639
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   640
    Show differences between revisions for the specified files, using
7983
7b813bdbd5d0 Change double spaces to single spaces in help texts.
Martin Geisler <mg@daimi.au.dk>
parents: 7758
diff changeset
   641
    an external program. The default program used is diff, with
2906
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2903
diff changeset
   642
    default options "-Npru".
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2903
diff changeset
   643
8076
5ec526c1a32f help texts: write command line switches as -a/--abc
Martin Geisler <mg@lazybytes.net>
parents: 8066
diff changeset
   644
    To select a different program, use the -p/--program option. The
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   645
    program will be passed the names of two directories to compare,
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   646
    unless the --per-file option is specified (see below). To pass
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   647
    additional options to the program, use -o/--option. These will be
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   648
    passed before the names of the directories or files to compare.
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   649
7990
cdb848e8c4b5 extdiff: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
   650
    When two revision arguments are given, then changes are shown
cdb848e8c4b5 extdiff: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
   651
    between those revisions. If only one revision is specified then
cdb848e8c4b5 extdiff: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
   652
    that revision is compared to the working directory, and, when no
cdb848e8c4b5 extdiff: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
   653
    revisions are specified, the working directory files are compared
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   654
    to its parent.
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   655
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   656
    The --per-file option runs the external program repeatedly on each
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   657
    file to diff, instead of once on two directories. By default,
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   658
    this happens one by one, where the next file diff is open in the
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   659
    external program only once the previous external program (for the
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   660
    previous file diff) has exited. If the external program has a
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   661
    graphical interface, it can open all the file diffs at once instead
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   662
    of one by one. See :hg:`help -e extdiff` for information about how
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   663
    to tell Mercurial that a given program has a graphical interface.
41487
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   664
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   665
    The --confirm option will prompt the user before each invocation of
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   666
    the external program. It is ignored if --per-file isn't specified.
fa471151d269 extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents: 41196
diff changeset
   667
    '''
34976
a8bc191fee5a py3: handle keyword arguments in hgext/extdiff.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34778
diff changeset
   668
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   669
    program = opts.get(b'program')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   670
    option = opts.get(b'option')
9519
0d3c1aa9d5de extdiff: fix defaulting to "diff" if no --program is given
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8934
diff changeset
   671
    if not program:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   672
        program = b'diff'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   673
        option = option or [b'-Npru']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   674
    cmdline = b' '.join(map(procutil.shellquote, [program] + option))
23680
4075f2f8ea53 extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23270
diff changeset
   675
    return dodiff(ui, repo, cmdline, pats, opts)
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   676
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   677
29721
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   678
class savedcmd(object):
29723
91b2f2176395 extdiff: isolate path variable of saved command to independent paragraph
Yuya Nishihara <yuya@tcha.org>
parents: 29722
diff changeset
   679
    """use external program to diff repository (or selected files)
29721
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   680
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   681
    Show differences between revisions for the specified files, using
29723
91b2f2176395 extdiff: isolate path variable of saved command to independent paragraph
Yuya Nishihara <yuya@tcha.org>
parents: 29722
diff changeset
   682
    the following program::
91b2f2176395 extdiff: isolate path variable of saved command to independent paragraph
Yuya Nishihara <yuya@tcha.org>
parents: 29722
diff changeset
   683
91b2f2176395 extdiff: isolate path variable of saved command to independent paragraph
Yuya Nishihara <yuya@tcha.org>
parents: 29722
diff changeset
   684
        %(path)s
29721
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   685
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   686
    When two revision arguments are given, then changes are shown
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   687
    between those revisions. If only one revision is specified then
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   688
    that revision is compared to the working directory, and, when no
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   689
    revisions are specified, the working directory files are compared
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   690
    to its parent.
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   691
    """
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   692
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   693
    def __init__(self, path, cmdline, isgui):
29721
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   694
        # We can't pass non-ASCII through docstrings (and path is
40806
151aec6494a8 extdiff: avoid double backslashes in the displayed tool path on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40407
diff changeset
   695
        # in an unknown encoding anyway), but avoid double separators on
151aec6494a8 extdiff: avoid double backslashes in the displayed tool path on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40407
diff changeset
   696
        # Windows
151aec6494a8 extdiff: avoid double backslashes in the displayed tool path on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40407
diff changeset
   697
        docpath = stringutil.escapestr(path).replace(b'\\\\', b'\\')
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   698
        self.__doc__ %= {'path': pycompat.sysstr(stringutil.uirepr(docpath))}
29721
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   699
        self._cmdline = cmdline
41584
a4cd77a425a3 extdiff: support tools that can be run simultaneously
Ludovic Chabant <ludovic@chabant.com>
parents: 41487
diff changeset
   700
        self._isgui = isgui
29721
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   701
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   702
    def __call__(self, ui, repo, *pats, **opts):
34976
a8bc191fee5a py3: handle keyword arguments in hgext/extdiff.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34778
diff changeset
   703
        opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   704
        options = b' '.join(map(procutil.shellquote, opts[b'option']))
29721
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   705
        if options:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   706
            options = b' ' + options
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   707
        return dodiff(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   708
            ui, repo, self._cmdline + options, pats, opts, guitool=self._isgui
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   709
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   710
29721
479076db51be extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents: 29630
diff changeset
   711
45410
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   712
def _gettooldetails(ui, cmd, path):
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   713
    """
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   714
    returns following things for a
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   715
    ```
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   716
    [extdiff]
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   717
    <cmd> = <path>
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   718
    ```
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   719
    entry:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   720
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   721
    cmd: command/tool name
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   722
    path: path to the tool
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   723
    cmdline: the command which should be run
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   724
    isgui: whether the tool uses GUI or not
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   725
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   726
    Reads all external tools related configs, whether it be extdiff section,
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   727
    diff-tools or merge-tools section, or its specified in an old format or
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   728
    the latest format.
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   729
    """
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   730
    path = util.expandpath(path)
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   731
    if cmd.startswith(b'cmd.'):
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   732
        cmd = cmd[4:]
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   733
        if not path:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   734
            path = procutil.findexe(cmd)
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   735
            if path is None:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   736
                path = filemerge.findexternaltool(ui, cmd) or cmd
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   737
        diffopts = ui.config(b'extdiff', b'opts.' + cmd)
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   738
        cmdline = procutil.shellquote(path)
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   739
        if diffopts:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   740
            cmdline += b' ' + diffopts
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   741
        isgui = ui.configbool(b'extdiff', b'gui.' + cmd)
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   742
    else:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   743
        if path:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   744
            # case "cmd = path opts"
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   745
            cmdline = path
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   746
            diffopts = len(pycompat.shlexsplit(cmdline)) > 1
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   747
        else:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   748
            # case "cmd ="
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   749
            path = procutil.findexe(cmd)
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   750
            if path is None:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   751
                path = filemerge.findexternaltool(ui, cmd) or cmd
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   752
            cmdline = procutil.shellquote(path)
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   753
            diffopts = False
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   754
        isgui = ui.configbool(b'extdiff', b'gui.' + cmd)
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   755
    # look for diff arguments in [diff-tools] then [merge-tools]
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   756
    if not diffopts:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   757
        key = cmd + b'.diffargs'
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   758
        for section in (b'diff-tools', b'merge-tools'):
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   759
            args = ui.config(section, key)
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   760
            if args:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   761
                cmdline += b' ' + args
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   762
                if isgui is None:
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   763
                    isgui = ui.configbool(section, cmd + b'.gui') or False
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   764
                break
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   765
    return cmd, path, cmdline, isgui
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   766
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   767
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   768
def uisetup(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   769
    for cmd, path in ui.configitems(b'extdiff'):
45409
a28da102fd36 extdiff: reorder an if-else conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45401
diff changeset
   770
        if cmd.startswith(b'opts.') or cmd.startswith(b'gui.'):
a28da102fd36 extdiff: reorder an if-else conditional
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45401
diff changeset
   771
            continue
45410
2d08dcf8fd9e extdiff: refactor cmdline and gui calculation login in a separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45409
diff changeset
   772
        cmd, path, cmdline, isgui = _gettooldetails(ui, cmd, path)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   773
        command(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   774
            cmd,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   775
            extdiffopts[:],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   776
            _(b'hg %s [OPTION]... [FILE]...') % cmd,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   777
            helpcategory=command.CATEGORY_FILE_CONTENTS,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   778
            inferrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   779
        )(savedcmd(path, cmdline, isgui))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41584
diff changeset
   780
29722
14c3afcb1c26 extdiff: export __doc__ of saved command for translation
Yuya Nishihara <yuya@tcha.org>
parents: 29721
diff changeset
   781
14c3afcb1c26 extdiff: export __doc__ of saved command for translation
Yuya Nishihara <yuya@tcha.org>
parents: 29721
diff changeset
   782
# tell hggettext to extract docstrings from these functions:
14c3afcb1c26 extdiff: export __doc__ of saved command for translation
Yuya Nishihara <yuya@tcha.org>
parents: 29721
diff changeset
   783
i18nfunctions = [savedcmd]