~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/weaverepo.py

  • Committer: Andrew Bennetts
  • Date: 2008-10-30 01:05:59 UTC
  • mto: This revision was merged to the branch mainline in revision 3813.
  • Revision ID: andrew.bennetts@canonical.com-20081030010559-tumoefnsmhg4snxo
Add contrib/bzr_ssh_path_limiter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Deprecated weave-based repository formats.
18
18
 
28
28
lazy_import(globals(), """
29
29
from bzrlib import (
30
30
    xml5,
31
 
    graph as _mod_graph,
32
31
    )
33
32
""")
34
33
from bzrlib import (
39
38
    lockdir,
40
39
    osutils,
41
40
    revision as _mod_revision,
42
 
    urlutils,
43
41
    versionedfile,
44
42
    weave,
45
43
    weavefile,
69
67
    def _serializer(self):
70
68
        return xml5.serializer_v5
71
69
 
72
 
    def _escape(self, file_or_path):
73
 
        if not isinstance(file_or_path, basestring):
74
 
            file_or_path = '/'.join(file_or_path)
75
 
        if file_or_path == '':
76
 
            return u''
77
 
        return urlutils.escape(osutils.safe_unicode(file_or_path))
78
 
 
79
70
    def __init__(self, _format, a_bzrdir):
80
71
        # we reuse one control files instance.
81
72
        dir_mode = a_bzrdir._get_dir_mode()
83
74
 
84
75
        def get_store(name, compressed=True, prefixed=False):
85
76
            # FIXME: This approach of assuming stores are all entirely compressed
86
 
            # or entirely uncompressed is tidy, but breaks upgrade from
87
 
            # some existing branches where there's a mixture; we probably
 
77
            # or entirely uncompressed is tidy, but breaks upgrade from 
 
78
            # some existing branches where there's a mixture; we probably 
88
79
            # still want the option to look for both.
89
 
            relpath = self._escape(name)
 
80
            relpath = a_bzrdir._control_files._escape(name)
90
81
            store = TextStore(a_bzrdir.transport.clone(relpath),
91
82
                              prefixed=prefixed, compressed=compressed,
92
83
                              dir_mode=dir_mode,
96
87
        # not broken out yet because the controlweaves|inventory_store
97
88
        # and texts bits are still different.
98
89
        if isinstance(_format, RepositoryFormat4):
99
 
            # cannot remove these - there is still no consistent api
 
90
            # cannot remove these - there is still no consistent api 
100
91
            # which allows access to this old info.
101
92
            self.inventory_store = get_store('inventory-store')
102
93
            self._text_store = get_store('text-store')
103
94
        super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files)
 
95
        self._fetch_order = 'topological'
 
96
        self._fetch_reconcile = True
104
97
 
105
98
    @needs_read_lock
106
99
    def _all_possible_ids(self):
111
104
 
112
105
    @needs_read_lock
113
106
    def _all_revision_ids(self):
114
 
        """Returns a list of all the revision ids in the repository.
 
107
        """Returns a list of all the revision ids in the repository. 
115
108
 
116
 
        These are in as much topological order as the underlying store can
 
109
        These are in as much topological order as the underlying store can 
117
110
        present: for weaves ghosts may lead to a lack of correctness until
118
111
        the reweave updates the parents list.
119
112
        """
191
184
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
192
185
    """A subclass of MetaDirRepository to set weave specific policy."""
193
186
 
 
187
    @property
 
188
    def _serializer(self):
 
189
        return xml5.serializer_v5
 
190
 
194
191
    def __init__(self, _format, a_bzrdir, control_files):
195
192
        super(WeaveMetaDirRepository, self).__init__(_format, a_bzrdir, control_files)
196
 
        self._serializer = _format._serializer
 
193
        self._fetch_order = 'topological'
 
194
        self._fetch_reconcile = True
197
195
 
198
196
    @needs_read_lock
199
197
    def _all_possible_ids(self):
204
202
 
205
203
    @needs_read_lock
206
204
    def _all_revision_ids(self):
207
 
        """Returns a list of all the revision ids in the repository.
 
205
        """Returns a list of all the revision ids in the repository. 
208
206
 
209
 
        These are in as much topological order as the underlying store can
 
207
        These are in as much topological order as the underlying store can 
210
208
        present: for weaves ghosts may lead to a lack of correctness until
211
209
        the reweave updates the parents list.
212
210
        """
267
265
    supports_tree_reference = False
268
266
    supports_ghosts = False
269
267
    supports_external_lookups = False
270
 
    supports_chks = False
271
 
    _fetch_order = 'topological'
272
 
    _fetch_reconcile = True
273
 
    fast_deltas = False
274
268
 
275
269
    def initialize(self, a_bzrdir, shared=False, _internal=False):
276
270
        """Create a weave repository."""
280
274
        if not _internal:
281
275
            # always initialized when the bzrdir is.
282
276
            return self.open(a_bzrdir, _found=True)
283
 
 
 
277
        
284
278
        # Create an empty weave
285
279
        sio = StringIO()
286
280
        weavefile.write_weave_v5(weave.Weave(), sio)
287
281
        empty_weave = sio.getvalue()
288
282
 
289
283
        mutter('creating repository in %s.', a_bzrdir.transport.base)
290
 
 
 
284
        
291
285
        # FIXME: RBC 20060125 don't peek under the covers
292
286
        # NB: no need to escape relative paths that are url safe.
293
287
        control_files = lockable_files.LockableFiles(a_bzrdir.transport,
298
292
        try:
299
293
            transport.mkdir_multi(['revision-store', 'weaves'],
300
294
                mode=a_bzrdir._get_dir_mode())
301
 
            transport.put_bytes_non_atomic('inventory.weave', empty_weave,
302
 
                mode=a_bzrdir._get_file_mode())
 
295
            transport.put_bytes_non_atomic('inventory.weave', empty_weave)
303
296
        finally:
304
297
            control_files.unlock()
305
298
        return self.open(a_bzrdir, _found=True)
317
310
        result.signatures = self._get_signatures(repo_transport, result)
318
311
        result.inventories = self._get_inventories(repo_transport, result)
319
312
        result.texts = self._get_texts(repo_transport, result)
320
 
        result.chk_bytes = None
321
313
        return result
322
314
 
 
315
    def check_conversion_target(self, target_format):
 
316
        pass
 
317
 
323
318
 
324
319
class RepositoryFormat4(PreSplitOutRepositoryFormat):
325
320
    """Bzr repository format 4.
335
330
 
336
331
    _matchingbzrdir = bzrdir.BzrDirFormat4()
337
332
 
 
333
    def __init__(self):
 
334
        super(RepositoryFormat4, self).__init__()
 
335
        self._fetch_order = 'topological'
 
336
        self._fetch_reconcile = True
 
337
 
338
338
    def get_format_description(self):
339
339
        """See RepositoryFormat.get_format_description()."""
340
340
        return "Repository format 4"
347
347
        """Format 4 is not supported.
348
348
 
349
349
        It is not supported because the model changed from 4 to 5 and the
350
 
        conversion logic is expensive - so doing it on the fly was not
 
350
        conversion logic is expensive - so doing it on the fly was not 
351
351
        feasible.
352
352
        """
353
353
        return False
382
382
 
383
383
    _versionedfile_class = weave.WeaveFile
384
384
    _matchingbzrdir = bzrdir.BzrDirFormat5()
385
 
    @property
386
 
    def _serializer(self):
387
 
        return xml5.serializer_v5
 
385
 
 
386
    def __init__(self):
 
387
        super(RepositoryFormat5, self).__init__()
 
388
        self._fetch_order = 'topological'
 
389
        self._fetch_reconcile = True
388
390
 
389
391
    def get_format_description(self):
390
392
        """See RepositoryFormat.get_format_description()."""
391
393
        return "Weave repository format 5"
392
394
 
393
 
    def network_name(self):
394
 
        """The network name for this format is the control dirs disk label."""
395
 
        return self._matchingbzrdir.get_format_string()
396
 
 
397
395
    def _get_inventories(self, repo_transport, repo, name='inventory'):
398
396
        mapper = versionedfile.ConstantMapper(name)
399
397
        return versionedfile.ThunkedVersionedFiles(repo_transport,
400
398
            weave.WeaveFile, mapper, repo.is_locked)
401
399
 
402
400
    def _get_revisions(self, repo_transport, repo):
 
401
        from bzrlib.xml5 import serializer_v5
403
402
        return RevisionTextStore(repo_transport.clone('revision-store'),
404
 
            xml5.serializer_v5, False, versionedfile.PrefixMapper(),
 
403
            serializer_v5, False, versionedfile.PrefixMapper(),
405
404
            repo.is_locked, repo.is_write_locked)
406
405
 
407
406
    def _get_signatures(self, repo_transport, repo):
427
426
 
428
427
    _versionedfile_class = weave.WeaveFile
429
428
    _matchingbzrdir = bzrdir.BzrDirFormat6()
430
 
    @property
431
 
    def _serializer(self):
432
 
        return xml5.serializer_v5
 
429
 
 
430
    def __init__(self):
 
431
        super(RepositoryFormat6, self).__init__()
 
432
        self._fetch_order = 'topological'
 
433
        self._fetch_reconcile = True
433
434
 
434
435
    def get_format_description(self):
435
436
        """See RepositoryFormat.get_format_description()."""
436
437
        return "Weave repository format 6"
437
438
 
438
 
    def network_name(self):
439
 
        """The network name for this format is the control dirs disk label."""
440
 
        return self._matchingbzrdir.get_format_string()
441
 
 
442
439
    def _get_inventories(self, repo_transport, repo, name='inventory'):
443
440
        mapper = versionedfile.ConstantMapper(name)
444
441
        return versionedfile.ThunkedVersionedFiles(repo_transport,
445
442
            weave.WeaveFile, mapper, repo.is_locked)
446
443
 
447
444
    def _get_revisions(self, repo_transport, repo):
 
445
        from bzrlib.xml5 import serializer_v5
448
446
        return RevisionTextStore(repo_transport.clone('revision-store'),
449
 
            xml5.serializer_v5, False, versionedfile.HashPrefixMapper(),
 
447
            serializer_v5, False, versionedfile.HashPrefixMapper(),
450
448
            repo.is_locked, repo.is_write_locked)
451
449
 
452
450
    def _get_signatures(self, repo_transport, repo):
475
473
 
476
474
    _versionedfile_class = weave.WeaveFile
477
475
    supports_ghosts = False
478
 
    supports_chks = False
479
 
 
480
 
    _fetch_order = 'topological'
481
 
    _fetch_reconcile = True
482
 
    fast_deltas = False
483
 
    @property
484
 
    def _serializer(self):
485
 
        return xml5.serializer_v5
486
476
 
487
477
    def get_format_string(self):
488
478
        """See RepositoryFormat.get_format_string()."""
492
482
        """See RepositoryFormat.get_format_description()."""
493
483
        return "Weave repository format 7"
494
484
 
 
485
    def check_conversion_target(self, target_format):
 
486
        pass
 
487
 
495
488
    def _get_inventories(self, repo_transport, repo, name='inventory'):
496
489
        mapper = versionedfile.ConstantMapper(name)
497
490
        return versionedfile.ThunkedVersionedFiles(repo_transport,
498
491
            weave.WeaveFile, mapper, repo.is_locked)
499
492
 
500
493
    def _get_revisions(self, repo_transport, repo):
 
494
        from bzrlib.xml5 import serializer_v5
501
495
        return RevisionTextStore(repo_transport.clone('revision-store'),
502
 
            xml5.serializer_v5, True, versionedfile.HashPrefixMapper(),
 
496
            serializer_v5, True, versionedfile.HashPrefixMapper(),
503
497
            repo.is_locked, repo.is_write_locked)
504
498
 
505
499
    def _get_signatures(self, repo_transport, repo):
526
520
 
527
521
        mutter('creating repository in %s.', a_bzrdir.transport.base)
528
522
        dirs = ['revision-store', 'weaves']
529
 
        files = [('inventory.weave', StringIO(empty_weave)),
 
523
        files = [('inventory.weave', StringIO(empty_weave)), 
530
524
                 ]
531
525
        utf8_files = [('format', self.get_format_string())]
532
 
 
 
526
 
533
527
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
534
528
        return self.open(a_bzrdir=a_bzrdir, _found=True)
535
529
 
536
530
    def open(self, a_bzrdir, _found=False, _override_transport=None):
537
531
        """See RepositoryFormat.open().
538
 
 
 
532
        
539
533
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
540
534
                                    repository at a slightly different url
541
535
                                    than normal. I.e. during 'upgrade'.
554
548
        result.signatures = self._get_signatures(repo_transport, result)
555
549
        result.inventories = self._get_inventories(repo_transport, result)
556
550
        result.texts = self._get_texts(repo_transport, result)
557
 
        result.chk_bytes = None
558
551
        result._transport = repo_transport
559
552
        return result
560
553
 
663
656
                continue
664
657
            result[key] = parents
665
658
        return result
666
 
 
667
 
    def get_known_graph_ancestry(self, keys):
668
 
        """Get a KnownGraph instance with the ancestry of keys."""
669
 
        keys = self.keys()
670
 
        parent_map = self.get_parent_map(keys)
671
 
        kg = _mod_graph.KnownGraph(parent_map)
672
 
        return kg
673
 
 
 
659
    
674
660
    def get_record_stream(self, keys, sort_order, include_delta_closure):
675
661
        for key in keys:
676
662
            text, parents = self._load_text_parents(key)
688
674
            path, ext = os.path.splitext(relpath)
689
675
            if ext == '.gz':
690
676
                relpath = path
691
 
            if not relpath.endswith('.sig'):
 
677
            if '.sig' not in relpath:
692
678
                relpaths.add(relpath)
693
679
        paths = list(relpaths)
694
680
        return set([self._mapper.unmap(path) for path in paths])
710
696
                continue
711
697
            result[key] = None
712
698
        return result
713
 
 
 
699
    
714
700
    def get_record_stream(self, keys, sort_order, include_delta_closure):
715
701
        for key in keys:
716
702
            text = self._load_text(key)