~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Martin Pool
  • Date: 2005-09-16 06:21:56 UTC
  • Revision ID: mbp@sourcefrog.net-20050916062156-cacf627b0d2edb22
- enable and disable more ancestry tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
17
17
 
 
18
import bzrlib.ui
 
19
from bzrlib.trace import note, warning
18
20
 
19
21
def _update_store_entry(obj, obj_id, branch, store_name, store):
20
22
    """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.
72
74
    """
73
 
    _update_store_entry(inv, inv_id, branch,
74
 
            'inventory-store', branch.inventory_store)
 
75
    raise NotImplementedError("can't update existing inventory entry")
 
76
 
75
77
 
76
78
def check(branch):
77
79
    """Run consistency checks on a branch.
81
83
    TODO: Check for extra files in the control directory.
82
84
    """
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
89
90
 
90
91
    branch.lock_read()
91
92
 
92
93
    try:
93
 
        pb = ProgressBar(show_spinner=True)
94
94
        last_rev_id = None
95
95
 
96
96
        missing_inventory_sha_cnt = 0
97
97
        missing_revision_sha_cnt = 0
 
98
        missing_revision_cnt = 0
98
99
 
99
100
        history = branch.revision_history()
100
101
        revno = 0
104
105
        # for all texts checked, text_id -> sha1
105
106
        checked_texts = {}
106
107
 
 
108
        progress = bzrlib.ui.ui_factory.progress_bar()
 
109
 
107
110
        for rev_id in history:
108
111
            revno += 1
109
 
            pb.update('checking revision', revno, revcount)
110
 
            mutter('    revision {%s}' % rev_id)
 
112
            progress.update('checking revision', revno, revcount)
 
113
            # mutter('    revision {%s}' % rev_id)
111
114
            rev = branch.get_revision(rev_id)
112
115
            if rev.revision_id != rev_id:
113
116
                raise BzrCheckError('wrong internal revision id in revision {%s}'
132
135
                        missing_revision_sha_cnt += 1
133
136
                        continue
134
137
                    prid = prr.revision_id
135
 
                    actual_sha = branch.get_revision_sha1(prid)
 
138
                    
 
139
                    try:
 
140
                        actual_sha = branch.get_revision_sha1(prid)
 
141
                    except NoSuchRevision:
 
142
                        missing_revision_cnt += 1
 
143
                        mutter("parent {%s} of {%s} not present in store",
 
144
                               prid, rev_id)
 
145
                        continue
 
146
                        
136
147
                    if prr.revision_sha1 != actual_sha:
137
148
                        raise BzrCheckError("mismatched revision sha1 for "
138
149
                                            "parent {%s} of {%s}: %s vs %s"
143
154
                                    "by {%s}"
144
155
                                    % (rev_id, last_rev_id))
145
156
 
146
 
            if rev.inventory_id != rev_id:
 
157
            if hasattr(rev, 'inventory_id') and rev.inventory_id != rev_id:
147
158
                mismatch_inv_id.append(rev_id)
148
159
 
149
160
            ## TODO: Check all the required fields are present on the revision.
150
161
 
151
162
            if rev.inventory_sha1:
152
 
                inv_sha1 = branch.get_inventory_sha1(rev.inventory_id)
 
163
                inv_sha1 = branch.get_inventory_sha1(rev_id)
153
164
                if inv_sha1 != rev.inventory_sha1:
154
165
                    raise BzrCheckError('Inventory sha1 hash doesn\'t match'
155
166
                        ' value in revision {%s}' % rev_id)
157
168
                missing_inventory_sha_cnt += 1
158
169
                mutter("no inventory_sha1 on revision {%s}" % rev_id)
159
170
 
160
 
            inv = branch.get_inventory(rev.inventory_id)
 
171
            inv = branch.get_inventory(rev_id)
161
172
            seen_ids = {}
162
173
            seen_names = {}
163
174
 
173
184
            for file_id in inv:
174
185
                i += 1
175
186
                if i & 31 == 0:
176
 
                    pb.tick()
 
187
                    progress.tick()
177
188
 
178
189
                ie = inv[file_id]
179
190
 
202
213
                        raise BzrCheckError('directory {%s} has text in revision {%s}'
203
214
                                % (file_id, rev_id))
204
215
 
205
 
            pb.tick()
 
216
            progress.tick()
206
217
            for path, ie in inv.iter_entries():
207
218
                if path in seen_names:
208
219
                    raise BzrCheckError('duplicated path %s '
214
225
    finally:
215
226
        branch.unlock()
216
227
 
217
 
    pb.clear()
 
228
    progress.clear()
218
229
 
219
 
    print 'checked %d revisions, %d file texts' % (revcount, len(checked_texts))
 
230
    note('checked %d revisions, %d file texts' % (revcount, len(checked_texts)))
220
231
    
221
232
    if missing_inventory_sha_cnt:
222
 
        print '%d revisions are missing inventory_sha1' % missing_inventory_sha_cnt
 
233
        note('%d revisions are missing inventory_sha1' % missing_inventory_sha_cnt)
223
234
 
224
235
    if missing_revision_sha_cnt:
225
 
        print '%d parent links are missing revision_sha1' % missing_revision_sha_cnt
 
236
        note('%d parent links are missing revision_sha1' % missing_revision_sha_cnt)
 
237
 
 
238
    if missing_revision_cnt:
 
239
        note('%d revisions are mentioned but not present' % missing_revision_cnt)
 
240
 
 
241
    if missing_revision_cnt:
 
242
        print '%d revisions are mentioned but not present' % missing_revision_cnt
226
243
 
227
244
    # stub this out for now because the main bzr branch has references
228
245
    # to revisions that aren't present in the store -- mbp 20050804
231
248
#        print '  (use "bzr upgrade" to fix them)'
232
249
 
233
250
    if mismatch_inv_id:
234
 
        print '%d revisions have mismatched inventory ids:' % len(mismatch_inv_id)
 
251
        warning('%d revisions have mismatched inventory ids:' % len(mismatch_inv_id))
235
252
        for rev_id in mismatch_inv_id:
236
 
            print '  ', rev_id
 
253
            warning('  %s', rev_id)