/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4597.9.8 by Vincent Ladeuil
Merge bzr.dev into cleanup
1
# Copyright (C) 2007-2010 Canonical Ltd
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
16
2592.3.24 by Robert Collins
Knit1 disk layout specified.
17
from bzrlib.lazy_import import lazy_import
18
lazy_import(globals(), """
19
from bzrlib import (
2100.3.31 by Aaron Bentley
Merged bzr.dev (17 tests failing)
20
    bzrdir,
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
21
    errors,
3224.5.26 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
22
    knit as _mod_knit,
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
23
    lockable_files,
24
    lockdir,
2249.5.16 by John Arbash Meinel
[merge] bzr.dev 2283
25
    osutils,
3224.5.26 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
26
    revision as _mod_revision,
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
27
    trace,
3224.5.26 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
28
    transactions,
29
    versionedfile,
30
    xml5,
31
    xml6,
32
    xml7,
33
    )
34
""")
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
35
from bzrlib.decorators import needs_read_lock, needs_write_lock
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
36
from bzrlib.repository import (
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
37
    InterRepository,
5199.1.1 by Andrew Bennetts
Allow repositories to support refresh_data during a write group.
38
    IsInWriteGroupError,
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
39
    RepositoryFormat,
40
    )
5815.4.1 by Jelmer Vernooij
Split versionedfile-specific stuff out into VersionedFileRepository.
41
from bzrlib.vf_repository import (
5815.4.19 by Jelmer Vernooij
Fix test failures.
42
    InterSameDataRepository,
5815.4.1 by Jelmer Vernooij
Split versionedfile-specific stuff out into VersionedFileRepository.
43
    MetaDirVersionedFileRepository,
5815.4.5 by Jelmer Vernooij
Use MetaDirVersionedFileRepositoryFormat (a Soyuz worthy name).
44
    MetaDirVersionedFileRepositoryFormat,
5815.4.2 by Jelmer Vernooij
split out versionedfile-specific stuff from commitbuilder.
45
    VersionedFileCommitBuilder,
46
    VersionedFileRootCommitBuilder,
5815.4.1 by Jelmer Vernooij
Split versionedfile-specific stuff out into VersionedFileRepository.
47
    )
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
48
from bzrlib import symbol_versioning
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
49
50
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
51
class _KnitParentsProvider(object):
52
53
    def __init__(self, knit):
54
        self._knit = knit
55
2490.2.28 by Aaron Bentley
Fix handling of null revision
56
    def __repr__(self):
57
        return 'KnitParentsProvider(%r)' % self._knit
58
3099.3.1 by John Arbash Meinel
Implement get_parent_map for ParentProviders
59
    def get_parent_map(self, keys):
4379.3.3 by Gary van der Merwe
Rename and add doc string for StackedParentsProvider.
60
        """See graph.StackedParentsProvider.get_parent_map"""
3099.3.1 by John Arbash Meinel
Implement get_parent_map for ParentProviders
61
        parent_map = {}
62
        for revision_id in keys:
3373.5.2 by John Arbash Meinel
Add repository_implementation tests for get_parent_map
63
            if revision_id is None:
64
                raise ValueError('get_parent_map(None) is not valid')
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
65
            if revision_id == _mod_revision.NULL_REVISION:
3146.1.2 by Aaron Bentley
ParentsProviders now provide tuples of parents, never lists
66
                parent_map[revision_id] = ()
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
67
            else:
68
                try:
3146.1.2 by Aaron Bentley
ParentsProviders now provide tuples of parents, never lists
69
                    parents = tuple(
70
                        self._knit.get_parents_with_ghosts(revision_id))
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
71
                except errors.RevisionNotPresent:
3146.1.1 by Aaron Bentley
Fix bad ghost handling in KnitParentsProvider
72
                    continue
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
73
                else:
74
                    if len(parents) == 0:
3146.1.2 by Aaron Bentley
ParentsProviders now provide tuples of parents, never lists
75
                        parents = (_mod_revision.NULL_REVISION,)
