Rev 2230: (broken) start moving things to branches in file:///home/mbp/bzr/Work/tags/

Martin Pool mbp at sourcefrog.net
Mon Feb 12 07:18:27 GMT 2007


------------------------------------------------------------
revno: 2230
revision-id: mbp at sourcefrog.net-20070212071826-5x37ixz8r6cylk75
parent: mbp at sourcefrog.net-20070124050955-q7fed1sy7ddc78ui
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: tags
timestamp: Mon 2007-02-12 18:18:26 +1100
message:
  (broken) start moving things to branches
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2007-01-19 02:46:50 +0000
+++ b/bzrlib/branch.py	2007-02-12 07:18:26 +0000
@@ -74,6 +74,97 @@
 
 
 ######################################################################
+# tag storage
+
+
+class _TagStore(object):
+    def __init__(self, repository):
+        self.repository = repository
+
+class _DisabledTagStore(_TagStore):
+    """Tag storage that refuses to store anything.
+
+    This is used by older formats that can't store tags.
+    """
+
+    def _not_supported(self, *a, **k):
+        raise errors.TagsNotSupported(self.repository)
+
+    def supports_tags(self):
+        return False
+
+    set_tag = _not_supported
+    get_tag_dict = _not_supported
+    _set_tag_dict = _not_supported
+    lookup_tag = _not_supported
+
+
+class _BasicTagStore(_TagStore):
+    """Tag storage in an unversioned repository control file.
+    """
+
+    def supports_tags(self):
+        return True
+
+    def set_tag(self, tag_name, tag_target):
+        """Add a tag definition to the repository.
+
+        Behaviour if the tag is already present is not defined (yet).
+        """
+        # all done with a write lock held, so this looks atomic
+        self.repository.lock_write()
+        try:
+            td = self.get_tag_dict()
+            td[tag_name] = tag_target
+            self._set_tag_dict(td)
+        finally:
+            self.repository.unlock()
+
+    def lookup_tag(self, tag_name):
+        """Return the referent string of a tag"""
+        td = self.get_tag_dict()
+        try:
+            return td[tag_name]
+        except KeyError:
+            raise errors.NoSuchTag(tag_name)
+
+    def get_tag_dict(self):
+        self.repository.lock_read()
+        try:
+            tag_content = self.repository.control_files.get_utf8('tags').read()
+            return self._deserialize_tag_dict(tag_content)
+        finally:
+            self.repository.unlock()
+
+    def _set_tag_dict(self, new_dict):
+        """Replace all tag definitions
+
+        :param new_dict: Dictionary from tag name to target.
+        """
+        self.repository.lock_read()
+        try:
+            self.repository.control_files.put_utf8('tags',
+                self._serialize_tag_dict(new_dict))
+        finally:
+            self.repository.unlock()
+
+    def _serialize_tag_dict(self, tag_dict):
+        s = []
+        for tag, target in sorted(tag_dict.items()):
+            # TODO: check that tag names and targets are acceptable
+            s.append(tag + '\t' + target + '\n')
+        return ''.join(s)
+
+    def _deserialize_tag_dict(self, tag_content):
+        """Convert the tag file into a dictionary of tags"""
+        d = {}
+        for l in tag_content.splitlines():
+            tag, target = l.split('\t', 1)
+            d[tag] = target
+        return d
+
+
+######################################################################
 # branch objects
 
 class Branch(object):
@@ -86,8 +177,11 @@
     # - RBC 20060112
     base = None
 
+    # override this to set the strategy for storing tags
+    _tag_store_class = _DisabledTagStore
+
     def __init__(self, *ignored, **ignored_too):
-        raise NotImplementedError('The Branch class is abstract')
+        self._tag_store = self._tag_store_class(self)
 
     def break_lock(self):
         """Break a lock if one is present from another instance.
@@ -628,6 +722,29 @@
             checkout_branch.pull(self, stop_revision=revision_id)
         return checkout.create_workingtree(revision_id)
 
+    def set_tag(self, tag_name, tag_target):
+        self._tag_store.set_tag(tag_name, tag_target)
+
+    def lookup_tag(self, tag_name):
+        return self._tag_store.lookup_tag(tag_name)
+
+    def get_tag_dict(self):
+        return self._tag_store.get_tag_dict()
+
+    def _set_tag_dict(self, new_dict):
+        return self._tag_store._set_tag_dict(new_dict)
+
+    def supports_tags(self):
+        return self._tag_store.supports_tags()
+
+    def copy_tags_to(self, to_repository):
+        """Copy tags to another repository.
+
+        Subclasses should not override this, but rather customize copying 
+        through the InterRepository mechanism.
+        """
+        return InterRepository.get(self, to_repository).copy_tags()
+
 
 class BranchFormat(object):
     """An encapsulation of the initialization and open routines for a format.
@@ -715,6 +832,23 @@
     def __str__(self):
         return self.get_format_string().rstrip()
 
