~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Robert Collins
  • Date: 2005-10-09 23:42:12 UTC
  • Revision ID: robertc@robertcollins.net-20051009234212-7973344d900afb0b
merge in niemeyers prefixed-store patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
import logging
86
86
import shutil
87
87
 
88
 
from bzrlib.branch import Branch, find_branch, BZR_BRANCH_FORMAT_5
 
88
from bzrlib.branch import Branch, find_branch
 
89
from bzrlib.branch import BZR_BRANCH_FORMAT_5, BZR_BRANCH_FORMAT_6
89
90
from bzrlib.revfile import Revfile
90
91
from bzrlib.weave import Weave
91
92
from bzrlib.weavefile import read_weave, write_weave
112
113
            return
113
114
        note('starting upgrade of %s', os.path.abspath(self.base))
114
115
        self._backup_control_dir()
115
 
        note('starting upgrade')
 
116
        self.pb = ui_factory.progress_bar()
 
117
        if self.old_format == 4:
 
118
            note('starting upgrade from format 4 to 5')
 
119
            self._convert_to_weaves()
 
120
            self._open_branch()
 
121
        if self.old_format == 5:
 
122
            note('starting upgrade from format 5 to 6')
 
123
            self._convert_to_prefixed()
 
124
            self._open_branch()
 
125
        note("finished")
 
126
 
 
127
 
 
128
    def _convert_to_prefixed(self):
 
129
        from bzrlib.store import hash_prefix
 
130
        for store_name in ["weaves", "revision-store"]:
 
131
            note("adding prefixes to %s" % store_name) 
 
132
            store_dir = os.path.join(self.base, ".bzr", store_name)
 
133
            for filename in os.listdir(store_dir):
 
134
                if filename.endswith(".weave") or filename.endswith(".gz"):
 
135
                    file_id = os.path.splitext(filename)[0]
 
136
                else:
 
137
                    file_id = filename
 
138
                prefix_dir = os.path.join(store_dir, hash_prefix(file_id))
 
139
                if not os.path.isdir(prefix_dir):
 
140
                    os.mkdir(prefix_dir)
 
141
                os.rename(os.path.join(store_dir, filename),
 
142
                          os.path.join(prefix_dir, filename))
 
143
        self._set_new_format(BZR_BRANCH_FORMAT_6)
 
144
 
 
145
 
 
146
    def _convert_to_weaves(self):
116
147
        note('note: upgrade may be faster if all store files are ungzipped first')
117
 
        self.pb = ui_factory.progress_bar()
118
148
        if not os.path.isdir(self.base + '/.bzr/weaves'):
119
149
            os.mkdir(self.base + '/.bzr/weaves')
120
150
        self.inv_weave = Weave('inventory')
144
174
        note('  %6d texts' % self.text_count)
145
175
        self._write_all_weaves()
146
176
        self._write_all_revs()
147
 
        self._set_new_format()
148
177
        self._cleanup_spare_files()
 
178
        self._set_new_format(BZR_BRANCH_FORMAT_5)
149
179
 
150
180
 
151
181
    def _open_branch(self):
152
182
        self.branch = Branch.open_downlevel(self.base)
153
 
        if self.branch._branch_format == 5:
154
 
            note('this branch is already in the most current format')
 
183
        self.old_format = self.branch._branch_format
 
184
        if self.old_format == 6:
 
185
            note('this branch is in the most current format')
155
186
            return False
156
 
        if self.branch._branch_format != 4:
 
187
        if self.old_format not in (4, 5):
157
188
            raise BzrError("cannot upgrade from branch format %r" %
158
189
                           self.branch._branch_format)
159
190
        return True
160
191
 
161
192
 
162
 
    def _set_new_format(self):
163
 
        self.branch.put_controlfile('branch-format', BZR_BRANCH_FORMAT_5)
 
193
    def _set_new_format(self, format):
 
194
        self.branch.put_controlfile('branch-format', format)
164
195
 
165
196
 
166
197
    def _cleanup_spare_files(self):