3099.3.1 by John Arbash Meinel
Implement get_parent_map for ParentProviders
76
                parent_map[revision_id] = parents
77
        return parent_map
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
78
79
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
80
class _KnitsParentsProvider(object):
81
82
    def __init__(self, knit, prefix=()):
83
        """Create a parent provider for string keys mapped to tuple keys."""
84
        self._knit = knit
85
        self._prefix = prefix
86
87
    def __repr__(self):
88
        return 'KnitsParentsProvider(%r)' % self._knit
89
90
    def get_parent_map(self, keys):
4379.3.3 by Gary van der Merwe
Rename and add doc string for StackedParentsProvider.
91
        """See graph.StackedParentsProvider.get_parent_map"""
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
92
        parent_map = self._knit.get_parent_map(
93
            [self._prefix + (key,) for key in keys])
94
        result = {}
95
        for key, parents in parent_map.items():
96
            revid = key[-1]
97
            if len(parents) == 0:
98
                parents = (_mod_revision.NULL_REVISION,)
99
            else:
100
                parents = tuple(parent[-1] for parent in parents)
101
            result[revid] = parents
102
        for revision_id in keys:
103
            if revision_id == _mod_revision.NULL_REVISION:
104
                result[revision_id] = ()
105
        return result
106
107
5815.4.1 by Jelmer Vernooij
Split versionedfile-specific stuff out into VersionedFileRepository.
108
class KnitRepository(MetaDirVersionedFileRepository):
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
109
    """Knit format repository."""
110
2889.1.2 by Robert Collins
Review feedback.
111
    # These attributes are inherited from the Repository base class. Setting
112
    # them to None ensures that if the constructor is changed to not initialize
113
    # them, or a subclass fails to call the constructor, that an error will
114
    # occur rather than the system working but generating incorrect data.
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
115
    _commit_builder_class = None
116
    _serializer = None
117
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
118
    def __init__(self, _format, a_bzrdir, control_files, _commit_builder_class,
119
        _serializer):
5815.4.1 by Jelmer Vernooij
Split versionedfile-specific stuff out into VersionedFileRepository.
120
        super(KnitRepository, self).__init__(_format, a_bzrdir, control_files)
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
121
        self._commit_builder_class = _commit_builder_class
122
        self._serializer = _serializer
2745.6.16 by Aaron Bentley
Update from review
123
        self._reconcile_fixes_text_parents = True
3830.3.6 by Martin Pool
Document _fetch_uses_delta and make it a class attribute
124
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
125
    @needs_read_lock
126
    def _all_revision_ids(self):
127
        """See Repository.all_revision_ids()."""
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
128
        return [key[0] for key in self.revisions.keys()]
129
130
    def _activate_new_inventory(self):
131
        """Put a replacement inventory.new into use as inventories."""
132
        # Copy the content across
133
        t = self._transport
134
        t.copy('inventory.new.kndx', 'inventory.kndx')
135
        try:
136
            t.copy('inventory.new.knit', 'inventory.knit')
137
        except errors.NoSuchFile:
138
            # empty inventories knit
139
            t.delete('inventory.knit')
140
        # delete the temp inventory
141
        t.delete('inventory.new.kndx')
142
        try:
143
            t.delete('inventory.new.knit')
144
        except errors.NoSuchFile:
145
            # empty inventories knit
146
            pass
147
        # Force index reload (sanity check)
148
        self.inventories._index._reset_cache()
149
        self.inventories.keys()
150
151
    def _backup_inventory(self):
152
        t = self._transport
153
        t.copy('inventory.kndx', 'inventory.backup.kndx')
154
        t.copy('inventory.knit', 'inventory.backup.knit')
155
156
    def _move_file_id(self, from_id, to_id):
157
        t = self._transport.clone('knits')
158
        from_rel_url = self.texts._index._mapper.map((from_id, None))
159
        to_rel_url = self.texts._index._mapper.map((to_id, None))