+    def supports_tags(self):
+        """True if this format supports tags stored in the branch"""
+        return False  # by default
+
+    def _initialize_control_files(self, a_bzrdir, utf8_files, lock_filename,
+            lock_class):
+        branch_transport = a_bzrdir.get_branch_transport(self)
+        control_files = lockable_files.LockableFiles(branch_transport,
+            lock_filename, lock_class)
+        control_files.create_lock()
+        control_files.lock_write()
+        try:
+            for filename, content in utf8_files:
+                control_files.put_utf8(filename, content)
+        finally:
+            control_files.unlock()
+
 
 class BzrBranchFormat4(BranchFormat):
     """Bzr branch format 4.
@@ -730,20 +864,11 @@
 
     def initialize(self, a_bzrdir):
         """Create a branch of this format in a_bzrdir."""
-        mutter('creating branch in %s', a_bzrdir.transport.base)
-        branch_transport = a_bzrdir.get_branch_transport(self)
         utf8_files = [('revision-history', ''),
                       ('branch-name', ''),
                       ]
-        control_files = lockable_files.LockableFiles(branch_transport,
-                             'branch-lock', lockable_files.TransportLock)
-        control_files.create_lock()
-        control_files.lock_write()
-        try:
-            for file, content in utf8_files:
-                control_files.put_utf8(file, content)
-        finally:
-            control_files.unlock()
+        self._initialize_control_files(a_bzrdir, utf8_files,
+             'branch-lock', lockable_files.TransportLock)
         return self.open(a_bzrdir, _found=True)
 
     def __init__(self):
@@ -829,8 +954,61 @@
                           a_bzrdir=a_bzrdir,
                           _repository=a_bzrdir.find_repository())
 
-    def __str__(self):
-        return "Bazaar-NG Metadir branch format 5"
+
+class BzrBranchFormatExperimental(BranchFormat):
+    """Bzr experimental branch format
+
+    This format has:
+     - a revision-history file.
+     - a format string
+     - a lock dir guarding the branch itself
+     - all of this stored in a branch/ subdirectory
+     - works with shared repositories.
+     - a tag dictionary in the branch
+
+    This format is new in bzr 0.15, but shouldn't be used for real data, 
+    only for testing.
+    """
+
+    def get_format_string(self):
+        """See BranchFormat.get_format_string()."""
+        return "Bazaar-NG branch format experimental\n"
+
+    def get_format_description(self):
+        """See BranchFormat.get_format_description()."""
+        return "Experimental branch format"
+        
+    def initialize(self, a_bzrdir):
+        """Create a branch of this format in a_bzrdir."""
+        utf8_files = [('format', self.get_format_string()),
+                      ('revision-history', ''),
+                      ('branch-name', ''),
+                      ('tags', ''),
+                      ]
+        self._initialize_control_files(a_bzrdir, utf8_files,
+            'lock', lockdir.LockDir)
+        return self.open(a_bzrdir, _found=True)
+
+    def __init__(self):
+        super(BzrBranchFormatExperimental, self).__init__()
+        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
+
+    def open(self, a_bzrdir, _found=False):
+        """Return the branch object for a_bzrdir
+
+        _found is a private parameter, do not use it. It is used to indicate
+               if format probing has already be done.
+        """
+        if not _found:
+            format = BranchFormat.find_format(a_bzrdir)
+            assert format.__class__ == self.__class__
+        transport = a_bzrdir.get_branch_transport(None)
+        control_files = lockable_files.LockableFiles(transport, 'lock',
+                                                     lockdir.LockDir)
+        return BzrBranchExperimental(_format=self,
+                          _control_files=control_files,
+                          a_bzrdir=a_bzrdir,
+                          _repository=a_bzrdir.find_repository())
 
 
 class BranchReferenceFormat(BranchFormat):
@@ -1397,6 +1575,15 @@
         return None
 
 
+class BzrBranchExperimental(BzrBranch5):
+
+    # TODO: within a lock scope, we could keep the tags in memory...
+    
+    _tag_store_class = _BasicTagStore
+
+
+
+
 class BranchTestProviderAdapter(object):
     """A tool to generate a suite testing multiple branch formats at once.
 

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-01-21 12:42:13 +0000
+++ b/bzrlib/repository.py	2007-02-12 07:18:26 +0000
@@ -72,97 +72,6 @@
 
 
 ######################################################################
