~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

Merge integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
"""Experiment in converting existing bzr branches to weaves."""
 
17
"""bzr upgrade logic."""
 
18
 
 
19
# change upgrade from .bzr to create a '.bzr-new', then do a bait and switch.
 
20
 
18
21
 
19
22
# To make this properly useful
20
23
#
73
76
 
74
77
import bzrlib
75
78
from bzrlib.branch import Branch
76
 
from bzrlib.branch import BZR_BRANCH_FORMAT_5, BZR_BRANCH_FORMAT_6
77
 
from bzrlib.branch import BzrBranchFormat, BzrBranchFormat4, BzrBranchFormat5, BzrBranchFormat6
 
79
import bzrlib.bzrdir as bzrdir
 
80
from bzrlib.bzrdir import BzrDirFormat, BzrDirFormat4, BzrDirFormat5, BzrDirFormat6
 
81
import bzrlib.errors as errors
78
82
from bzrlib.errors import NoSuchFile, UpgradeReadonly
79
83
import bzrlib.hashcache as hashcache
80
84
from bzrlib.lockable_files import LockableFiles
122
126
        note('starting upgrade of %s', self.base)
123
127
        self._backup_control_dir()
124
128
        self.pb = ui_factory.progress_bar()
125
 
        if isinstance(self.old_format, BzrBranchFormat4):
 
129
        if isinstance(self.old_format, BzrDirFormat4):
126
130
            note('starting upgrade from format 4 to 5')
 
131
            if isinstance(self.transport, LocalTransport):
 
132
                self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
127
133
            self._convert_to_weaves()
128
 
        if isinstance(self.old_format, BzrBranchFormat5):
 
134
        if isinstance(self.old_format, BzrDirFormat5):
129
135
            note('starting upgrade from format 5 to 6')
130
136
            self._convert_to_prefixed()
131
 
        if isinstance(self.transport, LocalTransport):
132
 
            cache = hashcache.HashCache(abspath(self.base))
133
 
            cache.clear()
134
 
            cache.write()
135
137
        note("finished")
136
138
 
137
139
    def _convert_to_prefixed(self):
155
157
                except NoSuchFile: # catches missing dirs strangely enough
156
158
                    store_transport.mkdir(prefix_dir)
157
159
                    store_transport.move(filename, prefix_dir + '/' + filename)
158
 
        self._set_new_format(BZR_BRANCH_FORMAT_6)
159
 
        self.branch = BzrBranchFormat6().open(self.transport)
160
 
        self.old_format = self.branch._branch_format
 
160
        self.old_format = BzrDirFormat6()
 
161
        self._set_new_format(self.old_format.get_format_string())
 
162
        self.bzrdir = self.old_format.open(self.transport)
 
163
        self.branch = self.bzrdir.open_branch()
161
164
 
162
165
    def _convert_to_weaves(self):
163
166
        note('note: upgrade may be faster if all store files are ungzipped first')
198
201
        note('  %6d revisions not present' % len(self.absent_revisions))
199
202
        note('  %6d texts' % self.text_count)
200
203
        self._cleanup_spare_files_after_format4()
201
 
        self._set_new_format(BZR_BRANCH_FORMAT_5)
202
 
        self.branch = BzrBranchFormat5().open(self.transport)
203
 
        self.old_format = self.branch._branch_format
 
204
        self.old_format = BzrDirFormat5()
 
205
        self._set_new_format(self.old_format.get_format_string())
 
206
        self.bzrdir = self.old_format.open(self.transport)
 
207
        self.branch = self.bzrdir.open_branch()
204
208
 
205
209
    def _open_branch(self):
206
 
        self.old_format = BzrBranchFormat.find_format(self.transport)
207
 
        self.branch = self.old_format.open(self.transport)
208
 
        if isinstance(self.old_format, BzrBranchFormat6):
 
210
        self.old_format = BzrDirFormat.find_format(self.transport)
 
211
        self.bzrdir = self.old_format.open(self.transport)
 
212
        self.branch = self.bzrdir.open_branch()
 
213
        if isinstance(self.old_format, BzrDirFormat6):
209
214
            note('this branch is in the most current format (%s)', self.old_format)
210
215
            return False
211
 
        if (not isinstance(self.old_format, BzrBranchFormat4) and
212
 
            not isinstance(self.old_format, BzrBranchFormat5)):
213
 
            raise BzrError("cannot upgrade from branch format %s" %
 
216
        if (not isinstance(self.old_format, BzrDirFormat4) and
 
217
            not isinstance(self.old_format, BzrDirFormat5) and
 
218
            not isinstance(self.old_format, bzrdir.BzrDirMetaFormat1)):
 
219
            raise errors.BzrError("cannot upgrade from branch format %s" %
214
220
                           self.branch._branch_format)
215
221
        return True
216
222