~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
484
484
    @needs_read_lock
485
485
    def is_shared(self):
486
486
        """Return True if this repository is flagged as a shared repository."""
487
 
        # FIXME format 4-6 cannot be shared, this is technically faulty.
488
 
        return self.control_files._transport.has('shared-storage')
 
487
        raise NotImplementedError(self.is_shared)
489
488
 
490
489
    @needs_write_lock
491
490
    def reconcile(self):
564
563
        :param new_value: True to restore the default, False to disable making
565
564
                          working trees.
566
565
        """
567
 
        # FIXME: split out into a new class/strategy ?
568
 
        if isinstance(self._format, (RepositoryFormat4,
569
 
                                     RepositoryFormat5,
570
 
                                     RepositoryFormat6)):
571
 
            raise NotImplementedError(self.set_make_working_trees)
572
 
        if new_value:
573
 
            try:
574
 
                self.control_files._transport.delete('no-working-trees')
575
 
            except errors.NoSuchFile:
576
 
                pass
577
 
        else:
578
 
            self.control_files.put_utf8('no-working-trees', '')
 
566
        raise NotImplementedError(self.set_make_working_trees)
579
567
    
580
568
    def make_working_trees(self):
581
569
        """Returns the policy for making working trees on new branches."""
582
 
        # FIXME: split out into a new class/strategy ?
583
 
        if isinstance(self._format, (RepositoryFormat4,
584
 
                                     RepositoryFormat5,
585
 
                                     RepositoryFormat6)):
586
 
            return True
587
 
        return not self.control_files._transport.has('no-working-trees')
 
570
        raise NotImplementedError(self.make_working_trees)
588
571
 
589
572
    @needs_write_lock
590
573
    def sign_revision(self, revision_id, gpg_strategy):
651
634
            text_store = get_store('text-store')
652
635
        super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store)
653
636
 
 
637
    @needs_read_lock
 
638
    def is_shared(self):
 
639
        """AllInOne repositories cannot be shared."""
 
640
        return False
 
641
 
 
642
    @needs_write_lock
 
643
    def set_make_working_trees(self, new_value):
 
644
        """Set the policy flag for making working trees when creating branches.
 
645
 
 
646
        This only applies to branches that use this repository.
 
647
 
 
648
        The default is 'True'.
 
649
        :param new_value: True to restore the default, False to disable making
 
650
                          working trees.
 
651
        """
 
652
        raise NotImplementedError(self.set_make_working_trees)
 
653
    
 
654
    def make_working_trees(self):
 
655
        """Returns the policy for making working trees on new branches."""
 
656
        return True
 
657
 
654
658
 
655
659
class MetaDirRepository(Repository):
656
660
    """Repositories in the new meta-dir layout."""
680
684
                ws.enable_cache = True
681
685
            return ws
682
686
 
 
687
    @needs_read_lock
 
688
    def is_shared(self):
 
689
        """Return True if this repository is flagged as a shared repository."""
 
690
        return self.control_files._transport.has('shared-storage')
 
691
 
 
692
    @needs_write_lock
 
693
    def set_make_working_trees(self, new_value):
 
694
        """Set the policy flag for making working trees when creating branches.
 
695
 
 
696
        This only applies to branches that use this repository.
 
697
 
 
698
        The default is 'True'.
 
699
        :param new_value: True to restore the default, False to disable making
 
700
                          working trees.
 
701
        """
 
702
        if new_value:
 
703
            try:
 
704
                self.control_files._transport.delete('no-working-trees')
 
705
            except errors.NoSuchFile:
 
706
                pass
 
707
        else:
 
708
            self.control_files.put_utf8('no-working-trees', '')
 
709
    
 
710
    def make_working_trees(self):
 
711
        """Returns the policy for making working trees on new branches."""
 
712
        return not self.control_files._transport.has('no-working-trees')
 
713
 
683
714
 
684
715
class KnitRepository(MetaDirRepository):
685
716
    """Knit format repository."""
689
720
        """See Repository.all_revision_ids()."""
690
721
        return self._revision_store.all_revision_ids(self.get_transaction())
691
722
 
 
723
    def fileid_involved_between_revs(self, from_revid, to_revid):
 
724
        """Find file_id(s) which are involved in the changes between revisions.
 
