~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-08 08:12:00 UTC
  • mfrom: (2858.2.5 remove-checks)
  • Revision ID: pqm@pqm.ubuntu.com-20071008081200-04a0byt5lo5tyft9
Remove old calls to safe_file_id and safe_revision_id (mbp)

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
            self._committer = committer
97
97
 
98
98
        self.new_inventory = Inventory(None)
99
 
        self._new_revision_id = osutils.safe_revision_id(revision_id)
 
99
        self._new_revision_id = revision_id
100
100
        self.parents = parents
101
101
        self.repository = repository
102
102
 
500
500
 
501
501
        returns the sha1 of the serialized inventory.
502
502
        """
503
 
        revision_id = osutils.safe_revision_id(revision_id)
504
503
        _mod_revision.check_not_reserved_id(revision_id)
505
504
        assert inv.revision_id is None or inv.revision_id == revision_id, \
506
505
            "Mismatch between inventory revision" \
533
532
                       If supplied its signature_needed method will be used
534
533
                       to determine if a signature should be made.
535
534
        """
536
 
        revision_id = osutils.safe_revision_id(revision_id)
537
535
        # TODO: jam 20070210 Shouldn't we check rev.revision_id and
538
536
        #       rev.parent_ids?
539
537
        _mod_revision.check_not_reserved_id(revision_id)
765
763
 
766
764
        revision_id: only return revision ids included by revision_id.
767
765
        """
768
 
        revision_id = osutils.safe_revision_id(revision_id)
769
766
        return InterRepository.get(other, self).missing_revision_ids(revision_id)
770
767
 
771
768
    @staticmethod
784
781
        This is a destructive operation! Do not use it on existing 
785
782
        repositories.
786
783
        """
787
 
        revision_id = osutils.safe_revision_id(revision_id)
788
784
        return InterRepository.get(self, destination).copy_content(revision_id)
789
785
 
790
786
    def commit_write_group(self):
814
810
 
815
811
        If revision_id is None all content is copied.
816
812
        """
817
 
        revision_id = osutils.safe_revision_id(revision_id)
818
813
        # fast path same-url fetch operations
819
814
        if self.has_same_location(source):
820
815
            # check that last_revision is in 'from' and then return a
846
841
        :param revprops: Optional dictionary of revision properties.
847
842
        :param revision_id: Optional revision id.
848
843
        """
849
 
        revision_id = osutils.safe_revision_id(revision_id)
850
844
        result = self._commit_builder_class(self, parents, config,
851
845
            timestamp, timezone, committer, revprops, revision_id)
852
846
        self.start_write_group()
932
926
        """True if this repository has a copy of the revision."""
933
927
        if 'evil' in debug.debug_flags:
934
928
            mutter_callsite(3, "has_revision is a LBYL symptom.")
935
 
        revision_id = osutils.safe_revision_id(revision_id)
936
929
        return self._revision_store.has_revision_id(revision_id,
937
930
                                                    self.get_transaction())
938
931
 
960
953
    @needs_read_lock
961
954
    def _get_revisions(self, revision_ids):
962
955
        """Core work logic to get many revisions without sanity checks."""
963
 
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
964
956
        for rev_id in revision_ids:
965
957
            if not rev_id or not isinstance(rev_id, basestring):
966
958
                raise errors.InvalidRevisionId(revision_id=rev_id, branch=self)
977
969
        # TODO: jam 20070210 This shouldn't be necessary since get_revision
978
970
        #       would have already do it.
979
971
        # TODO: jam 20070210 Just use _serializer.write_revision_to_string()
980
 
        revision_id = osutils.safe_revision_id(revision_id)
981
972
        rev = self.get_revision(revision_id)
982
973
        rev_tmp = StringIO()
983
974
        # the current serializer..
1018
1009
 
1019
1010
    @needs_write_lock
1020
1011
    def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
1021
 
        revision_id = osutils.safe_revision_id(revision_id)
1022
1012
        signature = gpg_strategy.sign(plaintext)
