Rev 6031: Add code to determine the moste recent tag. in http://bazaar.launchpad.net/~jameinel/bzr/2.5-up-to-date-609187
John Arbash Meinel
john at arbash-meinel.com
Mon Jul 18 16:52:56 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.5-up-to-date-609187
------------------------------------------------------------
revno: 6031
revision-id: john at arbash-meinel.com-20110718165156-f519epfjwqnq1juw
parent: john at arbash-meinel.com-20110718163649-h1m30rojfejn1b19
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.5-up-to-date-609187
timestamp: Mon 2011-07-18 18:51:56 +0200
message:
Add code to determine the moste recent tag.
This way, we can tell the user where the branch *is* at, so they can work out
how out-of-date we are, etc.
-------------- next part --------------
=== modified file 'bzrlib/plugins/launchpad/__init__.py'
--- a/bzrlib/plugins/launchpad/__init__.py 2011-07-18 16:36:49 +0000
+++ b/bzrlib/plugins/launchpad/__init__.py 2011-07-18 16:51:56 +0000
@@ -526,10 +526,15 @@
place = archive.title()
if series is not None:
place = '%s/%s' % (place, series.title())
+ best_tag = lp_api_lite.get_most_recent_tag(tags, the_branch)
+ if best_tag is None:
+ best_message = ''
+ else:
+ best_message = '\nThe most recent tag found is %s' % (best_tag,)
trace.warning(
'Packaging branch is not up-to-date. The most recent published\n'
- 'version in %s is %s, but it is not in the branch tags for:\n %s'
- % (place, latest_ver, the_branch.base))
+ 'version in %s is %s, but it is not in the branch tags for:\n %s%s'
+ % (place, latest_ver, the_branch.base, best_message))
def _register_hooks():
_mod_branch.Branch.hooks.install_named_hook('open',
=== modified file 'bzrlib/plugins/launchpad/lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-18 16:22:48 +0000
+++ b/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-18 16:51:56 +0000
@@ -37,6 +37,7 @@
import urllib2
from bzrlib import (
+ revision,
trace,
)
@@ -170,3 +171,19 @@
return lp.get_latest_version()
+def get_most_recent_tag(tag_dict, the_branch):
+ """Get the most recent revision that has been tagged."""
+ # Note: this assumes that a given rev won't get tagged multiple times. But
+ # it should be valid for the package importer branches that we care
+ # about
+ reverse_dict = dict((rev, tag) for tag, rev in tag_dict.iteritems())
+ the_branch.lock_read()
+ try:
+ last_rev = the_branch.last_revision()
+ graph = the_branch.repository.get_graph()
+ stop_revisions = (None, revision.NULL_REVISION)
+ for rev_id in graph.iter_lefthand_ancestry(last_rev, stop_revisions):
+ if rev_id in reverse_dict:
+ return reverse_dict[rev_id]
+ finally:
+ the_branch.unlock()
=== modified file 'bzrlib/plugins/launchpad/test_lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-18 16:22:48 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-18 16:51:56 +0000
@@ -325,3 +325,26 @@
'http://bazaar.launchpad.net/+branch'
'/~ubuntu-branches/debian/sid/foo/sid',
'debian', 'sid', 'foo')
+
+
+class TestGetMostRecentTag(tests.TestCaseWithMemoryTransport):
+
+ def make_simple_builder(self):
+ builder = self.make_branch_builder('tip')
+ builder.build_snapshot('A', [], [
+ ('add', ('', 'root-id', 'directory', None))])
+ b = builder.get_branch()
+ b.tags.set_tag('tip-1.0', 'A')
+ return builder, b, b.tags.get_tag_dict()
+
+ def test_get_most_recent_tag_tip(self):
+ builder, b, tag_dict = self.make_simple_builder()
+ self.assertEqual('tip-1.0',
+ lp_api_lite.get_most_recent_tag(tag_dict, b))
+
+ def test_get_most_recent_tag_older(self):
+ builder, b, tag_dict = self.make_simple_builder()
+ builder.build_snapshot('B', ['A'], [])
+ self.assertEqual('B', b.last_revision())
+ self.assertEqual('tip-1.0',
+ lp_api_lite.get_most_recent_tag(tag_dict, b))
More information about the bazaar-commits
mailing list