Rev 1431: Support deleting tags. in file:///data/jelmer/bzr-svn/tags/

Jelmer Vernooij jelmer at samba.org
Thu Jul 3 21:33:29 BST 2008


At file:///data/jelmer/bzr-svn/tags/

------------------------------------------------------------
revno: 1431
revision-id: jelmer at samba.org-20080703203327-5bplovdvone200dp
parent: jelmer at samba.org-20080703201334-n4gkcyfsndegaoi2
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: tags
timestamp: Thu 2008-07-03 22:33:27 +0200
message:
  Support deleting tags.
modified:
  branch.py                      svnbranch.py-20051017135706-11c749eb0dab04a7
  mapping3/__init__.py           __init__.py-20080502174630-9324zh25kka98vlw-1
  mapping3/scheme.py             scheme.py-20060516195850-95181aae6b272f9e
  tests/test_branch.py           test_branch.py-20060508162215-74ffeb5d608f8e20
  tests/test_scheme.py           test_scheme.py-20060621221855-va2xabhlxpmc9llx-1
=== modified file 'branch.py'
--- a/branch.py	2008-07-03 20:13:34 +0000
+++ b/branch.py	2008-07-03 20:33:27 +0000
@@ -19,7 +19,7 @@
 from bzrlib.branch import Branch, BranchFormat, BranchCheckResult, PullResult
 from bzrlib.bzrdir import BzrDir
 from bzrlib.errors import (NoSuchFile, DivergedBranches, NoSuchRevision, 
-                           NotBranchError, UnstackableBranchFormat)
+                           NoSuchTag, NotBranchError, UnstackableBranchFormat)
 from bzrlib.inventory import (Inventory)
 from bzrlib.revision import is_null, ensure_null, NULL_REVISION
 from bzrlib.workingtree import WorkingTree
@@ -52,8 +52,9 @@
 
 
 class SubversionTags:
-    def __init__(self, repository, project=""):
+    def __init__(self, repository, layout=None, project=""):
         self.repository = repository
+        self.layout = layout or repository.get_layout()
         self.project = project
 
     def set_tag(self, tag_name, tag_target):
@@ -65,7 +66,8 @@
         raise NotImplementedError
 
     def get_tag_dict(self):
-        return self.repository.find_tags(project=self.project)
+        return self.repository.find_tags(project=self.project, 
+                                         layout=self.layout)
 
     def get_reverse_tag_dict(self):
         """Returns a dict with revisions as keys
@@ -80,7 +82,23 @@
         return rev
 
     def delete_tag(self, tag_name):
-        raise NotImplementedError
+        path = self.layout.get_tag_path(tag_name, self.project)
+        parent = urlutils.dirname(path)
+        conn = self.repository.transport.connections.get(urlutils.join(self.repository.base, parent))
+        if self.repository.transport.check_path(path, self.repository.get_latest_revnum()) != core.NODE_DIR:
+            raise NoSuchTag(tag_name)
+        try:
+            ci = conn.get_commit_editor({"svn:log": "Remove tag %s" % tag_name})
+            try:
+                root = ci.open_root()
+                root.delete_entry(urlutils.basename(path))
+                root.close()
+            except:
+                ci.abort()
+                raise
+            ci.close()
+        finally:
+            self.repository.transport.add_connection(conn)
 
     def merge_to(self, to_tags, overwrite=False):
         raise NotImplementedError

=== modified file 'mapping3/__init__.py'
--- a/mapping3/__init__.py	2008-07-03 18:48:44 +0000
+++ b/mapping3/__init__.py	2008-07-03 20:33:27 +0000
@@ -109,6 +109,9 @@
     def get_tags(self, revnum, project="", pb=None):
         return self._get_root_paths(revnum, self.scheme.is_tag, project, pb)
 
+    def get_tag_path(self, name, project=""):
+        return self.scheme.get_tag_path(name)
+
     def is_branch_parent(self, path):
         # Na, na, na...
         return self.scheme.is_branch_parent(path)

=== modified file 'mapping3/scheme.py'
--- a/mapping3/scheme.py	2008-06-05 17:26:28 +0000
+++ b/mapping3/scheme.py	2008-07-03 20:33:27 +0000
@@ -15,7 +15,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Branching scheme implementations."""
 
