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 |
######################################################################
|
|
21 |
# consistency checks
|
|
22 |
||
|
114
by mbp at sourcefrog
- reactivate basic check command |
23 |
|
24 |
import bzrlib |
|
|
116
by mbp at sourcefrog
fix up debug output for check command |
25 |
from trace import mutter |
|
117
by mbp at sourcefrog
better messages from check command |
26 |
from errors import bailout |
|
114
by mbp at sourcefrog
- reactivate basic check command |
27 |
|
28 |
||
|
116
by mbp at sourcefrog
fix up debug output for check command |
29 |
def check(branch): |
30 |
mutter('checking tree %r' % branch.base) |
|
|
114
by mbp at sourcefrog
- reactivate basic check command |
31 |
|
|
117
by mbp at sourcefrog
better messages from check command |
32 |
mutter('checking revision history') |
|
114
by mbp at sourcefrog
- reactivate basic check command |
33 |
last_ptr = None |
34 |
for rid in branch.revision_history(): |
|
|
116
by mbp at sourcefrog
fix up debug output for check command |
35 |
mutter(' revision {%s}' % rid) |
|
114
by mbp at sourcefrog
- reactivate basic check command |
36 |
rev = branch.get_revision(rid) |
|
117
by mbp at sourcefrog
better messages from check command |
37 |
if rev.revision_id != rid: |
38 |
bailout('wrong internal revision id in revision {%s}' % rid) |
|
39 |
if rev.precursor != last_ptr: |
|
40 |
bailout('mismatched precursor in revision {%s}' % rid) |
|
|
114
by mbp at sourcefrog
- reactivate basic check command |
41 |
last_ptr = rid |
42 |
||
43 |
#mutter("checking tree")
|
|
44 |
#check_patches_exist()
|
|
45 |
#check_patch_chaining()
|
|
46 |
#check_patch_uniqueness()
|
|
47 |
#check_inventory()
|
|
|
116
by mbp at sourcefrog
fix up debug output for check command |
48 |
|
49 |
mutter('branch %s is OK' % branch.base) |
|
50 |
||
|
1
by mbp at sourcefrog
import from baz patch-364 |
51 |
## TODO: Check that previous-inventory and previous-manifest
|
52 |
## are the same as those stored in the previous changeset.
|
|
53 |
||
54 |
## TODO: Check all patches present in patch directory are
|
|
55 |
## mentioned in patch history; having an orphaned patch only gives
|
|
56 |
## a warning.
|
|
57 |
||
58 |
## TODO: Check cached data is consistent with data reconstructed
|
|
59 |
## from scratch.
|
|
60 |
||
61 |
## TODO: Check no control files are versioned.
|
|
62 |
||
63 |
## TODO: Check that the before-hash of each file in a later
|
|
64 |
## revision matches the after-hash in the previous revision to
|
|
65 |
## touch it.
|
|
66 |
||
67 |
||
68 |
def check_inventory(): |
|
69 |
mutter("checking inventory file and ids...") |
|
70 |
seen_ids = Set() |
|
71 |
seen_names = Set() |
|
72 |
||
73 |
for l in controlfile('inventory').readlines(): |
|
74 |
parts = l.split() |
|
75 |
if len(parts) != 2: |
|
76 |
bailout("malformed inventory line: " + `l`) |
|
77 |
file_id, name = parts |
|
78 |
||
79 |
if file_id in seen_ids: |
|
80 |
bailout("duplicated file id " + file_id) |
|
81 |
seen_ids.add(file_id) |
|
82 |
||
83 |
if name in seen_names: |
|
84 |
bailout("duplicated file name in inventory: " + quotefn(name)) |
|
85 |
seen_names.add(name) |
|
86 |
||
87 |
if is_control_file(name): |
|
88 |
raise BzrError("control file %s present in inventory" % quotefn(name)) |
|
89 |
||
90 |
||
91 |
def check_patches_exist(): |
|
92 |
"""Check constraint of current version: all patches exist""" |
|
93 |
mutter("checking all patches are present...") |
|
94 |
for pid in revision_history(): |
|
95 |
read_patch_header(pid) |
|
96 |
||
97 |
||
98 |
def check_patch_chaining(): |
|
99 |
"""Check ancestry of patches and history file is consistent""" |
|
100 |
mutter("checking patch chaining...") |
|
101 |
prev = None |
|
102 |
for pid in revision_history(): |
|
103 |
log_prev = read_patch_header(pid).precursor |
|
104 |
if log_prev != prev: |
|
105 |
bailout("inconsistent precursor links on " + pid) |
|
106 |
prev = pid |
|
107 |
||
108 |
||
109 |
def check_patch_uniqueness(): |
|
110 |
"""Make sure no patch is listed twice in the history. |
|
111 |
||
112 |
This should be implied by having correct ancestry but I'll check it
|
|
113 |
anyhow."""
|
|
114 |
mutter("checking history for duplicates...") |
|
115 |
seen = Set() |
|
116 |
for pid in revision_history(): |
|
117 |
if pid in seen: |
|
118 |
bailout("patch " + pid + " appears twice in history") |
|
119 |
seen.add(pid) |
|
120 |
||
121 |