~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Martin Pool
  • Date: 2006-06-20 03:57:11 UTC
  • mto: This revision was merged to the branch mainline in revision 1798.
  • Revision ID: mbp@sourcefrog.net-20060620035711-400bb6b6bc6ff95b
Add pyflakes makefile target; fix many warnings

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
 
import bzrlib.bzrdir as bzrdir
 
24
from bzrlib import bzrdir, check, gpg, errors, xml5, ui, transactions, osutils
25
25
from bzrlib.decorators import needs_read_lock, needs_write_lock
26
 
import bzrlib.errors as errors
27
26
from bzrlib.errors import InvalidRevisionId
28
 
import bzrlib.gpg as gpg
29
27
from bzrlib.graph import Graph
30
28
from bzrlib.inter import InterObject
31
29
from bzrlib.inventory import Inventory
37
35
from bzrlib.revision import NULL_REVISION, Revision
38
36
from bzrlib.store.versioned import VersionedFileStore, WeaveStore
39
37
from bzrlib.store.text import TextStore
40
 
from bzrlib.symbol_versioning import *
 
38
from bzrlib.symbol_versioning import (deprecated_method,
 
39
        zero_nine, 
 
40
        )
41
41
from bzrlib.trace import mutter, note
42
42
from bzrlib.tree import RevisionTree
43
43
from bzrlib.tsort import topo_sort
44
44
from bzrlib.testament import Testament
45
45
from bzrlib.tree import EmptyTree
46
 
import bzrlib.ui
47
46
from bzrlib.weave import WeaveFile
48
 
import bzrlib.xml5
49
47
 
50
48
 
51
49
class Repository(object):
72
70
        assert inv.revision_id is None or inv.revision_id == revid, \
73
71
            "Mismatch between inventory revision" \
74
72
            " id and insertion revid (%r, %r)" % (inv.revision_id, revid)
75
 
        inv_text = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
76
 
        inv_sha1 = bzrlib.osutils.sha_string(inv_text)
 
73
        inv_text = xml5.serializer_v5.write_inventory_to_string(inv)
 
74
        inv_sha1 = osutils.sha_string(inv_text)
77
75
        inv_vf = self.control_weaves.get_weave('inventory',
78
76
                                               self.get_transaction())
79
 
        self._inventory_add_lines(inv_vf, revid, parents, bzrlib.osutils.split_lines(inv_text))
 
77
        self._inventory_add_lines(inv_vf, revid, parents, osutils.split_lines(inv_text))
80
78
        return inv_sha1
81
79
 
82
80
    def _inventory_add_lines(self, inv_vf, revid, parents, lines):
226
224
        For instance, if the repository is at URL/.bzr/repository,
227
225
        Repository.open(URL) -> a Repository instance.
228
226
        """
229
 
        control = bzrlib.bzrdir.BzrDir.open(base)
 
227
        control = bzrdir.BzrDir.open(base)
230
228
        return control.open_repository()
231
229
 
232
230
    def copy_content_into(self, destination, revision_id=None, basis=None):
277
275
            result = a_bzrdir.create_repository()
278
276
        # FIXME RBC 20060209 split out the repository type to avoid this check ?
279
277
        elif isinstance(a_bzrdir._format,
280
 
                      (bzrlib.bzrdir.BzrDirFormat4,
281
 
                       bzrlib.bzrdir.BzrDirFormat5,
282
 
                       bzrlib.bzrdir.BzrDirFormat6)):
 
278
                      (bzrdir.BzrDirFormat4,
 
279
                       bzrdir.BzrDirFormat5,
 
280
                       bzrdir.BzrDirFormat6)):
283
281
            result = a_bzrdir.open_repository()
284
282
        else:
285
283
            result = self._format.initialize(a_bzrdir, shared=self.is_shared())
412
410
        :param revision_id: The expected revision id of the inventory.
413
411
        :param xml: A serialised inventory.
414
412
        """
415
 
        return bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
 
413
        return xml5.serializer_v5.read_inventory_from_string(xml)
416
414
 
417
415
    @needs_read_lock
418
416
    def get_inventory_xml(self, revision_id):
422
420
            iw = self.get_inventory_weave()
423
421
            return iw.get_text(revision_id)
424
422
        except IndexError:
425
 
            raise bzrlib.errors.HistoryMissing(self, 'inventory', revision_id)
 
423
            raise errors.HistoryMissing(self, 'inventory', revision_id)
426
424
 
427
425
    @needs_read_lock
428
426
    def get_inventory_sha1(self, revision_id):