-from bzrlib import ui
+from bzrlib import ui, urlutils
 from bzrlib.errors import BzrError
 from bzrlib.trace import mutter
 
@@ -47,6 +47,13 @@
         """
         raise NotImplementedError
 
+    def get_tag_path(self, name):
+        """Find the path for a tag.
+
+        :param name: Tag name.
+        """
+        raise NotImplementedError
+
     @staticmethod
     def find_scheme(name):
         """Find a branching scheme by name.
@@ -246,6 +253,12 @@
              "*/" * level + "branches/*",
              "*/" * level + "tags/*"])
 
+    def get_tag_path(self, name):
+        # Only implemented for level 0
+        if self.level == 0:
+            return urlutils.join("tags", name)
+        raise NotImplementedError
+
     def is_branch(self, path):
         """See BranchingScheme.is_branch()."""
         parts = path.strip("/").split("/")

=== modified file 'tests/test_branch.py'
--- a/tests/test_branch.py	2008-07-03 20:13:34 +0000
+++ b/tests/test_branch.py	2008-07-03 20:33:27 +0000
@@ -19,7 +19,7 @@
 from bzrlib import urlutils
 from bzrlib.branch import Branch
 from bzrlib.bzrdir import BzrDir
-from bzrlib.errors import NoSuchFile, NoSuchRevision, NotBranchError
+from bzrlib.errors import NoSuchFile, NoSuchRevision, NotBranchError, NoSuchTag
 from bzrlib.repository import Repository
 from bzrlib.revision import NULL_REVISION
 from bzrlib.trace import mutter
@@ -58,6 +58,27 @@
         b = Branch.open(repos_url + "/trunk")
         self.assertEquals(["foo"], b.tags.get_tag_dict().keys())
 
+    def test_tags_delete(self):
+        repos_url = self.make_repository("a")
+       
+        dc = self.get_commit_editor(repos_url)
+        tags = dc.add_dir("tags")
+        tags.add_dir("tags/foo")
+        dc.add_dir("trunk")
+        dc.close()
+
+        b = Branch.open(repos_url + "/trunk")
+        self.assertEquals(["foo"], b.tags.get_tag_dict().keys())
+        b.tags.delete_tag("foo")
+        b = Branch.open(repos_url + "/trunk")
+        self.assertEquals([], b.tags.get_tag_dict().keys())
+
+    def test_tags_delete_nonexistent(self):
+        repos_url = self.make_repository("a")
+       
+        b = Branch.open(repos_url + "/trunk")
+        self.assertRaises(NoSuchTag, b.tags.delete_tag, "foo")
+
     def test_get_branch_path_old(self):
         repos_url = self.make_repository("a")
 

=== modified file 'tests/test_scheme.py'
--- a/tests/test_scheme.py	2008-06-04 15:20:12 +0000
+++ b/tests/test_scheme.py	2008-07-03 20:33:27 +0000
@@ -446,6 +446,15 @@
     def test_is_branch_parent_other(self):
         self.assertFalse(TrunkBranchingScheme().is_branch_parent("trunk/foo"))
 
+    def test_get_tag_path_zero(self):
+        self.assertEquals("tags/foo", 
+                          TrunkBranchingScheme().get_tag_path("foo"))
+
+    def test_get_tag_path_nonzero(self):
+        self.assertRaises(NotImplementedError,
+                          TrunkBranchingScheme(2).get_tag_path, "foo")
+
+
 
 class SingleBranchingSchemeTests(TestCase):
     def test_is_branch(self):




More information about the bazaar-commits mailing list