/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
2241.1.15 by Martin Pool
doc
18
"""Old weave-based repository formats"""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
19
20
from StringIO import StringIO
21
22
from bzrlib import (
23
    bzrdir,
24
    lockable_files,
25
    lockdir,
26
    weave,
27
    weavefile,
2241.1.8 by Martin Pool
Set the repository's serializer in the places it's needed, not in the base class
28
    xml5,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
29
    )
30
from bzrlib.decorators import needs_read_lock, needs_write_lock
31
from bzrlib.repository import (
32
    MetaDirRepository,
33
    MetaDirRepositoryFormat,
34
    Repository,
35
    RepositoryFormat,
36
    )
37
from bzrlib.store.text import TextStore
38
from bzrlib.trace import mutter
39
40
41
class AllInOneRepository(Repository):
42
    """Legacy support - the repository behaviour for all-in-one branches."""
43
2241.1.8 by Martin Pool
Set the repository's serializer in the places it's needed, not in the base class
44
    _serializer = xml5.serializer_v5
45
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
46
    def __init__(self, _format, a_bzrdir, _revision_store, control_store, text_store):
47
        # we reuse one control files instance.
48
        dir_mode = a_bzrdir._control_files._dir_mode
49
        file_mode = a_bzrdir._control_files._file_mode
50
51
        def get_store(name, compressed=True, prefixed=False):
52
            # FIXME: This approach of assuming stores are all entirely compressed
53
            # or entirely uncompressed is tidy, but breaks upgrade from 
54
            # some existing branches where there's a mixture; we probably 
55
            # still want the option to look for both.
56
            relpath = a_bzrdir._control_files._escape(name)
57
            store = TextStore(a_bzrdir._control_files._transport.clone(relpath),
58
                              prefixed=prefixed, compressed=compressed,
59
                              dir_mode=dir_mode,
60
                              file_mode=file_mode)
61
            return store
62
63
        # not broken out yet because the controlweaves|inventory_store
64
        # and text_store | weave_store bits are still different.
65
        if isinstance(_format, RepositoryFormat4):
66
            # cannot remove these - there is still no consistent api 
67
            # which allows access to this old info.
68
            self.inventory_store = get_store('inventory-store')
69
            text_store = get_store('text-store')
70
        super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store)
71
72
    def get_commit_builder(self, branch, parents, config, timestamp=None,
73
                           timezone=None, committer=None, revprops=None,
74
                           revision_id=None):
75
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
76
        return Repository.get_commit_builder(self, branch, parents, config,
77
            timestamp, timezone, committer, revprops, revision_id)
78
79
    @needs_read_lock
80
    def is_shared(self):
81
        """AllInOne repositories cannot be shared."""
82
        return False
83
84
    @needs_write_lock
85
    def set_make_working_trees(self, new_value):
86
        """Set the policy flag for making working trees when creating branches.
87
88
        This only applies to branches that use this repository.
89
90
        The default is 'True'.
91
        :param new_value: True to restore the default, False to disable making
92
                          working trees.
93
        """
94
        raise NotImplementedError(self.set_make_working_trees)
95
    
96
    def make_working_trees(self):
97
        """Returns the policy for making working trees on new branches."""
98
        return True
99
100
101
class WeaveMetaDirRepository(MetaDirRepository):
102
    """A subclass of MetaDirRepository to set weave specific policy."""
103
2241.1.8 by Martin Pool
Set the repository's serializer in the places it's needed, not in the base class
104
    _serializer = xml5.serializer_v5
105
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
106
    def get_commit_builder(self, branch, parents, config, timestamp=None,
107
                           timezone=None, committer=None, revprops=None,
108
                           revision_id=None):
109
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
110
        return MetaDirRepository.get_commit_builder(self, branch, parents,
111
            config, timestamp, timezone, committer, revprops, revision_id)
112
113
114
class PreSplitOutRepositoryFormat(RepositoryFormat):
115
    """Base class for the pre split out repository formats."""
116
117
    rich_root_data = False
2323.5.17 by Martin Pool
Add supports_tree_reference to all repo formats (robert)
118
    supports_tree_reference = False
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
119
120
    def initialize(self, a_bzrdir, shared=False, _internal=False):
121
        """Create a weave repository.
122
        
123
        TODO: when creating split out bzr branch formats, move this to a common
124
        base for Format5, Format6. or something like that.
125
        """
126
        if shared:
127
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
128
129
        if not _internal:
130
            # always initialized when the bzrdir is.
131
            return self.open(a_bzrdir, _found=True)
132
        
133
        # Create an empty weave
134
        sio = StringIO()
135
        weavefile.write_weave_v5(weave.Weave(), sio)
136
        empty_weave = sio.getvalue()
137
138
        mutter('creating repository in %s.', a_bzrdir.transport.base)
139
        dirs = ['revision-store', 'weaves']
