bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2052.3.1
by John Arbash Meinel
Add tests to cleanup the copyright of all source files |
1 |
# Copyright (C) 2005, 2006 Canonical Ltd
|
|
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
17 |
"""Reconcilers are able to fix some potential data errors in a branch."""
|
|
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
18 |
|
19 |
||
|
2857.1.1
by Robert Collins
(robertc) Reconcile tweaks from the packs branch. (Robert Collins) |
20 |
__all__ = [ |
21 |
'KnitReconciler', |
|
22 |
'reconcile', |
|
23 |
'Reconciler', |
|
24 |
'RepoReconciler', |
|
25 |
]
|
|
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
26 |
|
27 |
||
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
28 |
from bzrlib import ui |
|
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
29 |
from bzrlib.trace import mutter |
|
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
30 |
from bzrlib.tsort import TopoSorter |
|
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
31 |
|
32 |
||
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
33 |
def reconcile(dir, other=None): |
|
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
34 |
"""Reconcile the data in dir. |
35 |
||
36 |
Currently this is limited to a inventory 'reweave'.
|
|
37 |
||
|
1570.1.8
by Robert Collins
Only reconcile if doing so will perform gc or correct ancestry. |
38 |
This is a convenience method, for using a Reconciler object.
|
39 |
||
40 |
Directly using Reconciler is recommended for library users that
|
|
41 |
desire fine grained control or analysis of the found issues.
|
|
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
42 |
|
43 |
:param other: another bzrdir to reconcile against.
|
|
|
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
44 |
"""
|
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
45 |
reconciler = Reconciler(dir, other=other) |
|
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
46 |
reconciler.reconcile() |
47 |
||
48 |
||
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
49 |
class Reconciler(object): |
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
50 |
"""Reconcilers are used to reconcile existing data.""" |
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
51 |
|
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
52 |
def __init__(self, dir, other=None): |
53 |
"""Create a Reconciler.""" |
|
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
54 |
self.bzrdir = dir |
55 |
||
56 |
def reconcile(self): |
|
|
1570.1.8
by Robert Collins
Only reconcile if doing so will perform gc or correct ancestry. |
57 |
"""Perform reconciliation. |
58 |
|
|
59 |
After reconciliation the following attributes document found issues:
|
|
60 |
inconsistent_parents: The number of revisions in the repository whose
|
|
61 |
ancestry was being reported incorrectly.
|
|
62 |
garbage_inventories: The number of inventory objects without revisions
|
|
63 |
that were garbage collected.
|
|
64 |
"""
|
|
|
1594.1.3
by Robert Collins
Fixup pb usage to use nested_progress_bar. |
65 |
self.pb = ui.ui_factory.nested_progress_bar() |
66 |
try: |
|
67 |
self._reconcile() |
|
68 |
finally: |
|
69 |
self.pb.finished() |
|
70 |
||
71 |
def _reconcile(self): |
|
72 |
"""Helper function for performing reconciliation.""" |
|
|
1570.1.11
by Robert Collins
Make reconcile work with shared repositories. |
73 |
self.repo = self.bzrdir.find_repository() |
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
74 |
self.pb.note('Reconciling repository %s', |
75 |
self.repo.bzrdir.root_transport.base) |
|
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
76 |
repo_reconciler = self.repo.reconcile(thorough=True) |
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
77 |
self.inconsistent_parents = repo_reconciler.inconsistent_parents |
78 |
self.garbage_inventories = repo_reconciler.garbage_inventories |
|
79 |
self.pb.note('Reconciliation complete.') |
|
80 |
||
81 |
||
82 |
class RepoReconciler(object): |
|
83 |
"""Reconciler that reconciles a repository. |
|
84 |
||
|
2857.1.2
by Robert Collins
Review feedback. |
85 |
The goal of repository reconciliation is to make any derived data
|
|
2857.1.1
by Robert Collins
(robertc) Reconcile tweaks from the packs branch. (Robert Collins) |
86 |
consistent with the core data committed by a user. This can involve
|
87 |
reindexing, or removing unreferenced data if that can interfere with
|
|
88 |
queries in a given repository.
|
|
89 |
||
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
90 |
Currently this consists of an inventory reweave with revision cross-checks.
|
91 |
"""
|
|
92 |
||
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
93 |
def __init__(self, repo, other=None, thorough=False): |
94 |
"""Construct a RepoReconciler. |
|
95 |
||
96 |
:param thorough: perform a thorough check which may take longer but
|
|
97 |
will correct non-data loss issues such as incorrect
|
|
98 |
cached data.
|
|
99 |
"""
|
|
100 |
self.garbage_inventories = 0 |
|
101 |
self.inconsistent_parents = 0 |
|
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
102 |
self.repo = repo |
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
103 |
self.thorough = thorough |
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
104 |
|
105 |
def reconcile(self): |
|
106 |
"""Perform reconciliation. |
|
107 |
|
|
108 |
After reconciliation the following attributes document found issues:
|
|
109 |
inconsistent_parents: The number of revisions in the repository whose
|
|
110 |
ancestry was being reported incorrectly.
|
|
111 |
garbage_inventories: The number of inventory objects without revisions
|
|
112 |
that were garbage collected.
|
|
113 |
"""
|
|
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
114 |
self.repo.lock_write() |
115 |
try: |
|
|
1594.1.3
by Robert Collins
Fixup pb usage to use nested_progress_bar. |
116 |
self.pb = ui.ui_factory.nested_progress_bar() |
117 |
try: |
|
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
118 |
self._reconcile_steps() |
|
1594.1.3
by Robert Collins
Fixup pb usage to use nested_progress_bar. |
119 |
finally: |
120 |
self.pb.finished() |
|
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
121 |
finally: |
122 |
self.repo.unlock() |
|
123 |
||
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
124 |
def _reconcile_steps(self): |
125 |
"""Perform the steps to reconcile this repository.""" |
|
|
1692.1.3
by Robert Collins
Finish the reconcile tweak: filled in ghosts are a data loss issue and need to be checked during fast reconciles. |
126 |
self._reweave_inventory() |
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
127 |
|
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
128 |
def _reweave_inventory(self): |
|
1692.1.3
by Robert Collins
Finish the reconcile tweak: filled in ghosts are a data loss issue and need to be checked during fast reconciles. |
129 |
"""Regenerate the inventory weave for the repository from scratch. |
130 |
|
|
131 |
This is a smart function: it will only do the reweave if doing it
|
|
132 |
will correct data issues. The self.thorough flag controls whether
|
|
133 |
only data-loss causing issues (!self.thorough) or all issues
|
|
134 |
(self.thorough) are treated as requiring the reweave.
|
|
135 |
"""
|
|
136 |
# local because needing to know about WeaveFile is a wart we want to hide
|
|
|
1563.2.42
by Robert Collins
Stop reconcile on weaves being quadratic. |
137 |
from bzrlib.weave import WeaveFile, Weave |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
138 |
transaction = self.repo.get_transaction() |
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
139 |
self.pb.update('Reading inventory data.') |
140 |
self.inventory = self.repo.get_inventory_weave() |
|
141 |
# the total set of revisions to process
|
|
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
142 |
self.pending = set([rev_id for rev_id in self.repo._revision_store.all_revision_ids(transaction)]) |
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
143 |
|
144 |
# mapping from revision_id to parents
|
|
145 |
self._rev_graph = {} |
|
|
1570.1.8
by Robert Collins
Only reconcile if doing so will perform gc or correct ancestry. |
146 |
# errors that we detect
|
147 |
self.inconsistent_parents = 0 |
|
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
148 |
# we need the revision id of each revision and its available parents list
|
|
1570.1.10
by Robert Collins
UI tweaks to reconcile - show progress for inventory backup. |
149 |
self._setup_steps(len(self.pending)) |
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
150 |
for rev_id in self.pending: |
151 |
# put a revision into the graph.
|
|
152 |
self._graph_revision(rev_id) |
|
|
1594.2.2
by Robert Collins
Trivial change to reconcile to mutter the cause of reconciliation to bzr.log |
153 |
self._check_garbage_inventories() |
|
1692.1.3
by Robert Collins
Finish the reconcile tweak: filled in ghosts are a data loss issue and need to be checked during fast reconciles. |
154 |
# if there are no inconsistent_parents and
|
155 |
# (no garbage inventories or we are not doing a thorough check)
|
|
156 |
if (not self.inconsistent_parents and |
|
157 |
(not self.garbage_inventories or not self.thorough)): |
|
|
1570.1.8
by Robert Collins
Only reconcile if doing so will perform gc or correct ancestry. |
158 |
self.pb.note('Inventory ok.') |
159 |
return
|
|
|
1570.1.10
by Robert Collins
UI tweaks to reconcile - show progress for inventory backup. |
160 |
self.pb.update('Backing up inventory...', 0, 0) |
|
1563.2.25
by Robert Collins
Merge in upstream. |
161 |
self.repo.control_weaves.copy(self.inventory, 'inventory.backup', self.repo.get_transaction()) |
|
1570.1.8
by Robert Collins
Only reconcile if doing so will perform gc or correct ancestry. |
162 |
self.pb.note('Backup Inventory created.') |
163 |
# asking for '' should never return a non-empty weave
|
|
|
1616.1.1
by Martin Pool
[merge] robertc |
164 |
new_inventory_vf = self.repo.control_weaves.get_empty('inventory.new', |
|
1570.1.8
by Robert Collins
Only reconcile if doing so will perform gc or correct ancestry. |
165 |
self.repo.get_transaction()) |
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
166 |
|
|
1570.1.4
by Robert Collins
Somewhat optimised version of reconciler. |
167 |
# we have topological order of revisions and non ghost parents ready.
|
|
1570.1.10
by Robert Collins
UI tweaks to reconcile - show progress for inventory backup. |
168 |
self._setup_steps(len(self._rev_graph)) |
|
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
169 |
for rev_id in TopoSorter(self._rev_graph.items()).iter_topo_order(): |
170 |
parents = self._rev_graph[rev_id] |
|
|
1570.1.4
by Robert Collins
Somewhat optimised version of reconciler. |
171 |
# double check this really is in topological order.
|
|
1616.1.1
by Martin Pool
[merge] robertc |
172 |
unavailable = [p for p in parents if p not in new_inventory_vf] |
|
1570.1.4
by Robert Collins
Somewhat optimised version of reconciler. |
173 |
assert len(unavailable) == 0 |
174 |
# this entry has all the non ghost parents in the inventory
|
|
175 |
# file already.
|
|
176 |
self._reweave_step('adding inventories') |
|
|
1616.1.1
by Martin Pool
[merge] robertc |
177 |
if isinstance(new_inventory_vf, WeaveFile): |
178 |
# It's really a WeaveFile, but we call straight into the
|
|
179 |
# Weave's add method to disable the auto-write-out behaviour.
|
|
|
1607.1.11
by Robert Collins
Merge from bzr.dev |
180 |
# This is done to avoid a revision_count * time-to-write additional overhead on
|
181 |
# reconcile.
|
|
|
1616.1.1
by Martin Pool
[merge] robertc |
182 |
new_inventory_vf._check_write_ok() |
|
2794.1.1
by Robert Collins
Allow knits to be instructed not to add a text based on a sha, for commit. |
183 |
Weave._add_lines(new_inventory_vf, rev_id, parents, |
|
2805.6.7
by Robert Collins
Review feedback. |
184 |
self.inventory.get_lines(rev_id), None, None, None, False, True) |
|
1563.2.42
by Robert Collins
Stop reconcile on weaves being quadratic. |
185 |
else: |
|
1616.1.1
by Martin Pool
[merge] robertc |
186 |
new_inventory_vf.add_lines(rev_id, parents, self.inventory.get_lines(rev_id)) |
|
1570.1.4
by Robert Collins
Somewhat optimised version of reconciler. |
187 |
|
|
1616.1.1
by Martin Pool
[merge] robertc |
188 |
if isinstance(new_inventory_vf, WeaveFile): |
189 |
new_inventory_vf._save() |
|
190 |
# if this worked, the set of new_inventory_vf.names should equal
|
|
|
1570.1.4
by Robert Collins
Somewhat optimised version of reconciler. |
191 |
# self.pending
|
|
1616.1.1
by Martin Pool
[merge] robertc |
192 |
assert set(new_inventory_vf.versions()) == self.pending |
|
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
193 |
self.pb.update('Writing weave') |
|
1616.1.1
by Martin Pool
[merge] robertc |
194 |
self.repo.control_weaves.copy(new_inventory_vf, 'inventory', self.repo.get_transaction()) |
|
1563.2.25
by Robert Collins
Merge in upstream. |
195 |
self.repo.control_weaves.delete('inventory.new', self.repo.get_transaction()) |
|
1570.1.3
by Robert Collins
Optimise reconcilation to only hit each revision once. |
196 |
self.inventory = None |
|
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
197 |
self.pb.note('Inventory regenerated.') |
|
1570.1.3
by Robert Collins
Optimise reconcilation to only hit each revision once. |
198 |
|
|
1570.1.10
by Robert Collins
UI tweaks to reconcile - show progress for inventory backup. |
199 |
def _setup_steps(self, new_total): |
200 |
"""Setup the markers we need to control the progress bar.""" |
|
201 |
self.total = new_total |
|
202 |
self.count = 0 |
|
203 |
||
|
1570.1.4
by Robert Collins
Somewhat optimised version of reconciler. |
204 |
def _graph_revision(self, rev_id): |
205 |
"""Load a revision into the revision graph.""" |
|
206 |
# pick a random revision
|
|
207 |
# analyse revision id rev_id and put it in the stack.
|
|
208 |
self._reweave_step('loading revisions') |
|
|
1570.1.13
by Robert Collins
Check for incorrect revision parentage in the weave during revision access. |
209 |
rev = self.repo.get_revision_reconcile(rev_id) |
|
1570.1.3
by Robert Collins
Optimise reconcilation to only hit each revision once. |
210 |
assert rev.revision_id == rev_id |
211 |
parents = [] |
|
212 |
for parent in rev.parent_ids: |
|
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
213 |
if self._parent_is_available(parent): |
|
1570.1.3
by Robert Collins
Optimise reconcilation to only hit each revision once. |
214 |
parents.append(parent) |
215 |
else: |
|
216 |
mutter('found ghost %s', parent) |
|
|
1570.1.4
by Robert Collins
Somewhat optimised version of reconciler. |
217 |
self._rev_graph[rev_id] = parents |
|
1692.1.3
by Robert Collins
Finish the reconcile tweak: filled in ghosts are a data loss issue and need to be checked during fast reconciles. |
218 |
if self._parents_are_inconsistent(rev_id, parents): |
|
1570.1.8
by Robert Collins
Only reconcile if doing so will perform gc or correct ancestry. |
219 |
self.inconsistent_parents += 1 |
|
1594.2.2
by Robert Collins
Trivial change to reconcile to mutter the cause of reconciliation to bzr.log |
220 |
mutter('Inconsistent inventory parents: id {%s} ' |
221 |
'inventory claims %r, ' |
|
222 |
'available parents are %r, ' |
|
223 |
'unavailable parents are %r', |
|
224 |
rev_id, |
|
|
1563.2.39
by Robert Collins
Merge from integration. |
225 |
set(self.inventory.get_parents(rev_id)), |
|
1594.2.2
by Robert Collins
Trivial change to reconcile to mutter the cause of reconciliation to bzr.log |
226 |
set(parents), |
227 |
set(rev.parent_ids).difference(set(parents))) |
|
228 |
||
|
1692.1.3
by Robert Collins
Finish the reconcile tweak: filled in ghosts are a data loss issue and need to be checked during fast reconciles. |
229 |
def _parents_are_inconsistent(self, rev_id, parents): |
230 |
"""Return True if the parents list of rev_id does not match the weave. |
|
231 |
||
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
232 |
This detects inconsistencies based on the self.thorough value:
|
|
1692.1.3
by Robert Collins
Finish the reconcile tweak: filled in ghosts are a data loss issue and need to be checked during fast reconciles. |
233 |
if thorough is on, the first parent value is checked as well as ghost
|
234 |
differences.
|
|
235 |
Otherwise only the ghost differences are evaluated.
|
|
236 |
"""
|
|
237 |
weave_parents = self.inventory.get_parents(rev_id) |
|
238 |
weave_missing_old_ghosts = set(weave_parents) != set(parents) |
|
239 |
first_parent_is_wrong = ( |
|
240 |
len(weave_parents) and len(parents) and |
|
241 |
parents[0] != weave_parents[0]) |
|
242 |
if self.thorough: |
|
243 |
return weave_missing_old_ghosts or first_parent_is_wrong |
|
244 |
else: |
|
245 |
return weave_missing_old_ghosts |
|
246 |
||
|
1594.2.2
by Robert Collins
Trivial change to reconcile to mutter the cause of reconciliation to bzr.log |
247 |
def _check_garbage_inventories(self): |
248 |
"""Check for garbage inventories which we cannot trust |
|
249 |
||
250 |
We cant trust them because their pre-requisite file data may not
|
|
251 |
be present - all we know is that their revision was not installed.
|
|
252 |
"""
|
|
|
1692.1.3
by Robert Collins
Finish the reconcile tweak: filled in ghosts are a data loss issue and need to be checked during fast reconciles. |
253 |
if not self.thorough: |
254 |
return
|
|
|
1563.2.39
by Robert Collins
Merge from integration. |
255 |
inventories = set(self.inventory.versions()) |
|
1594.2.2
by Robert Collins
Trivial change to reconcile to mutter the cause of reconciliation to bzr.log |
256 |
revisions = set(self._rev_graph.keys()) |
257 |
garbage = inventories.difference(revisions) |
|
258 |
self.garbage_inventories = len(garbage) |
|
259 |
for revision_id in garbage: |
|
260 |
mutter('Garbage inventory {%s} found.', revision_id) |
|
|
1570.1.4
by Robert Collins
Somewhat optimised version of reconciler. |
261 |
|
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
262 |
def _parent_is_available(self, parent): |
263 |
"""True if parent is a fully available revision |
|
264 |
||
265 |
A fully available revision has a inventory and a revision object in the
|
|
266 |
repository.
|
|
267 |
"""
|
|
268 |
return (parent in self._rev_graph or |
|
269 |
(parent in self.inventory and self.repo.has_revision(parent))) |
|
270 |
||
|
1570.1.4
by Robert Collins
Somewhat optimised version of reconciler. |
271 |
def _reweave_step(self, message): |
272 |
"""Mark a single step of regeneration complete.""" |
|
273 |
self.pb.update(message, self.count, self.total) |
|
274 |
self.count += 1 |
|
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
275 |
|
276 |
||
277 |
class KnitReconciler(RepoReconciler): |
|
278 |
"""Reconciler that reconciles a knit format repository. |
|
279 |
||
|
2857.1.1
by Robert Collins
(robertc) Reconcile tweaks from the packs branch. (Robert Collins) |
280 |
This will detect garbage inventories and remove them in thorough mode.
|
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
281 |
"""
|
282 |
||
283 |
def _reconcile_steps(self): |
|
284 |
"""Perform the steps to reconcile this repository.""" |
|
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
285 |
if self.thorough: |
286 |
self._load_indexes() |
|
287 |
# knits never suffer this
|
|
288 |
self._gc_inventory() |
|
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
289 |
|
290 |
def _load_indexes(self): |
|
291 |
"""Load indexes for the reconciliation.""" |
|
292 |
self.transaction = self.repo.get_transaction() |
|
293 |
self.pb.update('Reading indexes.', 0, 2) |
|
294 |
self.inventory = self.repo.get_inventory_weave() |
|
295 |
self.pb.update('Reading indexes.', 1, 2) |
|
296 |
self.revisions = self.repo._revision_store.get_revision_file(self.transaction) |
|
297 |
self.pb.update('Reading indexes.', 2, 2) |
|
298 |
||
299 |
def _gc_inventory(self): |
|
300 |
"""Remove inventories that are not referenced from the revision store.""" |
|
301 |
self.pb.update('Checking unused inventories.', 0, 1) |
|
302 |
self._check_garbage_inventories() |
|
303 |
self.pb.update('Checking unused inventories.', 1, 3) |
|
304 |
if not self.garbage_inventories: |
|
305 |
self.pb.note('Inventory ok.') |
|
306 |
return
|
|
307 |
self.pb.update('Backing up inventory...', 0, 0) |
|
308 |
self.repo.control_weaves.copy(self.inventory, 'inventory.backup', self.transaction) |
|
309 |
self.pb.note('Backup Inventory created.') |
|
310 |
# asking for '' should never return a non-empty weave
|
|
|
1616.1.1
by Martin Pool
[merge] robertc |
311 |
new_inventory_vf = self.repo.control_weaves.get_empty('inventory.new', |
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
312 |
self.transaction) |
313 |
||
314 |
# we have topological order of revisions and non ghost parents ready.
|
|
|
1594.2.9
by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all. |
315 |
self._setup_steps(len(self.revisions)) |
316 |
for rev_id in TopoSorter(self.revisions.get_graph().items()).iter_topo_order(): |
|
317 |
parents = self.revisions.get_parents(rev_id) |
|
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
318 |
# double check this really is in topological order.
|
|
1616.1.1
by Martin Pool
[merge] robertc |
319 |
unavailable = [p for p in parents if p not in new_inventory_vf] |
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
320 |
assert len(unavailable) == 0 |
321 |
# this entry has all the non ghost parents in the inventory
|
|
322 |
# file already.
|
|
323 |
self._reweave_step('adding inventories') |
|
324 |
# ugly but needed, weaves are just way tooooo slow else.
|
|
|
1616.1.1
by Martin Pool
[merge] robertc |
325 |
new_inventory_vf.add_lines(rev_id, parents, self.inventory.get_lines(rev_id)) |
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
326 |
|
|
1616.1.1
by Martin Pool
[merge] robertc |
327 |
# if this worked, the set of new_inventory_vf.names should equal
|
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
328 |
# self.pending
|
|
1616.1.1
by Martin Pool
[merge] robertc |
329 |
assert set(new_inventory_vf.versions()) == set(self.revisions.versions()) |
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
330 |
self.pb.update('Writing weave') |
|
1616.1.1
by Martin Pool
[merge] robertc |
331 |
self.repo.control_weaves.copy(new_inventory_vf, 'inventory', self.transaction) |
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
332 |
self.repo.control_weaves.delete('inventory.new', self.transaction) |
333 |
self.inventory = None |
|
334 |
self.pb.note('Inventory regenerated.') |
|
335 |
||
336 |
def _check_garbage_inventories(self): |
|
337 |
"""Check for garbage inventories which we cannot trust |
|
338 |
||
339 |
We cant trust them because their pre-requisite file data may not
|
|
340 |
be present - all we know is that their revision was not installed.
|
|
341 |
"""
|
|
342 |
inventories = set(self.inventory.versions()) |
|
343 |
revisions = set(self.revisions.versions()) |
|
344 |
garbage = inventories.difference(revisions) |
|
345 |
self.garbage_inventories = len(garbage) |
|
346 |
for revision_id in garbage: |
|
347 |
mutter('Garbage inventory {%s} found.', revision_id) |