annotate mercurial/admin/chainsaw.py @ 52125:1938d72e7a16

wireprotoserver: subclass the new `baseprotocolhandler` Protocol class
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 24 Oct 2024 20:50:47 -0400
parents 1c5810ce737e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
51864
1c5810ce737e typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51503
diff changeset
22 from __future__ import annotations
1c5810ce737e typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51503
diff changeset
23
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
24 import shutil
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
25
51503
d4095f7b000a admin-commands: move the chainsaw extension to the admin commands module
Raphaël Gomès <rgomes@octobus.net>
parents: 51435
diff changeset
26 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
27 from .. import (
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
28 cmdutil,
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
29 commands,
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
30 error,
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
31 localrepo,
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
32 registrar,
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
33 )
51503
d4095f7b000a admin-commands: move the chainsaw extension to the admin commands module
Raphaël Gomès <rgomes@octobus.net>
parents: 51435
diff changeset
34 from ..utils import (
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
35 urlutil,
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
36 )
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
37
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
38 cmdtable = {}
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
39 command = registrar.command(cmdtable)
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
40
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
41
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
42 @command(
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
43 b'admin::chainsaw-update',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
44 [
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
45 (
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
46 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
47 b'purge-unknown',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
48 True,
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
49 _(
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
50 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
51 b'in some cases interfere with the update.'
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
52 b'See also :hg:`purge`.'
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 ),
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
55 (
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
56 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
57 b'purge-ignored',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
58 True,
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
59 _(
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
60 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
61 b'instance to reuse previous compiler object files. '
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
62 b'See also :hg:`purge`.'
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 ),
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
65 (
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'rev',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
68 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
69 _(b'revision to update to'),
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
70 ),
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
71 (
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'source',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
74 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
75 _(b'repository to clone from'),
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
76 ),
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
77 (
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'dest',
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
80 b'',
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
81 _(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
82 ),
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
83 (
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
84 b'',
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
85 b'initial-clone-minimal',
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
86 False,
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
87 _(
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
88 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
89 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
90 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
91 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
92 ),
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
93 ),
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
94 ],
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
95 _(
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
96 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
97 ),
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
98 helpbasic=True,
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
99 norepo=True,
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
100 )
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
101 def update(ui, **opts):
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
102 """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
103
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
104 Context of application: *some* Continuous Integration (CI) systems,
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
105 packaging or deployment tools.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
106
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
107 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
108 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
109 updated at the given revision.
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
110
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
111 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
112 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
113
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
114 By default, it will:
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
115
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
116 - 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
117 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
118 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
119 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
120 - 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
121 is a concurrent write access.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
122 - perform recovery actions if needed
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
123 - revert any local modification.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
124 - purge unknown and ignored files.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
125 - 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
126
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
127 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
128 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
129 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
130 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
131 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
132
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
133 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
134 variable (see :hg:`scripting`).
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
135
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
136 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
137 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
138 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
139 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
140 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
141 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
142 deadline.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
143 """
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
144 rev = opts['rev']
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
145 source = opts['source']
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
146 repo_path = opts['dest']
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
147 if not rev:
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
148 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
149 if not source:
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
150 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
151 if not repo_path:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
152 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
153 repo_path = urlutil.urllocalpath(repo_path)
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
154
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
155 try:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
156 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
157 repo_created = False
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
158 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
159 except error.RepoError:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
160 try:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
161 shutil.rmtree(repo_path)
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
162 except FileNotFoundError:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
163 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
164 else:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
165 ui.status(
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
166 _(
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
167 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
168 b'at "%s"' % repo_path
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 )
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
171
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
172 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
173 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
174 repo_created = True
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
175
51431
fe68a2dc0bf2 chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents: 51429
diff changeset
176 if repo.svfs.tryunlink(b'lock'):
fe68a2dc0bf2 chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents: 51429
diff changeset
177 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
178 if repo.vfs.tryunlink(b'wlock'):
fe68a2dc0bf2 chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents: 51429
diff changeset
179 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
180 # 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
181 # 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
182 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
183 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
184 repo.recover()
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
185
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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 )
ad1066534237 chainsaw-update: exit early if one of the intermediate command fails
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51434
diff changeset
201 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
202 return ret
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
203
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 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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 )
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
213 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
214 return ret
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
215
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
216 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
217 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
218 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
219 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
220 return ret
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
221
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
222 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
223 _(
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 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
225 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
226 )
dd519ea71416 chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51433
diff changeset
227 % (rev, repo.root)
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
228 )