Mercurial > hg
annotate mercurial/admin/chainsaw.py @ 51699:bd1483fd7088
Latest image and pytype fix
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 22 Jul 2024 16:49:38 +0200 |
parents | d4095f7b000a |
children | 1c5810ce737e |
rev | line source |
---|---|
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
1 # chainsaw.py |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
2 # |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
3 # Copyright 2022 Georges Racinet <georges.racinet@octobus.net> |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
4 # |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
7 """chainsaw is a collection of single-minded and dangerous tools. (EXPERIMENTAL) |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
8 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
9 "Don't use a chainsaw to cut your food!" |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
10 |
51503
d4095f7b000a
admin-commands: move the chainsaw extension to the admin commands module
Raphaël Gomès <rgomes@octobus.net>
parents:
51435
diff
changeset
|
11 The chainsaw is a collection of commands that are so much geared towards a |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
12 specific use case in a specific context or environment that they are totally |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
13 inappropriate and **really dangerous** in other contexts. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
14 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
15 The help text of each command explicitly summarizes its context of application |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
16 and the wanted end result. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
17 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
18 It is recommended to run these commands with the ``HGPLAIN`` environment |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
19 variable (see :hg:`help scripting`). |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
20 """ |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
21 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
22 import shutil |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
23 |
51503
d4095f7b000a
admin-commands: move the chainsaw extension to the admin commands module
Raphaël Gomès <rgomes@octobus.net>
parents:
51435
diff
changeset
|
24 from ..i18n import _ |
d4095f7b000a
admin-commands: move the chainsaw extension to the admin commands module
Raphaël Gomès <rgomes@octobus.net>
parents:
51435
diff
changeset
|
25 from .. import ( |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
26 cmdutil, |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
27 commands, |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
28 error, |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
29 localrepo, |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
30 registrar, |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
31 ) |
51503
d4095f7b000a
admin-commands: move the chainsaw extension to the admin commands module
Raphaël Gomès <rgomes@octobus.net>
parents:
51435
diff
changeset
|
32 from ..utils import ( |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
33 urlutil, |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
34 ) |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
35 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
36 cmdtable = {} |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
37 command = registrar.command(cmdtable) |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
38 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
39 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
40 @command( |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
41 b'admin::chainsaw-update', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
42 [ |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
43 ( |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
44 b'', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
45 b'purge-unknown', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
46 True, |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
47 _( |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
48 b'Remove unversioned files before update. Disabling this can ' |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
49 b'in some cases interfere with the update.' |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
50 b'See also :hg:`purge`.' |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
51 ), |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
52 ), |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
53 ( |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
54 b'', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
55 b'purge-ignored', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
56 True, |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
57 _( |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
58 b'Remove ignored files before update. Disable this for ' |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
59 b'instance to reuse previous compiler object files. ' |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
60 b'See also :hg:`purge`.' |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
61 ), |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
62 ), |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
63 ( |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
64 b'', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
65 b'rev', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
66 b'', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
67 _(b'revision to update to'), |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
68 ), |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
69 ( |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
70 b'', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
71 b'source', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
72 b'', |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
73 _(b'repository to clone from'), |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
74 ), |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
75 ( |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
76 b'', |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
77 b'dest', |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
78 b'', |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
79 _(b'repository to update to REV (possibly cloning)'), |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
80 ), |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
81 ( |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
82 b'', |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
83 b'initial-clone-minimal', |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
84 False, |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
85 _( |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
86 b'Pull only the prescribed revision upon initial cloning. ' |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
87 b'This has the side effect of ignoring clone-bundles, ' |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
88 b'which if often slower on the client side and stressful ' |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
89 b'to the server than applying available clone bundles.' |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
90 ), |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
91 ), |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
92 ], |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
93 _( |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
94 b'hg admin::chainsaw-update [OPTION] --rev REV --source SOURCE --dest DEST' |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
95 ), |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
96 helpbasic=True, |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
97 norepo=True, |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
98 ) |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
99 def update(ui, **opts): |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
100 """pull and update to a given revision, no matter what, (EXPERIMENTAL) |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
101 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
102 Context of application: *some* Continuous Integration (CI) systems, |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
103 packaging or deployment tools. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
104 |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
105 Wanted end result: local repository at the given REPO_PATH, having the |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
106 latest changes to the given revision and with a clean working directory |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
107 updated at the given revision. |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
108 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
109 chainsaw-update pulls from one source, then updates the working directory |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
110 to the given revision, overcoming anything that would stand in the way. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
111 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
112 By default, it will: |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
113 |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
114 - clone if the local repo does not exist yet, **removing any directory |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
115 at the given path** that would not be a Mercurial repository. |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
116 The initial clone is full by default, so that clonebundles can be |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
117 applied. Use the --initial-clone-minimal flag to avoid this. |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
118 - break locks if needed, leading to possible corruption if there |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
119 is a concurrent write access. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
120 - perform recovery actions if needed |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
121 - revert any local modification. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
122 - purge unknown and ignored files. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
123 - go as far as to reclone if everything else failed (not implemented yet). |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
124 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
125 DO NOT use it for anything else than performing a series |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
126 of unattended updates, with full exclusive repository access each time |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
127 and without any other local work than running build scripts. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
128 In case the local repository is a share (see :hg:`help share`), exclusive |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
129 write access to the share source is also mandatory. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
130 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
131 It is recommended to run these commands with the ``HGPLAIN`` environment |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
132 variable (see :hg:`scripting`). |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
133 |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
134 Motivation: in Continuous Integration and Delivery systems (CI/CD), the |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
135 occasional remnant or bogus lock are common sources of waste of time (both |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
136 working time and calendar time). CI/CD scripts tend to grow with counter- |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
137 measures, often done in urgency. Also, whilst it is neat to keep |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
138 repositories from one job to the next (especially with large |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
139 repositories), an exceptional recloning is better than missing a release |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
140 deadline. |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
141 """ |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
142 rev = opts['rev'] |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
143 source = opts['source'] |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
144 repo_path = opts['dest'] |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
145 if not rev: |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
146 raise error.InputError(_(b'specify a target revision with --rev')) |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
147 if not source: |
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
148 raise error.InputError(_(b'specify a pull path with --source')) |
51433
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
149 if not repo_path: |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
150 raise error.InputError(_(b'specify a repo path with --dest')) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
151 repo_path = urlutil.urllocalpath(repo_path) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
152 |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
153 try: |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
154 repo = localrepo.instance(ui, repo_path, create=False) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
155 repo_created = False |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
156 ui.status(_(b'loaded repository at "%s"\n' % repo_path)) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
157 except error.RepoError: |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
158 try: |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
159 shutil.rmtree(repo_path) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
160 except FileNotFoundError: |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
161 ui.status(_(b'no such directory: "%s"\n' % repo_path)) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
162 else: |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
163 ui.status( |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
164 _( |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
165 b'removed non-repository file or directory ' |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
166 b'at "%s"' % repo_path |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
167 ) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
168 ) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
169 |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
170 ui.status(_(b'creating repository at "%s"\n' % repo_path)) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
171 repo = localrepo.instance(ui, repo_path, create=True) |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
172 repo_created = True |
d36a81d70f25
chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents:
51431
diff
changeset
|
173 |
51431
fe68a2dc0bf2
chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents:
51429
diff
changeset
|
174 if repo.svfs.tryunlink(b'lock'): |
fe68a2dc0bf2
chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents:
51429
diff
changeset
|
175 ui.status(_(b'had to break store lock\n')) |
fe68a2dc0bf2
chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents:
51429
diff
changeset
|
176 if repo.vfs.tryunlink(b'wlock'): |
fe68a2dc0bf2
chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents:
51429
diff
changeset
|
177 ui.status(_(b'had to break working copy lock\n')) |
51434
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
178 # If another process relock after the breacking above, the next locking |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
179 # will have to wait. |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
180 with repo.wlock(), repo.lock(): |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
181 ui.status(_(b'recovering after interrupted transaction, if any\n')) |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
182 repo.recover() |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
183 |
51434
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
184 ui.status(_(b'pulling from %s\n') % source) |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
185 if repo_created and not opts.get('initial_clone_minimal'): |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
186 pull_revs = [] |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
187 else: |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
188 pull_revs = [rev] |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
189 overrides = {(b'ui', b'quiet'): True} |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
190 with repo.ui.configoverride(overrides, b'chainsaw-update'): |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
191 pull = cmdutil.findcmd(b'pull', commands.table)[1][0] |
51435
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
192 ret = pull( |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
193 repo.ui, |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
194 repo, |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
195 source, |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
196 rev=pull_revs, |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
197 remote_hidden=False, |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
198 ) |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
199 if ret: |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
200 return ret |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
201 |
51434
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
202 purge = cmdutil.findcmd(b'purge', commands.table)[1][0] |
51435
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
203 ret = purge( |
51434
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
204 ui, |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
205 repo, |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
206 dirs=True, |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
207 all=opts.get('purge_ignored'), |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
208 files=opts.get('purge_unknown'), |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
209 confirm=False, |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
210 ) |
51435
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
211 if ret: |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
212 return ret |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
213 |
51434
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
214 ui.status(_(b'updating to revision \'%s\'\n') % rev) |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
215 update = cmdutil.findcmd(b'update', commands.table)[1][0] |
51435
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
216 ret = update(ui, repo, rev=rev, clean=True) |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
217 if ret: |
ad1066534237
chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51434
diff
changeset
|
218 return ret |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
219 |
51434
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
220 ui.status( |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
221 _( |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
222 b'chainsaw-update to revision \'%s\' ' |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
223 b'for repository at \'%s\' done\n' |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
224 ) |
dd519ea71416
chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51433
diff
changeset
|
225 % (rev, repo.root) |
51429
bc88aa7472de
chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
226 ) |