/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: John Arbash Meinel
  • Date: 2007-02-10 16:54:29 UTC
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070210165429-xbz7zv9ehhi6fspj
Finish auditing Repository, and fix generate_ids to always generate utf8 ids.

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
                       to determine if a signature should be made.
134
134
        """
135
135
        revision_id = osutils.safe_revision_id(revision_id)
 
136
        # TODO: jam 20070210 Shouldn't we check rev.revision_id and
 
137
        #       rev.parent_ids?
136
138
        _mod_revision.check_not_reserved_id(revision_id)
137
139
        if config is not None and config.signature_needed():
138
140
            if inv is None:
174
176
        if self._revision_store.text_store.listable():
175
177
            return self._revision_store.all_revision_ids(self.get_transaction())
176
178
        result = self._all_possible_ids()
 
179
        # TODO: jam 20070210 Ensure that _all_possible_ids returns non-unicode
 
180
        #       ids. (It should, since _revision_store's API should change to
 
181
        #       return utf8 revision_ids)
177
182
        return self._eliminate_revisions_not_present(result)
178
183
 
179
184
    def break_lock(self):
253
258
 
254
259
        revision_id: only return revision ids included by revision_id.
255
260
        """
 
261
        revision_id = osutils.safe_revision_id(revision_id)
256
262
        return InterRepository.get(other, self).missing_revision_ids(revision_id)
257
263
 
258
264
    @staticmethod
271
277
        This is a destructive operation! Do not use it on existing 
272
278
        repositories.
273
279
        """
 
280
        revision_id = osutils.safe_revision_id(revision_id)
274
281
        return InterRepository.get(self, destination).copy_content(revision_id, basis)
275
282
 
276
283
    def fetch(self, source, revision_id=None, pb=None):
278
285
 
279
286
        If revision_id is None all content is copied.
280
287
        """
 
288
        revision_id = osutils.safe_revision_id(revision_id)
281
289
        return InterRepository.get(source, self).fetch(revision_id=revision_id,
282
290
                                                       pb=pb)
283
291
 
326
334
    @needs_read_lock
327
335
    def has_revision(self, revision_id):
328
336
        """True if this repository has a copy of the revision."""
 
337
        revision_id = osutils.safe_revision_id(revision_id)
329
338
        return self._revision_store.has_revision_id(revision_id,
330
339
                                                    self.get_transaction())
331
340
 
341
350
        if not revision_id or not isinstance(revision_id, basestring):
342
351
            raise errors.InvalidRevisionId(revision_id=revision_id,
343
352
                                           branch=self)
344
 
        return self._revision_store.get_revisions([revision_id],
345
 
                                                  self.get_transaction())[0]
 
353
        return self.get_revisions([revision_id])[0]
 
354
 
346
355
    @needs_read_lock
347
356
    def get_revisions(self, revision_ids):
