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