~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: John Arbash Meinel
  • Date: 2006-06-18 02:21:57 UTC
  • mfrom: (1787 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1794.
  • Revision ID: john@arbash-meinel.com-20060618022157-6e33aa9b67c25e4f
[merge] bzr.dev 1787

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import time
22
22
from unittest import TestSuite
23
23
 
24
 
from bzrlib import bzrdir, check, delta, gpg, errors, xml5, ui, transactions, osutils
 
24
import bzrlib.bzrdir as bzrdir
25
25
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
26
import bzrlib.errors as errors
26
27
from bzrlib.errors import InvalidRevisionId
 
28
import bzrlib.gpg as gpg
27
29
from bzrlib.graph import Graph
28
30
from bzrlib.inter import InterObject
29
31
from bzrlib.inventory import Inventory
35
37
from bzrlib.revision import NULL_REVISION, Revision
36
38
from bzrlib.store.versioned import VersionedFileStore, WeaveStore
37
39
from bzrlib.store.text import TextStore
38
 
from bzrlib.symbol_versioning import (deprecated_method,
39
 
        zero_nine, 
40
 
        )
 
40
from bzrlib.symbol_versioning import *
41
41
from bzrlib.trace import mutter, note
42
42
from bzrlib.tree import RevisionTree, EmptyTree
43
43
from bzrlib.tsort import topo_sort
44
44
from bzrlib.testament import Testament
45
45
from bzrlib.tree import EmptyTree
 
46
from bzrlib.delta import compare_trees
 
47
import bzrlib.ui
46
48
from bzrlib.weave import WeaveFile
 
49
import bzrlib.xml5
47
50
 
48
51
 
49
52
class Repository(object):
70
73
        assert inv.revision_id is None or inv.revision_id == revid, \
71
74
            "Mismatch between inventory revision" \
72
75
            " id and insertion revid (%r, %r)" % (inv.revision_id, revid)
73
 
        inv_text = xml5.serializer_v5.write_inventory_to_string(inv)
74
 
        inv_sha1 = osutils.sha_string(inv_text)
 
76
        inv_text = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
 
77
        inv_sha1 = bzrlib.osutils.sha_string(inv_text)
75
78
        inv_vf = self.control_weaves.get_weave('inventory',
76
79
                                               self.get_transaction())
77
 
        self._inventory_add_lines(inv_vf, revid, parents, osutils.split_lines(inv_text))
 
80
        self._inventory_add_lines(inv_vf, revid, parents, bzrlib.osutils.split_lines(inv_text))
78
81
        return inv_sha1
79
82
 
80
83
    def _inventory_add_lines(self, inv_vf, revid, parents, lines):
117
120
        """Return all the possible revisions that we could find."""
118
121
        return self.get_inventory_weave().versions()
119
122
 
 
123
    @deprecated_method(zero_nine)
120
124
    def all_revision_ids(self):
121
125
        """Returns a list of all the revision ids in the repository. 
122
126
 
223
227
        For instance, if the repository is at URL/.bzr/repository,
224
228
        Repository.open(URL) -> a Repository instance.
225
229
        """
226
 
        control = bzrdir.BzrDir.open(base)
 
230
        control = bzrlib.bzrdir.BzrDir.open(base)
227
231
        return control.open_repository()
228
232
 
229
233
    def copy_content_into(self, destination, revision_id=None, basis=None):
274
278
            result = a_bzrdir.create_repository()
275
279
        # FIXME RBC 20060209 split out the repository type to avoid this check ?
276
280
        elif isinstance(a_bzrdir._format,
277
 
                      (bzrdir.BzrDirFormat4,
278
 
                       bzrdir.BzrDirFormat5,
279
 
                       bzrdir.BzrDirFormat6)):
 
281
                      (bzrlib.bzrdir.BzrDirFormat4,
 
282
                       bzrlib.bzrdir.BzrDirFormat5,
 
283
                       bzrlib.bzrdir.BzrDirFormat6)):
280
284
            result = a_bzrdir.open_repository()
281
285
        else:
282
286
            result = self._format.initialize(a_bzrdir, shared=self.is_shared())
343
347
            old_tree = EmptyTree()
344
348
        else:
345
349
            old_tree = self.revision_tree(revision.parent_ids[0])
346
 
        return delta.compare_trees(old_tree, new_tree)
 
350
        return compare_trees(old_tree, new_tree)
347
351
 
348
352
    def _check_revision_parents(self, revision, inventory):
349
353
        """Private to Repository and Fetch.
427
431
        :param revision_id: The expected revision id of the inventory.
428
432
        :param xml: A serialised inventory.
429
433
        """
430
 
        return xml5.serializer_v5.read_inventory_from_string(xml)
 
434
        return bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
431
435
 
432
436
    @needs_read_lock
433
437
    def get_inventory_xml(self, revision_id):
437
441
            iw = self.get_inventory_weave()
438
442
            return iw.get_text(revision_id)
439
443
        except IndexError:
440
 
            raise errors.HistoryMissing(self, 'inventory', revision_id)
 
