Rev 82: Support listing tags. in http://people.samba.org/bzr/jelmer/bzr-git/trunk

Jelmer Vernooij jelmer at samba.org
Sat Jul 26 19:05:56 BST 2008


At http://people.samba.org/bzr/jelmer/bzr-git/trunk

------------------------------------------------------------
revno: 82
revision-id: jelmer at samba.org-20080726180555-ll8rqbejw60x5l7v
parent: jelmer at samba.org-20080726163056-zthvhxutyfehir87
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sat 2008-07-26 20:05:55 +0200
message:
  Support listing tags.
modified:
  git_branch.py                  git_branch.py-20071108230535-su8dxk529f4uk9fx-2
  git_repository.py              git_repository.py-20071108234408-ygidvy5hviixghsd-2
  tests/test_git_branch.py       test_git_branch.py-20071108234408-ygidvy5hviixghsd-3
=== modified file 'git_branch.py'
--- a/git_branch.py	2008-07-26 15:54:48 +0000
+++ b/git_branch.py	2008-07-26 18:05:55 +0000
@@ -20,11 +20,23 @@
     branch,
     config,
     revision,
+    tag,
     )
 from bzrlib.decorators import needs_read_lock
 
 from bzrlib.plugins.git import ids
 
+class GitTagDict(tag.BasicTags):
+
+    def __init__(self, repository):
+        self.repository = repository
+
+    def get_tag_dict(self):
+        ret = {}
+        for tag in self.repository._git.tags:
+            ret[tag.name] = ids.convert_revision_id_git_to_bzr(tag.commit.id)
+        return ret
+
 
 class GitBranchConfig(config.BranchConfig):
     """BranchConfig that uses locations.conf in place of branch.conf"""
@@ -44,15 +56,18 @@
     def get_format_description(self):
         return 'Git Branch'
 
+    def supports_tags(self):
+        return True
+
 
 class GitBranch(branch.Branch):
     """An adapter to git repositories for bzr Branch objects."""
 
     def __init__(self, bzrdir, repository, head, base, lockfiles):
+        self.repository = repository
         super(GitBranch, self).__init__()
         self.control_files = lockfiles
         self.bzrdir = bzrdir
-        self.repository = repository
         self.head = head
         self.base = base
         self._format = GitBranchFormat()
@@ -67,6 +82,9 @@
             return revision.NULL_REVISION
         return ids.convert_revision_id_git_to_bzr(self.head)
 
+    def _make_tags(self):
+        return GitTagDict(self.repository)
+
     def get_parent(self):
         """See Branch.get_parent()."""
         return None
@@ -118,4 +136,4 @@
                                           local=True)
 
     def supports_tags(self):
-        return False
+        return True

=== modified file 'git_repository.py'
--- a/git_repository.py	2008-07-26 16:23:29 +0000
+++ b/git_repository.py	2008-07-26 18:05:55 +0000
@@ -104,6 +104,11 @@
     def supports_rich_root(self):
         return False
 
+    #def get_revision_delta(self, revision_id):
+    #    parent_revid = self.get_revision(revision_id).parent_ids[0]
+    #    diff = self._git.diff(ids.convert_revision_id_bzr_to_git(parent_revid),
+    #                   ids.convert_revision_id_bzr_to_git(revision_id))
+
     def get_ancestry(self, revision_id):
         revision_id = revision.ensure_null(revision_id)
         ret = []

=== modified file 'tests/test_git_branch.py'
--- a/tests/test_git_branch.py	2008-07-26 15:54:48 +0000
+++ b/tests/test_git_branch.py	2008-07-26 18:05:55 +0000
@@ -45,11 +45,14 @@
         self.assertEqual((0, revision.NULL_REVISION),
                          thebranch.last_revision_info())
 
+    def simple_commit_a(self):
+        tests.run_git('init')
+        self.build_tree(['a'])
+        tests.run_git('add', 'a')
+        tests.run_git('commit', '-m', 'a')
+
     def test_last_revision_is_valid(self):
-        tests.run_git('init')
-        self.build_tree(['a'])
-        tests.run_git('add', 'a')
-        tests.run_git('commit', '-m', 'a')
+        self.simple_commit_a()
         head = tests.run_git('rev-parse', 'HEAD').strip()
 
         thebranch = branch.Branch.open('.')
@@ -57,10 +60,7 @@
                          thebranch.last_revision())
 
     def test_revision_history(self):
-        tests.run_git('init')
-        self.build_tree(['a'])
-        tests.run_git('add', 'a')
-        tests.run_git('commit', '-m', 'a')
+        self.simple_commit_a()
         reva = tests.run_git('rev-parse', 'HEAD').strip()
         self.build_tree(['b'])
         tests.run_git('add', 'b')
@@ -70,6 +70,18 @@
         thebranch = branch.Branch.open('.')
         self.assertEqual([ids.convert_revision_id_git_to_bzr(r) for r in (reva, revb)],
                          thebranch.revision_history())
+
+    def test_tags(self):
+        self.simple_commit_a()
+        reva = tests.run_git('rev-parse', 'HEAD').strip()
+        
+        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
+        
+        newid = open('.git/refs/tags/foo').read().rstrip()
+
+        thebranch = branch.Branch.open('.')
+        self.assertEquals({"foo": ids.convert_revision_id_git_to_bzr(newid)},
+                          thebranch.tags.get_tag_dict())
         
 
 class TestWithGitBranch(tests.TestCaseWithTransport):




More information about the bazaar-commits mailing list