15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
from bzrlib.trace import note, warning
20
from bzrlib.osutils import rename, sha_string
19
22
def _update_store_entry(obj, obj_id, branch, store_name, store):
20
23
"""This is just a meta-function, which handles both revision entries
70
72
:param inv_id: The inventory id for this inventory
71
73
:param branch: The Branch where this entry will be stored.
73
_update_store_entry(inv, inv_id, branch,
74
'inventory-store', branch.inventory_store)
75
raise NotImplementedError("can't update existing inventory entry")
77
79
"""Run consistency checks on a branch.
81
83
TODO: Check for extra files in the control directory.
83
85
from bzrlib.trace import mutter
84
from bzrlib.errors import BzrCheckError
86
from bzrlib.errors import BzrCheckError, NoSuchRevision
85
87
from bzrlib.osutils import fingerprint_file
86
from bzrlib.progress import ProgressBar
87
88
from bzrlib.inventory import ROOT_ID
88
89
from bzrlib.branch import gen_root_id
93
pb = ProgressBar(show_spinner=True)
96
96
missing_inventory_sha_cnt = 0
97
97
missing_revision_sha_cnt = 0
98
missing_revision_cnt = 0
99
100
history = branch.revision_history()
101
102
revcount = len(history)
104
# for all texts checked, text_id -> sha1
104
checked_text_count = 0
106
progress = bzrlib.ui.ui_factory.progress_bar()
107
108
for rev_id in history:
109
pb.update('checking revision', revno, revcount)
110
mutter(' revision {%s}' % rev_id)
110
progress.update('checking revision', revno, revcount)
111
# mutter(' revision {%s}' % rev_id)
111
112
rev = branch.get_revision(rev_id)
112
113
if rev.revision_id != rev_id:
113
114
raise BzrCheckError('wrong internal revision id in revision {%s}'
132
133
missing_revision_sha_cnt += 1
134
135
prid = prr.revision_id
135
actual_sha = branch.get_revision_sha1(prid)
138
actual_sha = branch.get_revision_sha1(prid)
139
except NoSuchRevision:
140
missing_revision_cnt += 1
141
mutter("parent {%s} of {%s} not present in store",
136
145
if prr.revision_sha1 != actual_sha:
137
146
raise BzrCheckError("mismatched revision sha1 for "
138
147
"parent {%s} of {%s}: %s vs %s"
144
153
% (rev_id, last_rev_id))
146
if rev.inventory_id != rev_id:
147
mismatch_inv_id.append(rev_id)
149
155
## TODO: Check all the required fields are present on the revision.
151
157
if rev.inventory_sha1:
152
inv_sha1 = branch.get_inventory_sha1(rev.inventory_id)
158
inv_sha1 = branch.get_inventory_sha1(rev_id)
153
159
if inv_sha1 != rev.inventory_sha1:
154
160
raise BzrCheckError('Inventory sha1 hash doesn\'t match'
155
161
' value in revision {%s}' % rev_id)
183
190
% (ie.parent_id, rev_id))
185
192
if ie.kind == 'file':
186
if ie.text_id in checked_texts:
187
fp = checked_texts[ie.text_id]
189
if not ie.text_id in branch.text_store:
190
raise BzrCheckError('text {%s} not in text_store' % ie.text_id)
192
tf = branch.text_store[ie.text_id]
193
fp = fingerprint_file(tf)
194
checked_texts[ie.text_id] = fp
196
if ie.text_size != fp['size']:
193
text = tree.get_file_text(file_id)
194
checked_text_count += 1
195
if ie.text_size != len(text):
197
196
raise BzrCheckError('text {%s} wrong size' % ie.text_id)
198
if ie.text_sha1 != fp['sha1']:
197
if ie.text_sha1 != sha_string(text):
199
198
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
200
199
elif ie.kind == 'directory':
201
200
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
202
201
raise BzrCheckError('directory {%s} has text in revision {%s}'
203
202
% (file_id, rev_id))
206
205
for path, ie in inv.iter_entries():
207
206
if path in seen_names:
208
207
raise BzrCheckError('duplicated path %s '
209
208
'in inventory for revision {%s}'
210
209
% (path, rev_id))
211
seen_names[path] = True
210
seen_names[path] = True
212
211
last_rev_id = rev_id
219
print 'checked %d revisions, %d file texts' % (revcount, len(checked_texts))
218
note('checked %d revisions, %d file texts' % (revcount, checked_text_count))
221
220
if missing_inventory_sha_cnt:
222
print '%d revisions are missing inventory_sha1' % missing_inventory_sha_cnt
224
if missing_revision_sha_cnt:
225
print '%d parent links are missing revision_sha1' % missing_revision_sha_cnt
227
if (missing_inventory_sha_cnt
228
or missing_revision_sha_cnt):
229
print ' (use "bzr upgrade" to fix them)'
232
print '%d revisions have mismatched inventory ids:' % len(mismatch_inv_id)
233
for rev_id in mismatch_inv_id:
221
note('%d revisions are missing inventory_sha1' % missing_inventory_sha_cnt)
223
##if missing_revision_sha_cnt:
224
## note('%d parent links are missing revision_sha1' % missing_revision_sha_cnt)
226
if missing_revision_cnt:
227
note('%d revisions are mentioned but not present' % missing_revision_cnt)
229
if missing_revision_cnt:
230
print '%d revisions are mentioned but not present' % missing_revision_cnt
232
# stub this out for now because the main bzr branch has references
233
# to revisions that aren't present in the store -- mbp 20050804
234
# if (missing_inventory_sha_cnt
235
# or missing_revision_sha_cnt):
236
# print ' (use "bzr upgrade" to fix them)'