444
            raise bzrlib.errors.HistoryMissing(self, 'inventory', revision_id)
441
445
 
442
446
    @needs_read_lock
443
447
    def get_inventory_sha1(self, revision_id):
639
643
        return self._check(revision_ids)
640
644
 
641
645
    def _check(self, revision_ids):
642
 
        result = check.Check(self)
 
646
        result = bzrlib.check.Check(self)
643
647
        result.check()
644
648
        return result
645
649
 
916
920
        reconciler.reconcile()
917
921
        return reconciler
918
922
    
919
 
    def revision_parents(self, revision_id):
920
 
        return self._get_revision_vf().get_parents(revision_id)
921
 
 
 
923
    def revision_parents(self, revid):
 
924
        return self._get_revision_vf().get_parents(rev_id)
922
925
 
923
926
class RepositoryFormat(object):
924
927
    """A repository format.
960
963
        except errors.NoSuchFile:
961
964
            raise errors.NoRepositoryPresent(a_bzrdir)
962
965
        except KeyError:
963
 
            raise errors.UnknownFormatError(format=format_string)
 
966
            raise errors.UnknownFormatError(format_string)
964
967
 
965
968
    def _get_control_store(self, repo_transport, control_files):
966
969
        """Return the control store for this repository."""
1087
1090
        
1088
1091
        # Create an empty weave
1089
1092
        sio = StringIO()
1090
 
        write_weave_v5(Weave(), sio)
 
1093
        bzrlib.weavefile.write_weave_v5(Weave(), sio)
1091
1094
        empty_weave = sio.getvalue()
1092
1095
 
1093
1096
        mutter('creating repository in %s.', a_bzrdir.transport.base)
1153
1156
 
1154
1157
    def __init__(self):
1155
1158
        super(RepositoryFormat4, self).__init__()
1156
 
        self._matchingbzrdir = bzrdir.BzrDirFormat4()
 
1159
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat4()
1157
1160
 
1158
1161
    def get_format_description(self):
1159
1162
        """See RepositoryFormat.get_format_description()."""
1202
1205
 
1203
1206
    def __init__(self):
1204
1207
        super(RepositoryFormat5, self).__init__()
1205
 
        self._matchingbzrdir = bzrdir.BzrDirFormat5()
 
1208
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat5()
1206
1209
 
1207
1210
    def get_format_description(self):
1208
1211
        """See RepositoryFormat.get_format_description()."""
1232
1235
 
1233
1236
    def __init__(self):
1234
1237
        super(RepositoryFormat6, self).__init__()
1235
 
        self._matchingbzrdir = bzrdir.BzrDirFormat6()
 
1238
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat6()
1236
1239
 
1237
1240
    def get_format_description(self):
1238
1241
        """See RepositoryFormat.get_format_description()."""
1256
1259
 
1257
1260
    def __init__(self):
1258
1261
        super(MetaDirRepositoryFormat, self).__init__()
1259
 
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
 
1262
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirMetaFormat1()
1260
1263
 
1261
1264
    def _create_control_files(self, a_bzrdir):
1262
1265
        """Create the required files and the initial control_files object."""
1337
1340
 
1338
1341
        # Create an empty weave
1339
1342
        sio = StringIO()
1340
 
        write_weave_v5(Weave(), sio)
 
1343
        bzrlib.weavefile.write_weave_v5(Weave(), sio)
1341
1344
        empty_weave = sio.getvalue()
1342
1345
 
1343
1346
        mutter('creating repository in %s.', a_bzrdir.transport.base)
1448
1451
        repo_transport = a_bzrdir.get_repository_transport(None)
1449
1452
        control_files = LockableFiles(repo_transport, 'lock', LockDir)
1450
1453
        control_store = self._get_control_store(repo_transport, control_files)
1451
 
        transaction = transactions.WriteTransaction()
 
1454
        transaction = bzrlib.transactions.WriteTransaction()
1452
1455
        # trigger a write of the inventory store.
1453
1456
        control_store.get_weave_or_empty('inventory', transaction)
1454
1457
        _revision_store = self._get_revision_store(repo_transport, control_files)
1657
1660
                pass
1658
1661
            # FIXME do not peek!
1659
1662
            if self.source.control_files._transport.listable():
1660
 
                pb = ui.ui_factory.nested_progress_bar()
 
1663
                pb = bzrlib.ui.ui_factory.nested_progress_bar()
1661
1664
                try:
1662
1665
                    self.target.weave_store.copy_all_ids(
1663
1666
                        self.source.weave_store,
2086
2089
            # TODO: Rather than invoking sha_strings here, _add_text_to_weave
2087
2090
            # should return the SHA1 and size
2088
2091
            self._add_text_to_weave(file_id, new_lines, file_parents.keys())
2089
 
            return osutils.sha_strings(new_lines), \
 
2092
            return bzrlib.osutils.sha_strings(new_lines), \
2090
2093
                sum(map(len, new_lines))
2091
2094
 
2092
2095
    def modified_link(self, file_id, file_parents, link_target):