140
        files = [('inventory.weave', StringIO(empty_weave)),
141
                 ]
142
        
143
        # FIXME: RBC 20060125 don't peek under the covers
144
        # NB: no need to escape relative paths that are url safe.
145
        control_files = lockable_files.LockableFiles(a_bzrdir.transport,
146
                                'branch-lock', lockable_files.TransportLock)
147
        control_files.create_lock()
148
        control_files.lock_write()
149
        control_files._transport.mkdir_multi(dirs,
150
                mode=control_files._dir_mode)
151
        try:
152
            for file, content in files:
153
                control_files.put(file, content)
154
        finally:
155
            control_files.unlock()
156
        return self.open(a_bzrdir, _found=True)
157
158
    def _get_control_store(self, repo_transport, control_files):
159
        """Return the control store for this repository."""
160
        return self._get_versioned_file_store('',
161
                                              repo_transport,
162
                                              control_files,
163
                                              prefixed=False)
164
165
    def _get_text_store(self, transport, control_files):
166
        """Get a store for file texts for this format."""
167
        raise NotImplementedError(self._get_text_store)
168
169
    def open(self, a_bzrdir, _found=False):
170
        """See RepositoryFormat.open()."""
171
        if not _found:
172
            # we are being called directly and must probe.
173
            raise NotImplementedError
174
175
        repo_transport = a_bzrdir.get_repository_transport(None)
176
        control_files = a_bzrdir._control_files
177
        text_store = self._get_text_store(repo_transport, control_files)
178
        control_store = self._get_control_store(repo_transport, control_files)
179
        _revision_store = self._get_revision_store(repo_transport, control_files)
180
        return AllInOneRepository(_format=self,
181
                                  a_bzrdir=a_bzrdir,
182
                                  _revision_store=_revision_store,
183
                                  control_store=control_store,
184
                                  text_store=text_store)
185
186
    def check_conversion_target(self, target_format):
187
        pass
188
189
190
class RepositoryFormat4(PreSplitOutRepositoryFormat):
191
    """Bzr repository format 4.
192
193
    This repository format has:
194
     - flat stores
195
     - TextStores for texts, inventories,revisions.
196
197
    This format is deprecated: it indexes texts using a text id which is
198
    removed in format 5; initialization and write support for this format
199
    has been removed.
200
    """
201
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
202
    _matchingbzrdir = bzrdir.BzrDirFormat4()
203
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
204
    def __init__(self):
205
        super(RepositoryFormat4, self).__init__()
206
207
    def get_format_description(self):
208
        """See RepositoryFormat.get_format_description()."""
209
        return "Repository format 4"
210
211
    def initialize(self, url, shared=False, _internal=False):
212
        """Format 4 branches cannot be created."""
213
        raise errors.UninitializableFormat(self)
214
215
    def is_supported(self):
216
        """Format 4 is not supported.
217
218
        It is not supported because the model changed from 4 to 5 and the
219
        conversion logic is expensive - so doing it on the fly was not 
220
        feasible.
221
        """
222
        return False
223
224
    def _get_control_store(self, repo_transport, control_files):
225
        """Format 4 repositories have no formal control store at this point.
226
        
227
        This will cause any control-file-needing apis to fail - this is desired.
228
        """
229
        return None
230
    
231
    def _get_revision_store(self, repo_transport, control_files):
232
        """See RepositoryFormat._get_revision_store()."""
233
        from bzrlib.xml4 import serializer_v4
234
        return self._get_text_rev_store(repo_transport,
235
                                        control_files,
236
                                        'revision-store',
237
                                        serializer=serializer_v4)
238
239
    def _get_text_store(self, transport, control_files):
240
        """See RepositoryFormat._get_text_store()."""
241
242
243
class RepositoryFormat5(PreSplitOutRepositoryFormat):
244
    """Bzr control format 5.
245
246
    This repository format has:
247
     - weaves for file texts and inventory
248
     - flat stores
249
     - TextStores for revisions and signatures.
250
    """
251
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
252
    _versionedfile_class = weave.WeaveFile
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
253
    _matchingbzrdir = bzrdir.BzrDirFormat5()
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
254
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
255
    def __init__(self):
256
        super(RepositoryFormat5, self).__init__()
257
258
    def get_format_description(self):
259
        """See RepositoryFormat.get_format_description()."""
260
        return "Weave repository format 5"
261
262
    def _get_revision_store(self, repo_transport, control_files):
263
        """See RepositoryFormat._get_revision_store()."""
264
        """Return the revision store object for this a_bzrdir."""
265
        return self._get_text_rev_store(repo_transport,
266
                                        control_files,
267
                                        'revision-store',
268
                                        compressed=False)
269
270
    def _get_text_store(self, transport, control_files):
271
        """See RepositoryFormat._get_text_store()."""
