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 |
||
|
1335
by Martin Pool
doc |
18 |
# TODO: Check ancestries are correct for every revision: includes
|
19 |
# every committed so far, and in a reasonable order.
|
|
20 |
||
|
1104
by Martin Pool
- Add a simple UIFactory |
21 |
import bzrlib.ui |
|
1130
by Martin Pool
- check command writes output through logging not direct |
22 |
from bzrlib.trace import note, warning |
|
1346
by Martin Pool
- remove dead code from bzrlib.check |
23 |
from bzrlib.osutils import rename, sha_string, fingerprint_file |
24 |
from bzrlib.trace import mutter |
|
25 |
from bzrlib.errors import BzrCheckError, NoSuchRevision |
|
26 |
from bzrlib.inventory import ROOT_ID |
|
27 |
from bzrlib.branch import gen_root_id |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
28 |
|
|
1104
by Martin Pool
- Add a simple UIFactory |
29 |
|
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
30 |
def check(branch): |
|
654
by Martin Pool
- update check command to use aaron's progress code |
31 |
"""Run consistency checks on a branch. |
|
705
by Martin Pool
- updated check for revision parents and sha1 |
32 |
|
|
813
by Martin Pool
doc |
33 |
TODO: Also check non-mainline revisions mentioned as parents.
|
34 |
||
35 |
TODO: Check for extra files in the control directory.
|
|
|
654
by Martin Pool
- update check command to use aaron's progress code |
36 |
"""
|
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
37 |
branch.lock_read() |
|
676
by Martin Pool
- lock branch while checking |
38 |
|
39 |
try: |
|
|
705
by Martin Pool
- updated check for revision parents and sha1 |
40 |
last_rev_id = None |
|
676
by Martin Pool
- lock branch while checking |
41 |
|
42 |
missing_inventory_sha_cnt = 0 |
|
|
705
by Martin Pool
- updated check for revision parents and sha1 |
43 |
missing_revision_sha_cnt = 0 |
|
1118
by Martin Pool
- bzr check doesn't abort when trying to read a revision that's not |
44 |
missing_revision_cnt = 0 |
|
676
by Martin Pool
- lock branch while checking |
45 |
|
46 |
history = branch.revision_history() |
|
47 |
revno = 0 |
|
48 |
revcount = len(history) |
|
49 |
||
|
1287
by Martin Pool
- update check code for weave stores and new inventories |
50 |
checked_text_count = 0 |
|
676
by Martin Pool
- lock branch while checking |
51 |
|
|
1104
by Martin Pool
- Add a simple UIFactory |
52 |
progress = bzrlib.ui.ui_factory.progress_bar() |
53 |
||
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
54 |
for rev_id in history: |
|
676
by Martin Pool
- lock branch while checking |
55 |
revno += 1 |
|
1104
by Martin Pool
- Add a simple UIFactory |
56 |
progress.update('checking revision', revno, revcount) |
|
1097
by Martin Pool
- send trace messages out through python logging module |
57 |
# mutter(' revision {%s}' % rev_id)
|
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
58 |
rev = branch.get_revision(rev_id) |
59 |
if rev.revision_id != rev_id: |
|
|
705
by Martin Pool
- updated check for revision parents and sha1 |
60 |
raise BzrCheckError('wrong internal revision id in revision {%s}' |
61 |
% rev_id) |
|
62 |
||
63 |
# check the previous history entry is a parent of this entry
|
|
|
1313
by Martin Pool
- rename to Revision.parent_ids to avoid confusion with old usage |
64 |
if rev.parent_ids: |
|
705
by Martin Pool
- updated check for revision parents and sha1 |
65 |
if last_rev_id is None: |
66 |
raise BzrCheckError("revision {%s} has %d parents, but is the " |
|
67 |
"start of the branch"
|
|
|
1313
by Martin Pool
- rename to Revision.parent_ids to avoid confusion with old usage |
68 |
% (rev_id, len(rev.parent_ids))) |
69 |
for parent_id in rev.parent_ids: |
|
|
1311
by Martin Pool
- remove RevisionReference; just hold parent ids directly |
70 |
if parent_id == last_rev_id: |
|
705
by Martin Pool
- updated check for revision parents and sha1 |
71 |
break
|
72 |
else: |
|
73 |
raise BzrCheckError("previous revision {%s} not listed among " |
|
74 |
"parents of {%s}" |
|
75 |
% (last_rev_id, rev_id)) |
|
76 |
elif last_rev_id: |
|
|
1311
by Martin Pool
- remove RevisionReference; just hold parent ids directly |
77 |
raise BzrCheckError("revision {%s} has no parents listed " |
78 |
"but preceded by {%s}" |
|
|
705
by Martin Pool
- updated check for revision parents and sha1 |
79 |
% (rev_id, last_rev_id)) |
|
676
by Martin Pool
- lock branch while checking |
80 |
|
81 |
## TODO: Check all the required fields are present on the revision.
|
|
82 |
||
83 |
if rev.inventory_sha1: |
|
|
1222
by Martin Pool
- remove some more references to inventory_id |
84 |
inv_sha1 = branch.get_inventory_sha1(rev_id) |
|
676
by Martin Pool
- lock branch while checking |
85 |
if inv_sha1 != rev.inventory_sha1: |
86 |
raise BzrCheckError('Inventory sha1 hash doesn\'t match' |
|
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
87 |
' value in revision {%s}' % rev_id) |
|
676
by Martin Pool
- lock branch while checking |
88 |
else: |
89 |
missing_inventory_sha_cnt += 1 |
|
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
90 |
mutter("no inventory_sha1 on revision {%s}" % rev_id) |
|
676
by Martin Pool
- lock branch while checking |
91 |
|
|
1287
by Martin Pool
- update check code for weave stores and new inventories |
92 |
tree = branch.revision_tree(rev_id) |
93 |
inv = tree.inventory |
|
|
676
by Martin Pool
- lock branch while checking |
94 |
seen_ids = {} |
95 |
seen_names = {} |
|
96 |
||
97 |
## p('revision %d/%d file ids' % (revno, revcount))
|
|
98 |
for file_id in inv: |
|
99 |
if file_id in seen_ids: |
|
100 |
raise BzrCheckError('duplicated file_id {%s} ' |
|
101 |
'in inventory for revision {%s}' |
|
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
102 |
% (file_id, rev_id)) |
|
676
by Martin Pool
- lock branch while checking |
103 |
seen_ids[file_id] = True |
104 |
||
105 |
i = 0 |
|
106 |
for file_id in inv: |
|
107 |
i += 1 |
|
108 |
if i & 31 == 0: |
|
|
1104
by Martin Pool
- Add a simple UIFactory |
109 |
progress.tick() |
|
676
by Martin Pool
- lock branch while checking |
110 |
|
111 |
ie = inv[file_id] |
|
112 |
||
113 |
if ie.parent_id != None: |
|
114 |
if ie.parent_id not in seen_ids: |
|
115 |
raise BzrCheckError('missing parent {%s} in inventory for revision {%s}' |
|
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
116 |
% (ie.parent_id, rev_id)) |
|
676
by Martin Pool
- lock branch while checking |
117 |
|
118 |
if ie.kind == 'file': |
|
|
1287
by Martin Pool
- update check code for weave stores and new inventories |
119 |
text = tree.get_file_text(file_id) |
120 |
checked_text_count += 1 |
|
121 |
if ie.text_size != len(text): |
|
|
676
by Martin Pool
- lock branch while checking |
122 |
raise BzrCheckError('text {%s} wrong size' % ie.text_id) |
|
1287
by Martin Pool
- update check code for weave stores and new inventories |
123 |
if ie.text_sha1 != sha_string(text): |
|
676
by Martin Pool
- lock branch while checking |
124 |
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id) |
125 |
elif ie.kind == 'directory': |
|
126 |
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None: |
|
127 |
raise BzrCheckError('directory {%s} has text in revision {%s}' |
|
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
128 |
% (file_id, rev_id)) |
|
676
by Martin Pool
- lock branch while checking |
129 |
|
|
1104
by Martin Pool
- Add a simple UIFactory |
130 |
progress.tick() |
|
676
by Martin Pool
- lock branch while checking |
131 |
for path, ie in inv.iter_entries(): |
132 |
if path in seen_names: |
|
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
133 |
raise BzrCheckError('duplicated path %s ' |
|
676
by Martin Pool
- lock branch while checking |
134 |
'in inventory for revision {%s}' |
|
703
by Martin Pool
- split out a new 'bzr upgrade' command separate from |
135 |
% (path, rev_id)) |
|
1287
by Martin Pool
- update check code for weave stores and new inventories |
136 |
seen_names[path] = True |
|
705
by Martin Pool
- updated check for revision parents and sha1 |
137 |
last_rev_id = rev_id |
|
125
by mbp at sourcefrog
- check progress indicator for file texts |
138 |
|
|
676
by Martin Pool
- lock branch while checking |
139 |
finally: |
140 |
branch.unlock() |
|
|
121
by mbp at sourcefrog
- progress indicator while checking |
141 |
|
|
1104
by Martin Pool
- Add a simple UIFactory |
142 |
progress.clear() |
|
674
by Martin Pool
- check command now also checks new inventory_sha1 and |
143 |
|
|
1287
by Martin Pool
- update check code for weave stores and new inventories |
144 |
note('checked %d revisions, %d file texts' % (revcount, checked_text_count)) |
|
705
by Martin Pool
- updated check for revision parents and sha1 |
145 |
|
|
674
by Martin Pool
- check command now also checks new inventory_sha1 and |
146 |
if missing_inventory_sha_cnt: |
|
1130
by Martin Pool
- check command writes output through logging not direct |
147 |
note('%d revisions are missing inventory_sha1' % missing_inventory_sha_cnt) |
|
705
by Martin Pool
- updated check for revision parents and sha1 |
148 |
|
|
1287
by Martin Pool
- update check code for weave stores and new inventories |
149 |
##if missing_revision_sha_cnt:
|
150 |
## note('%d parent links are missing revision_sha1' % missing_revision_sha_cnt)
|
|
|
705
by Martin Pool
- updated check for revision parents and sha1 |
151 |
|
|
1118
by Martin Pool
- bzr check doesn't abort when trying to read a revision that's not |
152 |
if missing_revision_cnt: |
|
1130
by Martin Pool
- check command writes output through logging not direct |
153 |
note('%d revisions are mentioned but not present' % missing_revision_cnt) |
|
1118
by Martin Pool
- bzr check doesn't abort when trying to read a revision that's not |
154 |
|
155 |
if missing_revision_cnt: |
|
156 |
print '%d revisions are mentioned but not present' % missing_revision_cnt |
|
157 |
||
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
158 |
# stub this out for now because the main bzr branch has references
|
159 |
# to revisions that aren't present in the store -- mbp 20050804
|
|
160 |
# if (missing_inventory_sha_cnt
|
|
161 |
# or missing_revision_sha_cnt):
|
|
162 |
# print ' (use "bzr upgrade" to fix them)'
|