348
 
        return self._revision_store.get_revisions(revision_ids,
 
357
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
 
358
        revs = self._revision_store.get_revisions(revision_ids,
349
359
                                                  self.get_transaction())
 
360
        for rev in revs:
 
361
            assert not isinstance(rev.revision_id, unicode)
 
362
            for parent_id in rev.parent_ids:
 
363
                assert not isinstance(parent_id, unicode)
 
364
        return revs
350
365
 
351
366
    @needs_read_lock
352
367
    def get_revision_xml(self, revision_id):
353
 
        rev = self.get_revision(revision_id) 
 
368
        # TODO: jam 20070210 This shouldn't be necessary since get_revision
 
369
        #       would have already do it.
 
370
        # TODO: jam 20070210 Just use _serializer.write_revision_to_string()
 
371
        revision_id = osutils.safe_revision_id(revision_id)
 
372
        rev = self.get_revision(revision_id)
354
373
        rev_tmp = StringIO()
355
374
        # the current serializer..
356
375
        self._revision_store._serializer.write_revision(rev, rev_tmp)
360
379
    @needs_read_lock
361
380
    def get_revision(self, revision_id):
362
381
        """Return the Revision object for a named revision"""
 
382
        # TODO: jam 20070210 get_revision_reconcile should do this for us
 
383
        revision_id = osutils.safe_revision_id(revision_id)
363
384
        r = self.get_revision_reconcile(revision_id)
364
385
        # weave corruption can lead to absent revision markers that should be
365
386
        # present.
421
442
 
422
443
    @needs_write_lock
423
444
    def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
 
445
        revision_id = osutils.safe_revision_id(revision_id)
424
446
        signature = gpg_strategy.sign(plaintext)
425
447
        self._revision_store.add_revision_signature_text(revision_id,
426
448
                                                         signature,
437
459
        assert self._serializer.support_altered_by_hack, \
438
460
            ("fileids_altered_by_revision_ids only supported for branches " 
439
461
             "which store inventory as unnested xml, not on %r" % self)
440
 
        selected_revision_ids = set(revision_ids)
 
462
        selected_revision_ids = set(osutils.safe_revision_id(r)
 
463
                                    for r in revision_ids)
441
464
        w = self.get_inventory_weave()
442
465
        result = {}
443
466
 
507
530
    @needs_read_lock
508
531
    def get_inventory(self, revision_id):
509
532
        """Get Inventory object by hash."""
 
533
        # TODO: jam 20070210 Technically we don't need to sanitize, since all
 
534
        #       called functions must sanitize.
 
535
        revision_id = osutils.safe_revision_id(revision_id)
510
536
        return self.deserialise_inventory(
511
537
            revision_id, self.get_inventory_xml(revision_id))
512
538
 
516
542
        :param revision_id: The expected revision id of the inventory.
517
543
        :param xml: A serialised inventory.
518
544
        """
 
545
        revision_id = osutils.safe_revision_id(revision_id)
519
546
        result = self._serializer.read_inventory_from_string(xml)
520
547
        result.root.revision = revision_id
521
548
        return result
526
553
    @needs_read_lock
527
554
    def get_inventory_xml(self, revision_id):
528
555
        """Get inventory XML as a file object."""
 
556
        revision_id = osutils.safe_revision_id(revision_id)
529
557
        try:
530
 
            assert isinstance(revision_id, basestring), type(revision_id)
 
558
            assert isinstance(revision_id, str), type(revision_id)
531
559
            iw = self.get_inventory_weave()
532
560
            return iw.get_text(revision_id)
533
561
        except IndexError:
537
565
    def get_inventory_sha1(self, revision_id):
538
566
        """Return the sha1 hash of the inventory entry
539
567
        """
 
568
        # TODO: jam 20070210 Shouldn't this be deprecated / removed?
 
569
        revision_id = osutils.safe_revision_id(revision_id)
540
570
        return self.get_revision(revision_id).inventory_sha1
541
571
 
542
572
    @needs_read_lock
551
581
        # special case NULL_REVISION
552
582
        if revision_id == _mod_revision.NULL_REVISION:
553
583
            return {}
 
584
        revision_id = osutils.safe_revision_id(revision_id)
554
585
        a_weave = self.get_inventory_weave()
555
586
        all_revisions = self._eliminate_revisions_not_present(
556
587
                                a_weave.versions())
584
615
            pending = set(self.all_revision_ids())
585
616
            required = set([])
586
617
        else:
587
 
            pending = set(revision_ids)
 
618
            pending = set(osutils.safe_revision_id(r) for r in revision_ids)
588
619
            # special case NULL_REVISION
589
620
            if _mod_revision.NULL_REVISION in pending:
590
621
                pending.remove(_mod_revision.NULL_REVISION)
651
682
            return RevisionTree(self, Inventory(root_id=None), 
652
683
                                _mod_revision.NULL_REVISION)
653
684
        else:
 
685
            revision_id = osutils.safe_revision_id(revision_id)
654
686
            inv = self.get_revision_inventory(revision_id)
655
687
            return RevisionTree(self, inv, revision_id)
656
688
 
678
710
        """
679
711
        if revision_id is None:
680
712
            return [None]
 
713
        revision_id = osutils.safe_revision_id(revision_id)
681
714
        if not self.has_revision(revision_id):
682
715
            raise errors.NoSuchRevision(self, revision_id)
683
716
        w = self.get_inventory_weave()
692
725
        - it writes to stdout, it assumes that that is valid etc. Fix
693
726
        by creating a new more flexible convenience function.
694
727
        """
 
728
        revision_id = osutils.safe_revision_id(revision_id)
695
729
        tree = self.revision_tree(revision_id)
696
730
        # use inventory as it was in that revision
697
731
        file_id = tree.inventory.path2id(file)
705
739
    def get_transaction(self):
706
740
        return self.control_files.get_transaction()
707
741
 
708
 
    def revision_parents(self, revid):
709
 
        return self.get_inventory_weave().parent_names(revid)
 
742
    def revision_parents(self, revision_id):
 
743
        revision_id = osutils.safe_revision_id(revision_id)
 
744
        return self.get_inventory_weave().parent_names(revision_id)
710
745
 
711
746
    @needs_write_lock
712
747
    def set_make_working_trees(self, new_value):
726
761
 
727
762
    @needs_write_lock
728
763
    def sign_revision(self, revision_id, gpg_strategy):
 
764
        revision_id = osutils.safe_revision_id(revision_id)
729
765
        plaintext = Testament.from_revision(self, revision_id).as_short_text()
730
766
        self.store_revision_signature(gpg_strategy, plaintext, revision_id)
731
767
 
732
768
    @needs_read_lock
733
769
    def has_signature_for_revision_id(self, revision_id):
734
770
        """Query for a revision signature for revision_id in the repository."""
 
771
        revision_id = osutils.safe_revision_id(revision_id)
735
772
        return self._revision_store.has_signature(revision_id,
736
773
                                                  self.get_transaction())
737
774
 
738
775
    @needs_read_lock
739
776
    def get_signature_text(self, revision_id):
740
777
        """Return the text for a signature."""
 
778
        revision_id = osutils.safe_revision_id(revision_id)
741
779
        return self._revision_store.get_signature_text(revision_id,
742
780
                                                       self.get_transaction())
743
781
 
753
791
        if not revision_ids:
754
792
            raise ValueError("revision_ids must be non-empty in %s.check" 
755
793
                    % (self,))
 
794
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
756
795
        return self._check(revision_ids)
757
796
 
758
797
    def _check(self, revision_ids):
973
1012
        This determines the set of revisions which are involved, and then
974
1013
        finds all file ids affected by those revisions.
975
1014
        """
 
1015
        # TODO: jam 20070210 Is this function even used?
 
1016
        from_revid = osutils.safe_revision_id(from_revid)
 
1017
        to_revid = osutils.safe_revision_id(to_revid)
976
1018
        vf = self._get_revision_vf()
977
1019
        from_set = set(vf.get_ancestry(from_revid))
978
1020
        to_set = set(vf.get_ancestry(to_revid))
984
1026
 
985
1027
        :param last_revid: If None, last_revision() will be used.
986
1028
        """
 
1029
        # TODO: jam 20070210 Is this used anymore?
987
1030
        if not last_revid:
988
1031
            changed = set(self.all_revision_ids())
989
1032
        else:
1000
1043
        """
1001
1044
        if revision_id is None:
1002
1045
            return [None]
 
1046
        revision_id = osutils.safe_revision_id(revision_id)
1003
1047
        vf = self._get_revision_vf()
1004
1048
        try:
1005
1049
            return [None] + vf.get_ancestry(revision_id)
1009
1053
    @needs_read_lock
1010
1054
    def get_revision(self, revision_id):
1011
1055
        """Return the Revision object for a named revision"""
 
1056
        revision_id = osutils.safe_revision_id(revision_id)
1012
1057
        return self.get_revision_reconcile(revision_id)
1013
1058
 
1014
1059
    @needs_read_lock
1023
1068
        # special case NULL_REVISION
1024
1069
        if revision_id == _mod_revision.NULL_REVISION:
1025
1070
            return {}
 
1071
        revision_id = osutils.safe_revision_id(revision_id)
1026
1072
        a_weave = self._get_revision_vf()
1027
1073
        entire_graph = a_weave.get_graph()
1028
1074
        if revision_id is None:
1055
1101
            pending = set(self.all_revision_ids())
1056
1102
            required = set([])
1057
1103
        else:
1058
 
            pending = set(revision_ids)
 
1104
            pending = set(osutils.safe_revision_id(r) for r in revision_ids)
1059
1105
            # special case NULL_REVISION
1060
1106
            if _mod_revision.NULL_REVISION in pending:
1061
1107
                pending.remove(_mod_revision.NULL_REVISION)
1096
1142
        return reconciler
1097
1143
    
1098
1144
    def revision_parents(self, revision_id):
 
1145
        revision_id = osutils.safe_revision_id(revision_id)
1099
1146
        return self._get_revision_vf().get_parents(revision_id)
1100
1147
 
1101
1148
 
1141
1188
        :param revprops: Optional dictionary of revision properties.
1142
1189
        :param revision_id: Optional revision id.
1143
1190
        """
 
1191
        revision_id = osutils.safe_revision_id(revision_id)
1144
1192
        return RootCommitBuilder(self, parents, config, timestamp, timezone,
1145
1193
                                 committer, revprops, revision_id)
1146
1194
 
1884
1932
        # generic, possibly worst case, slow code path.
1885
1933
        target_ids = set(self.target.all_revision_ids())
1886
1934
        if revision_id is not None:
 
1935
            # TODO: jam 20070210 InterRepository is internal enough that it
 
1936
            #       should assume revision_ids are already utf-8
 
1937
            revision_id = osutils.safe_revision_id(revision_id)
1887
1938
            source_ids = self.source.get_ancestry(revision_id)
1888
1939
            assert source_ids[0] is None
1889
1940
            source_ids.pop(0)
1931
1982
            self.target.set_make_working_trees(self.source.make_working_trees())
1932
1983
        except NotImplementedError:
1933
1984
            pass
 
1985
        # TODO: jam 20070210 This is fairly internal, so we should probably
 
1986
        #       just assert that revision_id is not unicode.
 
1987
        revision_id = osutils.safe_revision_id(revision_id)
1934
1988
        # grab the basis available data
1935
1989
        if basis is not None:
1936
1990
            self.target.fetch(basis, revision_id=revision_id)
1947
2001
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
1948
2002
               self.source, self.source._format, self.target, 
1949
2003
               self.target._format)
 
2004
        # TODO: jam 20070210 This should be an assert, not a translate
 
2005
        revision_id = osutils.safe_revision_id(revision_id)
1950
2006
        f = GenericRepoFetcher(to_repository=self.target,
1951
2007
                               from_repository=self.source,
1952
2008
                               last_revision=revision_id,
1982
2038
    def copy_content(self, revision_id=None, basis=None):
1983
2039
        """See InterRepository.copy_content()."""
1984
2040
        # weave specific optimised path:
 
2041
        # TODO: jam 20070210 Internal, should be an assert, not translate
 
2042
        revision_id = osutils.safe_revision_id(revision_id)
1985
2043
        if basis is not None:
1986
2044
            # copy the basis in, then fetch remaining data.
1987
2045
            basis.copy_content_into(self.target, revision_id)
2024
2082
        from bzrlib.fetch import GenericRepoFetcher
2025
2083
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2026
2084
               self.source, self.source._format, self.target, self.target._format)
 
2085
        # TODO: jam 20070210 This should be an assert, not a translate
 
2086
        revision_id = osutils.safe_revision_id(revision_id)
2027
2087
        f = GenericRepoFetcher(to_repository=self.target,
2028
2088
                               from_repository=self.source,
2029
2089
                               last_revision=revision_id,
2098
2158
        from bzrlib.fetch import KnitRepoFetcher
2099
2159
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2100
2160
               self.source, self.source._format, self.target, self.target._format)
 
2161
        # TODO: jam 20070210 This should be an assert, not a translate
 
2162
        revision_id = osutils.safe_revision_id(revision_id)
2101
2163
        f = KnitRepoFetcher(to_repository=self.target,
2102
2164
                            from_repository=self.source,
2103
2165
                            last_revision=revision_id,
2154
2216
    def fetch(self, revision_id=None, pb=None):
2155
2217
        """See InterRepository.fetch()."""
2156
2218
        from bzrlib.fetch import Model1toKnit2Fetcher
 
2219
        # TODO: jam 20070210 This should be an assert, not a translate
 
2220
        revision_id = osutils.safe_revision_id(revision_id)
2157
2221
        f = Model1toKnit2Fetcher(to_repository=self.target,
2158
2222
                                 from_repository=self.source,
2159
2223
                                 last_revision=revision_id,
2175
2239
            self.target.set_make_working_trees(self.source.make_working_trees())
2176
2240
        except NotImplementedError:
2177
2241
            pass
 
2242
        # TODO: jam 20070210 Internal, assert, don't translate
 
2243
        revision_id = osutils.safe_revision_id(revision_id)
2178
2244
        # grab the basis available data
2179
2245
        if basis is not None:
2180
2246
            self.target.fetch(basis, revision_id=revision_id)
2205
2271
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2206
2272
               self.source, self.source._format, self.target, 
2207
2273
               self.target._format)
 
2274
        # TODO: jam 20070210 This should be an assert, not a translate
 
2275
        revision_id = osutils.safe_revision_id(revision_id)
2208
2276
        f = Knit1to2Fetcher(to_repository=self.target,
2209
2277
                            from_repository=self.source,
2210
2278
                            last_revision=revision_id,
2388
2456
            self._committer = committer
2389
2457
 
2390
2458
        self.new_inventory = Inventory(None)
2391
 
        self._new_revision_id = revision_id
 
2459
        self._new_revision_id = osutils.safe_revision_id(revision_id)
2392
2460
        self.parents = parents
2393
2461
        self.repository = repository
2394
2462