13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
# TODO: Check ancestries are correct for every revision: includes
18
18
# every committed so far, and in a reasonable order.
22
22
# TODO: Check for extra files in the control directory.
24
# TODO: Check revision, inventory and entry objects have all
24
# TODO: Check revision, inventory and entry objects have all
27
27
# TODO: Get every revision in the revision-store even if they're not
63
63
self.checked_weaves = set()
64
64
self.unreferenced_versions = set()
65
65
self.inconsistent_parents = []
66
self.rich_roots = repository.supports_rich_root()
67
self.text_key_references = {}
70
68
self.repository.lock_read()
168
166
rev_id - the one to check
170
168
rev = self.repository.get_revision(rev_id)
172
170
if rev.revision_id != rev_id:
173
171
raise BzrCheckError('wrong internal revision id in revision {%s}'
176
174
for parent in rev.parent_ids:
177
175
if not parent in self.planned_revisions:
178
# rev has a parent we didn't know about.
179
176
missing_links = self.missing_parent_links.get(parent, [])
180
177
missing_links.append(rev_id)
181
178
self.missing_parent_links[parent] = missing_links
184
181
if self.repository.has_revision(parent):
185
182
missing_ancestry = self.repository.get_ancestry(parent)
186
183
for missing in missing_ancestry:
187
if (missing is not None
184
if (missing is not None
188
185
and missing not in self.planned_revisions):
189
186
self.planned_revisions.append(missing)
191
188
self.ghosts.append(rev_id)
193
190
if rev.inventory_sha1:
194
# Loopback - this is currently circular logic as the
195
# knit get_inventory_sha1 call returns rev.inventory_sha1.
196
# Repository.py's get_inventory_sha1 should instead return
197
# inventories.get_record_stream([(revid,)]).next().sha1 or
199
191
inv_sha1 = self.repository.get_inventory_sha1(rev_id)
200
192
if inv_sha1 != rev.inventory_sha1:
201
193
raise BzrCheckError('Inventory sha1 hash doesn\'t match'
211
203
self.inventory_weave.check(progress_bar=self.progress)
212
204
self.progress.update('checking text storage', 1, 2)
213
205
self.repository.texts.check(progress_bar=self.progress)
214
weave_checker = self.repository._get_versioned_file_checker(
215
text_key_references=self.text_key_references)
206
weave_checker = self.repository._get_versioned_file_checker()
216
207
result = weave_checker.check_file_version_parents(
217
208
self.repository.texts, progress_bar=self.progress)
218
209
self.checked_weaves = weave_checker.file_ids
231
222
def _check_revision_tree(self, rev_id):
232
223
tree = self.repository.revision_tree(rev_id)
233
224
inv = tree.inventory
236
for path, ie in inv.iter_entries():
237
self._add_entry_to_text_key_references(inv, ie)
239
227
if file_id in seen_ids:
240
228
raise BzrCheckError('duplicated file_id {%s} '
241
229
'in inventory for revision {%s}'
242
230
% (file_id, rev_id))
243
seen_ids.add(file_id)
231
seen_ids[file_id] = True
244
234
ie.check(self, rev_id, inv, tree)
236
for path, ie in inv.iter_entries():
245
237
if path in seen_names:
246
238
raise BzrCheckError('duplicated path %s '
247
239
'in inventory for revision {%s}'
248
240
% (path, rev_id))
251
def _add_entry_to_text_key_references(self, inv, entry):
252
if not self.rich_roots and entry == inv.root:
254
key = (entry.file_id, entry.revision)
255
self.text_key_references.setdefault(key, False)
256
if entry.revision == inv.revision_id:
257
self.text_key_references[key] = True
241
seen_names[path] = True
260
244
@deprecated_function(deprecated_in((1,6,0)))
261
245
def check(branch, verbose):
262
246
"""Run consistency checks on a branch.
264
248
Results are reported through logging.
266
250
Deprecated in 1.6. Please use check_branch instead.
268
252
:raise BzrCheckError: if there's a consistency error.