160
        # We expect both files to always exist in this case.
161
        for suffix in ('.knit', '.kndx'):
162
            t.rename(from_rel_url + suffix, to_rel_url + suffix)
163
164
    def _remove_file_id(self, file_id):
165
        t = self._transport.clone('knits')
166
        rel_url = self.texts._index._mapper.map((file_id, None))
167
        for suffix in ('.kndx', '.knit'):
168
            try:
169
                t.delete(rel_url + suffix)
170
            except errors.NoSuchFile:
171
                pass
172
173
    def _temp_inventories(self):
174
        result = self._format._get_inventories(self._transport, self,
175
            'inventory.new')
176
        # Reconciling when the output has no revisions would result in no
177
        # writes - but we want to ensure there is an inventory for
178
        # compatibility with older clients that don't lazy-load.
179
        result.get_parent_map([('A',)])
180
        return result
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
181
182
    def fileid_involved_between_revs(self, from_revid, to_revid):
183
        """Find file_id(s) which are involved in the changes between revisions.
184
185
        This determines the set of revisions which are involved, and then
186
        finds all file ids affected by those revisions.
187
        """
188
        vf = self._get_revision_vf()
189
        from_set = set(vf.get_ancestry(from_revid))
190
        to_set = set(vf.get_ancestry(to_revid))
191
        changed = to_set.difference(from_set)
192
        return self._fileid_involved_by_set(changed)
193
194
    def fileid_involved(self, last_revid=None):
195
        """Find all file_ids modified in the ancestry of last_revid.
196
197
        :param last_revid: If None, last_revision() will be used.
198
        """
199
        if not last_revid:
200
            changed = set(self.all_revision_ids())
201
        else:
202
            changed = set(self.get_ancestry(last_revid))
203
        if None in changed:
204
            changed.remove(None)
205
        return self._fileid_involved_by_set(changed)
206
207
    @needs_read_lock
208
    def get_revision(self, revision_id):
209
        """Return the Revision object for a named revision"""
2249.5.16 by John Arbash Meinel
[merge] bzr.dev 2283
210
        revision_id = osutils.safe_revision_id(revision_id)
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
211
        return self.get_revision_reconcile(revision_id)
212
4145.1.2 by Robert Collins
Add a refresh_data method on Repository allowing cleaner handling of insertions into RemoteRepository objects with _real_repository instances.
213
    def _refresh_data(self):
214
        if not self.is_locked():
215
            return
5199.1.1 by Andrew Bennetts
Allow repositories to support refresh_data during a write group.
216
        if self.is_in_write_group():
217
            raise IsInWriteGroupError(self)
4145.1.2 by Robert Collins
Add a refresh_data method on Repository allowing cleaner handling of insertions into RemoteRepository objects with _real_repository instances.
218
        # Create a new transaction to force all knits to see the scope change.
219
        # This is safe because we're outside a write group.
220
        self.control_files._finish_transaction()
221
        if self.is_write_locked():
222
            self.control_files._set_write_transaction()
223
        else:
224
            self.control_files._set_read_transaction()
225
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
226
    @needs_write_lock
227
    def reconcile(self, other=None, thorough=False):
228
        """Reconcile this repository."""
229
        from bzrlib.reconcile import KnitReconciler
230
        reconciler = KnitReconciler(self, thorough=thorough)
231
        reconciler.reconcile()
232
        return reconciler
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
233
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
234
    def _make_parents_provider(self):
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
235
        return _KnitsParentsProvider(self.revisions)
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
236
2241.1.5 by Martin Pool
Move KnitFormat2 into repofmt
237
5815.4.5 by Jelmer Vernooij
Use MetaDirVersionedFileRepositoryFormat (a Soyuz worthy name).
238
class RepositoryFormatKnit(MetaDirVersionedFileRepositoryFormat):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
239
    """Bzr repository knit format (generalized).
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
240
241
    This repository format has:
242
     - knits for file texts and inventory
243
     - hash subdirectory based stores.
244
     - knits for revisions and signatures
245
     - TextStores for revisions and signatures.
246
     - a format marker of its own
247
     - an optional 'shared-storage' flag
248
     - an optional 'no-working-trees' flag
249
     - a LockDir lock
250
    """
