1
# Copyright (C) 2004, 2005 by Martin Pool
2
# Copyright (C) 2005 by Canonical Ltd
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.
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.
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
23
Upgrade branch to current format.
25
This causes objects to be rewritten into the current format.
27
If they change, their SHA-1 will of course change, which might
28
break any later signatures, or backreferences that check the
31
TODO: Check non-mainline revisions.
35
from bzrlib.trace import mutter
36
from bzrlib.errors import BzrCheckError
37
from bzrlib.progress import ProgressBar
42
pb = ProgressBar(show_spinner=True)
45
history = branch.revision_history()
47
revcount = len(history)
49
updated_revisions = []
51
# Set to True in the case that the previous revision entry
52
# was updated, since this will affect future revision entries
53
updated_previous_revision = False
55
for rev_id in history:
57
pb.update('upgrading revision', revno, revcount)
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
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)
73
for prr in rev.parents:
75
actual_sha1 = branch.get_revision_sha1(prr.revision_id)
76
except bzrlib.errors.NoSuchRevision:
77
mutter("parent {%s} of {%s} not present in branch; skipped"
78
% (prr.revision_id, rev_id))
81
if actual_sha1 != prr.revision_sha1:
82
mutter("parent {%s} of {%s} sha1 mismatch: "
84
% (prr.revision_id, rev_id,
85
actual_sha1, prr.revision_sha1))
86
prr.revision_sha1 = actual_sha1
90
updated_previous_revision = True
91
# We had to update this revision entries hashes
92
# Now we need to write out a new value
93
# This is a little bit invasive, since we are *rewriting* a
94
# revision entry. I'm not supremely happy about it, but
95
# there should be *some* way of making old entries have
96
# the full meta information.
97
import tempfile, os, errno
98
from bzrlib.xml import pack_xml
100
rev_tmp = tempfile.TemporaryFile()
101
pack_xml(rev, rev_tmp)
104
tmpfd, tmp_path = tempfile.mkstemp(prefix=rev_id, suffix='.gz',
105
dir=branch.controlfilename('revision-store'))
107
def special_rename(p1, p2):
108
if sys.platform == 'win32':
112
if e.errno != errno.ENOENT:
117
# TODO: We may need to handle the case where the old revision
118
# entry was not compressed (and thus did not end with .gz)
120
# Remove the old revision entry out of the way
121
rev_path = branch.controlfilename(['revision-store', rev_id+'.gz'])
122
special_rename(rev_path, tmp_path)
123
branch.revision_store.add(rev_tmp, rev_id) # Add the new one
124
os.remove(tmp_path) # Remove the old name
125
mutter(' Updated revision entry {%s}' % rev_id)
127
# On any exception, restore the old entry
128
special_rename(tmp_path, rev_path)
131
updated_revisions.append(rev_id)
133
updated_previous_revision = False
140
if updated_revisions:
141
print '%d revisions updated to current format' % len(updated_revisions)