annotate hgext/chainsaw.py @ 51434:dd519ea71416

chainsaw-update: lock the repository for the duration of the operation This should prevent and catch some misusage where something else try to touch the repository.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 23 Feb 2024 03:32:35 +0100
parents d36a81d70f25
children ad1066534237
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
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
11 The chainsaw extension provides commands that are so much geared towards a
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
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
24 from mercurial.i18n import _
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
25 from mercurial import (
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 )
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
32 from mercurial.utils import (
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 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
39 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
40 # be specifying the version(s) of Mercurial they are tested with, or
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
41 # leave the attribute unspecified.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
42 testedwith = b'ships-with-hg-core'
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
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
45 @command(
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
46 b'admin::chainsaw-update',
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 (
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
49 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
50 b'purge-unknown',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
51 True,
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 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
54 b'in some cases interfere with the update.'
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
55 b'See also :hg:`purge`.'
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
56 ),
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 (
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
59 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
60 b'purge-ignored',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
61 True,
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 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
64 b'instance to reuse previous compiler object files. '
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
65 b'See also :hg:`purge`.'
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
66 ),
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
67 ),
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 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
70 b'rev',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
71 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
72 _(b'revision to update to'),
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
73 ),
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
74 (
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
75 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
76 b'source',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
77 b'',
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
78 _(b'repository to clone from'),
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
79 ),
51433
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 b'',
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
82 b'dest',
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
83 b'',
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
84 _(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
85 ),
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
86 (
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
87 b'',
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
88 b'initial-clone-minimal',
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
89 False,
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 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
92 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
93 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
94 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
95 ),
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
96 ),
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
97 ],
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
98 _(
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
99 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
100 ),
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
101 helpbasic=True,
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
102 norepo=True,
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
103 )
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
104 def update(ui, **opts):
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
105 """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
106
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
107 Context of application: *some* Continuous Integration (CI) systems,
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
108 packaging or deployment tools.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
109
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
110 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
111 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
112 updated at the given revision.
51429
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 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
115 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
116
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
117 By default, it will:
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
118
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
119 - 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
120 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
121 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
122 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
123 - 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
124 is a concurrent write access.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
125 - perform recovery actions if needed
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
126 - revert any local modification.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
127 - purge unknown and ignored files.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
128 - 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
129
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
130 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
131 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
132 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
133 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
134 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
135
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
136 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
137 variable (see :hg:`scripting`).
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
138
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
139 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
140 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
141 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
142 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
143 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
144 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
145 deadline.
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
146 """
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
147 rev = opts['rev']
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
148 source = opts['source']
51433
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
149 repo_path = opts['dest']
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
150 if not rev:
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
151 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
152 if not source:
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
153 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
154 if not repo_path:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
155 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
156 repo_path = urlutil.urllocalpath(repo_path)
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
157
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 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
160 repo_created = False
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
161 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
162 except error.RepoError:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
163 try:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
164 shutil.rmtree(repo_path)
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
165 except FileNotFoundError:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
166 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
167 else:
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
168 ui.status(
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 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
171 b'at "%s"' % repo_path
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
172 )
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
173 )
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
174
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
175 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
176 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
177 repo_created = True
d36a81d70f25 chainsaw-update: taking care of initial cloning
Georges Racinet <georges.racinet@octobus.net>
parents: 51431
diff changeset
178
51431
fe68a2dc0bf2 chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents: 51429
diff changeset
179 if repo.svfs.tryunlink(b'lock'):
fe68a2dc0bf2 chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents: 51429
diff changeset
180 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
181 if repo.vfs.tryunlink(b'wlock'):
fe68a2dc0bf2 chainsaw-update: log actual locks breaking
Georges Racinet <georges.racinet@octobus.net>
parents: 51429
diff changeset
182 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
183 # 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
184 # 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
185 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
186 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
187 repo.recover()
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
188
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
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 pull = cmdutil.findcmd(b'pull', commands.table)[1][0]
dd519ea71416 chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51433
diff changeset
197 pull(repo.ui, repo, source, rev=pull_revs, remote_hidden=False)
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
198
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
199 purge = cmdutil.findcmd(b'purge', commands.table)[1][0]
dd519ea71416 chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51433
diff changeset
200 purge(
dd519ea71416 chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51433
diff changeset
201 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
202 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
203 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
204 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
205 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
206 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
207 )
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
208
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
209 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
210 update = cmdutil.findcmd(b'update', commands.table)[1][0]
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 update(ui, repo, rev=rev, clean=True)
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
212
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
213 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
214 _(
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 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
216 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
217 )
dd519ea71416 chainsaw-update: lock the repository for the duration of the operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51433
diff changeset
218 % (rev, repo.root)
51429
bc88aa7472de chainsaw: new extension for dangerous operations
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
219 )