251
2857.2.2 by Robert Collins
Review feedback.
252
    # Set this attribute in derived classes to control the repository class
253
    # created by open and initialize.
254
    repository_class = None
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
255
    # Set this attribute in derived classes to control the
256
    # _commit_builder_class that the repository objects will have passed to
257
    # their constructor.
258
    _commit_builder_class = None
259
    # Set this attribute in derived clases to control the _serializer that the
260
    # repository objects will have passed to their constructor.
3224.5.1 by Andrew Bennetts
Lots of assorted hackery to reduce the number of imports for common operations. Improves 'rocks', 'st' and 'help' times by ~50ms on my laptop.
261
    @property
262
    def _serializer(self):
263
        return xml5.serializer_v5
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
264
    # Knit based repositories handle ghosts reasonably well.
265
    supports_ghosts = True
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
266
    # External lookups are not supported in this format.
267
    supports_external_lookups = False
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
268
    # No CHK support.
269
    supports_chks = False
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
270
    _fetch_order = 'topological'
271
    _fetch_uses_deltas = True
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
272
    fast_deltas = False
5684.2.1 by Jelmer Vernooij
Add bzrlib.tests.per_repository_vf.
273
    supports_funky_characters = True
5766.1.1 by Jelmer Vernooij
Make revision-graph-can-have-wrong-parents a repository format attribute rather than a repository method.
274
    # The revision.kndx could potentially claim a revision has a different
275
    # parent to the revision text.
276
    revision_graph_can_have_wrong_parents = True
2857.2.2 by Robert Collins
Review feedback.
277
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
278
    def _get_inventories(self, repo_transport, repo, name='inventory'):
3224.5.26 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
279
        mapper = versionedfile.ConstantMapper(name)
280
        index = _mod_knit._KndxIndex(repo_transport, mapper,
281
            repo.get_transaction, repo.is_write_locked, repo.is_locked)
282
        access = _mod_knit._KnitKeyAccess(repo_transport, mapper)
283
        return _mod_knit.KnitVersionedFiles(index, access, annotated=False)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
284
285
    def _get_revisions(self, repo_transport, repo):
3224.5.26 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
286
        mapper = versionedfile.ConstantMapper('revisions')
287
        index = _mod_knit._KndxIndex(repo_transport, mapper,
288
            repo.get_transaction, repo.is_write_locked, repo.is_locked)
289
        access = _mod_knit._KnitKeyAccess(repo_transport, mapper)
290
        return _mod_knit.KnitVersionedFiles(index, access, max_delta_chain=0,
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
291
            annotated=False)
292
293
    def _get_signatures(self, repo_transport, repo):
3224.5.26 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
294
        mapper = versionedfile.ConstantMapper('signatures')
295
        index = _mod_knit._KndxIndex(repo_transport, mapper,
296
            repo.get_transaction, repo.is_write_locked, repo.is_locked)
297
        access = _mod_knit._KnitKeyAccess(repo_transport, mapper)
298
        return _mod_knit.KnitVersionedFiles(index, access, max_delta_chain=0,
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
299
            annotated=False)
300
301
    def _get_texts(self, repo_transport, repo):
3224.5.26 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
302
        mapper = versionedfile.HashEscapedPrefixMapper()
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
303
        base_transport = repo_transport.clone('knits')
3224.5.26 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
304
        index = _mod_knit._KndxIndex(base_transport, mapper,
305
            repo.get_transaction, repo.is_write_locked, repo.is_locked)
306
        access = _mod_knit._KnitKeyAccess(base_transport, mapper)
307
        return _mod_knit.KnitVersionedFiles(index, access, max_delta_chain=200,
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
308
            annotated=True)
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
309
310
    def initialize(self, a_bzrdir, shared=False):