465
463
        """
466
464
        result = Graph()
467
465
        if not revision_ids:
468
 
            pending = set(self.all_revision_ids())
 
466
            pending = set(self._all_revision_ids())
469
467
            required = set([])
470
468
        else:
471
469
            pending = set(revision_ids)
624
622
        return self._check(revision_ids)
625
623
 
626
624
    def _check(self, revision_ids):
627
 
        result = bzrlib.check.Check(self)
 
625
        result = check.Check(self)
628
626
        result.check()
629
627
        return result
630
628
 
861
859
        vf = self._get_revision_vf()
862
860
        versions = set(vf.versions())
863
861
        if not revision_ids:
864
 
            pending = set(self.all_revision_ids())
 
862
            pending = set(self._all_revision_ids())
865
863
            required = set([])
866
864
        else:
867
865
            pending = set(revision_ids)
901
899
        reconciler.reconcile()
902
900
        return reconciler
903
901
    
904
 
    def revision_parents(self, revid):
905
 
        return self._get_revision_vf().get_parents(rev_id)
 
902
    def revision_parents(self, revision_id):
 
903
        return self._get_revision_vf().get_parents(revision_id)
 
904
 
906
905
 
907
906
class RepositoryFormat(object):
908
907
    """A repository format.
1071
1070
        
1072
1071
        # Create an empty weave
1073
1072
        sio = StringIO()
1074
 
        bzrlib.weavefile.write_weave_v5(Weave(), sio)
 
1073
        write_weave_v5(Weave(), sio)
1075
1074
        empty_weave = sio.getvalue()
1076
1075
 
1077
1076
        mutter('creating repository in %s.', a_bzrdir.transport.base)
1137
1136
 
1138
1137
    def __init__(self):
1139
1138
        super(RepositoryFormat4, self).__init__()
1140
 
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat4()
 
1139
        self._matchingbzrdir = bzrdir.BzrDirFormat4()
1141
1140
 
1142
1141
    def get_format_description(self):
1143
1142
        """See RepositoryFormat.get_format_description()."""
1186
1185
 
1187
1186
    def __init__(self):
1188
1187
        super(RepositoryFormat5, self).__init__()
1189
 
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat5()
 
1188
        self._matchingbzrdir = bzrdir.BzrDirFormat5()
1190
1189
 
1191
1190
    def get_format_description(self):
1192
1191
        """See RepositoryFormat.get_format_description()."""
1216
1215
 
1217
1216
    def __init__(self):
1218
1217
        super(RepositoryFormat6, self).__init__()
1219
 
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat6()
 
1218
        self._matchingbzrdir = bzrdir.BzrDirFormat6()
1220
1219
 
1221
1220
    def get_format_description(self):
1222
1221
        """See RepositoryFormat.get_format_description()."""
1240
1239
 
1241
1240
    def __init__(self):
1242
1241
        super(MetaDirRepositoryFormat, self).__init__()
1243
 
        self._matchingbzrdir = bzrlib.bzrdir.BzrDirMetaFormat1()
 
1242
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1244
1243
 
1245
1244
    def _create_control_files(self, a_bzrdir):
1246
1245
        """Create the required files and the initial control_files object."""
1321
1320
 
1322
1321
        # Create an empty weave
1323
1322
        sio = StringIO()
1324
 
        bzrlib.weavefile.write_weave_v5(Weave(), sio)
 
1323
        write_weave_v5(Weave(), sio)
1325
1324
        empty_weave = sio.getvalue()
1326
1325
 
1327
1326
        mutter('creating repository in %s.', a_bzrdir.transport.base)
1432
1431
        repo_transport = a_bzrdir.get_repository_transport(None)
1433
1432
        control_files = LockableFiles(repo_transport, 'lock', LockDir)
1434
1433
        control_store = self._get_control_store(repo_transport, control_files)
1435
 
        transaction = bzrlib.transactions.WriteTransaction()
 
1434
        transaction = transactions.WriteTransaction()
1436
1435
        # trigger a write of the inventory store.
1437
1436
        control_store.get_weave_or_empty('inventory', transaction)
1438
1437
        _revision_store = self._get_revision_store(repo_transport, control_files)
1641
1640
                pass
1642
1641
            # FIXME do not peek!
1643
1642
            if self.source.control_files._transport.listable():
1644
 
                pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
1643
                pb = ui.ui_factory.nested_progress_bar()
1645
1644
                try:
1646
1645
                    self.target.weave_store.copy_all_ids(
1647
1646
                        self.source.weave_store,
2070
2069
            # TODO: Rather than invoking sha_strings here, _add_text_to_weave
2071
2070
            # should return the SHA1 and size
2072
2071
            self._add_text_to_weave(file_id, new_lines, file_parents.keys())
2073
 
            return bzrlib.osutils.sha_strings(new_lines), \
 
2072
            return osutils.sha_strings(new_lines), \
2074
2073
                sum(map(len, new_lines))
2075
2074
 
2076
2075
    def modified_link(self, file_id, file_parents, link_target):