1023
1013
        self._revision_store.add_revision_signature_text(revision_id,
1024
1014
                                                         signature,
1035
1025
        assert self._serializer.support_altered_by_hack, \
1036
1026
            ("fileids_altered_by_revision_ids only supported for branches " 
1037
1027
             "which store inventory as unnested xml, not on %r" % self)
1038
 
        selected_revision_ids = set(osutils.safe_revision_id(r)
1039
 
                                    for r in revision_ids)
 
1028
        selected_revision_ids = set(revision_ids)
1040
1029
        w = self.get_inventory_weave()
1041
1030
        result = {}
1042
1031
 
1184
1173
    @needs_read_lock
1185
1174
    def get_inventory(self, revision_id):
1186
1175
        """Get Inventory object by hash."""
1187
 
        # TODO: jam 20070210 Technically we don't need to sanitize, since all
1188
 
        #       called functions must sanitize.
1189
 
        revision_id = osutils.safe_revision_id(revision_id)
1190
1176
        return self.deserialise_inventory(
1191
1177
            revision_id, self.get_inventory_xml(revision_id))
1192
1178
 
1196
1182
        :param revision_id: The expected revision id of the inventory.
1197
1183
        :param xml: A serialised inventory.
1198
1184
        """
1199
 
        revision_id = osutils.safe_revision_id(revision_id)
1200
1185
        result = self._serializer.read_inventory_from_string(xml)
1201
1186
        result.root.revision = revision_id
1202
1187
        return result
1213
1198
    @needs_read_lock
1214
1199
    def get_inventory_xml(self, revision_id):
1215
1200
        """Get inventory XML as a file object."""
1216
 
        revision_id = osutils.safe_revision_id(revision_id)
1217
1201
        try:
1218
1202
            assert isinstance(revision_id, str), type(revision_id)
1219
1203
            iw = self.get_inventory_weave()
1225
1209
    def get_inventory_sha1(self, revision_id):
1226
1210
        """Return the sha1 hash of the inventory entry
1227
1211
        """
1228
 
        # TODO: jam 20070210 Shouldn't this be deprecated / removed?
1229
 
        revision_id = osutils.safe_revision_id(revision_id)
1230
1212
        return self.get_revision(revision_id).inventory_sha1
1231
1213
 
1232
1214
    @needs_read_lock
1258
1240
            pending = set(self.all_revision_ids())
1259
1241
            required = set([])
1260
1242
        else:
1261
 
            pending = set(osutils.safe_revision_id(r) for r in revision_ids)
 
1243
            pending = set(revision_ids)
1262
1244
            # special case NULL_REVISION
1263
1245
            if _mod_revision.NULL_REVISION in pending:
1264
1246
                pending.remove(_mod_revision.NULL_REVISION)
1297
1279
        :param revision_id: The revision id to start with.  All its lefthand
1298
1280
            ancestors will be traversed.
1299
1281
        """
1300
 
        revision_id = osutils.safe_revision_id(revision_id)
1301
1282
        if revision_id in (None, _mod_revision.NULL_REVISION):
1302
1283
            return
1303
1284
        next_id = revision_id
1361
1342
            return RevisionTree(self, Inventory(root_id=None), 
1362
1343
                                _mod_revision.NULL_REVISION)
1363
1344
        else:
1364
 
            revision_id = osutils.safe_revision_id(revision_id)
1365
1345
            inv = self.get_revision_inventory(revision_id)
1366
1346
            return RevisionTree(self, inv, revision_id)
1367
1347
 
1389
1369
        """
1390
1370
        if _mod_revision.is_null(revision_id):
1391
1371
            return [None]
1392
 
        revision_id = osutils.safe_revision_id(revision_id)
1393
1372
        if not self.has_revision(revision_id):
1394
1373
            raise errors.NoSuchRevision(self, revision_id)
1395
1374
        w = self.get_inventory_weave()
1415
1394
        - it writes to stdout, it assumes that that is valid etc. Fix
1416
1395
        by creating a new more flexible convenience function.
1417
1396
        """
1418
 
        revision_id = osutils.safe_revision_id(revision_id)
1419
1397
        tree = self.revision_tree(revision_id)
1420
1398
        # use inventory as it was in that revision
1421
1399
        file_id = tree.inventory.path2id(file)
1430
1408
        return self.control_files.get_transaction()
1431
1409
 
1432
1410
    def revision_parents(self, revision_id):
1433
 
        revision_id = osutils.safe_revision_id(revision_id)
1434
1411
        return self.get_inventory_weave().parent_names(revision_id)
1435
1412
 
1436
1413
    def get_parents(self, revision_ids):
1481
1458
 
1482
1459
    @needs_write_lock
1483
1460
    def sign_revision(self, revision_id, gpg_strategy):
1484
 
        revision_id = osutils.safe_revision_id(revision_id)
1485
1461
        plaintext = Testament.from_revision(self, revision_id).as_short_text()
1486
1462
        self.store_revision_signature(gpg_strategy, plaintext, revision_id)
1487
1463
 
1488
1464
    @needs_read_lock
1489
1465
    def has_signature_for_revision_id(self, revision_id):
1490
1466
        """Query for a revision signature for revision_id in the repository."""
1491
 
        revision_id = osutils.safe_revision_id(revision_id)
1492
1467
        return self._revision_store.has_signature(revision_id,
1493
1468
                                                  self.get_transaction())
1494
1469
 
1495
1470
    @needs_read_lock
1496
1471
    def get_signature_text(self, revision_id):
1497
1472
        """Return the text for a signature."""
1498
 
        revision_id = osutils.safe_revision_id(revision_id)
1499
1473
        return self._revision_store.get_signature_text(revision_id,
1500
1474
                                                       self.get_transaction())
1501
1475
 
1511
1485
        if not revision_ids:
1512
1486
            raise ValueError("revision_ids must be non-empty in %s.check" 
1513
1487
                    % (self,))
1514
 
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1515
1488
        return self._check(revision_ids)
1516
1489
 
1517
1490
    def _check(self, revision_ids):
1965
1938
        # generic, possibly worst case, slow code path.
1966
1939
        target_ids = set(self.target.all_revision_ids())
1967
1940
        if revision_id is not None:
1968
 
            # TODO: jam 20070210 InterRepository is internal enough that it
1969
 
            #       should assume revision_ids are already utf-8
1970
 
            revision_id = osutils.safe_revision_id(revision_id)
1971
1941
            source_ids = self.source.get_ancestry(revision_id)
1972
1942
            assert source_ids[0] is None
1973
1943
            source_ids.pop(0)
2026
1996
            self.target.set_make_working_trees(self.source.make_working_trees())
2027
1997
        except NotImplementedError:
2028
1998
            pass
2029
 
        # TODO: jam 20070210 This is fairly internal, so we should probably
2030
 
        #       just assert that revision_id is not unicode.
2031
 
        revision_id = osutils.safe_revision_id(revision_id)
2032
1999
        # but don't bother fetching if we have the needed data now.
2033
2000
        if (revision_id not in (None, _mod_revision.NULL_REVISION) and 
2034
2001
            self.target.has_revision(revision_id)):
2040
2007
        """See InterRepository.fetch()."""
2041
2008
        from bzrlib.fetch import GenericRepoFetcher
2042
2009
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2043
 
               self.source, self.source._format, self.target, 
 
2010
               self.source, self.source._format, self.target,
2044
2011
               self.target._format)
