Mercurial > hg > mercurial-source
annotate mercurial/repair.py @ 29946:bf7b8157c483 stable
strip: invalidate phase cache after stripping changeset (issue5235)
When we remove a changeset from the changelog, the phase cache must be
invalidated, otherwise it could refer to changesets that are no longer in the
repo.
To reproduce the failure, I created an extension querying the phase cache after
the strip transaction is over.
To do that, I stripped two commits with a bookmark on one of them to force
another transaction (we open a transaction for moving bookmarks)
after the strip transaction.
Without the fix in this patch, the test leads to a stacktrace showing the issue:
repair.strip(ui, repo, revs, backup)
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/repair.py", line 205, in strip
tr.close()
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/transaction.py", line 44, in _active
return func(self, *args, **kwds)
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/transaction.py", line 490, in close
self._postclosecallback[cat](self)
File "$TESTTMP/crashstrip2.py", line 4, in test
[repo.changelog.node(r) for r in repo.revs("not public()")]
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/changelog.py", line 337, in node
return super(changelog, self).node(rev)
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/revlog.py", line 377, in node
return self.index[rev][7]
IndexError: revlog index out of range
The situation was encountered in inhibit (evolve's repo) where we would crash
following the volatile set invalidation submitted by Augie in
e6f490e328635312ee214a12bc7fd3c7d46bf9ce. Before his patch the issue was masked
as we were not accessing the phasecache after stripping a revision.
This bug uncovered another but in histedit (see explanation in issue5235).
I changed the histedit test accordingly to avoid fixing two things at once.
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Thu, 12 May 2016 06:13:59 -0700 (2016-05-12) |
parents | 445a25bb70be |
children | 0d83ad967bf8 |
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> |
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # Copyright 2007 Matt Mackall |
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 |
26554
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
9 from __future__ import absolute_import |
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
10 |
16440
692bf06bb1af
repair: fix missing import
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
16388
diff
changeset
|
11 import errno |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
12 |
26554
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
13 from .i18n import _ |
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
14 from .node import short |
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
15 from . import ( |
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
16 bundle2, |
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
17 changegroup, |
27227
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27051
diff
changeset
|
18 error, |
26554
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
19 exchange, |
29618
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
20 obsolete, |
26554
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
21 util, |
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
22 ) |
d1419cfbd4f4
repair: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26442
diff
changeset
|
23 |
15386
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
24 def _bundle(repo, bases, heads, node, suffix, compress=True): |
5902
3afbd82a6c82
repair.py: don't use nested functions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5901
diff
changeset
|
25 """create a bundle with the specified revisions as a backup""" |
28601
7cbb3a01fa38
repair: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
28530
diff
changeset
|
26 cgversion = changegroup.safeversion(repo) |
23910
b21c2e0ee8a3
repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents:
23907
diff
changeset
|
27 |
b21c2e0ee8a3
repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents:
23907
diff
changeset
|
28 cg = changegroup.changegroupsubset(repo, bases, heads, 'strip', |
b21c2e0ee8a3
repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents:
23907
diff
changeset
|
29 version=cgversion) |
20977
a57dcd11be34
repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20975
diff
changeset
|
30 backupdir = "strip-backup" |
a57dcd11be34
repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20975
diff
changeset
|
31 vfs = repo.vfs |
a57dcd11be34
repair: make paths in "_bundle()" relative to ".hg"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20975
diff
changeset
|
32 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
|
33 vfs.mkdir(backupdir) |
23847
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
34 |
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
35 # Include a hash of all the nodes in the filename for uniqueness |
25824
28800ab40395
repair: use _hexlist() to build revset expression from binary nodes
Yuya Nishihara <yuya@tcha.org>
parents:
25773
diff
changeset
|
36 allcommits = repo.set('%ln::%ln', bases, heads) |
23847
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
37 allhashes = sorted(c.hex() for c in allcommits) |
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
38 totalhash = util.sha1(''.join(allhashes)).hexdigest() |
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
39 name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix) |
aa4a1672583e
bundles: do not overwrite existing backup bundles (BC)
Durham Goode <durham@fb.com>
parents:
22818
diff
changeset
|
40 |
27051
eb21b6679dc6
strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27049
diff
changeset
|
41 comp = None |
27049
c93f91c1db1c
strip: use bundle2 + cg2 by default when repository use general delta
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26598
diff
changeset
|
42 if cgversion != '01': |
24825
e0e28e910fa3
bundle2: rename format, parts and config to final names
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24354
diff
changeset
|
43 bundletype = "HG20" |
27051
eb21b6679dc6
strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27049
diff
changeset
|
44 if compress: |
eb21b6679dc6
strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27049
diff
changeset
|
45 comp = 'BZ' |
23910
b21c2e0ee8a3
repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents:
23907
diff
changeset
|
46 elif compress: |
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
|
47 bundletype = "HG10BZ" |
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
|
48 else: |
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
|
49 bundletype = "HG10UN" |
29407
ae53ecc47414
bundle: move writebundle() from changegroup.py to bundle2.py (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
29137
diff
changeset
|
50 return bundle2.writebundle(repo.ui, cg, name, bundletype, vfs, |
27051
eb21b6679dc6
strip: compress bundle2 backup using BZ
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27049
diff
changeset
|
51 compression=comp) |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
52 |
5907
b9a830fa10f6
simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5906
diff
changeset
|
53 def _collectfiles(repo, striprev): |
b9a830fa10f6
simplify revlog.strip interface and callers; add docstring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5906
diff
changeset
|
54 """find out the filelogs affected by the strip""" |
8460
e7e4e41b3bbc
repair: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8363
diff
changeset
|
55 files = set() |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
56 |
6752
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6749
diff
changeset
|
57 for x in xrange(striprev, len(repo)): |
8477
3e16c0fc2241
repair: bulk update sets
Martin Geisler <mg@lazybytes.net>
parents:
8460
diff
changeset
|
58 files.update(repo[x].files()) |
5899
98f8dec8f437
repair.py: split stripall into two functions; clean it up a bit
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5898
diff
changeset
|
59 |
8460
e7e4e41b3bbc
repair: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8363
diff
changeset
|
60 return sorted(files) |
5899
98f8dec8f437
repair.py: split stripall into two functions; clean it up a bit
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5898
diff
changeset
|
61 |
13702
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
62 def _collectbrokencsets(repo, files, striprev): |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
63 """return the changesets which will be broken by the truncation""" |
13705
73cfb7a5aa56
strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents:
13702
diff
changeset
|
64 s = set() |
13702
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
65 def collectone(revlog): |
20074
5fc2ae1c631b
strip: add faster revlog strip computation
Durham Goode <durham@fb.com>
parents:
18764
diff
changeset
|
66 _, brokenset = revlog.getstrippoint(striprev) |
5fc2ae1c631b
strip: add faster revlog strip computation
Durham Goode <durham@fb.com>
parents:
18764
diff
changeset
|
67 s.update([revlog.linkrev(r) for r in brokenset]) |
5906
f45f7390c1c5
strip: calculate list of extra nodes to save and pass it to changegroupsubset
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5902
diff
changeset
|
68 |
13705
73cfb7a5aa56
strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents:
13702
diff
changeset
|
69 collectone(repo.manifest) |
73cfb7a5aa56
strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents:
13702
diff
changeset
|
70 for fname in files: |
73cfb7a5aa56
strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents:
13702
diff
changeset
|
71 collectone(repo.file(fname)) |
5906
f45f7390c1c5
strip: calculate list of extra nodes to save and pass it to changegroupsubset
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5902
diff
changeset
|
72 |
13705
73cfb7a5aa56
strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents:
13702
diff
changeset
|
73 return s |
5906
f45f7390c1c5
strip: calculate list of extra nodes to save and pass it to changegroupsubset
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5902
diff
changeset
|
74 |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
75 def strip(ui, repo, nodelist, backup=True, topic='backup'): |
28208
56caab876bd8
repair: improves documentation of strip regarding locks
Laurent Charignon <lcharignon@fb.com>
parents:
27797
diff
changeset
|
76 # This function operates within a transaction of its own, but does |
56caab876bd8
repair: improves documentation of strip regarding locks
Laurent Charignon <lcharignon@fb.com>
parents:
27797
diff
changeset
|
77 # not take any lock on the repo. |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
78 # 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
|
79 # argument. |
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
80 if backup in ['none', 'strip']: |
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
81 backup = False |
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
82 |
18004
747a2f43d5d9
clfilter: strip logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17922
diff
changeset
|
83 repo = repo.unfiltered() |
18310
4499ba5ac35c
localrepo: introduce destroying function
Idan Kamara <idankk86@gmail.com>
parents:
18121
diff
changeset
|
84 repo.destroying() |
17027
c8eda7bbdcab
strip: incrementally update the branchheads cache after a strip
Joshua Redstone <joshua.redstone@fb.com>
parents:
16868
diff
changeset
|
85 |
5898
16f4129c19ac
repair.py: rename chlog to cl
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5897
diff
changeset
|
86 cl = repo.changelog |
16237
b5c0c7d0f83f
repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents:
15900
diff
changeset
|
87 # TODO handle undo of merge sets |
16252
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15900
diff
changeset
|
88 if isinstance(nodelist, str): |
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15900
diff
changeset
|
89 nodelist = [nodelist] |
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15900
diff
changeset
|
90 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:
15900
diff
changeset
|
91 striprev = min(striplist) |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
92 |
6147
53ae5af55db3
repair.py: rewrite a loop, making it cleaner and faster
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5907
diff
changeset
|
93 # 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:
5907
diff
changeset
|
94 # 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:
5907
diff
changeset
|
95 # 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:
5907
diff
changeset
|
96 # 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:
5907
diff
changeset
|
97 # 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:
5907
diff
changeset
|
98 # (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:
5907
diff
changeset
|
99 # 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:
15900
diff
changeset
|
100 tostrip = set(striplist) |
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15900
diff
changeset
|
101 for rev in striplist: |
16868
1093ad1e8903
revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents:
16745
diff
changeset
|
102 for desc in cl.descendants([rev]): |
16252
cf17e76be4dd
strip: enhance repair.strip to receive a list of nodes (issue3299)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
15900
diff
changeset
|
103 tostrip.add(desc) |
13702
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
104 |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
105 files = _collectfiles(repo, striprev) |
13705
73cfb7a5aa56
strip: simplify collectone
Matt Mackall <mpm@selenic.com>
parents:
13702
diff
changeset
|
106 saverevs = _collectbrokencsets(repo, files, striprev) |
13702
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
107 |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
108 # compute heads |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
109 saveheads = set(saverevs) |
6752
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6749
diff
changeset
|
110 for r in xrange(striprev + 1, len(cl)): |
13702
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
111 if r not in tostrip: |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
112 saverevs.add(r) |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
113 saveheads.difference_update(cl.parentrevs(r)) |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
114 saveheads.add(r) |
ffd370aa050b
strip: remove usage of extranodes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13362
diff
changeset
|
115 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
|
116 |
15386
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
117 # compute base nodes |
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
118 if saverevs: |
16868
1093ad1e8903
revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents:
16745
diff
changeset
|
119 descendants = set(cl.descendants(saverevs)) |
15386
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
120 saverevs.difference_update(descendants) |
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
121 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:
15900
diff
changeset
|
122 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
|
123 |
fe8caf28d580
strip: make query to get new bookmark target cheaper
Siddharth Agarwal <sid0@fb.com>
parents:
18004
diff
changeset
|
124 # For a set s, max(parents(s) - s) is the same as max(heads(::s - s)), but |
fe8caf28d580
strip: make query to get new bookmark target cheaper
Siddharth Agarwal <sid0@fb.com>
parents:
18004
diff
changeset
|
125 # is much faster |
fe8caf28d580
strip: make query to get new bookmark target cheaper
Siddharth Agarwal <sid0@fb.com>
parents:
18004
diff
changeset
|
126 newbmtarget = repo.revs('max(parents(%ld) - (%ld))', tostrip, tostrip) |
17264
ec7b9bec19c9
strip: move bookmarks to nearest ancestor rather than '.'
Augie Fackler <raf@durin42.com>
parents:
17027
diff
changeset
|
127 if newbmtarget: |
22818
d7b114493315
repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22057
diff
changeset
|
128 newbmtarget = repo[newbmtarget.first()].node() |
17264
ec7b9bec19c9
strip: move bookmarks to nearest ancestor rather than '.'
Augie Fackler <raf@durin42.com>
parents:
17027
diff
changeset
|
129 else: |
ec7b9bec19c9
strip: move bookmarks to nearest ancestor rather than '.'
Augie Fackler <raf@durin42.com>
parents:
17027
diff
changeset
|
130 newbmtarget = '.' |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
131 |
13362
ee01d9d84115
bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents:
12057
diff
changeset
|
132 bm = repo._bookmarks |
ee01d9d84115
bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents:
12057
diff
changeset
|
133 updatebm = [] |
ee01d9d84115
bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents:
12057
diff
changeset
|
134 for m in bm: |
ee01d9d84115
bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents:
12057
diff
changeset
|
135 rev = repo[bm[m]].rev() |
ee01d9d84115
bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents:
12057
diff
changeset
|
136 if rev in tostrip: |
ee01d9d84115
bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents:
12057
diff
changeset
|
137 updatebm.append(m) |
ee01d9d84115
bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents:
12057
diff
changeset
|
138 |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
139 # create a changegroup for all the branches we need to keep |
11197
4bb4895e1693
strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents:
10881
diff
changeset
|
140 backupfile = None |
20979
ad5b61370514
repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20977
diff
changeset
|
141 vfs = repo.vfs |
24354
f962692853c0
repair: define explicit local variable, don't reuse a comprehension variable
Mike Edgar <adgar@google.com>
parents:
24225
diff
changeset
|
142 node = nodelist[-1] |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
143 if backup: |
16388
e03d8a40521f
repair: allow giving strip backup a different name
Idan Kamara <idankk86@gmail.com>
parents:
16253
diff
changeset
|
144 backupfile = _bundle(repo, stripbases, cl.heads(), node, topic) |
20979
ad5b61370514
repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20977
diff
changeset
|
145 repo.ui.status(_("saved backup bundle to %s\n") % |
ad5b61370514
repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20977
diff
changeset
|
146 vfs.join(backupfile)) |
ad5b61370514
repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20977
diff
changeset
|
147 repo.ui.log("backupbundle", "saved backup bundle to %s\n", |
ad5b61370514
repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20977
diff
changeset
|
148 vfs.join(backupfile)) |
15386
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
149 if saveheads or savebases: |
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
|
150 # do not compress partial bundle if we remove it from disk later |
15386
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
151 chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp', |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
152 compress=False) |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
153 |
8073
e8a28556a0a8
strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
7361
diff
changeset
|
154 mfst = repo.manifest |
e8a28556a0a8
strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
7361
diff
changeset
|
155 |
25773
678d0bfdd31a
repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25087
diff
changeset
|
156 curtr = repo.currenttransaction() |
678d0bfdd31a
repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25087
diff
changeset
|
157 if curtr is not None: |
678d0bfdd31a
repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25087
diff
changeset
|
158 del curtr # avoid carrying reference to transaction for nothing |
678d0bfdd31a
repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25087
diff
changeset
|
159 msg = _('programming error: cannot strip from inside a transaction') |
27227
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27051
diff
changeset
|
160 raise error.Abort(msg, hint=_('contact your extension maintainer')) |
25773
678d0bfdd31a
repair: forbid strip from inside a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25087
diff
changeset
|
161 |
28528
60ea60fea5f3
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28526
diff
changeset
|
162 try: |
60ea60fea5f3
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28526
diff
changeset
|
163 with repo.transaction("strip") as tr: |
60ea60fea5f3
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28526
diff
changeset
|
164 offset = len(tr.entries) |
8073
e8a28556a0a8
strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
7361
diff
changeset
|
165 |
28528
60ea60fea5f3
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28526
diff
changeset
|
166 tr.startgroup() |
60ea60fea5f3
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28526
diff
changeset
|
167 cl.strip(striprev, tr) |
60ea60fea5f3
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28526
diff
changeset
|
168 mfst.strip(striprev, tr) |
60ea60fea5f3
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28526
diff
changeset
|
169 for fn in files: |
60ea60fea5f3
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28526
diff
changeset
|
170 repo.file(fn).strip(striprev, tr) |
60ea60fea5f3
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28526
diff
changeset
|
171 tr.endgroup() |
8073
e8a28556a0a8
strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
7361
diff
changeset
|
172 |
11197
4bb4895e1693
strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents:
10881
diff
changeset
|
173 for i in xrange(offset, len(tr.entries)): |
4bb4895e1693
strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents:
10881
diff
changeset
|
174 file, troffset, ignore = tr.entries[i] |
23890
37a92908a382
localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
23847
diff
changeset
|
175 repo.svfs(file, 'a').truncate(troffset) |
20885
f49d60fa40a5
fncache: clean up fncache during strips
Durham Goode <durham@fb.com>
parents:
20074
diff
changeset
|
176 if troffset == 0: |
f49d60fa40a5
fncache: clean up fncache during strips
Durham Goode <durham@fb.com>
parents:
20074
diff
changeset
|
177 repo.store.markremoved(file) |
11197
4bb4895e1693
strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents:
10881
diff
changeset
|
178 |
15386
6051d8e7e133
strip: backout 73307643a09f (issue3077)
Matt Mackall <mpm@selenic.com>
parents:
15068
diff
changeset
|
179 if saveheads or savebases: |
11202
f974fe896921
strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents:
11200
diff
changeset
|
180 ui.note(_("adding branch\n")) |
20979
ad5b61370514
repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20977
diff
changeset
|
181 f = vfs.open(chgrpfile, "rb") |
21064
4d9d490d7bbe
bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21063
diff
changeset
|
182 gen = exchange.readbundle(ui, f, chgrpfile, vfs) |
11202
f974fe896921
strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents:
11200
diff
changeset
|
183 if not repo.ui.verbose: |
f974fe896921
strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents:
11200
diff
changeset
|
184 # silence internal shuffling chatter |
f974fe896921
strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents:
11200
diff
changeset
|
185 repo.ui.pushbuffer() |
23910
b21c2e0ee8a3
repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents:
23907
diff
changeset
|
186 if isinstance(gen, bundle2.unbundle20): |
28530
add2ba16430e
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28528
diff
changeset
|
187 with repo.transaction('strip') as tr: |
add2ba16430e
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28528
diff
changeset
|
188 tr.hookargs = {'source': 'strip', |
add2ba16430e
with: use context manager for transaction in strip
Bryan O'Sullivan <bryano@fb.com>
parents:
28528
diff
changeset
|
189 'url': 'bundle:' + vfs.join(chgrpfile)} |
27437
75d550b7d8f5
strip: pass source and url to bundle2 processing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27341
diff
changeset
|
190 bundle2.applybundle(repo, gen, tr, source='strip', |
75d550b7d8f5
strip: pass source and url to bundle2 processing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27341
diff
changeset
|
191 url='bundle:' + vfs.join(chgrpfile)) |
23910
b21c2e0ee8a3
repair: add experimental option to write bundle2 files
Eric Sumner <ericsumner@fb.com>
parents:
23907
diff
changeset
|
192 else: |
27341
b1a0c534d9b4
repair: use cg?unpacker.apply() instead of changegroup.addchangegroup()
Augie Fackler <augie@google.com>
parents:
27264
diff
changeset
|
193 gen.apply(repo, 'strip', 'bundle:' + vfs.join(chgrpfile), True) |
11202
f974fe896921
strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents:
11200
diff
changeset
|
194 if not repo.ui.verbose: |
f974fe896921
strip: hide unbundle messages by default
Matt Mackall <mpm@selenic.com>
parents:
11200
diff
changeset
|
195 repo.ui.popbuffer() |
11197
4bb4895e1693
strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents:
10881
diff
changeset
|
196 f.close() |
29946
bf7b8157c483
strip: invalidate phase cache after stripping changeset (issue5235)
Laurent Charignon <lcharignon@fb.com>
parents:
29618
diff
changeset
|
197 repo._phasecache.invalidate() |
13362
ee01d9d84115
bookmarks: move strip support to repair
Matt Mackall <mpm@selenic.com>
parents:
12057
diff
changeset
|
198 |
27797
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
199 for m in updatebm: |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
200 bm[m] = repo[newbmtarget].node() |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
201 lock = tr = None |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
202 try: |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
203 lock = repo.lock() |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
204 tr = repo.transaction('repair') |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
205 bm.recordchange(tr) |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
206 tr.close() |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
207 finally: |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
208 tr.release() |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
209 lock.release() |
5f2e4eb08e41
repair: use bookmarks.recordchange instead of bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
27437
diff
changeset
|
210 |
16237
b5c0c7d0f83f
repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents:
15900
diff
changeset
|
211 # remove undo files |
20975
37cdf1fca1b2
localrepo: make "undofiles()" return list of tuples "(vfs, relative filename)"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20933
diff
changeset
|
212 for undovfs, undofile in repo.undofiles(): |
16237
b5c0c7d0f83f
repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents:
15900
diff
changeset
|
213 try: |
20975
37cdf1fca1b2
localrepo: make "undofiles()" return list of tuples "(vfs, relative filename)"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20933
diff
changeset
|
214 undovfs.unlink(undofile) |
26214
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26206
diff
changeset
|
215 except OSError as e: |
16237
b5c0c7d0f83f
repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents:
15900
diff
changeset
|
216 if e.errno != errno.ENOENT: |
20975
37cdf1fca1b2
localrepo: make "undofiles()" return list of tuples "(vfs, relative filename)"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20933
diff
changeset
|
217 ui.warn(_('error removing %s: %s\n') % |
37cdf1fca1b2
localrepo: make "undofiles()" return list of tuples "(vfs, relative filename)"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20933
diff
changeset
|
218 (undovfs.join(undofile), str(e))) |
16237
b5c0c7d0f83f
repair: remove undo files after strip
Idan Kamara <idankk86@gmail.com>
parents:
15900
diff
changeset
|
219 |
16705
c2d9ef43ff6c
check-code: ignore naked excepts with a "re-raise" comment
Brodie Rao <brodie@sf.io>
parents:
16636
diff
changeset
|
220 except: # re-raises |
11197
4bb4895e1693
strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents:
10881
diff
changeset
|
221 if backupfile: |
11600
76454cbc11e4
mark ui.warn strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
11333
diff
changeset
|
222 ui.warn(_("strip failed, full bundle stored in '%s'\n") |
20979
ad5b61370514
repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20977
diff
changeset
|
223 % vfs.join(backupfile)) |
11197
4bb4895e1693
strip: be quiet about temporary internal bundle
Matt Mackall <mpm@selenic.com>
parents:
10881
diff
changeset
|
224 elif saveheads: |
11600
76454cbc11e4
mark ui.warn strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
11333
diff
changeset
|
225 ui.warn(_("strip failed, partial bundle stored in '%s'\n") |
20979
ad5b61370514
repair: make "strip()" treat bundle files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20977
diff
changeset
|
226 % vfs.join(chgrpfile)) |
8073
e8a28556a0a8
strip: make repair.strip transactional to avoid repository corruption
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
7361
diff
changeset
|
227 raise |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
228 else: |
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
229 if saveheads or savebases: |
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
230 # Remove partial backup only if there were no exceptions |
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21064
diff
changeset
|
231 vfs.unlink(chgrpfile) |
4702
18e91c9def0c
strip: move strip code to a new repair module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
232 |
18395
904b7109938e
destroyed: drop complex branchcache rebuilt logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18311
diff
changeset
|
233 repo.destroyed() |
26206
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
234 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
235 def rebuildfncache(ui, repo): |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
236 """Rebuilds the fncache file from repo history. |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
237 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
238 Missing entries will be added. Extra entries will be removed. |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
239 """ |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
240 repo = repo.unfiltered() |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
241 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
242 if 'fncache' not in repo.requirements: |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
243 ui.warn(_('(not rebuilding fncache because repository does not ' |
26442
3e84f40232c7
repair: fix typo in warning message
Wagner Bruna <wbruna@yahoo.com>
parents:
26405
diff
changeset
|
244 'support fncache)\n')) |
26206
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
245 return |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
246 |
28515
0da102e4f203
with: use context manager in rebuildfncache again
Bryan O'Sullivan <bryano@fb.com>
parents:
28208
diff
changeset
|
247 with repo.lock(): |
26206
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
248 fnc = repo.store.fncache |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
249 # Trigger load of fncache. |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
250 if 'irrelevant' in fnc: |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
251 pass |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
252 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
253 oldentries = set(fnc.entries) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
254 newentries = set() |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
255 seenfiles = set() |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
256 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
257 repolen = len(repo) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
258 for rev in repo: |
29137
c7d45c5a8cea
repair: specify unit for ui.progress in rebuildfncache()
Anton Shestakov <av6@dwimlabs.net>
parents:
29136
diff
changeset
|
259 ui.progress(_('rebuilding'), rev, total=repolen, |
c7d45c5a8cea
repair: specify unit for ui.progress in rebuildfncache()
Anton Shestakov <av6@dwimlabs.net>
parents:
29136
diff
changeset
|
260 unit=_('changesets')) |
26206
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
261 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
262 ctx = repo[rev] |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
263 for f in ctx.files(): |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
264 # This is to minimize I/O. |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
265 if f in seenfiles: |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
266 continue |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
267 seenfiles.add(f) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
268 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
269 i = 'data/%s.i' % f |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
270 d = 'data/%s.d' % f |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
271 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
272 if repo.store._exists(i): |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
273 newentries.add(i) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
274 if repo.store._exists(d): |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
275 newentries.add(d) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
276 |
29136
43eb31ea2dcb
repair: use 'rebuilding' progress topic in rebuildfncache()
Anton Shestakov <av6@dwimlabs.net>
parents:
28702
diff
changeset
|
277 ui.progress(_('rebuilding'), None) |
26206
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
278 |
28702
6f248ba85309
treemanifest: fix debugrebuildfncache
Martin von Zweigbergk <martinvonz@google.com>
parents:
28678
diff
changeset
|
279 if 'treemanifest' in repo.requirements: # safe but unnecessary otherwise |
28678
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
28601
diff
changeset
|
280 for dir in util.dirs(seenfiles): |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
28601
diff
changeset
|
281 i = 'meta/%s/00manifest.i' % dir |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
28601
diff
changeset
|
282 d = 'meta/%s/00manifest.d' % dir |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
28601
diff
changeset
|
283 |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
28601
diff
changeset
|
284 if repo.store._exists(i): |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
28601
diff
changeset
|
285 newentries.add(i) |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
28601
diff
changeset
|
286 if repo.store._exists(d): |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
28601
diff
changeset
|
287 newentries.add(d) |
fb92927f9775
treemanifests: fix streaming clone
Martin von Zweigbergk <martinvonz@google.com>
parents:
28601
diff
changeset
|
288 |
26206
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
289 addcount = len(newentries - oldentries) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
290 removecount = len(oldentries - newentries) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
291 for p in sorted(oldentries - newentries): |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
292 ui.write(_('removing %s\n') % p) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
293 for p in sorted(newentries - oldentries): |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
294 ui.write(_('adding %s\n') % p) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
295 |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
296 if addcount or removecount: |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
297 ui.write(_('%d items added, %d removed from fncache\n') % |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
298 (addcount, removecount)) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
299 fnc.entries = newentries |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
300 fnc._dirty = True |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
301 |
28526
f1c316fd91f9
with: use context manager in rebuildfncache
Bryan O'Sullivan <bryano@fb.com>
parents:
28515
diff
changeset
|
302 with repo.transaction('fncache') as tr: |
26206
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
303 fnc.write(tr) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
304 else: |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
305 ui.write(_('fncache already up to date\n')) |
2882d6886919
repair: add functionality to rebuild fncache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25938
diff
changeset
|
306 |
27264
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
307 def stripbmrevset(repo, mark): |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
308 """ |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
309 The revset to strip when strip is called with -B mark |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
310 |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
311 Needs to live here so extensions can use it and wrap it even when strip is |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
312 not enabled or not present on a box. |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
313 """ |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
314 return repo.revs("ancestors(bookmark(%s)) - " |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
315 "ancestors(head() and not bookmark(%s)) - " |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
316 "ancestors(bookmark() and not bookmark(%s))", |
bcace0fbb4c8
strip: factor out revset calculation for strip -B
Ryan McElroy <rmcelroy@fb.com>
parents:
27227
diff
changeset
|
317 mark, mark, mark) |
29618
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
318 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
319 def deleteobsmarkers(obsstore, indices): |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
320 """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:
29407
diff
changeset
|
321 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
322 '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:
29407
diff
changeset
|
323 of the markers to be deleted. |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
324 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
325 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:
29407
diff
changeset
|
326 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:
29407
diff
changeset
|
327 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:
29407
diff
changeset
|
328 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:
29407
diff
changeset
|
329 if not indices: |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
330 # 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:
29407
diff
changeset
|
331 return |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
332 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
333 left = [] |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
334 current = obsstore._all |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
335 n = 0 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
336 for i, m in enumerate(current): |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
337 if i in indices: |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
338 n += 1 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
339 continue |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
340 left.append(m) |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
341 |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
342 newobsstorefile = obsstore.svfs('obsstore', 'w', atomictemp=True) |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
343 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:
29407
diff
changeset
|
344 newobsstorefile.write(bytes) |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
345 newobsstorefile.close() |
445a25bb70be
obsstore: move delete function from obsstore class to repair module
Kostia Balytskyi <ikostia@fb.com>
parents:
29407
diff
changeset
|
346 return n |