bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1
by mbp at sourcefrog
import from baz patch-364 |
1 |
# Copyright (C) 2004, 2005 by Martin Pool
|
2 |
# Copyright (C) 2005 by Canonical Ltd
|
|
3 |
||
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
||
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
||
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
||
19 |
||
20 |
||
|
654
by Martin Pool
- update check command to use aaron's progress code |
21 |
def check(branch): |
22 |
"""Run consistency checks on a branch. |
|
23 |
"""
|
|
|
651
by Martin Pool
- clean up imports |
24 |
import sys |
25 |
||
26 |
from bzrlib.trace import mutter |
|
27 |
from bzrlib.errors import BzrCheckError |
|
28 |
from bzrlib.osutils import fingerprint_file |
|
|
658
by Martin Pool
- clean up and add a bunch of options to the progress indicator |
29 |
from bzrlib.progress import ProgressBar |
|
651
by Martin Pool
- clean up imports |
30 |
|
|
121
by mbp at sourcefrog
- progress indicator while checking |
31 |
out = sys.stdout |
32 |
||
|
658
by Martin Pool
- clean up and add a bunch of options to the progress indicator |
33 |
pb = ProgressBar(show_spinner=True) |
|
114
by mbp at sourcefrog
- reactivate basic check command |
34 |
last_ptr = None |
|
543
by Martin Pool
- More cleanups for set type |
35 |
checked_revs = {} |
|
121
by mbp at sourcefrog
- progress indicator while checking |
36 |
|
37 |
history = branch.revision_history() |
|
38 |
revno = 0 |
|
39 |
revcount = len(history) |
|
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
40 |
|
41 |
checked_texts = {} |
|
|
121
by mbp at sourcefrog
- progress indicator while checking |
42 |
|
43 |
for rid in history: |
|
44 |
revno += 1 |
|
|
658
by Martin Pool
- clean up and add a bunch of options to the progress indicator |
45 |
pb.update('checking revision', revno, revcount) |
|
116
by mbp at sourcefrog
fix up debug output for check command |
46 |
mutter(' revision {%s}' % rid) |
|
114
by mbp at sourcefrog
- reactivate basic check command |
47 |
rev = branch.get_revision(rid) |
|
117
by mbp at sourcefrog
better messages from check command |
48 |
if rev.revision_id != rid: |
|
650
by Martin Pool
- remove calls to bailout() from check code |
49 |
raise BzrCheckError('wrong internal revision id in revision {%s}' % rid) |
|
117
by mbp at sourcefrog
better messages from check command |
50 |
if rev.precursor != last_ptr: |
|
650
by Martin Pool
- remove calls to bailout() from check code |
51 |
raise BzrCheckError('mismatched precursor in revision {%s}' % rid) |
|
114
by mbp at sourcefrog
- reactivate basic check command |
52 |
last_ptr = rid |
|
119
by mbp at sourcefrog
check revisions are not duplicated in history |
53 |
if rid in checked_revs: |
|
650
by Martin Pool
- remove calls to bailout() from check code |
54 |
raise BzrCheckError('repeated revision {%s}' % rid) |
|
543
by Martin Pool
- More cleanups for set type |
55 |
checked_revs[rid] = True |
|
114
by mbp at sourcefrog
- reactivate basic check command |
56 |
|
|
120
by mbp at sourcefrog
more check functions |
57 |
## TODO: Check all the required fields are present on the revision.
|
58 |
||
59 |
inv = branch.get_inventory(rev.inventory_id) |
|
|
543
by Martin Pool
- More cleanups for set type |
60 |
seen_ids = {} |
61 |
seen_names = {} |
|
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
62 |
|
|
654
by Martin Pool
- update check command to use aaron's progress code |
63 |
## p('revision %d/%d file ids' % (revno, revcount))
|
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
64 |
for file_id in inv: |
65 |
if file_id in seen_ids: |
|
|
654
by Martin Pool
- update check command to use aaron's progress code |
66 |
raise BzrCheckError('duplicated file_id {%s} ' |
67 |
'in inventory for revision {%s}' |
|
68 |
% (file_id, rid)) |
|
|
543
by Martin Pool
- More cleanups for set type |
69 |
seen_ids[file_id] = True |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
70 |
|
71 |
i = 0 |
|
72 |
len_inv = len(inv) |
|
73 |
for file_id in inv: |
|
74 |
i += 1 |
|
|
662
by Martin Pool
- tune check progress indicator |
75 |
if i & 31 == 0: |
|
658
by Martin Pool
- clean up and add a bunch of options to the progress indicator |
76 |
pb.tick() |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
77 |
|
78 |
ie = inv[file_id] |
|
79 |
||
80 |
if ie.parent_id != None: |
|
81 |
if ie.parent_id not in seen_ids: |
|
|
650
by Martin Pool
- remove calls to bailout() from check code |
82 |
raise BzrCheckError('missing parent {%s} in inventory for revision {%s}' |
|
184
by mbp at sourcefrog
pychecker fixups |
83 |
% (ie.parent_id, rid)) |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
84 |
|
85 |
if ie.kind == 'file': |
|
86 |
if ie.text_id in checked_texts: |
|
87 |
fp = checked_texts[ie.text_id] |
|
88 |
else: |
|
89 |
if not ie.text_id in branch.text_store: |
|
|
650
by Martin Pool
- remove calls to bailout() from check code |
90 |
raise BzrCheckError('text {%s} not in text_store' % ie.text_id) |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
91 |
|
92 |
tf = branch.text_store[ie.text_id] |
|
|
651
by Martin Pool
- clean up imports |
93 |
fp = fingerprint_file(tf) |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
94 |
checked_texts[ie.text_id] = fp |
95 |
||
96 |
if ie.text_size != fp['size']: |
|
|
650
by Martin Pool
- remove calls to bailout() from check code |
97 |
raise BzrCheckError('text {%s} wrong size' % ie.text_id) |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
98 |
if ie.text_sha1 != fp['sha1']: |
|
650
by Martin Pool
- remove calls to bailout() from check code |
99 |
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id) |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
100 |
elif ie.kind == 'directory': |
101 |
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None: |
|
|
650
by Martin Pool
- remove calls to bailout() from check code |
102 |
raise BzrCheckError('directory {%s} has text in revision {%s}' |
|
184
by mbp at sourcefrog
pychecker fixups |
103 |
% (file_id, rid)) |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
104 |
|
|
658
by Martin Pool
- clean up and add a bunch of options to the progress indicator |
105 |
pb.tick() |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
106 |
for path, ie in inv.iter_entries(): |
107 |
if path in seen_names: |
|
|
654
by Martin Pool
- update check command to use aaron's progress code |
108 |
raise BzrCheckError('duplicated path %r ' |
109 |
'in inventory for revision {%s}' |
|
110 |
% (path, revid)) |
|
|
543
by Martin Pool
- More cleanups for set type |
111 |
seen_names[path] = True |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
112 |
|
|
121
by mbp at sourcefrog
- progress indicator while checking |
113 |
|
|
654
by Martin Pool
- update check command to use aaron's progress code |
114 |
pb.clear() |
|
248
by mbp at sourcefrog
- Better progress and completion indicator from check command |
115 |
print 'checked %d revisions, %d file texts' % (revcount, len(checked_texts)) |
|
121
by mbp at sourcefrog
- progress indicator while checking |
116 |