Mercurial > public > mercurial-scm > hg
annotate mercurial/repair.py @ 50276:8011017629be stable
undo-files: extract the cleanup code from strip in a function
This logic is duplicated in multiple places and it missing some important parts.
So lets start dealing with the duplication first.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 06 Mar 2023 12:57:46 +0100 |
parents | d44e3c45f0e4 |
children | cd680b45a920 |
rev | line source |
---|---|
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # repair.py - functions for repository repair for mercurial |
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
3 # Copyright 2005, 2006 Chris Mason <mason@suse.com> |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46638
diff
changeset
|
4 # Copyright 2007 Olivia Mackall |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
5 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8073
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
10263 | 7 # GNU General Public License version 2 or any later version. |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
8 |
25970
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25874
diff
changeset
|
9 |
16440
692bf06bb1af
repair: fix missing import
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
16388
diff
changeset
|
10 import errno |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
11 |
25970
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25874
diff
changeset
|
12 from .i18n import _ |
34222
6193d810f7bb
repair: reliably obtain bytestr of node ids
Augie Fackler <raf@durin42.com>
parents:
33725
diff
changeset
|
13 from .node import ( |
6193d810f7bb
repair: reliably obtain bytestr of node ids
Augie Fackler <raf@durin42.com>
parents:
33725
diff
changeset
|
14 hex, |
6193d810f7bb
repair: reliably obtain bytestr of node ids
Augie Fackler <raf@durin42.com>
parents:
33725
diff
changeset
|
15 short, |
6193d810f7bb
repair: reliably obtain bytestr of node ids
Augie Fackler <raf@durin42.com>
parents:
33725
diff
changeset
|
16 ) |
25970
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25874
diff
changeset
|
17 from . import ( |
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25874
diff
changeset
|
18 bundle2, |
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25874
diff
changeset
|
19 changegroup, |
32468
4c4d91908492
strip: use the 'writenewbundle' function to get bundle on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32296
diff
changeset
|
20 discovery, |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26425
diff
changeset
|
21 error, |
25970
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25874
diff
changeset
|
22 exchange, |
28868
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
23 obsolete, |
33143
d09ae850296d
obsutil: move 'exclusivemarkers' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33108
diff
changeset
|
24 obsutil, |
43523
c21aca51b392
utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
25 pathutil, |
39745
b2ec79559a4b
strip: ignore orphaned internal changesets while computing safe strip roots
Boris Feld <boris.feld@octobus.net>
parents:
39686
diff
changeset
|
26 phases, |
45372
77b8588dd84e
requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45371
diff
changeset
|
27 requirements, |
45552
10284ce3d5ed
scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45372
diff
changeset
|
28 scmutil, |
47437
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
29 util, |
25970
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25874
diff
changeset
|
30 ) |
44060
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43793
diff
changeset
|
31 from .utils import ( |
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43793
diff
changeset
|
32 hashutil, |
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43793
diff
changeset
|
33 stringutil, |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46895
diff
changeset
|
34 urlutil, |
44060
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43793
diff
changeset
|
35 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
36 |
25970
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25874
diff
changeset
|
37 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
38 def backupbundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
39 repo, bases, heads, node, suffix, compress=True, obsolescence=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
40 ): |
5905
3afbd82a6c82
repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5904
diff
changeset
|
41 """create a bundle with the specified revisions as a backup""" |
23898
b21c2e0ee8a3
repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents:
23895
diff
changeset
|
42 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
43 backupdir = b"strip-backup" |
20977
a57dcd11be34
repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20975
diff
changeset
|
44 vfs = repo.vfs |
a57dcd11be34
repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20975
diff
changeset
|
45 if not vfs.isdir(backupdir): |
a57dcd11be34
repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20975
diff
changeset
|
46 vfs.mkdir(backupdir) |
23835
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
47 |
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
48 # Include a hash of all the nodes in the filename for uniqueness |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
49 allcommits = repo.set(b'%ln::%ln', bases, heads) |
23835
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
50 allhashes = sorted(c.hex() for c in allcommits) |
44060
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43793
diff
changeset
|
51 totalhash = hashutil.sha1(b''.join(allhashes)).digest() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
52 name = b"%s/%s-%s-%s.hg" % ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
53 backupdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
54 short(node), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
55 hex(totalhash[:4]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
56 suffix, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
57 ) |
23835
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
58 |
34144
91f0677dc920
repair: preserve phase also when not using generaldelta (issue5678)
Martin von Zweigbergk <martinvonz@google.com>
parents:
33490
diff
changeset
|
59 cgversion = changegroup.localversion(repo) |
26425
eb21b6679dc6
strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26423
diff
changeset
|
60 comp = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
61 if cgversion != b'01': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 bundletype = b"HG20" |
26425
eb21b6679dc6
strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26423
diff
changeset
|
63 if compress: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
64 comp = b'BZ' |
23898
b21c2e0ee8a3
repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents:
23895
diff
changeset
|
65 elif compress: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
66 bundletype = b"HG10BZ" |
11791
00cde9bddbe4
repair: do not compress partial bundle if we do not keep it on disk
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11600
diff
changeset
|
67 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
68 bundletype = b"HG10UN" |
32468
4c4d91908492
strip: use the 'writenewbundle' function to get bundle on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32296
diff
changeset
|
69 |
45144
c93dd9d9f1e6
discovery: change users of `outgoing.missingheads` to `outgoing.ancestorsof`
Manuel Jacob <me@manueljacob.de>
parents:
44452
diff
changeset
|
70 outgoing = discovery.outgoing(repo, missingroots=bases, ancestorsof=heads) |
33032
8e3021fd1a44
strip: include phases in bundle (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32930
diff
changeset
|
71 contentopts = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
72 b'cg.version': cgversion, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
73 b'obsolescence': obsolescence, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
74 b'phases': True, |
33032
8e3021fd1a44
strip: include phases in bundle (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32930
diff
changeset
|
75 } |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
76 return bundle2.writenewbundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
77 repo.ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
78 repo, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 b'strip', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
80 name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
81 bundletype, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
82 outgoing, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
83 contentopts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
84 vfs, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
85 compression=comp, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
86 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
87 |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
88 |
5910
b9a830fa10f6
simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5909
diff
changeset
|
89 def _collectfiles(repo, striprev): |
b9a830fa10f6
simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5909
diff
changeset
|
90 """find out the filelogs affected by the strip""" |
8462
e7e4e41b3bbc
repair: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8363
diff
changeset
|
91 files = set() |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
92 |
49284
d44e3c45f0e4
py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
93 for x in range(striprev, len(repo)): |
8479
3e16c0fc2241
repair: bulk update sets
Martin Geisler <mg@lazybytes.net>
parents:
8462
diff
changeset
|
94 files.update(repo[x].files()) |
5902
98f8dec8f437
repair.py: split stripall into two functions; clean it up a bit
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5901
diff
changeset
|
95 |
8462
e7e4e41b3bbc
repair: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8363
diff
changeset
|
96 return sorted(files) |
5902
98f8dec8f437
repair.py: split stripall into two functions; clean it up a bit
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5901
diff
changeset
|
97 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
98 |
33724
6626d12e7a85
repair: refactor broken linkrev collection
Durham Goode <durham@fb.com>
parents:
33490
diff
changeset
|
99 def _collectrevlog(revlog, striprev): |
6626d12e7a85
repair: refactor broken linkrev collection
Durham Goode <durham@fb.com>
parents:
33490
diff
changeset
|
100 _, brokenset = revlog.getstrippoint(striprev) |
6626d12e7a85
repair: refactor broken linkrev collection
Durham Goode <durham@fb.com>
parents:
33490
diff
changeset
|
101 return [revlog.linkrev(r) for r in brokenset] |
6626d12e7a85
repair: refactor broken linkrev collection
Durham Goode <durham@fb.com>
parents:
33490
diff
changeset
|
102 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
103 |
13702
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
104 def _collectbrokencsets(repo, files, striprev): |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
105 """return the changesets which will be broken by the truncation""" |
13705
73cfb7a5aa56
strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents:
13702
diff
changeset
|
106 s = set() |
5909
f45f7390c1c5
strip: calculate list of extra nodes to save and pass it to changegroupsubset
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5905
diff
changeset
|
107 |
42913
a8b249b2f8cc
strip: fix bug with treemanifests and unordered linkrevs
Martin von Zweigbergk <martinvonz@google.com>
parents:
42912
diff
changeset
|
108 for revlog in manifestrevlogs(repo): |
a8b249b2f8cc
strip: fix bug with treemanifests and unordered linkrevs
Martin von Zweigbergk <martinvonz@google.com>
parents:
42912
diff
changeset
|
109 s.update(_collectrevlog(revlog, striprev)) |
13705
73cfb7a5aa56
strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents:
13702
diff
changeset
|
110 for fname in files: |
33724
6626d12e7a85
repair: refactor broken linkrev collection
Durham Goode <durham@fb.com>
parents:
33490
diff
changeset
|
111 s.update(_collectrevlog(repo.file(fname), striprev)) |
5909
f45f7390c1c5
strip: calculate list of extra nodes to save and pass it to changegroupsubset
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5905
diff
changeset
|
112 |
13705
73cfb7a5aa56
strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents:
13702
diff
changeset
|
113 return s |
5909
f45f7390c1c5
strip: calculate list of extra nodes to save and pass it to changegroupsubset
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5905
diff
changeset
|
114 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
115 |
50276
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
116 def cleanup_undo_files(repo): |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
117 """remove "undo" files used by the rollback logic |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
118 |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
119 This is useful to prevent rollback running in situation were it does not |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
120 make sense. For example after a strip. |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
121 """ |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
122 for undovfs, undofile in repo.undofiles(): |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
123 try: |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
124 undovfs.unlink(undofile) |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
125 except OSError as e: |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
126 if e.errno != errno.ENOENT: |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
127 msg = _(b'error removing %s: %s\n') |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
128 msg %= (undovfs.join(undofile), stringutil.forcebytestr(e)) |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
129 repo.ui.warn(msg) |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
130 |
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
131 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
132 def strip(ui, repo, nodelist, backup=True, topic=b'backup'): |
32922
eb84b4ad41e5
repair: clarify in comment that caller must take lock, but not transaction
Martin von Zweigbergk <martinvonz@google.com>
parents:
32883
diff
changeset
|
133 # This function requires the caller to lock the repo, but it operates |
eb84b4ad41e5
repair: clarify in comment that caller must take lock, but not transaction
Martin von Zweigbergk <martinvonz@google.com>
parents:
32883
diff
changeset
|
134 # within a transaction of its own, and thus requires there to be no current |
eb84b4ad41e5
repair: clarify in comment that caller must take lock, but not transaction
Martin von Zweigbergk <martinvonz@google.com>
parents:
32883
diff
changeset
|
135 # transaction when it is called. |
32924
f044295cdb7a
repair: move check for existing transaction earlier
Martin von Zweigbergk <martinvonz@google.com>
parents:
32923
diff
changeset
|
136 if repo.currenttransaction() is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
137 raise error.ProgrammingError(b'cannot strip from inside a transaction') |
32924
f044295cdb7a
repair: move check for existing transaction earlier
Martin von Zweigbergk <martinvonz@google.com>
parents:
32923
diff
changeset
|
138 |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
139 # Simple way to maintain backwards compatibility for this |
445472225ccd
strip: remove -b/--backup codepaths
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
140 # argument. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
141 if backup in [b'none', b'strip']: |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
142 backup = False |
445472225ccd
strip: remove -b/--backup codepaths
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
143 |
18004
747a2f43d5d9
clfilter: strip logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17922
diff
changeset
|
144 repo = repo.unfiltered() |
18310
4499ba5ac35c
localrepo: introduce destroying function
Idan Kamara <idankk86@gmail.com>
parents:
18121
diff
changeset
|
145 repo.destroying() |
41098
cfd95219102d
strip: move attributes shortcut assigned earlier
Boris Feld <boris.feld@octobus.net>
parents:
41076
diff
changeset
|
146 vfs = repo.vfs |
42681
a1f10edcf6a6
strip: access bookmark before getting a reference to changelog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42254
diff
changeset
|
147 # load bookmark before changelog to avoid side effect from outdated |
a1f10edcf6a6
strip: access bookmark before getting a reference to changelog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42254
diff
changeset
|
148 # changelog (see repo._refreshchangelog) |
a1f10edcf6a6
strip: access bookmark before getting a reference to changelog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42254
diff
changeset
|
149 repo._bookmarks |
41098
cfd95219102d
strip: move attributes shortcut assigned earlier
Boris Feld <boris.feld@octobus.net>
parents:
41076
diff
changeset
|
150 cl = repo.changelog |
17013
c8eda7bbdcab
strip: incrementally update the branchheads cache after a strip
Joshua Redstone <joshua.redstone@fb.com>
parents:
16867
diff
changeset
|
151 |
16237
b5c0c7d0f83f
repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents:
15901
diff
changeset
|
152 # TODO handle undo of merge sets |
43741
8accf5fa9930
repair: fix an `isinstance(nodelist, str)` check for py3
Matt Harbison <matt_harbison@yahoo.com>
parents:
43117
diff
changeset
|
153 if isinstance(nodelist, bytes): |
16252
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15901
diff
changeset
|
154 nodelist = [nodelist] |
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15901
diff
changeset
|
155 striplist = [cl.rev(node) for node in nodelist] |
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15901
diff
changeset
|
156 striprev = min(striplist) |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
157 |
30707
987dbe87aad6
repair: combine two loops over changelog revisions
Martin von Zweigbergk <martinvonz@google.com>
parents:
30706
diff
changeset
|
158 files = _collectfiles(repo, striprev) |
987dbe87aad6
repair: combine two loops over changelog revisions
Martin von Zweigbergk <martinvonz@google.com>
parents:
30706
diff
changeset
|
159 saverevs = _collectbrokencsets(repo, files, striprev) |
987dbe87aad6
repair: combine two loops over changelog revisions
Martin von Zweigbergk <martinvonz@google.com>
parents:
30706
diff
changeset
|
160 |
6147
53ae5af55db3
repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5910
diff
changeset
|
161 # Some revisions with rev > striprev may not be descendants of striprev. |
53ae5af55db3
repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5910
diff
changeset
|
162 # We have to find these revisions and put them in a bundle, so that |
53ae5af55db3
repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5910
diff
changeset
|
163 # we can restore them after the truncations. |
53ae5af55db3
repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5910
diff
changeset
|
164 # To create the bundle we use repo.changegroupsubset which requires |
53ae5af55db3
repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5910
diff
changeset
|
165 # the list of heads and bases of the set of interesting revisions. |
53ae5af55db3
repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5910
diff
changeset
|
166 # (head = revision in the set that has no descendant in the set; |
53ae5af55db3
repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5910
diff
changeset
|
167 # base = revision in the set that has no ancestor in the set) |
16252
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15901
diff
changeset
|
168 tostrip = set(striplist) |
30707
987dbe87aad6
repair: combine two loops over changelog revisions
Martin von Zweigbergk <martinvonz@google.com>
parents:
30706
diff
changeset
|
169 saveheads = set(saverevs) |
30706
2e4862646f02
repair: speed up stripping of many roots
Martin von Zweigbergk <martinvonz@google.com>
parents:
30375
diff
changeset
|
170 for r in cl.revs(start=striprev + 1): |
2e4862646f02
repair: speed up stripping of many roots
Martin von Zweigbergk <martinvonz@google.com>
parents:
30375
diff
changeset
|
171 if any(p in tostrip for p in cl.parentrevs(r)): |
2e4862646f02
repair: speed up stripping of many roots
Martin von Zweigbergk <martinvonz@google.com>
parents:
30375
diff
changeset
|
172 tostrip.add(r) |
13702
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
173 |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
174 if r not in tostrip: |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
175 saverevs.add(r) |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
176 saveheads.difference_update(cl.parentrevs(r)) |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
177 saveheads.add(r) |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
178 saveheads = [cl.node(r) for r in saveheads] |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
179 |
15386
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
180 # compute base nodes |
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
181 if saverevs: |
16867
1093ad1e8903
revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents:
16745
diff
changeset
|
182 descendants = set(cl.descendants(saverevs)) |
15386
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
183 saverevs.difference_update(descendants) |
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
184 savebases = [cl.node(r) for r in saverevs] |
16252
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15901
diff
changeset
|
185 stripbases = [cl.node(r) for r in tostrip] |
18040
fe8caf28d580
strip: make query to get new bookmark target cheaper
Siddharth Agarwal <sid0@fb.com>
parents:
18004
diff
changeset
|
186 |
32629
71eb6a098315
strip: strip obsmarkers exclusive to the stripped changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32628
diff
changeset
|
187 stripobsidx = obsmarkers = () |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
188 if repo.ui.configbool(b'devel', b'strip-obsmarkers'): |
33143
d09ae850296d
obsutil: move 'exclusivemarkers' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33108
diff
changeset
|
189 obsmarkers = obsutil.exclusivemarkers(repo, stripbases) |
32629
71eb6a098315
strip: strip obsmarkers exclusive to the stripped changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32628
diff
changeset
|
190 if obsmarkers: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
191 stripobsidx = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
192 i for i, m in enumerate(repo.obsstore) if m in obsmarkers |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
193 ] |
32629
71eb6a098315
strip: strip obsmarkers exclusive to the stripped changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32628
diff
changeset
|
194 |
41102
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
195 newbmtarget, updatebm = _bookmarkmovements(repo, tostrip) |
13362
ee01d9d84115
bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents:
12057
diff
changeset
|
196 |
11197
4bb4895e1693
strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents:
10881
diff
changeset
|
197 backupfile = None |
24252
f962692853c0
repair: define explicit local variable, don't reuse a comprehension variable
Mike Edgar <adgar@google.com>
parents:
24170
diff
changeset
|
198 node = nodelist[-1] |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
199 if backup: |
41100
399010051cf4
strip: extract code to create strip backup
Boris Feld <boris.feld@octobus.net>
parents:
41099
diff
changeset
|
200 backupfile = _createstripbackup(repo, stripbases, node, topic) |
41099
e80329a3952c
strip: clarify comment around bundle create
Boris Feld <boris.feld@octobus.net>
parents:
41098
diff
changeset
|
201 # create a changegroup for all the branches we need to keep |
29954
769aee32fae0
strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents:
29953
diff
changeset
|
202 tmpbundlefile = None |
29951
e7acbe538baf
strip: simplify some repeated conditions
Martin von Zweigbergk <martinvonz@google.com>
parents:
29708
diff
changeset
|
203 if saveheads: |
29954
769aee32fae0
strip: don't use "full" and "partial" to describe bundles
Martin von Zweigbergk <martinvonz@google.com>
parents:
29953
diff
changeset
|
204 # do not compress temporary bundle if we remove it from disk later |
32628
5732e6d2b369
strip: do not include obsolescence markers for the temporary bundle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32623
diff
changeset
|
205 # |
5732e6d2b369
strip: do not include obsolescence markers for the temporary bundle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32623
diff
changeset
|
206 # We do not include obsolescence, it might re-introduce prune markers |
5732e6d2b369
strip: do not include obsolescence markers for the temporary bundle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32623
diff
changeset
|
207 # we are trying to strip. This is harmless since the stripped markers |
5732e6d2b369
strip: do not include obsolescence markers for the temporary bundle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32623
diff
changeset
|
208 # are already backed up and we did not touched the markers for the |
5732e6d2b369
strip: do not include obsolescence markers for the temporary bundle
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32623
diff
changeset
|
209 # saved changesets. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
210 tmpbundlefile = backupbundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
211 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
212 savebases, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
213 saveheads, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
214 node, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
215 b'temp', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
216 compress=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
217 obsolescence=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
218 ) |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
219 |
41076
8ecb17b7f432
procutil: correct spelling of uninterruptable -> uninterruptible
Kyle Lippincott <spectral@google.com>
parents:
39745
diff
changeset
|
220 with ui.uninterruptible(): |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
221 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
222 with repo.transaction(b"strip") as tr: |
39686
3d22aef3ecd5
transaction: make entries a private attribute (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
223 # TODO this code violates the interface abstraction of the |
3d22aef3ecd5
transaction: make entries a private attribute (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
224 # transaction and makes assumptions that file storage is |
3d22aef3ecd5
transaction: make entries a private attribute (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
225 # using append-only files. We'll need some kind of storage |
3d22aef3ecd5
transaction: make entries a private attribute (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
226 # API to handle stripping for us. |
45871
a985c4fb23ca
transaction: change list of journal entries into a dictionary
Joerg Sonnenberger <joerg@bec.de>
parents:
45869
diff
changeset
|
227 oldfiles = set(tr._offsetmap.keys()) |
45872
ec73a6a75985
transaction: split new files into a separate set
Joerg Sonnenberger <joerg@bec.de>
parents:
45871
diff
changeset
|
228 oldfiles.update(tr._newfiles) |
8073
e8a28556a0a8
strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
7361
diff
changeset
|
229 |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
230 tr.startgroup() |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
231 cl.strip(striprev, tr) |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
232 stripmanifest(repo, striprev, tr, files) |
8073
e8a28556a0a8
strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
7361
diff
changeset
|
233 |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
234 for fn in files: |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
235 repo.file(fn).strip(striprev, tr) |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
236 tr.endgroup() |
11197
4bb4895e1693
strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents:
10881
diff
changeset
|
237 |
45871
a985c4fb23ca
transaction: change list of journal entries into a dictionary
Joerg Sonnenberger <joerg@bec.de>
parents:
45869
diff
changeset
|
238 entries = tr.readjournal() |
a985c4fb23ca
transaction: change list of journal entries into a dictionary
Joerg Sonnenberger <joerg@bec.de>
parents:
45869
diff
changeset
|
239 |
a985c4fb23ca
transaction: change list of journal entries into a dictionary
Joerg Sonnenberger <joerg@bec.de>
parents:
45869
diff
changeset
|
240 for file, troffset in entries: |
a985c4fb23ca
transaction: change list of journal entries into a dictionary
Joerg Sonnenberger <joerg@bec.de>
parents:
45869
diff
changeset
|
241 if file in oldfiles: |
a985c4fb23ca
transaction: change list of journal entries into a dictionary
Joerg Sonnenberger <joerg@bec.de>
parents:
45869
diff
changeset
|
242 continue |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
243 with repo.svfs(file, b'a', checkambig=True) as fp: |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
244 fp.truncate(troffset) |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
245 if troffset == 0: |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
246 repo.store.markremoved(file) |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
247 |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
248 deleteobsmarkers(repo.obsstore, stripobsidx) |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
249 del repo.obsstore |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
250 repo.invalidatevolatilesets() |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
251 repo._phasecache.filterunknown(repo) |
32629
71eb6a098315
strip: strip obsmarkers exclusive to the stripped changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32628
diff
changeset
|
252 |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
253 if tmpbundlefile: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
254 ui.note(_(b"adding branch\n")) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
255 f = vfs.open(tmpbundlefile, b"rb") |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
256 gen = exchange.readbundle(ui, f, tmpbundlefile, vfs) |
47437
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
257 # silence internal shuffling chatter |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
258 maybe_silent = ( |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
259 repo.ui.silent() |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
260 if not repo.ui.verbose |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
261 else util.nullcontextmanager() |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
262 ) |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
263 with maybe_silent: |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
264 tmpbundleurl = b'bundle:' + vfs.join(tmpbundlefile) |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
265 txnname = b'strip' |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
266 if not isinstance(gen, bundle2.unbundle20): |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
267 txnname = b"strip\n%s" % urlutil.hidepassword( |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
268 tmpbundleurl |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
269 ) |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
270 with repo.transaction(txnname) as tr: |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
271 bundle2.applybundle( |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
272 repo, gen, tr, source=b'strip', url=tmpbundleurl |
7a430116f639
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)
Martin von Zweigbergk <martinvonz@google.com>
parents:
46907
diff
changeset
|
273 ) |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
274 f.close() |
31626
0febf8e4e2ce
repair: use context manager for lock management
Matt Harbison <matt_harbison@yahoo.com>
parents:
31324
diff
changeset
|
275 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
276 with repo.transaction(b'repair') as tr: |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
277 bmchanges = [(m, repo[newbmtarget].node()) for m in updatebm] |
41102
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
278 repo._bookmarks.applychanges(repo, tr, bmchanges) |
27157
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
26797
diff
changeset
|
279 |
50276
8011017629be
undo-files: extract the cleanup code from strip in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
280 cleanup_undo_files(repo) |
16237
b5c0c7d0f83f
repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents:
15901
diff
changeset
|
281 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
282 except: # re-raises |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
283 if backupfile: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
284 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
285 _(b"strip failed, backup bundle stored in '%s'\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
286 % vfs.join(backupfile) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
287 ) |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
288 if tmpbundlefile: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
289 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
290 _(b"strip failed, unrecovered changes stored in '%s'\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
291 % vfs.join(tmpbundlefile) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
292 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
293 ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
294 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
295 b"(fix the problem, then recover the changesets with " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
296 b"\"hg unbundle '%s'\")\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
297 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
298 % vfs.join(tmpbundlefile) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
299 ) |
38527
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
300 raise |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
301 else: |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
302 if tmpbundlefile: |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
303 # Remove temporary bundle only if there were no exceptions |
6e0c66ef8cd0
repair: mark the critical section of strip() as unsafe
Augie Fackler <augie@google.com>
parents:
38394
diff
changeset
|
304 vfs.unlink(tmpbundlefile) |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
305 |
18395
904b7109938e
destroyed: drop complex branchcache rebuilt logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18311
diff
changeset
|
306 repo.destroyed() |
30274
c1345969f6c5
repair: make strip() return backup file path
Martin von Zweigbergk <martinvonz@google.com>
parents:
30001
diff
changeset
|
307 # return the backup file path (or None if 'backup' was False) so |
c1345969f6c5
repair: make strip() return backup file path
Martin von Zweigbergk <martinvonz@google.com>
parents:
30001
diff
changeset
|
308 # extensions can use it |
c1345969f6c5
repair: make strip() return backup file path
Martin von Zweigbergk <martinvonz@google.com>
parents:
30001
diff
changeset
|
309 return backupfile |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
310 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
311 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
312 def softstrip(ui, repo, nodelist, backup=True, topic=b'backup'): |
41798
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
313 """perform a "soft" strip using the archived phase""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
314 tostrip = [c.node() for c in repo.set(b'sort(%ln::)', nodelist)] |
41798
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
315 if not tostrip: |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
316 return None |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
317 |
46515
cd9154343160
softstrip: fix a reference to an undefined variable
Martin von Zweigbergk <martinvonz@google.com>
parents:
46514
diff
changeset
|
318 backupfile = None |
41798
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
319 if backup: |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
320 node = tostrip[0] |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
321 backupfile = _createstripbackup(repo, tostrip, node, topic) |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
322 |
46514
beaa233e81f7
softstrip: move _bookmarkmovements() call to where it's needed
Martin von Zweigbergk <martinvonz@google.com>
parents:
45872
diff
changeset
|
323 newbmtarget, updatebm = _bookmarkmovements(repo, tostrip) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
324 with repo.transaction(b'strip') as tr: |
41798
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
325 phases.retractboundary(repo, tr, phases.archived, tostrip) |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
326 bmchanges = [(m, repo[newbmtarget].node()) for m in updatebm] |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
327 repo._bookmarks.applychanges(repo, tr, bmchanges) |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
328 return backupfile |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
329 |
8c42b4a3d447
strip: introduce a soft strip option
Boris Feld <boris.feld@octobus.net>
parents:
41102
diff
changeset
|
330 |
41102
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
331 def _bookmarkmovements(repo, tostrip): |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
332 # compute necessary bookmark movement |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
333 bm = repo._bookmarks |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
334 updatebm = [] |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
335 for m in bm: |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
336 rev = repo[bm[m]].rev() |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
337 if rev in tostrip: |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
338 updatebm.append(m) |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
339 newbmtarget = None |
42246
e10b8058da84
repair: reword comment about bookmarks logic
Augie Fackler <augie@google.com>
parents:
41798
diff
changeset
|
340 # If we need to move bookmarks, compute bookmark |
e10b8058da84
repair: reword comment about bookmarks logic
Augie Fackler <augie@google.com>
parents:
41798
diff
changeset
|
341 # targets. Otherwise we can skip doing this logic. |
e10b8058da84
repair: reword comment about bookmarks logic
Augie Fackler <augie@google.com>
parents:
41798
diff
changeset
|
342 if updatebm: |
41102
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
343 # For a set s, max(parents(s) - s) is the same as max(heads(::s - s)), |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
344 # but is much faster |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
345 newbmtarget = repo.revs(b'max(parents(%ld) - (%ld))', tostrip, tostrip) |
41102
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
346 if newbmtarget: |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
347 newbmtarget = repo[newbmtarget.first()].node() |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
348 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
349 newbmtarget = b'.' |
41102
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
350 return newbmtarget, updatebm |
c9a2c4d0e80f
strip: extract bookmark movement into a separate function
Boris Feld <boris.feld@octobus.net>
parents:
41101
diff
changeset
|
351 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
352 |
41100
399010051cf4
strip: extract code to create strip backup
Boris Feld <boris.feld@octobus.net>
parents:
41099
diff
changeset
|
353 def _createstripbackup(repo, stripbases, node, topic): |
399010051cf4
strip: extract code to create strip backup
Boris Feld <boris.feld@octobus.net>
parents:
41099
diff
changeset
|
354 # backup the changeset we are about to strip |
399010051cf4
strip: extract code to create strip backup
Boris Feld <boris.feld@octobus.net>
parents:
41099
diff
changeset
|
355 vfs = repo.vfs |
399010051cf4
strip: extract code to create strip backup
Boris Feld <boris.feld@octobus.net>
parents:
41099
diff
changeset
|
356 cl = repo.changelog |
399010051cf4
strip: extract code to create strip backup
Boris Feld <boris.feld@octobus.net>
parents:
41099
diff
changeset
|
357 backupfile = backupbundle(repo, stripbases, cl.heads(), node, topic) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
358 repo.ui.status(_(b"saved backup bundle to %s\n") % vfs.join(backupfile)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
359 repo.ui.log( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
360 b"backupbundle", b"saved backup bundle to %s\n", vfs.join(backupfile) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
361 ) |
41100
399010051cf4
strip: extract code to create strip backup
Boris Feld <boris.feld@octobus.net>
parents:
41099
diff
changeset
|
362 return backupfile |
399010051cf4
strip: extract code to create strip backup
Boris Feld <boris.feld@octobus.net>
parents:
41099
diff
changeset
|
363 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
364 |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
365 def safestriproots(ui, repo, nodes): |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
366 """return list of roots of nodes where descendants are covered by nodes""" |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
367 torev = repo.unfiltered().changelog.rev |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44060
diff
changeset
|
368 revs = {torev(n) for n in nodes} |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
369 # tostrip = wanted - unsafe = wanted - ancestors(orphaned) |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
370 # orphaned = affected - wanted |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
371 # affected = descendants(roots(wanted)) |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
372 # wanted = revs |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
373 revset = b'%ld - ( ::( (roots(%ld):: and not _phase(%s)) -%ld) )' |
39745
b2ec79559a4b
strip: ignore orphaned internal changesets while computing safe strip roots
Boris Feld <boris.feld@octobus.net>
parents:
39686
diff
changeset
|
374 tostrip = set(repo.revs(revset, revs, revs, phases.internal, revs)) |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
375 notstrip = revs - tostrip |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
376 if notstrip: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
377 nodestr = b', '.join(sorted(short(repo[n].node()) for n in notstrip)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
378 ui.warn( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
379 _(b'warning: orphaned descendants detected, not stripping %s\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
380 % nodestr |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
381 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
382 return [c.node() for c in repo.set(b'roots(%ld)', tostrip)] |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
383 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
384 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
385 class stripcallback: |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
386 """used as a transaction postclose callback""" |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
387 |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
388 def __init__(self, ui, repo, backup, topic): |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
389 self.ui = ui |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
390 self.repo = repo |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
391 self.backup = backup |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
392 self.topic = topic or b'backup' |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
393 self.nodelist = [] |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
394 |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
395 def addnodes(self, nodes): |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
396 self.nodelist.extend(nodes) |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
397 |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
398 def __call__(self, tr): |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
399 roots = safestriproots(self.ui, self.repo, self.nodelist) |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
400 if roots: |
33108
208de1534ebd
strip: respect the backup option in stripcallback
Jun Wu <quark@fb.com>
parents:
33087
diff
changeset
|
401 strip(self.ui, self.repo, roots, self.backup, self.topic) |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
402 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
403 |
38799
2002c193f2bc
rebase: support "history-editing-backup" config option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
38783
diff
changeset
|
404 def delayedstrip(ui, repo, nodelist, topic=None, backup=True): |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
405 """like strip, but works inside transaction and won't strip irreverent revs |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
406 |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
407 nodelist must explicitly contain all descendants. Otherwise a warning will |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
408 be printed that some nodes are not stripped. |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
409 |
38799
2002c193f2bc
rebase: support "history-editing-backup" config option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
38783
diff
changeset
|
410 Will do a backup if `backup` is True. The last non-None "topic" will be |
2002c193f2bc
rebase: support "history-editing-backup" config option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
38783
diff
changeset
|
411 used as the backup topic name. The default backup topic name is "backup". |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
412 """ |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
413 tr = repo.currenttransaction() |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
414 if not tr: |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
415 nodes = safestriproots(ui, repo, nodelist) |
38799
2002c193f2bc
rebase: support "history-editing-backup" config option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
38783
diff
changeset
|
416 return strip(ui, repo, nodes, backup=backup, topic=topic) |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
417 # transaction postclose callbacks are called in alphabet order. |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
418 # use '\xff' as prefix so we are likely to be called last. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
419 callback = tr.getpostclose(b'\xffstrip') |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
420 if callback is None: |
38799
2002c193f2bc
rebase: support "history-editing-backup" config option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
38783
diff
changeset
|
421 callback = stripcallback(ui, repo, backup=backup, topic=topic) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
422 tr.addpostclose(b'\xffstrip', callback) |
33087
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
423 if topic: |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
424 callback.topic = topic |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
425 callback.addnodes(nodelist) |
fcd1c483f5ea
strip: add a delayedstrip method that works in a transaction
Jun Wu <quark@fb.com>
parents:
33043
diff
changeset
|
426 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
427 |
33725
86ea201eaeb9
repair: move manifest strip to a separate function
Durham Goode <durham@fb.com>
parents:
33724
diff
changeset
|
428 def stripmanifest(repo, striprev, tr, files): |
42912
6d0fdba635e5
repair: extract a helper for generating all manifest revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
42715
diff
changeset
|
429 for revlog in manifestrevlogs(repo): |
6d0fdba635e5
repair: extract a helper for generating all manifest revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
42715
diff
changeset
|
430 revlog.strip(striprev, tr) |
33725
86ea201eaeb9
repair: move manifest strip to a separate function
Durham Goode <durham@fb.com>
parents:
33724
diff
changeset
|
431 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
432 |
42912
6d0fdba635e5
repair: extract a helper for generating all manifest revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
42715
diff
changeset
|
433 def manifestrevlogs(repo): |
6d0fdba635e5
repair: extract a helper for generating all manifest revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
42715
diff
changeset
|
434 yield repo.manifestlog.getstorage(b'') |
45552
10284ce3d5ed
scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45372
diff
changeset
|
435 if scmutil.istreemanifest(repo): |
42254
d811f17090a3
repair: reword comments that I noticed while working on source formatting
Augie Fackler <augie@google.com>
parents:
42246
diff
changeset
|
436 # This logic is safe if treemanifest isn't enabled, but also |
d811f17090a3
repair: reword comments that I noticed while working on source formatting
Augie Fackler <augie@google.com>
parents:
42246
diff
changeset
|
437 # pointless, so we skip it if treemanifest isn't enabled. |
47877
2174f54aab18
store: return just one filename in walk functions
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47875
diff
changeset
|
438 for t, unencoded, size in repo.store.datafiles(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
439 if unencoded.startswith(b'meta/') and unencoded.endswith( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
440 b'00manifest.i' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
441 ): |
32296
7e07d5836063
hg: backout optimizing for treemanifests
Durham Goode <durham@fb.com>
parents:
32197
diff
changeset
|
442 dir = unencoded[5:-12] |
42912
6d0fdba635e5
repair: extract a helper for generating all manifest revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
42715
diff
changeset
|
443 yield repo.manifestlog.getstorage(dir) |
32196
a2be2abe9476
strip: move tree strip logic to it's own function
Durham Goode <durham@fb.com>
parents:
31875
diff
changeset
|
444 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
445 |
47875
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
446 def rebuildfncache(ui, repo, only_data=False): |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
447 """Rebuilds the fncache file from repo history. |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
448 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
449 Missing entries will be added. Extra entries will be removed. |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
450 """ |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
451 repo = repo.unfiltered() |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
452 |
46638
b4c2a2af25e2
requirements: also add a fncache constant
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46515
diff
changeset
|
453 if requirements.FNCACHE_REQUIREMENT not in repo.requirements: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
454 ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
455 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
456 b'(not rebuilding fncache because repository does not ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
457 b'support fncache)\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
458 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
459 ) |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
460 return |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
461 |
27860
0da102e4f203
with: use context manager in rebuildfncache again
Bryan O'Sullivan <bryano@fb.com>
parents:
27553
diff
changeset
|
462 with repo.lock(): |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
463 fnc = repo.store.fncache |
42715
f59f8a5e9096
fncache: make debugrebuildfncache not fail on broken fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
42681
diff
changeset
|
464 fnc.ensureloaded(warn=ui.warn) |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
465 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
466 oldentries = set(fnc.entries) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
467 newentries = set() |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
468 seenfiles = set() |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
469 |
47875
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
470 if only_data: |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
471 # Trust the listing of .i from the fncache, but not the .d. This is |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
472 # much faster, because we only need to stat every possible .d files, |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
473 # instead of reading the full changelog |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
474 for f in fnc: |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
475 if f[:5] == b'data/' and f[-2:] == b'.i': |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
476 seenfiles.add(f[5:-2]) |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
477 newentries.add(f) |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
478 dataf = f[:-2] + b'.d' |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
479 if repo.store._exists(dataf): |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
480 newentries.add(dataf) |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
481 else: |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
482 progress = ui.makeprogress( |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
483 _(b'rebuilding'), unit=_(b'changesets'), total=len(repo) |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
484 ) |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
485 for rev in repo: |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
486 progress.update(rev) |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
487 |
47875
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
488 ctx = repo[rev] |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
489 for f in ctx.files(): |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
490 # This is to minimize I/O. |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
491 if f in seenfiles: |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
492 continue |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
493 seenfiles.add(f) |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
494 |
47875
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
495 i = b'data/%s.i' % f |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
496 d = b'data/%s.d' % f |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
497 |
47875
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
498 if repo.store._exists(i): |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
499 newentries.add(i) |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
500 if repo.store._exists(d): |
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
501 newentries.add(d) |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
502 |
47875
0fb328bb2459
debugrebuildfncache: add a cheaper option to rebuild the fncache
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
47437
diff
changeset
|
503 progress.complete() |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
504 |
45372
77b8588dd84e
requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45371
diff
changeset
|
505 if requirements.TREEMANIFEST_REQUIREMENT in repo.requirements: |
42254
d811f17090a3
repair: reword comments that I noticed while working on source formatting
Augie Fackler <augie@google.com>
parents:
42246
diff
changeset
|
506 # This logic is safe if treemanifest isn't enabled, but also |
d811f17090a3
repair: reword comments that I noticed while working on source formatting
Augie Fackler <augie@google.com>
parents:
42246
diff
changeset
|
507 # pointless, so we skip it if treemanifest isn't enabled. |
43523
c21aca51b392
utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
508 for dir in pathutil.dirs(seenfiles): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
509 i = b'meta/%s/00manifest.i' % dir |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
510 d = b'meta/%s/00manifest.d' % dir |
28007
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
27930
diff
changeset
|
511 |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
27930
diff
changeset
|
512 if repo.store._exists(i): |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
27930
diff
changeset
|
513 newentries.add(i) |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
27930
diff
changeset
|
514 if repo.store._exists(d): |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
27930
diff
changeset
|
515 newentries.add(d) |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
27930
diff
changeset
|
516 |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
517 addcount = len(newentries - oldentries) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
518 removecount = len(oldentries - newentries) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
519 for p in sorted(oldentries - newentries): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
520 ui.write(_(b'removing %s\n') % p) |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
521 for p in sorted(newentries - oldentries): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
522 ui.write(_(b'adding %s\n') % p) |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
523 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
524 if addcount or removecount: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
525 ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
526 _(b'%d items added, %d removed from fncache\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
527 % (addcount, removecount) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
528 ) |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
529 fnc.entries = newentries |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
530 fnc._dirty = True |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
531 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
532 with repo.transaction(b'fncache') as tr: |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
533 fnc.write(tr) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
534 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
535 ui.write(_(b'fncache already up to date\n')) |
25652
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25404
diff
changeset
|
536 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42913
diff
changeset
|
537 |
28868
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
538 def deleteobsmarkers(obsstore, indices): |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
539 """Delete some obsmarkers from obsstore and return how many were deleted |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
540 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
541 'indices' is a list of ints which are the indices |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
542 of the markers to be deleted. |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
543 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
544 Every invocation of this function completely rewrites the obsstore file, |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
545 skipping the markers we want to be removed. The new temporary file is |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
546 created, remaining markers are written there and on .close() this file |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
547 gets atomically renamed to obsstore, thus guaranteeing consistency.""" |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
548 if not indices: |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
549 # we don't want to rewrite the obsstore with the same content |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
550 return |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
551 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
552 left = [] |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
553 current = obsstore._all |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
554 n = 0 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
555 for i, m in enumerate(current): |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
556 if i in indices: |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
557 n += 1 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
558 continue |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
559 left.append(m) |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
560 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
561 newobsstorefile = obsstore.svfs(b'obsstore', b'w', atomictemp=True) |
28868
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
562 for bytes in obsolete.encodemarkers(left, True, obsstore._version): |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
563 newobsstorefile.write(bytes) |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
564 newobsstorefile.close() |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
28666
diff
changeset
|
565 return n |