Mercurial > hg
annotate mercurial/shelve.py @ 45892:06b64fabf91c
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
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 02 Nov 2020 11:03:56 +0100 |
parents | 073bb7563931 |
children | 89a2afe31e82 |
rev | line source |
---|---|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1 # shelve.py - save/restore working directory state |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
2 # |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
3 # Copyright 2013 Facebook, Inc. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
4 # |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
7 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
8 """save and restore changes to the working directory |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
9 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
10 The "hg shelve" command saves changes made to the working directory |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
11 and reverts those changes, resetting the working directory to a clean |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
12 state. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
13 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
14 Later on, the "hg unshelve" command restores the changes saved by "hg |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
15 shelve". Changes can be restored even after updating to a different |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
16 parent, in which case Mercurial's merge machinery will resolve any |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
17 conflicts if necessary. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
18 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
19 You can have more than one shelved change outstanding at a time; each |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
20 shelved change has a distinct name. For details, see the help for "hg |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
21 shelve". |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
22 """ |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
23 from __future__ import absolute_import |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
24 |
25113
0ca8410ea345
util: drop alias for collections.deque
Martin von Zweigbergk <martinvonz@google.com>
parents:
25104
diff
changeset
|
25 import collections |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
26 import errno |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
27 import itertools |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36607
diff
changeset
|
28 import stat |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28862
diff
changeset
|
29 |
42541
3de4f17f4824
shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42540
diff
changeset
|
30 from .i18n import _ |
43085
eef9a2d67051
py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
31 from .pycompat import open |
42541
3de4f17f4824
shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42540
diff
changeset
|
32 from . import ( |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
33 bookmarks, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
34 bundle2, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
35 bundlerepo, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
36 changegroup, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
37 cmdutil, |
34097
f7d41b85bbf6
changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents:
33440
diff
changeset
|
38 discovery, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
39 error, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
40 exchange, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
41 hg, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
42 lock as lockmod, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
43 mdiff, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
44 merge, |
44856
b7808443ed6a
mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents:
44595
diff
changeset
|
45 mergestate as mergestatemod, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
46 node as nodemod, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
47 patch, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
48 phases, |
35005
aad6b9fdfc75
py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34496
diff
changeset
|
49 pycompat, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
50 repair, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
51 scmutil, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
52 templatefilters, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
53 util, |
31244
636f55b9ba23
vfs: use 'vfs' module directly in 'hgext.shelve'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31096
diff
changeset
|
54 vfs as vfsmod, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
55 ) |
42541
3de4f17f4824
shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42540
diff
changeset
|
56 from .utils import ( |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
57 dateutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
58 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
59 ) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
60 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
61 backupdir = b'shelve-backup' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 shelvedir = b'shelved' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
63 shelvefileextensions = [b'hg', b'patch', b'shelve'] |
30554
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30542
diff
changeset
|
64 # universal extension is present in all types of shelves |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
65 patchextension = b'patch' |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
66 |
30381
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
67 # we never need the user, so we use a |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
68 # generic user for all shelve operations |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
69 shelveuser = b'shelve@localhost' |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
70 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
71 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
72 class shelvedfile(object): |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
73 """Helper for the file storing a single shelve |
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
74 |
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
75 Handles common functions on shelve files (.hg/.patch) using |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
76 the vfs layer""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
77 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
78 def __init__(self, repo, name, filetype=None): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
79 self.repo = repo |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
80 self.name = name |
31335
3acc7af5859c
shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31312
diff
changeset
|
81 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
3acc7af5859c
shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31312
diff
changeset
|
82 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) |
23895
cda18ded2c48
changegroup.writebundle: provide ui
Eric Sumner <ericsumner@fb.com>
parents:
23877
diff
changeset
|
83 self.ui = self.repo.ui |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
84 if filetype: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
85 self.fname = name + b'.' + filetype |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
86 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
87 self.fname = name |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
88 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
89 def exists(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
90 return self.vfs.exists(self.fname) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
91 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
92 def filename(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
93 return self.vfs.join(self.fname) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
94 |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
95 def backupfilename(self): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
96 def gennames(base): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
97 yield base |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 base, ext = base.rsplit(b'.', 1) |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
99 for i in itertools.count(1): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
100 yield b'%s-%d.%s' % (base, i, ext) |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
101 |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
102 name = self.backupvfs.join(self.fname) |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
103 for n in gennames(name): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
104 if not self.backupvfs.exists(n): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
105 return n |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
106 |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
107 def movetobackup(self): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
108 if not self.backupvfs.isdir(): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
109 self.backupvfs.makedir() |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
110 util.rename(self.filename(), self.backupfilename()) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
111 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
112 def stat(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
113 return self.vfs.stat(self.fname) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
114 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
115 def opener(self, mode=b'rb'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
116 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
117 return self.vfs(self.fname, mode) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25260
diff
changeset
|
118 except IOError as err: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
119 if err.errno != errno.ENOENT: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
120 raise |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
121 raise error.Abort(_(b"shelved change '%s' not found") % self.name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
122 |
41007
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40854
diff
changeset
|
123 def applybundle(self, tr): |
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
124 fp = self.opener() |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
125 try: |
39519
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
126 targetphase = phases.internal |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
127 if not phases.supportinternal(self.repo): |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
128 targetphase = phases.secret |
21064
4d9d490d7bbe
bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21063
diff
changeset
|
129 gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
130 pretip = self.repo[b'tip'] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
131 bundle2.applybundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
132 self.repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
133 gen, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
134 tr, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
135 source=b'unshelve', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
136 url=b'bundle:' + self.vfs.join(self.fname), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
137 targetphase=targetphase, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
138 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 shelvectx = self.repo[b'tip'] |
39889
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39888
diff
changeset
|
140 if pretip == shelvectx: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
141 shelverev = tr.changes[b'revduplicates'][-1] |
39889
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39888
diff
changeset
|
142 shelvectx = self.repo[shelverev] |
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39888
diff
changeset
|
143 return shelvectx |
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
144 finally: |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
145 fp.close() |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
146 |
22898
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
147 def bundlerepo(self): |
39601
84d6e9a2b104
shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39519
diff
changeset
|
148 path = self.vfs.join(self.fname) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
149 return bundlerepo.instance( |
43720
132470ee53fe
shelve: add the missing `create` parameter to the bundlerepo constructor
Matt Harbison <matt_harbison@yahoo.com>
parents:
43719
diff
changeset
|
150 self.repo.baseui, b'bundle://%s+%s' % (self.repo.root, path), False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
151 ) |
39601
84d6e9a2b104
shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39519
diff
changeset
|
152 |
26506
edecf059fda6
shelve: move changegroup generation inside writebundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26505
diff
changeset
|
153 def writebundle(self, bases, node): |
27931
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
154 cgversion = changegroup.safeversion(self.repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
155 if cgversion == b'01': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
156 btype = b'HG10BZ' |
27931
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
157 compression = None |
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
158 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
159 btype = b'HG20' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
160 compression = b'BZ' |
26507
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
161 |
39373
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39372
diff
changeset
|
162 repo = self.repo.unfiltered() |
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39372
diff
changeset
|
163 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
164 outgoing = discovery.outgoing( |
45144
c93dd9d9f1e6
discovery: change users of `outgoing.missingheads` to `outgoing.ancestorsof`
Manuel Jacob <me@manueljacob.de>
parents:
44856
diff
changeset
|
165 repo, missingroots=bases, ancestorsof=[node] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
166 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
167 cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve') |
34097
f7d41b85bbf6
changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents:
33440
diff
changeset
|
168 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
169 bundle2.writebundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
170 self.ui, cg, self.fname, btype, self.vfs, compression=compression |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
171 ) |
20983
2778616de7ce
shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20982
diff
changeset
|
172 |
39343
bab58b1d87c7
shelve: rename method for data write/read
Boris Feld <boris.feld@octobus.net>
parents:
39342
diff
changeset
|
173 def writeinfo(self, info): |
31554
7485e45807e4
shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents:
31543
diff
changeset
|
174 scmutil.simplekeyvaluefile(self.vfs, self.fname).write(info) |
7485e45807e4
shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents:
31543
diff
changeset
|
175 |
39343
bab58b1d87c7
shelve: rename method for data write/read
Boris Feld <boris.feld@octobus.net>
parents:
39342
diff
changeset
|
176 def readinfo(self): |
31554
7485e45807e4
shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents:
31543
diff
changeset
|
177 return scmutil.simplekeyvaluefile(self.vfs, self.fname).read() |
7485e45807e4
shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents:
31543
diff
changeset
|
178 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
179 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
180 class shelvedstate(object): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
181 """Handle persistence during unshelving operations. |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
182 |
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
183 Handles saving and restoring a shelved state. Ensures that different |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
184 versions of a shelved state are possible and handles them appropriately. |
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
185 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
186 |
32285
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
187 _version = 2 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
188 _filename = b'shelvedstate' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
189 _keep = b'keep' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
190 _nokeep = b'nokeep' |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
191 # colon is essential to differentiate from a real bookmark name |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
192 _noactivebook = b':no-active-bookmark' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
193 _interactive = b'interactive' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
194 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
195 @classmethod |
32285
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
196 def _verifyandtransform(cls, d): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
197 """Some basic shelvestate syntactic verification and transformation""" |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
198 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
199 d[b'originalwctx'] = nodemod.bin(d[b'originalwctx']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
200 d[b'pendingctx'] = nodemod.bin(d[b'pendingctx']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
201 d[b'parents'] = [nodemod.bin(h) for h in d[b'parents'].split(b' ')] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
202 d[b'nodestoremove'] = [ |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
203 nodemod.bin(h) for h in d[b'nodestoremove'].split(b' ') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
204 ] |
32284
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
205 except (ValueError, TypeError, KeyError) as err: |
36496
7af7443877da
py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36185
diff
changeset
|
206 raise error.CorruptedState(pycompat.bytestr(err)) |
32284
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
207 |
32285
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
208 @classmethod |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
209 def _getversion(cls, repo): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
210 """Read version information from shelvestate file""" |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
211 fp = repo.vfs(cls._filename) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
212 try: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
213 version = int(fp.readline().strip()) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
214 except ValueError as err: |
36496
7af7443877da
py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36185
diff
changeset
|
215 raise error.CorruptedState(pycompat.bytestr(err)) |
32285
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
216 finally: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
217 fp.close() |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
218 return version |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
219 |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
220 @classmethod |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
221 def _readold(cls, repo): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
222 """Read the old position-based version of a shelvestate file""" |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
223 # Order is important, because old shelvestate file uses it |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
224 # to detemine values of fields (i.g. name is on the second line, |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
225 # originalwctx is on the third and so forth). Please do not change. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
226 keys = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
227 b'version', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
228 b'name', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
229 b'originalwctx', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
230 b'pendingctx', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
231 b'parents', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
232 b'nodestoremove', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
233 b'branchtorestore', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
234 b'keep', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
235 b'activebook', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
236 ] |
32285
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
237 # this is executed only seldomly, so it is not a big deal |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
238 # that we open this file twice |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
239 fp = repo.vfs(cls._filename) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
240 d = {} |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
241 try: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
242 for key in keys: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
243 d[key] = fp.readline().strip() |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
244 finally: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
245 fp.close() |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
246 return d |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
247 |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
248 @classmethod |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
249 def load(cls, repo): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
250 version = cls._getversion(repo) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
251 if version < cls._version: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
252 d = cls._readold(repo) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
253 elif version == cls._version: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
254 d = scmutil.simplekeyvaluefile(repo.vfs, cls._filename).read( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
255 firstlinenonkeyval=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
256 ) |
32285
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
257 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
258 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
259 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
260 b'this version of shelve is incompatible ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
261 b'with the version used in this repo' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
262 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
263 ) |
32285
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
264 |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
265 cls._verifyandtransform(d) |
29536
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
266 try: |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
267 obj = cls() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
268 obj.name = d[b'name'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
269 obj.wctx = repo[d[b'originalwctx']] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
270 obj.pendingctx = repo[d[b'pendingctx']] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
271 obj.parents = d[b'parents'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
272 obj.nodestoremove = d[b'nodestoremove'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
273 obj.branchtorestore = d.get(b'branchtorestore', b'') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
274 obj.keep = d.get(b'keep') == cls._keep |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
275 obj.activebookmark = b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
276 if d.get(b'activebook', b'') != cls._noactivebook: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
277 obj.activebookmark = d.get(b'activebook', b'') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
278 obj.interactive = d.get(b'interactive') == cls._interactive |
32284
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
279 except (error.RepoLookupError, KeyError) as err: |
36496
7af7443877da
py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36185
diff
changeset
|
280 raise error.CorruptedState(pycompat.bytestr(err)) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
281 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
282 return obj |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
283 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
284 @classmethod |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
285 def save( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
286 cls, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
287 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
288 name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
289 originalwctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
290 pendingctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
291 nodestoremove, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
292 branchtorestore, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
293 keep=False, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
294 activebook=b'', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
295 interactive=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
296 ): |
32285
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
297 info = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
298 b"name": name, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
299 b"originalwctx": nodemod.hex(originalwctx.node()), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
300 b"pendingctx": nodemod.hex(pendingctx.node()), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
301 b"parents": b' '.join( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
302 [nodemod.hex(p) for p in repo.dirstate.parents()] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
303 ), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
304 b"nodestoremove": b' '.join( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
305 [nodemod.hex(n) for n in nodestoremove] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
306 ), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
307 b"branchtorestore": branchtorestore, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
308 b"keep": cls._keep if keep else cls._nokeep, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
309 b"activebook": activebook or cls._noactivebook, |
32285
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32284
diff
changeset
|
310 } |
42662
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42658
diff
changeset
|
311 if interactive: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
312 info[b'interactive'] = cls._interactive |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
313 scmutil.simplekeyvaluefile(repo.vfs, cls._filename).write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
314 info, firstline=(b"%d" % cls._version) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
315 ) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
316 |
19908
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
317 @classmethod |
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
318 def clear(cls, repo): |
31311
f59b6cf663a9
vfs: use repo.vfs.unlinkpath
Mads Kiilerich <mads@kiilerich.com>
parents:
31244
diff
changeset
|
319 repo.vfs.unlinkpath(cls._filename, ignoremissing=True) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
320 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
321 |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
322 def cleanupoldbackups(repo): |
31335
3acc7af5859c
shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31312
diff
changeset
|
323 vfs = vfsmod.vfs(repo.vfs.join(backupdir)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
324 maxbackups = repo.ui.configint(b'shelve', b'maxbackups') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
325 hgfiles = [f for f in vfs.listdir() if f.endswith(b'.' + patchextension)] |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36607
diff
changeset
|
326 hgfiles = sorted([(vfs.stat(f)[stat.ST_MTIME], f) for f in hgfiles]) |
40029
e2697acd9381
cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents:
39889
diff
changeset
|
327 if maxbackups > 0 and maxbackups < len(hgfiles): |
25774
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
328 bordermtime = hgfiles[-maxbackups][0] |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
329 else: |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
330 bordermtime = None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
331 for mtime, f in hgfiles[: len(hgfiles) - maxbackups]: |
25774
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
332 if mtime == bordermtime: |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
333 # keep it, because timestamp can't decide exact order of backups |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
334 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
335 base = f[: -(1 + len(patchextension))] |
30378
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
336 for ext in shelvefileextensions: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
337 vfs.tryunlink(base + b'.' + ext) |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
338 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
339 |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
340 def _backupactivebookmark(repo): |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
341 activebookmark = repo._activebookmark |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
342 if activebookmark: |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
343 bookmarks.deactivate(repo) |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
344 return activebookmark |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
345 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
346 |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
347 def _restoreactivebookmark(repo, mark): |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
348 if mark: |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
349 bookmarks.activate(repo, mark) |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
350 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
351 |
41007
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40854
diff
changeset
|
352 def _aborttransaction(repo, tr): |
26522
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
353 '''Abort current transaction for shelve/unshelve, but keep dirstate |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
354 ''' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
355 dirstatebackupname = b'dirstate.shelve' |
38869
ad24b581e4d9
narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents:
38783
diff
changeset
|
356 repo.dirstate.savebackup(tr, dirstatebackupname) |
29270
48b38b16a8f8
shelve: use backup functions instead of manually copying dirstate
Mateusz Kwapich <mitrandir@fb.com>
parents:
29205
diff
changeset
|
357 tr.abort() |
38869
ad24b581e4d9
narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents:
38783
diff
changeset
|
358 repo.dirstate.restorebackup(None, dirstatebackupname) |
26522
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
359 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
360 |
30379
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
361 def getshelvename(repo, parent, opts): |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
362 """Decide on the name this shelve is going to have""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
363 |
30379
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
364 def gennames(): |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
365 yield label |
32968
4107eb8a5648
shelve: allow unlimited shelved changes per name
Jun Wu <quark@fb.com>
parents:
32930
diff
changeset
|
366 for i in itertools.count(1): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
367 yield b'%s-%02d' % (label, i) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
368 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
369 name = opts.get(b'name') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
370 label = repo._activebookmark or parent.branch() or b'default' |
30379
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
371 # slashes aren't allowed in filenames, therefore we rename it |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
372 label = label.replace(b'/', b'_') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
373 label = label.replace(b'\\', b'_') |
30671
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30554
diff
changeset
|
374 # filenames must not start with '.' as it should not be hidden |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
375 if label.startswith(b'.'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
376 label = label.replace(b'.', b'_', 1) |
30379
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
377 |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
378 if name: |
30554
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30542
diff
changeset
|
379 if shelvedfile(repo, name, patchextension).exists(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
380 e = _(b"a shelved change named '%s' already exists") % name |
30379
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
381 raise error.Abort(e) |
30671
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30554
diff
changeset
|
382 |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30554
diff
changeset
|
383 # ensure we are not creating a subdirectory or a hidden file |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
384 if b'/' in name or b'\\' in name: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
385 raise error.Abort( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
386 _(b'shelved change names can not contain slashes') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
387 ) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
388 if name.startswith(b'.'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
389 raise error.Abort(_(b"shelved change names can not start with '.'")) |
30671
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30554
diff
changeset
|
390 |
30379
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
391 else: |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
392 for n in gennames(): |
30554
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30542
diff
changeset
|
393 if not shelvedfile(repo, n, patchextension).exists(): |
30379
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
394 name = n |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
395 break |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
396 |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
397 return name |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
398 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
399 |
30380
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
400 def mutableancestors(ctx): |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
401 """return all mutable ancestors for ctx (included) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
402 |
30380
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
403 Much faster than the revset ancestors(ctx) & draft()""" |
32291
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32285
diff
changeset
|
404 seen = {nodemod.nullrev} |
30380
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
405 visit = collections.deque() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
406 visit.append(ctx) |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
407 while visit: |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
408 ctx = visit.popleft() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
409 yield ctx.node() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
410 for parent in ctx.parents(): |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
411 rev = parent.rev() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
412 if rev not in seen: |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
413 seen.add(rev) |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
414 if parent.mutable(): |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
415 visit.append(parent) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
416 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
417 |
30381
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
418 def getcommitfunc(extra, interactive, editor=False): |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
419 def commitfunc(ui, repo, message, match, opts): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
420 hasmq = util.safehasattr(repo, b'mq') |
30381
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
421 if hasmq: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
422 saved, repo.mq.checkapplied = repo.mq.checkapplied, False |
39519
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
423 |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
424 targetphase = phases.internal |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
425 if not phases.supportinternal(repo): |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
426 targetphase = phases.secret |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
427 overrides = {(b'phases', b'new-commit'): targetphase} |
30381
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
428 try: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
429 editor_ = False |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
430 if editor: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
431 editor_ = cmdutil.getcommiteditor( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
432 editform=b'shelve.shelve', **pycompat.strkwargs(opts) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
433 ) |
31462 | 434 with repo.ui.configoverride(overrides): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
435 return repo.commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
436 message, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
437 shelveuser, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
438 opts.get(b'date'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
439 match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
440 editor=editor_, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
441 extra=extra, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
442 ) |
30381
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
443 finally: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
444 if hasmq: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
445 repo.mq.checkapplied = saved |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
446 |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
447 def interactivecommitfunc(ui, repo, *pats, **opts): |
35005
aad6b9fdfc75
py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34496
diff
changeset
|
448 opts = pycompat.byteskwargs(opts) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
449 match = scmutil.match(repo[b'.'], pats, {}) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
450 message = opts[b'message'] |
30381
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
451 return commitfunc(ui, repo, message, match, opts) |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
452 |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
453 return interactivecommitfunc if interactive else commitfunc |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
454 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
455 |
30382
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30381
diff
changeset
|
456 def _nothingtoshelvemessaging(ui, repo, pats, opts): |
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30381
diff
changeset
|
457 stat = repo.status(match=scmutil.match(repo[None], pats, opts)) |
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30381
diff
changeset
|
458 if stat.deleted: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
459 ui.status( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43085
diff
changeset
|
460 _(b"nothing changed (%d missing files, see 'hg status')\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
461 % len(stat.deleted) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
462 ) |
30382
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30381
diff
changeset
|
463 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
464 ui.status(_(b"nothing changed\n")) |
30382
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30381
diff
changeset
|
465 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
466 |
42012
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
467 def _shelvecreatedcommit(repo, node, name, match): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
468 info = {b'node': nodemod.hex(node)} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
469 shelvedfile(repo, name, b'shelve').writeinfo(info) |
30383
455f7856db20
shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30382
diff
changeset
|
470 bases = list(mutableancestors(repo[node])) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
471 shelvedfile(repo, name, b'hg').writebundle(bases, node) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
472 with shelvedfile(repo, name, patchextension).opener(b'wb') as fp: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
473 cmdutil.exportfile( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
474 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
475 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
476 |
30383
455f7856db20
shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30382
diff
changeset
|
477 |
30384
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30383
diff
changeset
|
478 def _includeunknownfiles(repo, pats, opts, extra): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
479 s = repo.status(match=scmutil.match(repo[None], pats, opts), unknown=True) |
30384
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30383
diff
changeset
|
480 if s.unknown: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
481 extra[b'shelve_unknown'] = b'\0'.join(s.unknown) |
30384
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30383
diff
changeset
|
482 repo[None].add(s.unknown) |
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30383
diff
changeset
|
483 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
484 |
41007
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40854
diff
changeset
|
485 def _finishshelve(repo, tr): |
39744
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39601
diff
changeset
|
486 if phases.supportinternal(repo): |
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39601
diff
changeset
|
487 tr.close() |
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39601
diff
changeset
|
488 else: |
41007
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40854
diff
changeset
|
489 _aborttransaction(repo, tr) |
30385
b573d7ca31c4
shelve: move shelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30384
diff
changeset
|
490 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
491 |
39342
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38869
diff
changeset
|
492 def createcmd(ui, repo, pats, opts): |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38869
diff
changeset
|
493 """subcommand that creates a new shelve""" |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38869
diff
changeset
|
494 with repo.wlock(): |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38869
diff
changeset
|
495 cmdutil.checkunfinished(repo) |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38869
diff
changeset
|
496 return _docreatecmd(ui, repo, pats, opts) |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38869
diff
changeset
|
497 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
498 |
30380
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30379
diff
changeset
|
499 def _docreatecmd(ui, repo, pats, opts): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
500 wctx = repo[None] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
501 parents = wctx.parents() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
502 parent = parents[0] |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
503 origbranch = wctx.branch() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
504 |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
505 if parent.node() != nodemod.nullid: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
506 desc = b"changes to: %s" % parent.description().split(b'\n', 1)[0] |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
507 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
508 desc = b'(changes in empty repository)' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
509 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
510 if not opts.get(b'message'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
511 opts[b'message'] = desc |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
512 |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
513 lock = tr = activebookmark = None |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
514 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
515 lock = repo.lock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
516 |
19951
d51c4d85ec23
spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents:
19943
diff
changeset
|
517 # use an uncommitted transaction to generate the bundle to avoid |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
518 # pull races. ensure we don't print the abort message to stderr. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
519 tr = repo.transaction(b'shelve', report=lambda x: None) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
520 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
521 interactive = opts.get(b'interactive', False) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
522 includeunknown = opts.get(b'unknown', False) and not opts.get( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
523 b'addremove', False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
524 ) |
27908
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
525 |
30379
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30378
diff
changeset
|
526 name = getshelvename(repo, parent, opts) |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
527 activebookmark = _backupactivebookmark(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
528 extra = {b'internal': b'shelve'} |
27908
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
529 if includeunknown: |
30384
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30383
diff
changeset
|
530 _includeunknownfiles(repo, pats, opts, extra) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
531 |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
532 if _iswctxonnewbranch(repo) and not _isbareshelve(pats, opts): |
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
533 # In non-bare shelve we don't store newly created branch |
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
534 # at bundled commit |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
535 repo.dirstate.setbranch(repo[b'.'].branch()) |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
536 |
30381
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30380
diff
changeset
|
537 commitfunc = getcommitfunc(extra, interactive, editor=True) |
24478
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
538 if not interactive: |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
539 node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
540 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
541 node = cmdutil.dorecord( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
542 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
543 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
544 commitfunc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
545 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
546 False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
547 cmdutil.recordfilter, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
548 *pats, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
549 **pycompat.strkwargs(opts) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
550 ) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
551 if not node: |
30382
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30381
diff
changeset
|
552 _nothingtoshelvemessaging(ui, repo, pats, opts) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
553 return 1 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
554 |
42012
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
555 # Create a matcher so that prefetch doesn't attempt to fetch |
42013
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
556 # the entire repository pointlessly, and as an optimisation |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
557 # for movedirstate, if needed. |
42012
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
558 match = scmutil.matchfiles(repo, repo[node].files()) |
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
559 _shelvecreatedcommit(repo, node, name, match) |
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
560 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
561 ui.status(_(b'shelved as %s\n') % name) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
562 if opts[b'keep']: |
42013
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
563 with repo.dirstate.parentchange(): |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
564 scmutil.movedirstate(repo, parent, match) |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
565 else: |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
566 hg.update(repo, parent.node()) |
45860
073bb7563931
shelve: clear merge state after partial shelve
Martin von Zweigbergk <martinvonz@google.com>
parents:
45577
diff
changeset
|
567 ms = mergestatemod.mergestate.read(repo) |
073bb7563931
shelve: clear merge state after partial shelve
Martin von Zweigbergk <martinvonz@google.com>
parents:
45577
diff
changeset
|
568 if not ms.unresolvedcount(): |
073bb7563931
shelve: clear merge state after partial shelve
Martin von Zweigbergk <martinvonz@google.com>
parents:
45577
diff
changeset
|
569 ms.reset() |
073bb7563931
shelve: clear merge state after partial shelve
Martin von Zweigbergk <martinvonz@google.com>
parents:
45577
diff
changeset
|
570 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
571 if origbranch != repo[b'.'].branch() and not _isbareshelve(pats, opts): |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
572 repo.dirstate.setbranch(origbranch) |
26523
1d23bf6cd90a
shelve: restore shelved dirstate explicitly after aborting transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26522
diff
changeset
|
573 |
41007
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40854
diff
changeset
|
574 _finishshelve(repo, tr) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
575 finally: |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
576 _restoreactivebookmark(repo, activebookmark) |
27197
6df3ec5bb813
shelve: widen wlock scope of shelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27092
diff
changeset
|
577 lockmod.release(tr, lock) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
578 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
579 |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
580 def _isbareshelve(pats, opts): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
581 return ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
582 not pats |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
583 and not opts.get(b'interactive', False) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
584 and not opts.get(b'include', False) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
585 and not opts.get(b'exclude', False) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
586 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
587 |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
588 |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
589 def _iswctxonnewbranch(repo): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
590 return repo[None].branch() != repo[b'.'].branch() |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
591 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
592 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
593 def cleanupcmd(ui, repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
594 """subcommand that deletes all shelves""" |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
595 |
27835
c448d7e00bf9
with: use context manager for wlock in shelve cleanupcmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27834
diff
changeset
|
596 with repo.wlock(): |
28862
39130afcce60
shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents:
28666
diff
changeset
|
597 for (name, _type) in repo.vfs.readdir(shelvedir): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
598 suffix = name.rsplit(b'.', 1)[-1] |
30378
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
599 if suffix in shelvefileextensions: |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
600 shelvedfile(repo, name).movetobackup() |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
601 cleanupoldbackups(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
602 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
603 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
604 def deletecmd(ui, repo, pats): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
605 """subcommand that deletes a specific shelve""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
606 if not pats: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
607 raise error.Abort(_(b'no shelved changes specified!')) |
27836
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
608 with repo.wlock(): |
43719
cb23d9e3e21f
shelve: fix a missing variable in the exception handler for delete
Matt Harbison <matt_harbison@yahoo.com>
parents:
43117
diff
changeset
|
609 for name in pats: |
cb23d9e3e21f
shelve: fix a missing variable in the exception handler for delete
Matt Harbison <matt_harbison@yahoo.com>
parents:
43117
diff
changeset
|
610 try: |
30378
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
611 for suffix in shelvefileextensions: |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
612 shfile = shelvedfile(repo, name, suffix) |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
613 # patch file is necessary, as it should |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
614 # be present for any kind of shelve, |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
615 # but the .hg file is optional as in future we |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
616 # will add obsolete shelve with does not create a |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
617 # bundle |
30554
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30542
diff
changeset
|
618 if shfile.exists() or suffix == patchextension: |
30378
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
619 shfile.movetobackup() |
43719
cb23d9e3e21f
shelve: fix a missing variable in the exception handler for delete
Matt Harbison <matt_harbison@yahoo.com>
parents:
43117
diff
changeset
|
620 except OSError as err: |
cb23d9e3e21f
shelve: fix a missing variable in the exception handler for delete
Matt Harbison <matt_harbison@yahoo.com>
parents:
43117
diff
changeset
|
621 if err.errno != errno.ENOENT: |
cb23d9e3e21f
shelve: fix a missing variable in the exception handler for delete
Matt Harbison <matt_harbison@yahoo.com>
parents:
43117
diff
changeset
|
622 raise |
cb23d9e3e21f
shelve: fix a missing variable in the exception handler for delete
Matt Harbison <matt_harbison@yahoo.com>
parents:
43117
diff
changeset
|
623 raise error.Abort(_(b"shelved change '%s' not found") % name) |
27836
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
624 cleanupoldbackups(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
625 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
626 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
627 def listshelves(repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
628 """return all shelves in repo as list of (time, filename)""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
629 try: |
28862
39130afcce60
shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents:
28666
diff
changeset
|
630 names = repo.vfs.readdir(shelvedir) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25260
diff
changeset
|
631 except OSError as err: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
632 if err.errno != errno.ENOENT: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
633 raise |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
634 return [] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
635 info = [] |
22199
b3e51675f98e
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents:
22184
diff
changeset
|
636 for (name, _type) in names: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
637 pfx, sfx = name.rsplit(b'.', 1) |
30554
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30542
diff
changeset
|
638 if not pfx or sfx != patchextension: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
639 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
640 st = shelvedfile(repo, name).stat() |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36607
diff
changeset
|
641 info.append((st[stat.ST_MTIME], shelvedfile(repo, pfx).filename())) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
642 return sorted(info, reverse=True) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
643 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
644 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
645 def listcmd(ui, repo, pats, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
646 """subcommand that displays the list of shelves""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
647 pats = set(pats) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
648 width = 80 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
649 if not ui.plain(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
650 width = ui.termwidth() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
651 namelabel = b'shelve.newest' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
652 ui.pager(b'shelve') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
653 for mtime, name in listshelves(repo): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
654 sname = util.split(name)[1] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
655 if pats and sname not in pats: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
656 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
657 ui.write(sname, label=namelabel) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
658 namelabel = b'shelve.name' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
659 if ui.quiet: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
660 ui.write(b'\n') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
661 continue |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
662 ui.write(b' ' * (16 - len(sname))) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
663 used = 16 |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36496
diff
changeset
|
664 date = dateutil.makedate(mtime) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
665 age = b'(%s)' % templatefilters.age(date, abbrev=True) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
666 ui.write(age, label=b'shelve.age') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
667 ui.write(b' ' * (12 - len(age))) |
19855
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
668 used += 12 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
669 with open(name + b'.' + patchextension, b'rb') as fp: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
670 while True: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
671 line = fp.readline() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
672 if not line: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
673 break |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
674 if not line.startswith(b'#'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
675 desc = line.rstrip() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
676 if ui.formatted(): |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
677 desc = stringutil.ellipsis(desc, width - used) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
678 ui.write(desc) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
679 break |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
680 ui.write(b'\n') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
681 if not (opts[b'patch'] or opts[b'stat']): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
682 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
683 difflines = fp.readlines() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
684 if opts[b'patch']: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
685 for chunk, label in patch.difflabel(iter, difflines): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
686 ui.write(chunk, label=label) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
687 if opts[b'stat']: |
30407
e1677cc29da6
patch: remove unused git parameter from patch.diffstat()
Henning Schild <henning@hennsch.de>
parents:
30385
diff
changeset
|
688 for chunk, label in patch.diffstatui(difflines, width=width): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
689 ui.write(chunk, label=label) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
690 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
691 |
38715
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
692 def patchcmds(ui, repo, pats, opts): |
30823
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30671
diff
changeset
|
693 """subcommand that displays shelves""" |
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30671
diff
changeset
|
694 if len(pats) == 0: |
38715
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
695 shelves = listshelves(repo) |
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
696 if not shelves: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
697 raise error.Abort(_(b"there are no shelves to show")) |
38715
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
698 mtime, name = shelves[0] |
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
699 sname = util.split(name)[1] |
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
700 pats = [sname] |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
701 |
30823
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30671
diff
changeset
|
702 for shelfname in pats: |
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30671
diff
changeset
|
703 if not shelvedfile(repo, shelfname, patchextension).exists(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
704 raise error.Abort(_(b"cannot find shelf %s") % shelfname) |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
705 |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
706 listcmd(ui, repo, pats, opts) |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
707 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
708 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
709 def checkparents(repo, state): |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
710 """check parent while resuming an unshelve""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
711 if state.parents != repo.dirstate.parents(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
712 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43085
diff
changeset
|
713 _(b'working directory parents do not match unshelve state') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
714 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
715 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
716 |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
717 def _loadshelvedstate(ui, repo, opts): |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
718 try: |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
719 state = shelvedstate.load(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
720 if opts.get(b'keep') is None: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
721 opts[b'keep'] = state.keep |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
722 except IOError as err: |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
723 if err.errno != errno.ENOENT: |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
724 raise |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
725 cmdutil.wrongtooltocontinue(repo, _(b'unshelve')) |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
726 except error.CorruptedState as err: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
727 ui.debug(pycompat.bytestr(err) + b'\n') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
728 if opts.get(b'continue'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
729 msg = _(b'corrupted shelved state file') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
730 hint = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
731 b'please run hg unshelve --abort to abort unshelve ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
732 b'operation' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
733 ) |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
734 raise error.Abort(msg, hint=hint) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
735 elif opts.get(b'abort'): |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
736 shelvedstate.clear(repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
737 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
738 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
739 b'could not read shelved state file, your ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
740 b'working copy may be in an unexpected state\n' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
741 b'please update to some commit\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
742 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
743 ) |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
744 return state |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
745 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
746 |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
747 def unshelveabort(ui, repo, state): |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
748 """subcommand that abort an in-progress unshelve""" |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
749 with repo.lock(): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
750 try: |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
751 checkparents(repo, state) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
752 |
44270
f546d2170b0f
merge: introduce a clean_update() for that use-case
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
753 merge.clean_update(state.pendingctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
754 if state.activebookmark and state.activebookmark in repo._bookmarks: |
38462
61e4cf1be5b2
shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents:
37967
diff
changeset
|
755 bookmarks.activate(repo, state.activebookmark) |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
756 mergefiles(ui, repo, state.wctx, state.pendingctx) |
39744
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39601
diff
changeset
|
757 if not phases.supportinternal(repo): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
758 repair.strip( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
759 ui, repo, state.nodestoremove, backup=False, topic=b'shelve' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
760 ) |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
761 finally: |
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
762 shelvedstate.clear(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
763 ui.warn(_(b"unshelve of '%s' aborted\n") % state.name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
764 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
765 |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
766 def hgabortunshelve(ui, repo): |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
767 """logic to abort unshelve using 'hg abort""" |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
768 with repo.wlock(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
769 state = _loadshelvedstate(ui, repo, {b'abort': True}) |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
770 return unshelveabort(ui, repo, state) |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
771 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
772 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
773 def mergefiles(ui, repo, wctx, shelvectx): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
774 """updates to wctx and merges the changes from shelvectx into the |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
775 dirstate.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
776 with ui.configoverride({(b'ui', b'quiet'): True}): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
777 hg.update(repo, wctx.node()) |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
778 ui.pushbuffer(True) |
45375
8c466bcb0879
revert: remove dangerous `parents` argument from `cmdutil.revert()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
45151
diff
changeset
|
779 cmdutil.revert(ui, repo, shelvectx) |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
780 ui.popbuffer() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
781 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
782 |
28573
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
783 def restorebranch(ui, repo, branchtorestore): |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
784 if branchtorestore and branchtorestore != repo.dirstate.branch(): |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
785 repo.dirstate.setbranch(branchtorestore) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
786 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
787 _(b'marked working directory as branch %s\n') % branchtorestore |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
788 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
789 |
28573
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
790 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
791 def unshelvecleanup(ui, repo, name, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
792 """remove related files after an unshelve""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
793 if not opts.get(b'keep'): |
30378
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
794 for filetype in shelvefileextensions: |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
795 shfile = shelvedfile(repo, name, filetype) |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
796 if shfile.exists(): |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29841
diff
changeset
|
797 shfile.movetobackup() |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
798 cleanupoldbackups(repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
799 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
800 |
42662
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42658
diff
changeset
|
801 def unshelvecontinue(ui, repo, state, opts): |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
802 """subcommand to continue an in-progress unshelve""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
803 # We're finishing off a merge. First parent is our original |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
804 # parent, second is the temporary "fake" commit we're unshelving. |
42662
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42658
diff
changeset
|
805 interactive = state.interactive |
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42658
diff
changeset
|
806 basename = state.name |
27838
60b850b7e4ef
with: use context manager for lock in continue
Bryan O'Sullivan <bryano@fb.com>
parents:
27837
diff
changeset
|
807 with repo.lock(): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
808 checkparents(repo, state) |
44856
b7808443ed6a
mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents:
44595
diff
changeset
|
809 ms = mergestatemod.mergestate.read(repo) |
33313
ea03b3223611
shelve: don't reimplement mergestate.unresolved()
Martin von Zweigbergk <martinvonz@google.com>
parents:
33043
diff
changeset
|
810 if list(ms.unresolved()): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
811 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
812 _(b"unresolved conflicts, can't continue"), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
813 hint=_(b"see 'hg resolve', then 'hg unshelve --continue'"), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
814 ) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
815 |
38463
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
816 shelvectx = repo[state.parents[1]] |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
817 pendingctx = state.pendingctx |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
818 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
819 with repo.dirstate.parentchange(): |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
820 repo.setparents(state.pendingctx.node(), nodemod.nullid) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
821 repo.dirstate.write(repo.currenttransaction()) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
822 |
39519
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
823 targetphase = phases.internal |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
824 if not phases.supportinternal(repo): |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39387
diff
changeset
|
825 targetphase = phases.secret |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
826 overrides = {(b'phases', b'new-commit'): targetphase} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
827 with repo.ui.configoverride(overrides, b'unshelve'): |
38463
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
828 with repo.dirstate.parentchange(): |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
829 repo.setparents(state.parents[0], nodemod.nullid) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
830 newnode, ispartialunshelve = _createunshelvectx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
831 ui, repo, shelvectx, basename, interactive, opts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
832 ) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
833 |
38463
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
834 if newnode is None: |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
835 shelvectx = state.pendingctx |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
836 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
837 b'note: unshelved changes already existed ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
838 b'in the working copy\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
839 ) |
38463
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
840 ui.status(msg) |
22842
d43d116a118c
shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21852
diff
changeset
|
841 else: |
38463
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
842 # only strip the shelvectx if we produced one |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
843 state.nodestoremove.append(newnode) |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
844 shelvectx = repo[newnode] |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38462
diff
changeset
|
845 |
45577
5c8230ca37f2
merge: replace calls to hg.updaterepo() by merge.update()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45375
diff
changeset
|
846 merge.update(pendingctx) |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
847 mergefiles(ui, repo, state.wctx, shelvectx) |
28573
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
848 restorebranch(ui, repo, state.branchtorestore) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
849 |
42702
4814d993fe21
unshelve: handle stripping changesets on interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42668
diff
changeset
|
850 if not phases.supportinternal(repo): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
851 repair.strip( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
852 ui, repo, state.nodestoremove, backup=False, topic=b'shelve' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
853 ) |
42703
073cfff9aaef
unshelve: delete shelvedstate after a successful unshelve --continue
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42702
diff
changeset
|
854 shelvedstate.clear(repo) |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
855 if not ispartialunshelve: |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
856 unshelvecleanup(ui, repo, state.name, opts) |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
857 _restoreactivebookmark(repo, state.activebookmark) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
858 ui.status(_(b"unshelve of '%s' complete\n") % state.name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
859 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
860 |
42614
117437f3f541
continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42599
diff
changeset
|
861 def hgcontinueunshelve(ui, repo): |
117437f3f541
continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42599
diff
changeset
|
862 """logic to resume unshelve using 'hg continue'""" |
117437f3f541
continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42599
diff
changeset
|
863 with repo.wlock(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
864 state = _loadshelvedstate(ui, repo, {b'continue': True}) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
865 return unshelvecontinue(ui, repo, state, {b'keep': state.keep}) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
866 |
42614
117437f3f541
continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42599
diff
changeset
|
867 |
30453
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
868 def _commitworkingcopychanges(ui, repo, opts, tmpwctx): |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
869 """Temporarily commit working copy changes before moving unshelve commit""" |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
870 # Store pending changes in a commit and remember added in case a shelve |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
871 # contains unknown files that are part of the pending change |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
872 s = repo.status() |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
873 addedbefore = frozenset(s.added) |
30846
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
874 if not (s.modified or s.added or s.removed): |
30453
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
875 return tmpwctx, addedbefore |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
876 ui.status( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
877 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
878 b"temporarily committing pending changes " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
879 b"(restore with 'hg unshelve --abort')\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
880 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
881 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
882 extra = {b'internal': b'shelve'} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
883 commitfunc = getcommitfunc(extra=extra, interactive=False, editor=False) |
30453
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
884 tempopts = {} |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
885 tempopts[b'message'] = b"pending changes temporary commit" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
886 tempopts[b'date'] = opts.get(b'date') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
887 with ui.configoverride({(b'ui', b'quiet'): True}): |
31757
473f2fcc7629
shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents:
31664
diff
changeset
|
888 node = cmdutil.commit(ui, repo, commitfunc, [], tempopts) |
30453
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
889 tmpwctx = repo[node] |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
890 return tmpwctx, addedbefore |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30407
diff
changeset
|
891 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
892 |
41007
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40854
diff
changeset
|
893 def _unshelverestorecommit(ui, repo, tr, basename): |
30454
672026aece64
shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30453
diff
changeset
|
894 """Recreate commit in the repository during the unshelve""" |
39373
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39372
diff
changeset
|
895 repo = repo.unfiltered() |
39387
da84cca65036
shelve: fix crash on unshelve without .shelve metadata file
Yuya Nishihara <yuya@tcha.org>
parents:
39376
diff
changeset
|
896 node = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
897 if shelvedfile(repo, basename, b'shelve').exists(): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
898 node = shelvedfile(repo, basename, b'shelve').readinfo()[b'node'] |
39374
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39373
diff
changeset
|
899 if node is None or node not in repo: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
900 with ui.configoverride({(b'ui', b'quiet'): True}): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
901 shelvectx = shelvedfile(repo, basename, b'hg').applybundle(tr) |
39375
38373da1af02
shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents:
39374
diff
changeset
|
902 # We might not strip the unbundled changeset, so we should keep track of |
38373da1af02
shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents:
39374
diff
changeset
|
903 # the unshelve node in case we need to reuse it (eg: unshelve --keep) |
38373da1af02
shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents:
39374
diff
changeset
|
904 if node is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
905 info = {b'node': nodemod.hex(shelvectx.node())} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
906 shelvedfile(repo, basename, b'shelve').writeinfo(info) |
39374
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39373
diff
changeset
|
907 else: |
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39373
diff
changeset
|
908 shelvectx = repo[node] |
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39373
diff
changeset
|
909 |
30454
672026aece64
shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30453
diff
changeset
|
910 return repo, shelvectx |
672026aece64
shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30453
diff
changeset
|
911 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
912 |
42656
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
913 def _createunshelvectx(ui, repo, shelvectx, basename, interactive, opts): |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
914 """Handles the creation of unshelve commit and updates the shelve if it |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
915 was partially unshelved. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
916 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
917 If interactive is: |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
918 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
919 * False: Commits all the changes in the working directory. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
920 * True: Prompts the user to select changes to unshelve and commit them. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
921 Update the shelve with remaining changes. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
922 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
923 Returns the node of the new commit formed and a bool indicating whether |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
924 the shelve was partially unshelved.Creates a commit ctx to unshelve |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
925 interactively or non-interactively. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
926 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
927 The user might want to unshelve certain changes only from the stored |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
928 shelve in interactive. So, we would create two commits. One with requested |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
929 changes to unshelve at that time and the latter is shelved for future. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
930 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
931 Here, we return both the newnode which is created interactively and a |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
932 bool to know whether the shelve is partly done or completely done. |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
933 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
934 opts[b'message'] = shelvectx.description() |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
935 opts[b'interactive-unshelve'] = True |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
936 pats = [] |
42656
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
937 if not interactive: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
938 newnode = repo.commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
939 text=shelvectx.description(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
940 extra=shelvectx.extra(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
941 user=shelvectx.user(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
942 date=shelvectx.date(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
943 ) |
42656
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
944 return newnode, False |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
945 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
946 commitfunc = getcommitfunc(shelvectx.extra(), interactive=True, editor=True) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
947 newnode = cmdutil.dorecord( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
948 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
949 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
950 commitfunc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
951 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
952 False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
953 cmdutil.recordfilter, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
954 *pats, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
955 **pycompat.strkwargs(opts) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
956 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
957 snode = repo.commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
958 text=shelvectx.description(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
959 extra=shelvectx.extra(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
960 user=shelvectx.user(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
961 ) |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
962 if snode: |
42658
d5cdce3d9164
unshelve: create a matcher only if required on creating unshelve ctx
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42657
diff
changeset
|
963 m = scmutil.matchfiles(repo, repo[snode].files()) |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
964 _shelvecreatedcommit(repo, snode, basename, m) |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
965 |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
966 return newnode, bool(snode) |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
967 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
968 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
969 def _rebaserestoredcommit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
970 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
971 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
972 opts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
973 tr, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
974 oldtiprev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
975 basename, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
976 pctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
977 tmpwctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
978 shelvectx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
979 branchtorestore, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
980 activebookmark, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
981 ): |
30455
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30454
diff
changeset
|
982 """Rebase restored commit from its original location to a destination""" |
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30454
diff
changeset
|
983 # If the shelve is not immediately on top of the commit |
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30454
diff
changeset
|
984 # we'll be merging with, rebase it to be on top. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
985 interactive = opts.get(b'interactive') |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
986 if tmpwctx.node() == shelvectx.p1().node() and not interactive: |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
987 # We won't skip on interactive mode because, the user might want to |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
988 # unshelve certain changes only. |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
989 return shelvectx, False |
30455
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30454
diff
changeset
|
990 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
991 overrides = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
992 (b'ui', b'forcemerge'): opts.get(b'tool', b''), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
993 (b'phases', b'new-commit'): phases.secret, |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
994 } |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
995 with repo.ui.configoverride(overrides, b'unshelve'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
996 ui.status(_(b'rebasing shelved changes\n')) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
997 stats = merge.graft( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
998 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
999 shelvectx, |
44332
69b091cdc506
shelve: fix ordering of merge labels
Kyle Lippincott <spectral@google.com>
parents:
43981
diff
changeset
|
1000 labels=[b'working-copy', b'shelve'], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1001 keepconflictparent=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1002 ) |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1003 if stats.unresolvedcount: |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1004 tr.close() |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1005 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1006 nodestoremove = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1007 repo.changelog.node(rev) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1008 for rev in pycompat.xrange(oldtiprev, len(repo)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1009 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1010 shelvedstate.save( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1011 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1012 basename, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1013 pctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1014 tmpwctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1015 nodestoremove, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1016 branchtorestore, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1017 opts.get(b'keep'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1018 activebookmark, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1019 interactive, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1020 ) |
45151
e429e7c801b2
error: normalize "unresolved conflicts" error messages with a custom class
Daniel Ploch <dploch@google.com>
parents:
45144
diff
changeset
|
1021 raise error.ConflictResolutionRequired(b'unshelve') |
30455
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30454
diff
changeset
|
1022 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1023 with repo.dirstate.parentchange(): |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1024 repo.setparents(tmpwctx.node(), nodemod.nullid) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1025 newnode, ispartialunshelve = _createunshelvectx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1026 ui, repo, shelvectx, basename, interactive, opts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1027 ) |
30455
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30454
diff
changeset
|
1028 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1029 if newnode is None: |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1030 shelvectx = tmpwctx |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1031 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1032 b'note: unshelved changes already existed ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1033 b'in the working copy\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1034 ) |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1035 ui.status(msg) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1036 else: |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38508
diff
changeset
|
1037 shelvectx = repo[newnode] |
45577
5c8230ca37f2
merge: replace calls to hg.updaterepo() by merge.update()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45375
diff
changeset
|
1038 merge.update(tmpwctx) |
30455
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30454
diff
changeset
|
1039 |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
1040 return shelvectx, ispartialunshelve |
30455
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30454
diff
changeset
|
1041 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1042 |
30456
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30455
diff
changeset
|
1043 def _forgetunknownfiles(repo, shelvectx, addedbefore): |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30455
diff
changeset
|
1044 # Forget any files that were unknown before the shelve, unknown before |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30455
diff
changeset
|
1045 # unshelve started, but are now added. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1046 shelveunknown = shelvectx.extra().get(b'shelve_unknown') |
30456
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30455
diff
changeset
|
1047 if not shelveunknown: |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30455
diff
changeset
|
1048 return |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1049 shelveunknown = frozenset(shelveunknown.split(b'\0')) |
30456
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30455
diff
changeset
|
1050 addedafter = frozenset(repo.status().added) |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30455
diff
changeset
|
1051 toforget = (addedafter & shelveunknown) - addedbefore |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30455
diff
changeset
|
1052 repo[None].forget(toforget) |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30455
diff
changeset
|
1053 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1054 |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
1055 def _finishunshelve(repo, oldtiprev, tr, activebookmark): |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
1056 _restoreactivebookmark(repo, activebookmark) |
30457
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30456
diff
changeset
|
1057 # The transaction aborting will strip all the commits for us, |
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30456
diff
changeset
|
1058 # but it doesn't update the inmemory structures, so addchangegroup |
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30456
diff
changeset
|
1059 # hooks still fire and try to operate on the missing commits. |
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30456
diff
changeset
|
1060 # Clean up manually to prevent this. |
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30456
diff
changeset
|
1061 repo.unfiltered().changelog.strip(oldtiprev, tr) |
41007
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40854
diff
changeset
|
1062 _aborttransaction(repo, tr) |
30457
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30456
diff
changeset
|
1063 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1064 |
30846
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1065 def _checkunshelveuntrackedproblems(ui, repo, shelvectx): |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1066 """Check potential problems which may result from working |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1067 copy having untracked changes.""" |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1068 wcdeleted = set(repo.status().deleted) |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1069 shelvetouched = set(shelvectx.files()) |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1070 intersection = wcdeleted.intersection(shelvetouched) |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1071 if intersection: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1072 m = _(b"shelved change touches missing files") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1073 hint = _(b"run hg status to see which files are missing") |
30846
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1074 raise error.Abort(m, hint=hint) |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1075 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1076 |
44595
47c1226463a1
shelve: split up dounshelve() in unshelvecmd() and _dounshelve()
Martin von Zweigbergk <martinvonz@google.com>
parents:
44438
diff
changeset
|
1077 def unshelvecmd(ui, repo, *shelved, **opts): |
35005
aad6b9fdfc75
py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34496
diff
changeset
|
1078 opts = pycompat.byteskwargs(opts) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1079 abortf = opts.get(b'abort') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1080 continuef = opts.get(b'continue') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1081 interactive = opts.get(b'interactive') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1082 if not abortf and not continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1083 cmdutil.checkunfinished(repo) |
31021
4189d790e8a4
shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents:
30846
diff
changeset
|
1084 shelved = list(shelved) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1085 if opts.get(b"name"): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1086 shelved.append(opts[b"name"]) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1087 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1088 if interactive and opts.get(b'keep'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1089 raise error.Abort(_(b'--keep on --interactive is not yet supported')) |
42662
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42658
diff
changeset
|
1090 if abortf or continuef: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1091 if abortf and continuef: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1092 raise error.Abort(_(b'cannot use both abort and continue')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1093 if shelved: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1094 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1095 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1096 b'cannot combine abort/continue with ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1097 b'naming a shelved change' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1098 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1099 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1100 if abortf and opts.get(b'tool', False): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1101 ui.warn(_(b'tool option will be ignored\n')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1102 |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
1103 state = _loadshelvedstate(ui, repo, opts) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1104 if abortf: |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
1105 return unshelveabort(ui, repo, state) |
42668
52a383451739
unshelve: add abort on using continue and interactive together
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42662
diff
changeset
|
1106 elif continuef and interactive: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1107 raise error.Abort(_(b'cannot use both continue and interactive')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1108 elif continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1109 return unshelvecontinue(ui, repo, state, opts) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1110 elif len(shelved) > 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1111 raise error.Abort(_(b'can only unshelve one change at a time')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1112 elif not shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1113 shelved = listshelves(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1114 if not shelved: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1115 raise error.Abort(_(b'no shelved changes to apply!')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1116 basename = util.split(shelved[0][1])[1] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1117 ui.status(_(b"unshelving change '%s'\n") % basename) |
42662
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42658
diff
changeset
|
1118 else: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1119 basename = shelved[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1120 |
30554
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30542
diff
changeset
|
1121 if not shelvedfile(repo, basename, patchextension).exists(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1122 raise error.Abort(_(b"shelved change '%s' not found") % basename) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1123 |
44595
47c1226463a1
shelve: split up dounshelve() in unshelvecmd() and _dounshelve()
Martin von Zweigbergk <martinvonz@google.com>
parents:
44438
diff
changeset
|
1124 return _dounshelve(ui, repo, basename, opts) |
47c1226463a1
shelve: split up dounshelve() in unshelvecmd() and _dounshelve()
Martin von Zweigbergk <martinvonz@google.com>
parents:
44438
diff
changeset
|
1125 |
47c1226463a1
shelve: split up dounshelve() in unshelvecmd() and _dounshelve()
Martin von Zweigbergk <martinvonz@google.com>
parents:
44438
diff
changeset
|
1126 |
47c1226463a1
shelve: split up dounshelve() in unshelvecmd() and _dounshelve()
Martin von Zweigbergk <martinvonz@google.com>
parents:
44438
diff
changeset
|
1127 def _dounshelve(ui, repo, basename, opts): |
39373
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39372
diff
changeset
|
1128 repo = repo.unfiltered() |
27287
c9ceea3f2d8e
shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27198
diff
changeset
|
1129 lock = tr = None |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1130 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1131 lock = repo.lock() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1132 tr = repo.transaction(b'unshelve', report=lambda x: None) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1133 oldtiprev = len(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1134 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1135 pctx = repo[b'.'] |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
1136 tmpwctx = pctx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1137 # The goal is to have a commit structure like so: |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
1138 # ...-> pctx -> tmpwctx -> shelvectx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1139 # where tmpwctx is an optional commit with the user's pending changes |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1140 # and shelvectx is the unshelved changes. Then we merge it all down |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
1141 # to the original pctx. |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1142 |
31664
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31555
diff
changeset
|
1143 activebookmark = _backupactivebookmark(repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1144 tmpwctx, addedbefore = _commitworkingcopychanges( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1145 ui, repo, opts, tmpwctx |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1146 ) |
41007
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40854
diff
changeset
|
1147 repo, shelvectx = _unshelverestorecommit(ui, repo, tr, basename) |
37967
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1148 _checkunshelveuntrackedproblems(ui, repo, shelvectx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1149 branchtorestore = b'' |
37967
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1150 if shelvectx.branch() != shelvectx.p1().branch(): |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1151 branchtorestore = shelvectx.branch() |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1152 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1153 shelvectx, ispartialunshelve = _rebaserestoredcommit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1154 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1155 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1156 opts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1157 tr, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1158 oldtiprev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1159 basename, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1160 pctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1161 tmpwctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1162 shelvectx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1163 branchtorestore, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1164 activebookmark, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42761
diff
changeset
|
1165 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1166 overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1167 with ui.configoverride(overrides, b'unshelve'): |
37967
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1168 mergefiles(ui, repo, pctx, shelvectx) |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1169 restorebranch(ui, repo, branchtorestore) |
42704
6957f7b93e03
unshelve: clear shelvedstate and _finishunshelve() on partial unshelve
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42703
diff
changeset
|
1170 shelvedstate.clear(repo) |
6957f7b93e03
unshelve: clear shelvedstate and _finishunshelve() on partial unshelve
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42703
diff
changeset
|
1171 _finishunshelve(repo, oldtiprev, tr, activebookmark) |
42733
d684449eef67
unshelve: forget unknown files after a partial unshelve
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42704
diff
changeset
|
1172 _forgetunknownfiles(repo, shelvectx, addedbefore) |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
1173 if not ispartialunshelve: |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
1174 unshelvecleanup(ui, repo, basename, opts) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1175 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1176 if tr: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1177 tr.release() |
27287
c9ceea3f2d8e
shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27198
diff
changeset
|
1178 lockmod.release(lock) |