311
        """Create a knit format 1 repository.
312
313
        :param a_bzrdir: bzrdir to contain the new repository; must already
314
            be initialized.
315
        :param shared: If true the repository will be initialized as a shared
316
                       repository.
317
        """
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
318
        trace.mutter('creating repository in %s.', a_bzrdir.transport.base)
2592.3.60 by Robert Collins
Nuke per-fileid indices for a single unified index.
319
        dirs = ['knits']
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
320
        files = []
321
        utf8_files = [('format', self.get_format_string())]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
322
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
323
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
324
        repo_transport = a_bzrdir.get_repository_transport(None)
325
        control_files = lockable_files.LockableFiles(repo_transport,
326
                                'lock', lockdir.LockDir)
327
        transaction = transactions.WriteTransaction()
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
328
        result = self.open(a_bzrdir=a_bzrdir, _found=True)
329
        result.lock_write()
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
330
        # the revision id here is irrelevant: it will not be stored, and cannot
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
331
        # already exist, we do this to create files on disk for older clients.
332
        result.inventories.get_parent_map([('A',)])
333
        result.revisions.get_parent_map([('A',)])
334
        result.signatures.get_parent_map([('A',)])
335
        result.unlock()
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
336
        self._run_post_repo_init_hooks(result, a_bzrdir, shared)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
337
        return result
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
338
339
    def open(self, a_bzrdir, _found=False, _override_transport=None):
340
        """See RepositoryFormat.open().
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
341
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
342
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
343
                                    repository at a slightly different url
344
                                    than normal. I.e. during 'upgrade'.
345
        """
346
        if not _found:
347
            format = RepositoryFormat.find_format(a_bzrdir)
348
        if _override_transport is not None:
349
            repo_transport = _override_transport
350
        else:
351
            repo_transport = a_bzrdir.get_repository_transport(None)
352
        control_files = lockable_files.LockableFiles(repo_transport,
353
                                'lock', lockdir.LockDir)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
354
        repo = self.repository_class(_format=self,
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
355
                              a_bzrdir=a_bzrdir,
356
                              control_files=control_files,
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
357
                              _commit_builder_class=self._commit_builder_class,
358
                              _serializer=self._serializer)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
359
        repo.revisions = self._get_revisions(repo_transport, repo)
360
        repo.signatures = self._get_signatures(repo_transport, repo)
361
        repo.inventories = self._get_inventories(repo_transport, repo)
362
        repo.texts = self._get_texts(repo_transport, repo)
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
363
        repo.chk_bytes = None
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
364
        repo._transport = repo_transport
365
        return repo
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
366
367
368
class RepositoryFormatKnit1(RepositoryFormatKnit):
369
    """Bzr repository knit format 1.
370
371
    This repository format has:
372
     - knits for file texts and inventory
373
     - hash subdirectory based stores.
374
     - knits for revisions and signatures
375
     - TextStores for revisions and signatures.
376
     - a format marker of its own
377
     - an optional 'shared-storage' flag
378
     - an optional 'no-working-trees' flag
379
     - a LockDir lock
380
381
    This format was introduced in bzr 0.8.
382
    """
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
383
2592.3.22 by Robert Collins
Add new experimental repository formats.
384
    repository_class = KnitRepository
5815.4.2 by Jelmer Vernooij
split out versionedfile-specific stuff from commitbuilder.
385
    _commit_builder_class = VersionedFileCommitBuilder
3224.5.1 by Andrew Bennetts
Lots of assorted hackery to reduce the number of imports for common operations. Improves 'rocks', 'st' and 'help' times by ~50ms on my laptop.
386
    @property
387
    def _serializer(self):
388
        return xml5.serializer_v5
2592.3.22 by Robert Collins
Add new experimental repository formats.
389
2100.3.35 by Aaron Bentley
equality operations on bzrdir
390
    def __ne__(self, other):
2100.3.31 by Aaron Bentley
Merged bzr.dev (17 tests failing)
391
        return self.__class__ is not other.__class__
