1
# Copyright (C) 2005 Canonical Ltd
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.
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.
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
17
from copy import deepcopy
18
from cStringIO import StringIO
19
from unittest import TestSuite
20
import xml.sax.saxutils
23
import bzrlib.bzrdir as bzrdir
24
from bzrlib.decorators import needs_read_lock, needs_write_lock
25
import bzrlib.errors as errors
26
from bzrlib.errors import InvalidRevisionId
27
from bzrlib.lockable_files import LockableFiles
28
from bzrlib.osutils import safe_unicode
29
from bzrlib.revision import NULL_REVISION
30
from bzrlib.store import copy_all
31
from bzrlib.store.weave import WeaveStore
32
from bzrlib.store.text import TextStore
33
from bzrlib.symbol_versioning import *
34
from bzrlib.trace import mutter
35
from bzrlib.tree import RevisionTree
36
from bzrlib.testament import Testament
37
from bzrlib.tree import EmptyTree
42
class Repository(object):
43
"""Repository holding history for one or more branches.
45
The repository holds and retrieves historical information including
46
revisions and file history. It's normally accessed only by the Branch,
47
which views a particular line of development through that history.
49
The Repository builds on top of Stores and a Transport, which respectively
50
describe the disk data format and the way of accessing the (possibly
55
def _all_possible_ids(self):
56
"""Return all the possible revisions that we could find."""
57
return self.get_inventory_weave().names()
60
def all_revision_ids(self):
61
"""Returns a list of all the revision ids in the repository.
63
These are in as much topological order as the underlying store can
64
present: for weaves ghosts may lead to a lack of correctness until
65
the reweave updates the parents list.
67
result = self._all_possible_ids()
68
return self._eliminate_revisions_not_present(result)
71
def _eliminate_revisions_not_present(self, revision_ids):
72
"""Check every revision id in revision_ids to see if we have it.
74
Returns a set of the present revisions.
77
for id in revision_ids:
78
if self.has_revision(id):
84
"""Construct the current default format repository in a_bzrdir."""
85
return RepositoryFormat.get_default_format().initialize(a_bzrdir)
87
def __init__(self, _format, a_bzrdir):
89
if isinstance(_format, (RepositoryFormat4,
92
# legacy: use a common control files.
93
self.control_files = a_bzrdir._control_files
95
self.control_files = LockableFiles(a_bzrdir.get_repository_transport(None),
98
dir_mode = self.control_files._dir_mode
99
file_mode = self.control_files._file_mode
100
self._format = _format
101
self.bzrdir = a_bzrdir
103
def get_weave(name, prefixed=False):
105
name = safe_unicode(name)
108
relpath = self.control_files._escape(name)
109
weave_transport = self.control_files._transport.clone(relpath)
110
ws = WeaveStore(weave_transport, prefixed=prefixed,
113
if self.control_files._transport.should_cache():
114
ws.enable_cache = True
117
def get_store(name, compressed=True, prefixed=False):
118
# FIXME: This approach of assuming stores are all entirely compressed
119
# or entirely uncompressed is tidy, but breaks upgrade from
120
# some existing branches where there's a mixture; we probably
121
# still want the option to look for both.
123
name = safe_unicode(name)
126
relpath = self.control_files._escape(name)
127
store = TextStore(self.control_files._transport.clone(relpath),
128
prefixed=prefixed, compressed=compressed,
131
#if self._transport.should_cache():
132
# cache_path = os.path.join(self.cache_root, name)
133
# os.mkdir(cache_path)
134
# store = bzrlib.store.CachedStore(store, cache_path)
137
if isinstance(self._format, RepositoryFormat4):
138
self.inventory_store = get_store('inventory-store')
139
self.text_store = get_store('text-store')
140
self.revision_store = get_store('revision-store')
141
elif isinstance(self._format, RepositoryFormat5):
142
self.control_weaves = get_weave('')
143
self.weave_store = get_weave('weaves')
144
self.revision_store = get_store('revision-store', compressed=False)
145
elif isinstance(self._format, RepositoryFormat6):
146
self.control_weaves = get_weave('')
147
self.weave_store = get_weave('weaves', prefixed=True)
148
self.revision_store = get_store('revision-store', compressed=False,
150
elif isinstance(self._format, RepositoryFormat7):
151
self.control_weaves = get_weave('')
152
self.weave_store = get_weave('weaves', prefixed=True)
153
self.revision_store = get_store('revision-store', compressed=False,
155
self.revision_store.register_suffix('sig')
157
def lock_write(self):
158
self.control_files.lock_write()
161
self.control_files.lock_read()
164
def missing_revision_ids(self, other, revision_id=None):
165
"""Return the revision ids that other has that this does not.
167
These are returned in topological order.
169
revision_id: only return revision ids included by revision_id.
171
if self._compatible_formats(other):
172
# fast path for weave-inventory based stores.
173
# we want all revisions to satisft revision_id in other.
174
# but we dont want to stat every file here and there.
175
# we want then, all revisions other needs to satisfy revision_id
176
# checked, but not those that we have locally.
177
# so the first thing is to get a subset of the revisions to
178
# satisfy revision_id in other, and then eliminate those that
179
# we do already have.
180
# this is slow on high latency connection to self, but as as this
181
# disk format scales terribly for push anyway due to rewriting
182
# inventory.weave, this is considered acceptable.
184
if revision_id is not None:
185
other_ids = other.get_ancestry(revision_id)
186
assert other_ids.pop(0) == None
188
other_ids = other._all_possible_ids()
189
other_ids_set = set(other_ids)
190
# other ids is the worst case to pull now.
191
# now we want to filter other_ids against what we actually
192
# have, but dont try to stat what we know we dont.
193
my_ids = set(self._all_possible_ids())
194
possibly_present_revisions = my_ids.intersection(other_ids_set)
195
actually_present_revisions = set(self._eliminate_revisions_not_present(possibly_present_revisions))
196
required_revisions = other_ids_set.difference(actually_present_revisions)
197
required_topo_revisions = [rev_id for rev_id in other_ids if rev_id in required_revisions]
198
if revision_id is not None:
199
# we used get_ancestry to determine other_ids then we are assured all
200
# revisions referenced are present as they are installed in topological order.
201
return required_topo_revisions
203
# we only have an estimate of whats available
204
return other._eliminate_revisions_not_present(required_topo_revisions)
206
my_ids = set(self.all_revision_ids())
207
if revision_id is not None:
208
other_ids = other.get_ancestry(revision_id)
209
assert other_ids.pop(0) == None
211
other_ids = other.all_revision_ids()
212
result_set = set(other_ids).difference(my_ids)
213
return [rev_id for rev_id in other_ids if rev_id in result_set]
217
"""Open the repository rooted at base.
219
For instance, if the repository is at URL/.bzr/repository,
220
Repository.open(URL) -> a Repository instance.
222
control = bzrdir.BzrDir.open(base)
223
return control.open_repository()
225
def _compatible_formats(self, other):
226
"""Return True if the stores in self and other are 'compatible'
228
'compatible' means that they are both the same underlying type
229
i.e. both weave stores, or both knits and thus support fast-path
231
return (isinstance(self._format, (RepositoryFormat5,
233
RepositoryFormat7)) and
234
isinstance(other._format, (RepositoryFormat5,
239
def copy_content_into(self, destination, revision_id=None, basis=None):
240
"""Make a complete copy of the content in self into destination.
242
This is a destructive operation! Do not use it on existing
245
destination.lock_write()
248
destination.set_make_working_trees(self.make_working_trees())
249
except NotImplementedError:
253
if self._compatible_formats(destination):
254
if basis is not None:
255
# copy the basis in, then fetch remaining data.
256
basis.copy_content_into(destination, revision_id)
257
destination.fetch(self, revision_id=revision_id)
260
if self.control_files._transport.listable():
261
pb = bzrlib.ui.ui_factory.progress_bar()
262
copy_all(self.weave_store,
263
destination.weave_store, pb=pb)
264
pb.update('copying inventory', 0, 1)
265
destination.control_weaves.copy_multi(
266
self.control_weaves, ['inventory'])
267
copy_all(self.revision_store,
268
destination.revision_store, pb=pb)
270
destination.fetch(self, revision_id=revision_id)
271
# compatible v4 stores
272
elif isinstance(self._format, RepositoryFormat4):
273
if not isinstance(destination._format, RepositoryFormat4):
274
raise BzrError('cannot copy v4 branches to anything other than v4 branches.')
275
store_pairs = ((self.text_store, destination.text_store),
276
(self.inventory_store, destination.inventory_store),
277
(self.revision_store, destination.revision_store))
279
for from_store, to_store in store_pairs:
280
copy_all(from_store, to_store)
281
except UnlistableStore:
282
raise UnlistableBranch(from_store)
285
destination.fetch(self, revision_id=revision_id)
290
def fetch(self, source, revision_id=None):
291
"""Fetch the content required to construct revision_id from source.
293
If revision_id is None all content is copied.
295
from bzrlib.fetch import RepoFetcher
296
mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
297
source, source._format, self, self._format)
298
RepoFetcher(to_repository=self, from_repository=source, last_revision=revision_id)
301
self.control_files.unlock()
304
def clone(self, a_bzrdir, revision_id=None, basis=None):
305
"""Clone this repository into a_bzrdir using the current format.
307
Currently no check is made that the format of this repository and
308
the bzrdir format are compatible. FIXME RBC 20060201.
310
if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
311
# use target default format.
312
result = a_bzrdir.create_repository()
313
# FIXME RBC 20060209 split out the repository type to avoid this check ?
314
elif isinstance(a_bzrdir._format,
315
(bzrdir.BzrDirFormat4,
316
bzrdir.BzrDirFormat5,
317
bzrdir.BzrDirFormat6)):
318
result = a_bzrdir.open_repository()
320
result = self._format.initialize(a_bzrdir, shared=self.is_shared())
321
self.copy_content_into(result, revision_id, basis)
324
def has_revision(self, revision_id):
325
"""True if this branch has a copy of the revision.
327
This does not necessarily imply the revision is merge
328
or on the mainline."""
329
return (revision_id is None
330
or self.revision_store.has_id(revision_id))
333
def get_revision_xml_file(self, revision_id):
334
"""Return XML file object for revision object."""
335
if not revision_id or not isinstance(revision_id, basestring):
336
raise InvalidRevisionId(revision_id=revision_id, branch=self)
338
return self.revision_store.get(revision_id)
339
except (IndexError, KeyError):
340
raise bzrlib.errors.NoSuchRevision(self, revision_id)
343
def get_revision_xml(self, revision_id):
344
return self.get_revision_xml_file(revision_id).read()
347
def get_revision(self, revision_id):
348
"""Return the Revision object for a named revision"""
349
xml_file = self.get_revision_xml_file(revision_id)
352
r = bzrlib.xml5.serializer_v5.read_revision(xml_file)
353
except SyntaxError, e:
354
raise bzrlib.errors.BzrError('failed to unpack revision_xml',
358
assert r.revision_id == revision_id
362
def get_revision_sha1(self, revision_id):
363
"""Hash the stored value of a revision, and return it."""
364
# In the future, revision entries will be signed. At that
365
# point, it is probably best *not* to include the signature
366
# in the revision hash. Because that lets you re-sign
367
# the revision, (add signatures/remove signatures) and still
368
# have all hash pointers stay consistent.
369
# But for now, just hash the contents.
370
return bzrlib.osutils.sha_file(self.get_revision_xml_file(revision_id))
373
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
374
self.revision_store.add(StringIO(gpg_strategy.sign(plaintext)),
377
def fileid_involved_between_revs(self, from_revid, to_revid):
378
"""Find file_id(s) which are involved in the changes between revisions.
380
This determines the set of revisions which are involved, and then
381
finds all file ids affected by those revisions.
383
# TODO: jam 20060119 This code assumes that w.inclusions will
384
# always be correct. But because of the presence of ghosts
385
# it is possible to be wrong.
386
# One specific example from Robert Collins:
387
# Two branches, with revisions ABC, and AD
388
# C is a ghost merge of D.
389
# Inclusions doesn't recognize D as an ancestor.
390
# If D is ever merged in the future, the weave
391
# won't be fixed, because AD never saw revision C
392
# to cause a conflict which would force a reweave.
393
w = self.get_inventory_weave()
394
from_set = set(w.inclusions([w.lookup(from_revid)]))
395
to_set = set(w.inclusions([w.lookup(to_revid)]))
396
included = to_set.difference(from_set)
397
changed = map(w.idx_to_name, included)
398
return self._fileid_involved_by_set(changed)
400
def fileid_involved(self, last_revid=None):
401
"""Find all file_ids modified in the ancestry of last_revid.
403
:param last_revid: If None, last_revision() will be used.
405
w = self.get_inventory_weave()
407
changed = set(w._names)
409
included = w.inclusions([w.lookup(last_revid)])
410
changed = map(w.idx_to_name, included)
411
return self._fileid_involved_by_set(changed)
413
def fileid_involved_by_set(self, changes):
414
"""Find all file_ids modified by the set of revisions passed in.
416
:param changes: A set() of revision ids
418
# TODO: jam 20060119 This line does *nothing*, remove it.
419
# or better yet, change _fileid_involved_by_set so
420
# that it takes the inventory weave, rather than
421
# pulling it out by itself.
422
return self._fileid_involved_by_set(changes)
424
def _fileid_involved_by_set(self, changes):
425
"""Find the set of file-ids affected by the set of revisions.
427
:param changes: A set() of revision ids.
428
:return: A set() of file ids.
430
This peaks at the Weave, interpreting each line, looking to
431
see if it mentions one of the revisions. And if so, includes
432
the file id mentioned.
433
This expects both the Weave format, and the serialization
434
to have a single line per file/directory, and to have
435
fileid="" and revision="" on that line.
437
assert isinstance(self._format, (RepositoryFormat5,
439
RepositoryFormat7)), \
440
"fileid_involved only supported for branches which store inventory as unnested xml"
442
w = self.get_inventory_weave()
444
for line in w._weave:
446
# it is ugly, but it is due to the weave structure
447
if not isinstance(line, basestring): continue
449
start = line.find('file_id="')+9
450
if start < 9: continue
451
end = line.find('"', start)
453
file_id = xml.sax.saxutils.unescape(line[start:end])
455
# check if file_id is already present
456
if file_id in file_ids: continue
458
start = line.find('revision="')+10
459
if start < 10: continue
460
end = line.find('"', start)
462
revision_id = xml.sax.saxutils.unescape(line[start:end])
464
if revision_id in changes:
465
file_ids.add(file_id)
469
def get_inventory_weave(self):
470
return self.control_weaves.get_weave('inventory',
471
self.get_transaction())
474
def get_inventory(self, revision_id):
475
"""Get Inventory object by hash."""
476
xml = self.get_inventory_xml(revision_id)
477
return bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
480
def get_inventory_xml(self, revision_id):
481
"""Get inventory XML as a file object."""
483
assert isinstance(revision_id, basestring), type(revision_id)
484
iw = self.get_inventory_weave()
485
return iw.get_text(iw.lookup(revision_id))
487
raise bzrlib.errors.HistoryMissing(self, 'inventory', revision_id)
490
def get_inventory_sha1(self, revision_id):
491
"""Return the sha1 hash of the inventory entry
493
return self.get_revision(revision_id).inventory_sha1
496
def get_revision_inventory(self, revision_id):
497
"""Return inventory of a past revision."""
498
# TODO: Unify this with get_inventory()
499
# bzr 0.0.6 and later imposes the constraint that the inventory_id
500
# must be the same as its revision, so this is trivial.
501
if revision_id is None:
502
# This does not make sense: if there is no revision,
503
# then it is the current tree inventory surely ?!
504
# and thus get_root_id() is something that looks at the last
505
# commit on the branch, and the get_root_id is an inventory check.
506
raise NotImplementedError
507
# return Inventory(self.get_root_id())
509
return self.get_inventory(revision_id)
513
"""Return True if this repository is flagged as a shared repository."""
514
# FIXME format 4-6 cannot be shared, this is technically faulty.
515
return self.control_files._transport.has('shared-storage')
518
def revision_tree(self, revision_id):
519
"""Return Tree for a revision on this branch.
521
`revision_id` may be None for the null revision, in which case
522
an `EmptyTree` is returned."""
523
# TODO: refactor this to use an existing revision object
524
# so we don't need to read it in twice.
525
if revision_id is None or revision_id == NULL_REVISION:
528
inv = self.get_revision_inventory(revision_id)
529
return RevisionTree(self, inv, revision_id)
532
def get_ancestry(self, revision_id):
533
"""Return a list of revision-ids integrated by a revision.
535
This is topologically sorted.
537
if revision_id is None:
539
if not self.has_revision(revision_id):
540
raise errors.NoSuchRevision(self, revision_id)
541
w = self.get_inventory_weave()
542
return [None] + map(w.idx_to_name,
543
w.inclusions([w.lookup(revision_id)]))
546
def print_file(self, file, revision_id):
547
"""Print `file` to stdout.
549
FIXME RBC 20060125 as John Meinel points out this is a bad api
550
- it writes to stdout, it assumes that that is valid etc. Fix
551
by creating a new more flexible convenience function.
553
tree = self.revision_tree(revision_id)
554
# use inventory as it was in that revision
555
file_id = tree.inventory.path2id(file)
557
raise BzrError("%r is not present in revision %s" % (file, revno))
559
revno = self.revision_id_to_revno(revision_id)
560
except errors.NoSuchRevision:
561
# TODO: This should not be BzrError,
562
# but NoSuchFile doesn't fit either
563
raise BzrError('%r is not present in revision %s'
564
% (file, revision_id))
566
raise BzrError('%r is not present in revision %s'
568
tree.print_file(file_id)
570
def get_transaction(self):
571
return self.control_files.get_transaction()
574
def set_make_working_trees(self, new_value):
575
"""Set the policy flag for making working trees when creating branches.
577
This only applies to branches that use this repository.
579
The default is 'True'.
580
:param new_value: True to restore the default, False to disable making
583
# FIXME: split out into a new class/strategy ?
584
if isinstance(self._format, (RepositoryFormat4,
587
raise NotImplementedError(self.set_make_working_trees)
590
self.control_files._transport.delete('no-working-trees')
591
except errors.NoSuchFile:
594
self.control_files.put_utf8('no-working-trees', '')
596
def make_working_trees(self):
597
"""Returns the policy for making working trees on new branches."""
598
# FIXME: split out into a new class/strategy ?
599
if isinstance(self._format, (RepositoryFormat4,
603
return not self.control_files._transport.has('no-working-trees')
606
def sign_revision(self, revision_id, gpg_strategy):
607
plaintext = Testament.from_revision(self, revision_id).as_short_text()
608
self.store_revision_signature(gpg_strategy, plaintext, revision_id)
611
class RepositoryFormat(object):
612
"""A repository format.
614
Formats provide three things:
615
* An initialization routine to construct repository data on disk.
616
* a format string which is used when the BzrDir supports versioned
618
* an open routine which returns a Repository instance.
620
Formats are placed in an dict by their format string for reference
621
during opening. These should be subclasses of RepositoryFormat
624
Once a format is deprecated, just deprecate the initialize and open
625
methods on the format class. Do not deprecate the object, as the
626
object will be created every system load.
628
Common instance attributes:
629
_matchingbzrdir - the bzrdir format that the repository format was
630
originally written to work with. This can be used if manually
631
constructing a bzrdir and repository, or more commonly for test suite
635
_default_format = None
636
"""The default format used for new repositories."""
639
"""The known formats."""
642
def find_format(klass, a_bzrdir):
643
"""Return the format for the repository object in a_bzrdir."""
645
transport = a_bzrdir.get_repository_transport(None)
646
format_string = transport.get("format").read()
647
return klass._formats[format_string]
648
except errors.NoSuchFile:
649
raise errors.NoRepositoryPresent(a_bzrdir)
651
raise errors.UnknownFormatError(format_string)
654
def get_default_format(klass):
655
"""Return the current default format."""
656
return klass._default_format
658
def get_format_string(self):
659
"""Return the ASCII format string that identifies this format.
661
Note that in pre format ?? repositories the format string is
662
not permitted nor written to disk.
664
raise NotImplementedError(self.get_format_string)
666
def initialize(self, a_bzrdir, shared=False):
667
"""Initialize a repository of this format in a_bzrdir.
669
:param a_bzrdir: The bzrdir to put the new repository in it.
670
:param shared: The repository should be initialized as a sharable one.
672
This may raise UninitializableFormat if shared repository are not
673
compatible the a_bzrdir.
676
def is_supported(self):
677
"""Is this format supported?
679
Supported formats must be initializable and openable.
680
Unsupported formats may not support initialization or committing or
681
some other features depending on the reason for not being supported.
685
def open(self, a_bzrdir, _found=False):
686
"""Return an instance of this format for the bzrdir a_bzrdir.
688
_found is a private parameter, do not use it.
691
# we are being called directly and must probe.
692
raise NotImplementedError
693
return Repository(_format=self, a_bzrdir=a_bzrdir)
696
def register_format(klass, format):
697
klass._formats[format.get_format_string()] = format
700
def set_default_format(klass, format):
701
klass._default_format = format
704
def unregister_format(klass, format):
705
assert klass._formats[format.get_format_string()] is format
706
del klass._formats[format.get_format_string()]
709
class PreSplitOutRepositoryFormat(RepositoryFormat):
710
"""Base class for the pre split out repository formats."""
712
def initialize(self, a_bzrdir, shared=False, _internal=False):
713
"""Create a weave repository.
715
TODO: when creating split out bzr branch formats, move this to a common
716
base for Format5, Format6. or something like that.
718
from bzrlib.weavefile import write_weave_v5
719
from bzrlib.weave import Weave
722
raise errors.IncompatibleFormat(self, a_bzrdir._format)
725
# always initialized when the bzrdir is.
726
return Repository(_format=self, a_bzrdir=a_bzrdir)
728
# Create an empty weave
730
bzrlib.weavefile.write_weave_v5(Weave(), sio)
731
empty_weave = sio.getvalue()
733
mutter('creating repository in %s.', a_bzrdir.transport.base)
734
dirs = ['revision-store', 'weaves']
735
lock_file = 'branch-lock'
736
files = [('inventory.weave', StringIO(empty_weave)),
739
# FIXME: RBC 20060125 dont peek under the covers
740
# NB: no need to escape relative paths that are url safe.
741
control_files = LockableFiles(a_bzrdir.transport, 'branch-lock')
742
control_files.lock_write()
743
control_files._transport.mkdir_multi(dirs,
744
mode=control_files._dir_mode)
746
for file, content in files:
747
control_files.put(file, content)
749
control_files.unlock()
750
return Repository(_format=self, a_bzrdir=a_bzrdir)
753
class RepositoryFormat4(PreSplitOutRepositoryFormat):
754
"""Bzr repository format 4.
756
This repository format has:
758
- TextStores for texts, inventories,revisions.
760
This format is deprecated: it indexes texts using a text id which is
761
removed in format 5; initializationa and write support for this format
766
super(RepositoryFormat4, self).__init__()
767
self._matchingbzrdir = bzrdir.BzrDirFormat4()
769
def initialize(self, url, shared=False, _internal=False):
770
"""Format 4 branches cannot be created."""
771
raise errors.UninitializableFormat(self)
773
def is_supported(self):
774
"""Format 4 is not supported.
776
It is not supported because the model changed from 4 to 5 and the
777
conversion logic is expensive - so doing it on the fly was not
783
class RepositoryFormat5(PreSplitOutRepositoryFormat):
784
"""Bzr control format 5.
786
This repository format has:
787
- weaves for file texts and inventory
789
- TextStores for revisions and signatures.
793
super(RepositoryFormat5, self).__init__()
794
self._matchingbzrdir = bzrdir.BzrDirFormat5()
797
class RepositoryFormat6(PreSplitOutRepositoryFormat):
798
"""Bzr control format 6.
800
This repository format has:
801
- weaves for file texts and inventory
802
- hash subdirectory based stores.
803
- TextStores for revisions and signatures.
807
super(RepositoryFormat6, self).__init__()
808
self._matchingbzrdir = bzrdir.BzrDirFormat6()
811
class RepositoryFormat7(RepositoryFormat):
814
This repository format has:
815
- weaves for file texts and inventory
816
- hash subdirectory based stores.
817
- TextStores for revisions and signatures.
818
- a format marker of its own
819
- an optional 'shared-storage' flag
822
def get_format_string(self):
823
"""See RepositoryFormat.get_format_string()."""
824
return "Bazaar-NG Repository format 7"
826
def initialize(self, a_bzrdir, shared=False):
827
"""Create a weave repository.
829
:param shared: If true the repository will be initialized as a shared
832
from bzrlib.weavefile import write_weave_v5
833
from bzrlib.weave import Weave
835
# Create an empty weave
837
bzrlib.weavefile.write_weave_v5(Weave(), sio)
838
empty_weave = sio.getvalue()
840
mutter('creating repository in %s.', a_bzrdir.transport.base)
841
dirs = ['revision-store', 'weaves']
842
files = [('inventory.weave', StringIO(empty_weave)),
844
utf8_files = [('format', self.get_format_string())]
846
# FIXME: RBC 20060125 dont peek under the covers
847
# NB: no need to escape relative paths that are url safe.
849
repository_transport = a_bzrdir.get_repository_transport(self)
850
repository_transport.put(lock_file, StringIO()) # TODO get the file mode from the bzrdir lock files., mode=file_mode)
851
control_files = LockableFiles(repository_transport, 'lock')
852
control_files.lock_write()
853
control_files._transport.mkdir_multi(dirs,
854
mode=control_files._dir_mode)
856
for file, content in files:
857
control_files.put(file, content)
858
for file, content in utf8_files:
859
control_files.put_utf8(file, content)
861
control_files.put_utf8('shared-storage', '')
863
control_files.unlock()
864
return Repository(_format=self, a_bzrdir=a_bzrdir)
867
super(RepositoryFormat7, self).__init__()
868
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
871
# formats which have no format string are not discoverable
872
# and not independently creatable, so are not registered.
873
__default_format = RepositoryFormat7()
874
RepositoryFormat.register_format(__default_format)
875
RepositoryFormat.set_default_format(__default_format)
876
_legacy_formats = [RepositoryFormat4(),
881
class RepositoryTestProviderAdapter(object):
882
"""A tool to generate a suite testing multiple repository formats at once.
884
This is done by copying the test once for each transport and injecting
885
the transport_server, transport_readonly_server, and bzrdir_format and
886
repository_format classes into each copy. Each copy is also given a new id()
887
to make it easy to identify.
890
def __init__(self, transport_server, transport_readonly_server, formats):
891
self._transport_server = transport_server
892
self._transport_readonly_server = transport_readonly_server
893
self._formats = formats
895
def adapt(self, test):
897
for repository_format, bzrdir_format in self._formats:
898
new_test = deepcopy(test)
899
new_test.transport_server = self._transport_server
900
new_test.transport_readonly_server = self._transport_readonly_server
901
new_test.bzrdir_format = bzrdir_format
902
new_test.repository_format = repository_format
903
def make_new_test_id():
904
new_id = "%s(%s)" % (new_test.id(), repository_format.__class__.__name__)
905
return lambda: new_id
906
new_test.id = make_new_test_id()
907
result.addTest(new_test)