2045
 
        # TODO: jam 20070210 This should be an assert, not a translate
2046
 
        revision_id = osutils.safe_revision_id(revision_id)
2047
2012
        f = GenericRepoFetcher(to_repository=self.target,
2048
2013
                               from_repository=self.source,
2049
2014
                               last_revision=revision_id,
2090
2055
    def copy_content(self, revision_id=None):
2091
2056
        """See InterRepository.copy_content()."""
2092
2057
        # weave specific optimised path:
2093
 
        # TODO: jam 20070210 Internal, should be an assert, not translate
2094
 
        revision_id = osutils.safe_revision_id(revision_id)
2095
2058
        try:
2096
2059
            self.target.set_make_working_trees(self.source.make_working_trees())
2097
2060
        except NotImplementedError:
2124
2087
        from bzrlib.fetch import GenericRepoFetcher
2125
2088
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2126
2089
               self.source, self.source._format, self.target, self.target._format)
2127
 
        # TODO: jam 20070210 This should be an assert, not a translate
2128
 
        revision_id = osutils.safe_revision_id(revision_id)
2129
2090
        f = GenericRepoFetcher(to_repository=self.target,
2130
2091
                               from_repository=self.source,
2131
2092
                               last_revision=revision_id,
2204
2165
        from bzrlib.fetch import KnitRepoFetcher
2205
2166
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2206
2167
               self.source, self.source._format, self.target, self.target._format)
2207
 
        # TODO: jam 20070210 This should be an assert, not a translate
2208
 
        revision_id = osutils.safe_revision_id(revision_id)
2209
2168
        f = KnitRepoFetcher(to_repository=self.target,
2210
2169
                            from_repository=self.source,
2211
2170
                            last_revision=revision_id,
2260
2219
    def fetch(self, revision_id=None, pb=None):
2261
2220
        """See InterRepository.fetch()."""
2262
2221
        from bzrlib.fetch import Model1toKnit2Fetcher
2263
 
        # TODO: jam 20070210 This should be an assert, not a translate
2264
 
        revision_id = osutils.safe_revision_id(revision_id)
2265
2222
        f = Model1toKnit2Fetcher(to_repository=self.target,
2266
2223
                                 from_repository=self.source,
2267
2224
                                 last_revision=revision_id,
2282
2239
            self.target.set_make_working_trees(self.source.make_working_trees())
2283
2240
        except NotImplementedError:
2284
2241
            pass
2285
 
        # TODO: jam 20070210 Internal, assert, don't translate
2286
 
        revision_id = osutils.safe_revision_id(revision_id)
2287
2242
        # but don't bother fetching if we have the needed data now.
2288
2243
        if (revision_id not in (None, _mod_revision.NULL_REVISION) and 
2289
2244
            self.target.has_revision(revision_id)):
2316
2271
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2317
2272
               self.source, self.source._format, self.target, 
2318
2273
               self.target._format)
2319
 
        # TODO: jam 20070210 This should be an assert, not a translate
2320
 
        revision_id = osutils.safe_revision_id(revision_id)
2321
2274
        f = Knit1to2Fetcher(to_repository=self.target,
2322
2275
                            from_repository=self.source,
2323
2276
                            last_revision=revision_id,