392
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
393
    def get_format_string(self):
394
        """See RepositoryFormat.get_format_string()."""
395
        return "Bazaar-NG Knit Repository Format 1"
396
397
    def get_format_description(self):
398
        """See RepositoryFormat.get_format_description()."""
399
        return "Knit repository format 1"
400
401
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
402
class RepositoryFormatKnit3(RepositoryFormatKnit):
2996.2.5 by Aaron Bentley
Correct docstring
403
    """Bzr repository knit format 3.
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
404
2100.3.31 by Aaron Bentley
Merged bzr.dev (17 tests failing)
405
    This repository format has:
406
     - knits for file texts and inventory
407
     - hash subdirectory based stores.
408
     - knits for revisions and signatures
409
     - TextStores for revisions and signatures.
410
     - a format marker of its own
411
     - an optional 'shared-storage' flag
412
     - an optional 'no-working-trees' flag
413
     - a LockDir lock
414
     - support for recording full info about the tree root
415
     - support for recording tree-references
416
    """
417
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
418
    repository_class = KnitRepository
5815.4.2 by Jelmer Vernooij
split out versionedfile-specific stuff from commitbuilder.
419
    _commit_builder_class = VersionedFileRootCommitBuilder
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
420
    rich_root_data = True
4988.9.1 by Jelmer Vernooij
Add experimental flag to RepositoryFormat.
421
    experimental = True
2323.5.16 by Martin Pool
rename support_tree_reference to supports_
422
    supports_tree_reference = True
3224.5.1 by Andrew Bennetts
Lots of assorted hackery to reduce the number of imports for common operations. Improves 'rocks', 'st' and 'help' times by ~50ms on my laptop.
423
    @property
424
    def _serializer(self):
425
        return xml7.serializer_v7
2100.3.31 by Aaron Bentley
Merged bzr.dev (17 tests failing)
426
427
    def _get_matching_bzrdir(self):
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
428
        return bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
2100.3.31 by Aaron Bentley
Merged bzr.dev (17 tests failing)
429
430
    def _ignore_setting_bzrdir(self, format):
431
        pass
432
433
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
434
435
    def get_format_string(self):
436
        """See RepositoryFormat.get_format_string()."""
2255.2.230 by Robert Collins
Update tree format signatures to mention introducing bzr version.
437
        return "Bazaar Knit Repository Format 3 (bzr 0.15)\n"
2100.3.31 by Aaron Bentley
Merged bzr.dev (17 tests failing)
438
439
    def get_format_description(self):
440
        """See RepositoryFormat.get_format_description()."""
441
        return "Knit repository format 3"
442
2535.3.53 by Andrew Bennetts
Remove get_stream_as_bytes from KnitVersionedFile's API, make it a function in knitrepo.py instead.
443
2996.2.1 by Aaron Bentley
Add KnitRepositoryFormat4
444
class RepositoryFormatKnit4(RepositoryFormatKnit):
445
    """Bzr repository knit format 4.
446
447
    This repository format has everything in format 3, except for
448
    tree-references:
449
     - knits for file texts and inventory
450
     - hash subdirectory based stores.
451
     - knits for revisions and signatures
452
     - TextStores for revisions and signatures.
453
     - a format marker of its own
454
     - an optional 'shared-storage' flag
455
     - an optional 'no-working-trees' flag
456
     - a LockDir lock
457
     - support for recording full info about the tree root
458
    """
459
460
    repository_class = KnitRepository
5815.4.2 by Jelmer Vernooij
split out versionedfile-specific stuff from commitbuilder.
461
    _commit_builder_class = VersionedFileRootCommitBuilder
2996.2.1 by Aaron Bentley
Add KnitRepositoryFormat4
462
    rich_root_data = True
463
    supports_tree_reference = False
3224.5.1 by Andrew Bennetts
Lots of assorted hackery to reduce the number of imports for common operations. Improves 'rocks', 'st' and 'help' times by ~50ms on my laptop.
464
    @property