272
        return self._get_versioned_file_store('weaves', transport, control_files, prefixed=False)
273
274
275
class RepositoryFormat6(PreSplitOutRepositoryFormat):
276
    """Bzr control format 6.
277
278
    This repository format has:
279
     - weaves for file texts and inventory
280
     - hash subdirectory based stores.
281
     - TextStores for revisions and signatures.
282
    """
283
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
284
    _versionedfile_class = weave.WeaveFile
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
285
    _matchingbzrdir = bzrdir.BzrDirFormat6()
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
286
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
287
    def __init__(self):
288
        super(RepositoryFormat6, self).__init__()
289
290
    def get_format_description(self):
291
        """See RepositoryFormat.get_format_description()."""
292
        return "Weave repository format 6"
293
294
    def _get_revision_store(self, repo_transport, control_files):
295
        """See RepositoryFormat._get_revision_store()."""
296
        return self._get_text_rev_store(repo_transport,
297
                                        control_files,
298
                                        'revision-store',
299
                                        compressed=False,
300
                                        prefixed=True)
301
302
    def _get_text_store(self, transport, control_files):
303
        """See RepositoryFormat._get_text_store()."""
304
        return self._get_versioned_file_store('weaves', transport, control_files)
305
306
307
class RepositoryFormat7(MetaDirRepositoryFormat):
308
    """Bzr repository 7.
309
310
    This repository format has:
311
     - weaves for file texts and inventory
312
     - hash subdirectory based stores.
313
     - TextStores for revisions and signatures.
314
     - a format marker of its own
315
     - an optional 'shared-storage' flag
316
     - an optional 'no-working-trees' flag
317
    """
318
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
319
    _versionedfile_class = weave.WeaveFile
320
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
321
    def _get_control_store(self, repo_transport, control_files):
322
        """Return the control store for this repository."""
323
        return self._get_versioned_file_store('',
324
                                              repo_transport,
325
                                              control_files,
326
                                              prefixed=False)
327
328
    def get_format_string(self):
329
        """See RepositoryFormat.get_format_string()."""
330
        return "Bazaar-NG Repository format 7"
331
332
    def get_format_description(self):
333
        """See RepositoryFormat.get_format_description()."""
334
        return "Weave repository format 7"
335
336
    def check_conversion_target(self, target_format):
337
        pass
338
339
    def _get_revision_store(self, repo_transport, control_files):
340
        """See RepositoryFormat._get_revision_store()."""
341
        return self._get_text_rev_store(repo_transport,
342
                                        control_files,
343
                                        'revision-store',
344
                                        compressed=False,
345
                                        prefixed=True,
346
                                        )
347
348
    def _get_text_store(self, transport, control_files):
349
        """See RepositoryFormat._get_text_store()."""
350
        return self._get_versioned_file_store('weaves',
351
                                              transport,
352
                                              control_files)
353
354
    def initialize(self, a_bzrdir, shared=False):
355
        """Create a weave repository.
356
357
        :param shared: If true the repository will be initialized as a shared
358
                       repository.
359
        """
360
        # Create an empty weave
361
        sio = StringIO()
362
        weavefile.write_weave_v5(weave.Weave(), sio)
363
        empty_weave = sio.getvalue()
364
365
        mutter('creating repository in %s.', a_bzrdir.transport.base)
366
        dirs = ['revision-store', 'weaves']
367
        files = [('inventory.weave', StringIO(empty_weave)), 
368
                 ]
369
        utf8_files = [('format', self.get_format_string())]
370
 
371
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
372
        return self.open(a_bzrdir=a_bzrdir, _found=True)
373
374
    def open(self, a_bzrdir, _found=False, _override_transport=None):
375
        """See RepositoryFormat.open().
376
        
377
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
378
                                    repository at a slightly different url
379
                                    than normal. I.e. during 'upgrade'.
380
        """
381
        if not _found:
382
            format = RepositoryFormat.find_format(a_bzrdir)
383
            assert format.__class__ ==  self.__class__
384
        if _override_transport is not None:
385
            repo_transport = _override_transport
386
        else:
387
            repo_transport = a_bzrdir.get_repository_transport(None)
388
        control_files = lockable_files.LockableFiles(repo_transport,
389
                                'lock', lockdir.LockDir)
390
        text_store = self._get_text_store(repo_transport, control_files)
391
        control_store = self._get_control_store(repo_transport, control_files)
392
        _revision_store = self._get_revision_store(repo_transport, control_files)
393
        return WeaveMetaDirRepository(_format=self,
394
            a_bzrdir=a_bzrdir,
395
            control_files=control_files,
396
            _revision_store=_revision_store,
397
            control_store=control_store,
398
            text_store=text_store)
399
400
401
_legacy_formats = [RepositoryFormat4(),
402
                   RepositoryFormat5(),
403
                   RepositoryFormat6()]