1
by mbp at sourcefrog
import from baz patch-364 |
1 |
#! /usr/bin/python
|
2 |
||
3 |
||
4 |
# Copyright (C) 2004, 2005 by Martin Pool
|
|
5 |
# Copyright (C) 2005 by Canonical Ltd
|
|
6 |
||
7 |
||
8 |
# This program is free software; you can redistribute it and/or modify
|
|
9 |
# it under the terms of the GNU General Public License as published by
|
|
10 |
# the Free Software Foundation; either version 2 of the License, or
|
|
11 |
# (at your option) any later version.
|
|
12 |
||
13 |
# This program is distributed in the hope that it will be useful,
|
|
14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
# GNU General Public License for more details.
|
|
17 |
||
18 |
# You should have received a copy of the GNU General Public License
|
|
19 |
# along with this program; if not, write to the Free Software
|
|
20 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 |
||
22 |
||
23 |
||
24 |
######################################################################
|
|
25 |
# consistency checks
|
|
26 |
||
27 |
def check(): |
|
28 |
"""Consistency check of tree."""
|
|
29 |
assert_in_tree() |
|
30 |
mutter("checking tree") |
|
31 |
check_patches_exist() |
|
32 |
check_patch_chaining() |
|
33 |
check_patch_uniqueness() |
|
34 |
check_inventory() |
|
35 |
mutter("tree looks OK") |
|
36 |
## TODO: Check that previous-inventory and previous-manifest
|
|
37 |
## are the same as those stored in the previous changeset.
|
|
38 |
||
39 |
## TODO: Check all patches present in patch directory are
|
|
40 |
## mentioned in patch history; having an orphaned patch only gives
|
|
41 |
## a warning.
|
|
42 |
||
43 |
## TODO: Check cached data is consistent with data reconstructed
|
|
44 |
## from scratch.
|
|
45 |
||
46 |
## TODO: Check no control files are versioned.
|
|
47 |
||
48 |
## TODO: Check that the before-hash of each file in a later
|
|
49 |
## revision matches the after-hash in the previous revision to
|
|
50 |
## touch it.
|
|
51 |
||
52 |
||
53 |
def check_inventory(): |
|
54 |
mutter("checking inventory file and ids...") |
|
55 |
seen_ids = Set() |
|
56 |
seen_names = Set() |
|
57 |
||
58 |
for l in controlfile('inventory').readlines(): |
|
59 |
parts = l.split() |
|
60 |
if len(parts) != 2: |
|
61 |
bailout("malformed inventory line: " + `l`) |
|
62 |
file_id, name = parts |
|
63 |
||
64 |
if file_id in seen_ids: |
|
65 |
bailout("duplicated file id " + file_id) |
|
66 |
seen_ids.add(file_id) |
|
67 |
||
68 |
if name in seen_names: |
|
69 |
bailout("duplicated file name in inventory: " + quotefn(name)) |
|
70 |
seen_names.add(name) |
|
71 |
||
72 |
if is_control_file(name): |
|
73 |
raise BzrError("control file %s present in inventory" % quotefn(name)) |
|
74 |
||
75 |
||
76 |
def check_patches_exist(): |
|
77 |
"""Check constraint of current version: all patches exist"""
|
|
78 |
mutter("checking all patches are present...") |
|
79 |
for pid in revision_history(): |
|
80 |
read_patch_header(pid) |
|
81 |
||
82 |
||
83 |
def check_patch_chaining(): |
|
84 |
"""Check ancestry of patches and history file is consistent"""
|
|
85 |
mutter("checking patch chaining...") |
|
86 |
prev = None |
|
87 |
for pid in revision_history(): |
|
88 |
log_prev = read_patch_header(pid).precursor |
|
89 |
if log_prev != prev: |
|
90 |
bailout("inconsistent precursor links on " + pid) |
|
91 |
prev = pid |
|
92 |
||
93 |
||
94 |
def check_patch_uniqueness(): |
|
95 |
"""Make sure no patch is listed twice in the history.
|
|
96 |
||
97 |
This should be implied by having correct ancestry but I'll check it
|
|
98 |
anyhow."""
|
|
99 |
mutter("checking history for duplicates...") |
|
100 |
seen = Set() |
|
101 |
for pid in revision_history(): |
|
102 |
if pid in seen: |
|
103 |
bailout("patch " + pid + " appears twice in history") |
|
104 |
seen.add(pid) |
|
105 |
||
106 |