51
52
# was updated, since this will affect future revision entries
52
53
updated_previous_revision = False
55
for rev_id in history:
56
57
pb.update('upgrading revision', revno, revcount)
57
mutter(' revision {%s}' % rid)
58
rev = branch.get_revision(rid)
59
if rev.revision_id != rid:
60
raise BzrCheckError('wrong internal revision id in revision {%s}' % rid)
61
if rev.precursor != last_ptr:
62
raise BzrCheckError('mismatched precursor in revision {%s}' % rid)
64
if rid in checked_revs:
65
raise BzrCheckError('repeated revision {%s}' % rid)
66
checked_revs[rid] = True
68
## TODO: Check all the required fields are present on the revision.
58
rev = branch.get_revision(rev_id)
59
if rev.revision_id != rev_id:
60
raise BzrCheckError('wrong internal revision id in revision {%s}'
65
# if set to true, revision must be written out
71
if rev.inventory_sha1:
72
#mutter(' checking inventory hash {%s}' % rev.inventory_sha1)
73
inv_sha1 = branch.get_inventory_sha1(rev.inventory_id)
74
if inv_sha1 != rev.inventory_sha1:
75
raise BzrCheckError('Inventory sha1 hash doesn\'t match'
76
' value in revision {%s}' % rid)
78
inv_sha1 = branch.get_inventory_sha1(rev.inventory_id)
79
rev.inventory_sha1 = inv_sha1
68
if rev.inventory_sha1 is None:
69
rev.inventory_sha1 = branch.get_inventory_sha1(rev.inventory_id)
71
mutter(" set inventory_sha1 on {%s}" % rev_id)
83
if rev.precursor_sha1:
84
precursor_sha1 = branch.get_revision_sha1(rev.precursor)
85
if updated_previous_revision:
86
# we don't expect the hashes to match, because
87
# we had to modify the previous revision_history entry.
88
rev.precursor_sha1 = precursor_sha1
73
for prr in rev.parents:
74
actual_sha1 = branch.get_revision_sha1(prr.revision_id)
75
if (updated_previous_revision
76
or prr.revision_sha1 is None):
77
if prr.revision_sha1 != actual_sha1:
78
prr.revision_sha1 = actual_sha1
91
#mutter(' checking precursor hash {%s}' % rev.precursor_sha1)
92
if rev.precursor_sha1 != precursor_sha1:
93
raise BzrCheckError('Precursor sha1 hash doesn\'t match'
94
' value in revision {%s}' % rid)
96
precursor_sha1 = branch.get_revision_sha1(rev.precursor)
97
rev.precursor_sha1 = precursor_sha1
80
elif actual_sha1 != prr.revision_sha1:
81
raise BzrCheckError("parent {%s} of {%s} sha1 mismatch: "
83
% (prr.revision_id, rev_id,
84
actual_sha1, prr.revision_sha1))
101
87
updated_previous_revision = True
110
96
rev.write_xml(rev_tmp)
113
tmpfd, tmp_path = tempfile.mkstemp(prefix=rid, suffix='.gz',
99
tmpfd, tmp_path = tempfile.mkstemp(prefix=rev_id, suffix='.gz',
114
100
dir=branch.controlfilename('revision-store'))
116
102
def special_rename(p1, p2):
127
113
# entry was not compressed (and thus did not end with .gz)
129
115
# Remove the old revision entry out of the way
130
rev_path = branch.controlfilename(['revision-store', rid+'.gz'])
116
rev_path = branch.controlfilename(['revision-store', rev_id+'.gz'])
131
117
special_rename(rev_path, tmp_path)
132
branch.revision_store.add(rev_tmp, rid) # Add the new one
118
branch.revision_store.add(rev_tmp, rev_id) # Add the new one
133
119
os.remove(tmp_path) # Remove the old name
134
mutter(' Updated revision entry {%s}' % rid)
120
mutter(' Updated revision entry {%s}' % rev_id)
136
122
# On any exception, restore the old entry
137
123
special_rename(tmp_path, rev_path)
140
updated_revisions.append(rid)
126
updated_revisions.append(rev_id)
142
128
updated_previous_revision = False