-# tag storage
-
-
-class _TagStore(object):
-    def __init__(self, repository):
-        self.repository = repository
-
-class _DisabledTagStore(_TagStore):
-    """Tag storage that refuses to store anything.
-
-    This is used by older formats that can't store tags.
-    """
-
-    def _not_supported(self, *a, **k):
-        raise errors.TagsNotSupported(self.repository)
-
-    def supports_tags(self):
-        return False
-
-    set_tag = _not_supported
-    get_tag_dict = _not_supported
-    _set_tag_dict = _not_supported
-    lookup_tag = _not_supported
-
-
-class _BasicTagStore(_TagStore):
-    """Tag storage in an unversioned repository control file.
-    """
-
-    def supports_tags(self):
-        return True
-
-    def set_tag(self, tag_name, tag_target):
-        """Add a tag definition to the repository.
-
-        Behaviour if the tag is already present is not defined (yet).
-        """
-        # all done with a write lock held, so this looks atomic
-        self.repository.lock_write()
-        try:
-            td = self.get_tag_dict()
-            td[tag_name] = tag_target
-            self._set_tag_dict(td)
-        finally:
-            self.repository.unlock()
-
-    def lookup_tag(self, tag_name):
-        """Return the referent string of a tag"""
-        td = self.get_tag_dict()
-        try:
-            return td[tag_name]
-        except KeyError:
-            raise errors.NoSuchTag(tag_name)
-
-    def get_tag_dict(self):
-        self.repository.lock_read()
-        try:
-            tag_content = self.repository.control_files.get_utf8('tags').read()
-            return self._deserialize_tag_dict(tag_content)
-        finally:
-            self.repository.unlock()
-
-    def _set_tag_dict(self, new_dict):
-        """Replace all tag definitions
-
-        :param new_dict: Dictionary from tag name to target.
-        """
-        self.repository.lock_read()
-        try:
-            self.repository.control_files.put_utf8('tags',
-                self._serialize_tag_dict(new_dict))
-        finally:
-            self.repository.unlock()
-
-    def _serialize_tag_dict(self, tag_dict):
-        s = []
-        for tag, target in sorted(tag_dict.items()):
-            # TODO: check that tag names and targets are acceptable
-            s.append(tag + '\t' + target + '\n')
-        return ''.join(s)
-
-    def _deserialize_tag_dict(self, tag_content):
-        """Convert the tag file into a dictionary of tags"""
-        d = {}
-        for l in tag_content.splitlines():
-            tag, target = l.split('\t', 1)
-            d[tag] = target
-        return d
-
-
-######################################################################
 # Repositories
 
 class Repository(object):
@@ -177,9 +86,6 @@
     remote) disk.
     """
 
-    # override this to set the strategy for storing tags
-    _tag_store_class = _DisabledTagStore
-
     _file_ids_altered_regex = lazy_regex.lazy_compile(
         r'file_id="(?P<file_id>[^"]+)"'
         r'.*revision="(?P<revision_id>[^"]+)"'
@@ -319,7 +225,6 @@
         # on whether escaping is required.
         self._warn_if_deprecated()
         self._serializer = xml5.serializer_v5
-        self._tag_store = self._tag_store_class(self)
 
     def __repr__(self):
         return '%s(%r)' % (self.__class__.__name__, 
@@ -873,29 +778,6 @@
                 except UnicodeEncodeError:
                     raise errors.NonAsciiRevisionId(method, self)
 
-    def set_tag(self, tag_name, tag_target):
-        self._tag_store.set_tag(tag_name, tag_target)
-
-    def lookup_tag(self, tag_name):
-        return self._tag_store.lookup_tag(tag_name)
-
-    def get_tag_dict(self):
-        return self._tag_store.get_tag_dict()
-
-    def _set_tag_dict(self, new_dict):
-        return self._tag_store._set_tag_dict(new_dict)
-
-    def supports_tags(self):
-        return self._tag_store.supports_tags()
-
-    def copy_tags_to(self, to_repository):
-        """Copy tags to another repository.
-
-        Subclasses should not override this, but rather customize copying 
-        through the InterRepository mechanism.
-        """
-        return InterRepository.get(self, to_repository).copy_tags()
-
 
 class AllInOneRepository(Repository):
     """Legacy support - the repository behaviour for all-in-one branches."""
@@ -1213,10 +1095,6 @@
 
     # corresponds to RepositoryFormatKnit2
     
-    # TODO: within a lock scope, we could keep the tags in memory...
-    
-    _tag_store_class = _BasicTagStore
-
     def __init__(self, _format, a_bzrdir, control_files, _revision_store,
                  control_store, text_store):
         KnitRepository.__init__(self, _format, a_bzrdir, control_files,
@@ -1418,10 +1296,6 @@
         assert klass._formats[format.get_format_string()] is format
         del klass._formats[format.get_format_string()]
 
-    def supports_tags(self):
-        """True if this format supports tags stored in the repository"""
-        return False  # by default
-
 
 class PreSplitOutRepositoryFormat(RepositoryFormat):
     """Base class for the pre split out repository formats."""
@@ -1887,7 +1761,6 @@
      - an optional 'no-working-trees' flag
      - a LockDir lock
      - Support for recording full info about the tree root
-     - A tag dictionary stored in the repository, pointing to revisions
     """
     
     rich_root_data = True




More information about the bazaar-commits mailing list