465
    def _serializer(self):
466
        return xml6.serializer_v6
2996.2.1 by Aaron Bentley
Add KnitRepositoryFormat4
467
468
    def _get_matching_bzrdir(self):
469
        return bzrdir.format_registry.make_bzrdir('rich-root')
470
471
    def _ignore_setting_bzrdir(self, format):
472
        pass
473
474
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
475
476
    def get_format_string(self):
477
        """See RepositoryFormat.get_format_string()."""
478
        return 'Bazaar Knit Repository Format 4 (bzr 1.0)\n'
479
480
    def get_format_description(self):
481
        """See RepositoryFormat.get_format_description()."""
482
        return "Knit repository format 4"
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
483
484
485
class InterKnitRepo(InterSameDataRepository):
486
    """Optimised code paths between Knit based repositories."""
487
488
    @classmethod
489
    def _get_repo_format_to_test(self):
490
        return RepositoryFormatKnit1()
491
492
    @staticmethod
493
    def is_compatible(source, target):
494
        """Be compatible with known Knit formats.
495
496
        We don't test for the stores being of specific types because that
497
        could lead to confusing results, and there is no need to be
498
        overly general.
499
        """
500
        try:
501
            are_knits = (isinstance(source._format, RepositoryFormatKnit) and
502
                isinstance(target._format, RepositoryFormatKnit))
503
        except AttributeError:
504
            return False
505
        return are_knits and InterRepository._same_model(source, target)
506
507
    @needs_read_lock
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
508
    def search_missing_revision_ids(self,
509
            revision_id=symbol_versioning.DEPRECATED_PARAMETER,
5535.3.32 by Andrew Bennetts
Implement if_present_ids behaviour in all implementations and code paths of searching_missing_revision_ids
510
            find_ghosts=True, revision_ids=None, if_present_ids=None):
5536.2.6 by Andrew Bennetts
Fix docstring typo.
511
        """See InterRepository.search_missing_revision_ids()."""
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
512
        if symbol_versioning.deprecated_passed(revision_id):
513
            symbol_versioning.warn(
514
                'search_missing_revision_ids(revision_id=...) was '
5536.3.3 by Andrew Bennetts
Merge lp:bzr.
515
                'deprecated in 2.4.  Use revision_ids=[...] instead.',
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
516
                DeprecationWarning, stacklevel=2)
517
            if revision_ids is not None:
518
                raise AssertionError(
519
                    'revision_ids is mutually exclusive with revision_id')
520
            if revision_id is not None:
521
                revision_ids = [revision_id]
522
        del revision_id
5535.3.32 by Andrew Bennetts
Implement if_present_ids behaviour in all implementations and code paths of searching_missing_revision_ids
523
        source_ids_set = self._present_source_revisions_for(
524
            revision_ids, if_present_ids)
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
525
        # source_ids is the worst possible case we may need to pull.
526
        # now we want to filter source_ids against what we actually
527
        # have in target, but don't try to check for existence where we know
528
        # we do not have a revision as that would be pointless.
529
        target_ids = set(self.target.all_revision_ids())
530
        possibly_present_revisions = target_ids.intersection(source_ids_set)
531
        actually_present_revisions = set(
532
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
533
        required_revisions = source_ids_set.difference(actually_present_revisions)
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
534
        if revision_ids is not None:
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
535
            # we used get_ancestry to determine source_ids then we are assured all
536
            # revisions referenced are present as they are installed in topological order.
537
            # and the tip revision was validated by get_ancestry.
538
            result_set = required_revisions
539
        else:
540
            # if we just grabbed the possibly available ids, then
541
            # we only have an estimate of whats available and need to validate
542
            # that against the revision records.
543
            result_set = set(
544
                self.source._eliminate_revisions_not_present(required_revisions))
545
        return self.source.revision_ids_to_search_result(result_set)
546
547
548
InterRepository.register_optimiser(InterKnitRepo)