Rev 1430: Implement get_tag_dict for subversion branches. in file:///data/jelmer/bzr-svn/tags/

Jelmer Vernooij jelmer at samba.org
Thu Jul 3 21:13:35 BST 2008


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

------------------------------------------------------------
revno: 1430
revision-id: jelmer at samba.org-20080703201334-n4gkcyfsndegaoi2
parent: jelmer at samba.org-20080703185323-pfj2a2qtitnh6zop
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: tags
timestamp: Thu 2008-07-03 22:13:34 +0200
message:
  Implement get_tag_dict for subversion branches.
modified:
  branch.py                      svnbranch.py-20051017135706-11c749eb0dab04a7
  layout.py                      layout.py-20080323165407-y9qw8nx4oykvoe1k-1
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
  tests/test_branch.py           test_branch.py-20060508162215-74ffeb5d608f8e20
=== modified file 'branch.py'
--- a/branch.py	2008-07-01 21:10:34 +0000
+++ b/branch.py	2008-07-03 20:13:34 +0000
@@ -51,6 +51,41 @@
         pass
 
 
+class SubversionTags:
+    def __init__(self, repository, project=""):
+        self.repository = repository
+        self.project = project
+
+    def set_tag(self, tag_name, tag_target):
+        # TODO: copy tag_target to tags/tag_name
+        raise NotImplementedError
+
+    def lookup_tag(self, tag_name):
+        # TODO: Check if tags/tag_name exists and return revid
+        raise NotImplementedError
+
+    def get_tag_dict(self):
+        return self.repository.find_tags(project=self.project)
+
+    def get_reverse_tag_dict(self):
+        """Returns a dict with revisions as keys
+           and a list of tags for that revision as value"""
+        d = self.get_tag_dict()
+        rev = {}
+        for key in d:
+            try:
+                rev[d[key]].append(key)
+            except KeyError:
+                rev[d[key]] = [key]
+        return rev
+
+    def delete_tag(self, tag_name):
+        raise NotImplementedError
+
+    def merge_to(self, to_tags, overwrite=False):
+        raise NotImplementedError
+
+
 class SvnBranch(Branch):
     """Maps to a Branch in a Subversion repository """
     def __init__(self, repository, branch_path):
@@ -62,8 +97,8 @@
         :param revnum: Subversion revision number of the branch to 
             look at; none for latest.
         """
+        self.repository = repository
         super(SvnBranch, self).__init__()
-        self.repository = repository
         assert isinstance(self.repository, SvnRepository)
         self.control_files = FakeControlFiles()
         self._format = SvnBranchFormat()
@@ -86,6 +121,9 @@
         if not self.mapping.is_branch(branch_path):
             raise NotSvnBranchPath(branch_path, mapping=self.mapping)
 
+    def _make_tags(self):
+        return SubversionTags(self.repository)
+
     def set_branch_path(self, branch_path):
         """Change the branch path for this branch.
 

=== modified file 'layout.py'
--- a/layout.py	2008-07-01 19:26:24 +0000
+++ b/layout.py	2008-07-03 20:13:34 +0000
@@ -70,7 +70,7 @@
         """
         raise NotImplementedError
 
-    def get_tags(self, project="", revnum=None):
+    def get_tags(self, revnum, project="", pb=None):
         """Retrieve a list of paths that refer to tags in a specific revision.
 
         :result: Iterator over tuples with (project, branch path)

=== modified file 'repository.py'
--- a/repository.py	2008-07-03 18:53:23 +0000
+++ b/repository.py	2008-07-03 20:13:34 +0000
@@ -729,7 +729,7 @@
         return branches
 
     @needs_read_lock
-    def find_tags(self, layout=None, revnum=None):
+    def find_tags(self, layout=None, revnum=None, project=None):
         """Find branches underneath this repository.
 
         """
@@ -742,7 +742,7 @@
         tags = {}
         pb = ui.ui_factory.nested_progress_bar()
         try:
-            for project, bp, nick in layout.get_tags(revnum, pb=pb):
+            for project, bp, nick in layout.get_tags(revnum, project=project, pb=pb):
                 try:
                     tags[nick] = self.generate_revision_id(revnum, bp, 
                                                            self.get_mapping())

=== modified file 'tests/test_branch.py'
--- a/tests/test_branch.py	2008-07-01 21:10:09 +0000
+++ b/tests/test_branch.py	2008-07-03 20:13:34 +0000
@@ -46,6 +46,18 @@
         branch = Branch.open(repos_url)
         self.assertEqual("", branch.get_branch_path())
 
+    def test_tags_dict(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())
+
     def test_get_branch_path_old(self):
         repos_url = self.make_repository("a")
 




More information about the bazaar-commits mailing list