Rev 2240: Tag methods now available through Branch.tags.add_tag, etc in http://sourcefrog.net/bzr/tags
Martin Pool
mbp at sourcefrog.net
Tue Feb 20 07:50:01 GMT 2007
At http://sourcefrog.net/bzr/tags
------------------------------------------------------------
revno: 2240
revision-id: mbp at sourcefrog.net-20070220075000-2hz26ddu1hm28jrl
parent: mbp at sourcefrog.net-20070220054112-5ch1jqmy9m5zbk72
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: tags
timestamp: Tue 2007-02-20 18:50:00 +1100
message:
Tag methods now available through Branch.tags.add_tag, etc
modified:
BRANCH.TODO BRANCH.TODO-20060103052123-79ac4969351c03a9
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/revisionspec.py revisionspec.py-20050907152633-17567659fd5c0ddb
bzrlib/tag.py tag.py-20070212110532-91cw79inah2cfozx-1
bzrlib/tests/blackbox/test_tags.py test_tags.py-20070116132048-5h4qak2cm22jlb9e-1
bzrlib/tests/branch_implementations/test_tags.py test_tags.py-20070212110545-w2s799hm2jlbsmg5-1
bzrlib/tests/test_revisionnamespaces.py testrevisionnamespaces.py-20050711050225-8b4af89e6b1efe84
bzrlib/tests/test_tag.py test_tag.py-20070212110532-91cw79inah2cfozx-2
=== modified file 'BRANCH.TODO'
--- a/BRANCH.TODO 2007-02-20 05:25:57 +0000
+++ b/BRANCH.TODO 2007-02-20 07:50:00 +0000
@@ -40,13 +40,14 @@
- make tag on arbitrary revisions
- copy tags when cloning the repository
- copy tags on push and pull
-
-Plan
-----
-
- move tag operations onto branch
- store tags in bencode format - or nul-delimited
- test use of unicode tags
+ - rename TagStore and change to branch.tags
+
+Plan
+----
+
- delete tags, and mark as deleted
- record who set tags, when, why
- tests that -d accepts urls, etc
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-02-15 01:23:29 +0000
+++ b/bzrlib/branch.py 2007-02-20 07:50:00 +0000
@@ -41,8 +41,8 @@
from bzrlib.config import BranchConfig, TreeConfig
from bzrlib.lockable_files import LockableFiles, TransportLock
from bzrlib.tag import (
- BasicTagStore,
- DisabledTagStore,
+ BasicTags,
+ DisabledTags,
)
""")
@@ -93,11 +93,11 @@
base = None
# override this to set the strategy for storing tags
- def _make_tag_store(self):
- return DisabledTagStore(self)
+ def _make_tags(self):
+ return DisabledTags(self)
def __init__(self, *ignored, **ignored_too):
- self._tag_store = self._make_tag_store()
+ self.tags = self._make_tags()
def break_lock(self):
"""Break a lock if one is present from another instance.
@@ -656,21 +656,6 @@
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_branch):
"""Copy tags to another branch.
"""
@@ -679,7 +664,7 @@
return
to_branch.lock_write()
try:
- to_branch._set_tag_dict(self.get_tag_dict())
+ to_branch.tags._set_tag_dict(self.tags.get_tag_dict())
finally:
to_branch.unlock()
@@ -1696,8 +1681,8 @@
def is_supported(cls):
return True
- def _make_tag_store(self):
- return BasicTagStore(self)
+ def _make_tags(self):
+ return BasicTags(self)
@classmethod
def supports_tags(cls):
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-02-15 01:23:29 +0000
+++ b/bzrlib/builtins.py 2007-02-20 07:50:00 +0000
@@ -892,7 +892,7 @@
This method has common command-line behaviour about handling
error cases.
"""
- if not from_branch.supports_tags():
+ if not from_branch.tags.supports_tags():
# obviously nothing to copy
return
# TODO: give a warning if the source format supports tags and actually has
@@ -3190,7 +3190,7 @@
revision_id = revision[0].in_history(branch).rev_id
else:
revision_id = branch.last_revision()
- branch.set_tag(tag_name, revision_id)
+ branch.tags.set_tag(tag_name, revision_id)
self.outf.write('created tag %s' % tag_name)
=== modified file 'bzrlib/revisionspec.py'
--- a/bzrlib/revisionspec.py 2007-02-15 01:23:29 +0000
+++ b/bzrlib/revisionspec.py 2007-02-20 07:50:00 +0000
@@ -486,7 +486,7 @@
def _match_on(self, branch, revs):
# Can raise tags not supported, NoSuchTag, etc
return RevisionInfo.from_revision_id(branch,
- branch.lookup_tag(self.spec),
+ branch.tags.lookup_tag(self.spec),
revs)
SPEC_TYPES.append(RevisionSpec_tag)
=== modified file 'bzrlib/tag.py'
--- a/bzrlib/tag.py 2007-02-13 13:18:37 +0000
+++ b/bzrlib/tag.py 2007-02-20 07:50:00 +0000
@@ -14,11 +14,16 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-"""Tag storage"""
-
-# NOTE: Don't try to call this 'tags.py', vim seems to get confused about
-# whether it's a tag or source file.
-
+"""Tag strategies.
+
+These are contained within a branch and normally constructed
+when the branch is opened. Clients should typically do
+
+ Branch.tags.add('name', 'value')
+"""
+
+# NOTE: I was going to call this tags.py, but vim seems to think all files
+# called tags* are ctags files... mbp 20070220.
from bzrlib import (
@@ -27,16 +32,12 @@
from bzrlib.util import bencode
-######################################################################
-# tag storage
-
-
-class _TagStore(object):
+class _Tags(object):
def __init__(self, branch):
self.branch = branch
-class DisabledTagStore(_TagStore):
+class DisabledTags(_Tags):
"""Tag storage that refuses to store anything.
This is used by older formats that can't store tags.
@@ -54,7 +55,7 @@
lookup_tag = _not_supported
-class BasicTagStore(_TagStore):
+class BasicTags(_Tags):
"""Tag storage in an unversioned branch control file.
"""
=== modified file 'bzrlib/tests/blackbox/test_tags.py'
--- a/bzrlib/tests/blackbox/test_tags.py 2007-02-15 01:28:07 +0000
+++ b/bzrlib/tests/blackbox/test_tags.py 2007-02-20 07:50:00 +0000
@@ -59,34 +59,35 @@
out, err = self.run_bzr('tag', '-d', 'branch', 'NEWTAG')
self.assertContainsRe(out, 'created tag NEWTAG')
# tag should be observable through the api
- self.assertEquals(t.branch.get_tag_dict(), dict(NEWTAG='first-revid'))
+ self.assertEquals(t.branch.tags.get_tag_dict(),
+ dict(NEWTAG='first-revid'))
# can also create tags using -r
self.run_bzr('tag', '-d', 'branch', 'tag2', '-r1')
- self.assertEquals(t.branch.lookup_tag('tag2'), 'first-revid')
+ self.assertEquals(t.branch.tags.lookup_tag('tag2'), 'first-revid')
def test_branch_push_pull_merge_copies_tags(self):
t = self.make_branch_and_tree('branch1')
t.commit(allow_pointless=True, message='initial commit',
rev_id='first-revid')
b1 = t.branch
- b1.set_tag('tag1', 'first-revid')
+ b1.tags.set_tag('tag1', 'first-revid')
# branching copies the tag across
self.run_bzr('branch', 'branch1', 'branch2')
b2 = Branch.open('branch2')
- self.assertEquals(b2.lookup_tag('tag1'), 'first-revid')
+ self.assertEquals(b2.tags.lookup_tag('tag1'), 'first-revid')
# make a new tag and pull it
- b1.set_tag('tag2', 'twa')
+ b1.tags.set_tag('tag2', 'twa')
self.run_bzr('pull', '-d', 'branch2', 'branch1')
- self.assertEquals(b2.lookup_tag('tag2'), 'twa')
+ self.assertEquals(b2.tags.lookup_tag('tag2'), 'twa')
# make a new tag and push it
- b1.set_tag('tag3', 'san')
+ b1.tags.set_tag('tag3', 'san')
self.run_bzr('push', '-d', 'branch1', 'branch2')
- self.assertEquals(b2.lookup_tag('tag3'), 'san')
+ self.assertEquals(b2.tags.lookup_tag('tag3'), 'san')
# make a new tag and merge it
t.commit(allow_pointless=True, message='second commit',
rev_id='second-revid')
t2 = WorkingTree.open('branch2')
t2.commit(allow_pointless=True, message='commit in second')
- b1.set_tag('tag4', 'second-revid')
+ b1.tags.set_tag('tag4', 'second-revid')
self.run_bzr('merge', '-d', 'branch2', 'branch1')
- self.assertEquals(b2.lookup_tag('tag4'), 'second-revid')
+ self.assertEquals(b2.tags.lookup_tag('tag4'), 'second-revid')
=== modified file 'bzrlib/tests/branch_implementations/test_tags.py'
--- a/bzrlib/tests/branch_implementations/test_tags.py 2007-02-13 13:01:00 +0000
+++ b/bzrlib/tests/branch_implementations/test_tags.py 2007-02-20 07:50:00 +0000
@@ -14,7 +14,11 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-"""Tags stored within a repository"""
+"""Tags stored within a branch
+
+The tags are actually in the Branch.tags namespace, but these are
+1:1 with Branch implementations so can be tested from here.
+"""
import os
import re
@@ -47,27 +51,27 @@
def test_tags_initially_empty(self):
b = self.make_branch('b')
- tags = b.get_tag_dict()
+ tags = b.tags.get_tag_dict()
self.assertEqual(tags, {})
def test_make_and_lookup_tag(self):
b = self.make_branch('b')
- b.set_tag('tag-name', 'target-revid-1')
- b.set_tag('other-name', 'target-revid-2')
+ b.tags.set_tag('tag-name', 'target-revid-1')
+ b.tags.set_tag('other-name', 'target-revid-2')
# then reopen the branch and see they're still there
b = Branch.open('b')
- self.assertEqual(b.get_tag_dict(),
+ self.assertEqual(b.tags.get_tag_dict(),
{'tag-name': 'target-revid-1',
'other-name': 'target-revid-2',
})
# read one at a time
- result = b.lookup_tag('tag-name')
+ result = b.tags.lookup_tag('tag-name')
self.assertEqual(result, 'target-revid-1')
def test_no_such_tag(self):
b = self.make_branch('b')
try:
- b.lookup_tag('bosko')
+ b.tags.lookup_tag('bosko')
except errors.NoSuchTag, e:
self.assertEquals(e.tag_name, 'bosko')
self.assertEquals(str(e), 'No such tag: bosko')
@@ -77,9 +81,9 @@
def test_copy_tags(self):
b1 = self.make_branch('b1')
b2 = self.make_branch('b2')
- b1.set_tag('tagname', 'revid')
+ b1.tags.set_tag('tagname', 'revid')
b1.copy_tags_to(b2)
- self.assertEquals(b2.lookup_tag('tagname'), 'revid')
+ self.assertEquals(b2.tags.lookup_tag('tagname'), 'revid')
def test_unicode_tag(self):
b1 = self.make_branch('b')
@@ -87,8 +91,8 @@
# in anticipation of the planned change to treating revision ids as
# just 8bit strings
revid = ('revid' + tag_name).encode('utf-8')
- b1.set_tag(tag_name, revid)
- self.assertEquals(b1.lookup_tag(tag_name), revid)
+ b1.tags.set_tag(tag_name, revid)
+ self.assertEquals(b1.tags.lookup_tag(tag_name), revid)
class TestUnsupportedTags(TestCaseWithBranch):
@@ -110,10 +114,10 @@
def test_tag_methods_raise(self):
b = self.make_branch('b')
self.assertRaises(errors.TagsNotSupported,
- b.set_tag, 'foo', 'bar')
- self.assertRaises(errors.TagsNotSupported,
- b.lookup_tag, 'foo')
- self.assertRaises(errors.TagsNotSupported,
- b.set_tag, 'foo', 'bar')
+ b.tags.set_tag, 'foo', 'bar')
+ self.assertRaises(errors.TagsNotSupported,
+ b.tags.lookup_tag, 'foo')
+ self.assertRaises(errors.TagsNotSupported,
+ b.tags.set_tag, 'foo', 'bar')
=== modified file 'bzrlib/tests/test_revisionnamespaces.py'
--- a/bzrlib/tests/test_revisionnamespaces.py 2007-02-12 11:46:43 +0000
+++ b/bzrlib/tests/test_revisionnamespaces.py 2007-02-20 07:50:00 +0000
@@ -355,7 +355,7 @@
self.assertEqual(spec.spec, 'bzr-0.14')
def test_lookup_tag(self):
- self.tree.branch.set_tag('bzr-0.14', 'r1')
+ self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
self.assertInHistoryIs(1, 'r1', 'tag:bzr-0.14')
def test_failed_lookup(self):
=== modified file 'bzrlib/tests/test_tag.py'
--- a/bzrlib/tests/test_tag.py 2007-02-13 13:01:00 +0000
+++ b/bzrlib/tests/test_tag.py 2007-02-20 07:50:00 +0000
@@ -16,6 +16,7 @@
from bzrlib import tag
+from bzrlib.tag import BasicTags
from bzrlib.tests import TestCase
class TestTagSerialization(TestCase):
@@ -27,7 +28,7 @@
#
# This release stores them in bencode as a dictionary from name to
# target.
- store = tag.BasicTagStore(branch=None)
+ store = BasicTags(branch=None)
td = dict(stable='stable-revid', boring='boring-revid')
packed = store._serialize_tag_dict(td)
expected = r'd6:boring12:boring-revid6:stable12:stable-revide'
More information about the bazaar-commits
mailing list