725
 
 
726
        This determines the set of revisions which are involved, and then
 
727
        finds all file ids affected by those revisions.
 
728
        """
 
729
        vf = self._get_revision_vf()
 
730
        from_set = set(vf.get_ancestry(from_revid))
 
731
        to_set = set(vf.get_ancestry(to_revid))
 
732
        changed = to_set.difference(from_set)
 
733
        return self._fileid_involved_by_set(changed)
 
734
 
 
735
    def fileid_involved(self, last_revid=None):
 
736
        """Find all file_ids modified in the ancestry of last_revid.
 
737
 
 
738
        :param last_revid: If None, last_revision() will be used.
 
739
        """
 
740
        if not last_revid:
 
741
            changed = set(self.all_revision_ids())
 
742
        else:
 
743
            changed = set(self.get_ancestry(last_revid))
 
744
        if None in changed:
 
745
            changed.remove(None)
 
746
        return self._fileid_involved_by_set(changed)
 
747
 
692
748
    @needs_read_lock
693
749
    def get_ancestry(self, revision_id):
694
750
        """Return a list of revision-ids integrated by a revision.
697
753
        """
698
754
        if revision_id is None:
699
755
            return [None]
700
 
        vf = self._revision_store.get_revision_file(self.get_transaction())
 
756
        vf = self._get_revision_vf()
701
757
        try:
702
758
            return [None] + vf.get_ancestry(revision_id)
703
759
        except errors.RevisionNotPresent:
709
765
        return self.get_revision_reconcile(revision_id)
710
766
 
711
767
    @needs_read_lock
 
768
    def get_revision_graph(self, revision_id=None):
 
769
        """Return a dictionary containing the revision graph.
 
770
        
 
771
        :return: a dictionary of revision_id->revision_parents_list.
 
772
        """
 
773
        weave = self._get_revision_vf()
 
774
        entire_graph = weave.get_graph()
 
775
        if revision_id is None:
 
776
            return weave.get_graph()
 
777
        elif revision_id not in weave:
 
778
            raise errors.NoSuchRevision(self, revision_id)
 
779
        else:
 
780
            # add what can be reached from revision_id
 
781
            result = {}
 
782
            pending = set([revision_id])
 
783
            while len(pending) > 0:
 
784
                node = pending.pop()
 
785
                result[node] = weave.get_parents(node)
 
786
                for revision_id in result[node]:
 
787
                    if revision_id not in result:
 
788
                        pending.add(revision_id)
 
789
            return result
 
790
 
 
791
    @needs_read_lock
712
792
    def get_revision_graph_with_ghosts(self, revision_ids=None):
713
793
        """Return a graph of the revisions with ghosts marked as applicable.
714
794
 
716
796
        :return: a Graph object with the graph reachable from revision_ids.
717
797
        """
718
798
        result = Graph()
719
 
        vf = self._revision_store.get_revision_file(self.get_transaction())
 
799
        vf = self._get_revision_vf()
720
800
        versions = vf.versions()
721
801
        if not revision_ids:
722
802
            pending = set(self.all_revision_ids())
744
824
            done.add(result)
745
825
        return result
746
826
 
 
827
    def _get_revision_vf(self):
 
828
        """:return: a versioned file containing the revisions."""
 
829
        vf = self._revision_store.get_revision_file(self.get_transaction())
 
830
        return vf
 
831
 
747
832
    @needs_write_lock
748
833
    def reconcile(self):
749
834
        """Reconcile this repository."""
752
837
        reconciler.reconcile()
753
838
        return reconciler
754
839
    
 
840
    def revision_parents(self, revid):
 
841
        return self._get_revision_vf().get_parents(rev_id)
755
842
 
756
843
class RepositoryFormat(object):
757
844
    """A repository format.