Rev 2223: ../msg.tmp in file:///home/mbp/bzr/Work/tags/

Martin Pool mbp at sourcefrog.net
Thu Jan 18 09:25:26 GMT 2007


------------------------------------------------------------
revno: 2223
revision-id: mbp at sourcefrog.net-20070118092525-ade9bnc5q8r6oaxx
parent: mbp at sourcefrog.net-20070116132138-vhziz9hpfc8za0uj
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: tags
timestamp: Thu 2007-01-18 20:25:25 +1100
message:
  ../msg.tmp
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/revisionspec.py         revisionspec.py-20050907152633-17567659fd5c0ddb
  bzrlib/tests/repository_implementations/test_tags.py test_tags.py-20070114073919-azsbo9l26ph1rr09-1
  bzrlib/tests/test_revisionnamespaces.py testrevisionnamespaces.py-20050711050225-8b4af89e6b1efe84
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2006-12-07 16:21:39 +0000
+++ b/bzrlib/branch.py	2007-01-18 09:25:25 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-01-16 13:21:38 +0000
+++ b/bzrlib/builtins.py	2007-01-18 09:25:25 +0000
@@ -3009,7 +3009,7 @@
     def run(self, tag_name, directory='.'):
         branch, relpath = Branch.open_containing(directory)
         revision_id = branch.last_revision()
-        branch.repository.make_tag(tag_name, revision_id)
+        branch.repository.set_tag(tag_name, revision_id)
         self.outf.write('created tag %s' % tag_name)
 
 

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-01-16 13:21:38 +0000
+++ b/bzrlib/repository.py	2007-01-18 09:25:25 +0000
@@ -1152,7 +1152,7 @@
         self.control_files.put_utf8('tags', self._format._serialize_tag_dict(new_dict))
 
     @needs_write_lock
-    def make_tag(self, tag_name, tag_target):
+    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).

=== modified file 'bzrlib/revisionspec.py'
--- a/bzrlib/revisionspec.py	2006-11-08 16:29:27 +0000
+++ b/bzrlib/revisionspec.py	2007-01-18 09:25:25 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -93,6 +93,18 @@
         return '<bzrlib.revisionspec.RevisionInfo object %s, %s for %r>' % (
             self.revno, self.rev_id, self.branch)
 
+    @staticmethod
+    def from_revision_id(branch, revision_id, revs):
+        """Construct a RevisionInfo given just the id.
+
+        Use this if you don't know or care what the revno is.
+        """
+        try:
+            revno = revs.index(revision_id) + 1
+        except ValueError:
+            revno = None
+        return RevisionInfo(branch, revno, revision_id)
+
 
 # classes in this list should have a "prefix" attribute, against which
 # string specs are matched
@@ -365,11 +377,7 @@
     prefix = 'revid:'
 
     def _match_on(self, branch, revs):
-        try:
-            revno = revs.index(self.spec) + 1
-        except ValueError:
-            revno = None
-        return RevisionInfo(branch, revno, self.spec)
+        return RevisionInfo.from_revision_id(branch, self.spec, revs)
 
 SPEC_TYPES.append(RevisionSpec_revid)
 
@@ -463,16 +471,21 @@
 
 
 class RevisionSpec_tag(RevisionSpec):
-    """To be implemented."""
-
-    help_txt = """To be implemented."""
+    """Select a revision identified by tag name"""
+
+    help_txt = """Selects a revision identified by a tag name.
+
+    Tags are stored in the repository and created by the 'tag'
+    command.
+    """
 
     prefix = 'tag:'
 
     def _match_on(self, branch, revs):
-        raise errors.InvalidRevisionSpec(self.user_spec, branch,
-                                         'tag: namespace registered,'
-                                         ' but not implemented')
+        # Can raise tags not supported, NoSuchTag, etc
+        return RevisionInfo.from_revision_id(branch,
+            branch.lookup_tag(self.spec),
+            revs)
 
 SPEC_TYPES.append(RevisionSpec_tag)
 

=== modified file 'bzrlib/tests/repository_implementations/test_tags.py'
--- a/bzrlib/tests/repository_implementations/test_tags.py	2007-01-16 13:21:38 +0000
+++ b/bzrlib/tests/repository_implementations/test_tags.py	2007-01-18 09:25:25 +0000
@@ -62,7 +62,7 @@
 
     def test_make_and_lookup_tag(self):
         repo = self.make_repository('repo')
-        repo.make_tag('tag-name', 'target-revid-1')
+        repo.set_tag('tag-name', 'target-revid-1')
         result = repo.lookup_tag('tag-name')
         self.assertEqual(result, 'target-revid-1')
 

=== modified file 'bzrlib/tests/test_revisionnamespaces.py'
--- a/bzrlib/tests/test_revisionnamespaces.py	2006-10-16 10:03:21 +0000
+++ b/bzrlib/tests/test_revisionnamespaces.py	2007-01-18 09:25:25 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2004, 2005, 2006 Canonical Ltd
+# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,11 +19,17 @@
 import time
 
 from bzrlib import (
+    bzrdir,
     errors,
+    repository,
     )
 from bzrlib.builtins import merge
 from bzrlib.tests import TestCase, TestCaseWithTransport
-from bzrlib.revisionspec import RevisionSpec, RevisionSpec_revno
+from bzrlib.revisionspec import (
+    RevisionSpec,
+    RevisionSpec_revno,
+    RevisionSpec_tag,
+    )
 
 
 def spec_in_history(spec, branch):
@@ -335,9 +341,28 @@
 
 class TestRevisionSpec_tag(TestRevisionSpec):
     
-    def test_invalid(self):
-        self.assertInvalid('tag:foo', extra='\ntag: namespace registered,'
-                                            ' but not implemented')
+    def make_branch_and_tree(self, relpath):
+        # override format as the default one may not support tags
+        control = bzrdir.BzrDir.create(relpath)
+        repo = repository.RepositoryFormatKnit2().initialize(control)
+        control.create_branch()
+        return control.create_workingtree()
+
+    def test_from_string_tag(self):
+        spec = RevisionSpec.from_string('tag:bzr-0.14')
+        self.assertIsInstance(spec, RevisionSpec_tag)
+        self.assertEqual(spec.spec, 'bzr-0.14')
+
+    def test_lookup_tag(self):
+        self.tree.branch.repository.set_tag('bzr-0.14', 'r1')
+        self.assertInHistoryIs(1, 'r1', 'tag:bzr-0.14')
+
+    def test_failed_lookup(self):
+        # tags that don't exist give a specific message: arguably we should
+        # just give InvalidRevisionSpec but I think this is more helpful
+        self.assertRaises(errors.NoSuchTag,
+            self.get_in_history,
+            'tag:some-random-tag')
 
 
 class TestRevisionSpec_date(TestRevisionSpec):




More information about the bazaar-commits mailing list