~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-22 18:02:01 UTC
  • mto: This revision was merged to the branch mainline in revision 6408.
  • Revision ID: jelmer@samba.org-20111222180201-4zufxn3iaf3frgr3
Add BzrDir.update_feature_flags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
786
786
    def __repr__(self):
787
787
        return "<%s at %r>" % (self.__class__.__name__, self.user_url)
788
788
 
 
789
    def update_feature_flags(self, updated_flags):
 
790
        """Update the features required by this bzrdir.
 
791
 
 
792
        :param updated_flags: Dictionary mapping feature names to necessities
 
793
            A necessity can be None to indicate the feature should be removed
 
794
        """
 
795
        self.control_files.lock_write()
 
796
        try:
 
797
            for name, necessity in updated_flags.iteritems():
 
798
                if necessity is None:
 
799
                    try:
 
800
                        del self._format.features[name]
 
801
                    except KeyError:
 
802
                        pass
 
803
                else:
 
804
                    self._format.features[name] = necessity
 
805
            self.transport.put_bytes('branch-format', self._format.as_string())
 
806
        finally:
 
807
            self.control_files.unlock()
 
808
 
789
809
 
790
810
class BzrDirMeta1(BzrDir):
791
811
    """A .bzr meta version 1 control object.
796
816
    present within a BzrDir.
797
817
    """
798
818
 
 
819
    def __init__(self, _transport, _format):
 
820
        super(BzrDirMeta1, self).__init__(_transport, _format)
 
821
        self.control_files = lockable_files.LockableFiles(self.control_transport,
 
822
            self._format._lock_file_name, self._format._lock_class)
 
823
 
799
824
    def can_convert_format(self):
800
825
        """See BzrDir.can_convert_format()."""
801
826
        return True
993
1018
    BzrDirMeta1.
994
1019
    """
995
1020
 
996
 
    def __init__(self, _transport, _format):
997
 
        super(BzrDirMeta1Colo, self).__init__(_transport, _format)
998
 
        self.control_files = lockable_files.LockableFiles(self.control_transport,
999
 
            self._format._lock_file_name, self._format._lock_class)
1000
 
 
1001
1021
    def _get_branch_path(self, name):
1002
1022
        """Obtain the branch path to use.
1003
1023
 
1451
1471
                       "This is a Bazaar control directory.\n"
1452
1472
                       "Do not change any files in this directory.\n"
1453
1473
                       "See http://bazaar.canonical.com/ for more information about Bazaar.\n"),
1454
 
                      ('branch-format', self.get_format_string()),
 
1474
                      ('branch-format', self.as_string()),
1455
1475
                      ]
1456
1476
        # NB: no need to escape relative paths that are url safe.
1457
1477
        control_files = lockable_files.LockableFiles(bzrdir_transport,
1866
1886
    def convert(self, to_convert, pb):
1867
1887
        """See Converter.convert()."""
1868
1888
        to_convert.transport.put_bytes('branch-format',
1869
 
            self.target_format.get_format_string())
 
1889
            self.target_format.as_string())
1870
1890
        return BzrDir.open_from_transport(to_convert.root_transport)
1871
1891
 
1872
1892
 
1892
1912
        finally:
1893
1913
            to_convert.control_files.unlock()
1894
1914
        to_convert.transport.put_bytes('branch-format',
1895
 
            self.target_format.get_format_string())
 
1915
            self.target_format.as_string())
1896
1916
        return BzrDir.open_from_transport(to_convert.root_transport)
1897
1917
 
1898
1918