Merge lp:~jelmer/bzr-builddeb/upstream-revspec into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 669
Proposed branch: lp:~jelmer/bzr-builddeb/upstream-revspec
Merge into: lp:bzr-builddeb
Diff against target: 218 lines (+150/-12)
4 files modified
__init__.py (+7/-2)
debian/changelog (+6/-0)
revspec.py (+59/-4)
tests/test_revspec.py (+78/-6)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/upstream-revspec
Reviewer Review Type Date Requested Status
Bzr-builddeb-hackers Pending
Review via email: mp+86141@code.launchpad.net

Description of the change

Add a "upstream:" revision specifier, which can look up specific upstream revisions or the one matching the current working tree.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2011-12-03 01:24:37 +0000
3+++ __init__.py 2011-12-17 17:02:23 +0000
4@@ -240,10 +240,15 @@
5 from bzrlib.revisionspec import revspec_registry
6 revspec_registry.register_lazy("package:",
7 "bzrlib.plugins.builddeb.revspec", "RevisionSpec_package")
8+ revspec_registry.register_lazy("upstream:",
9+ "bzrlib.plugins.builddeb.revspec", "RevisionSpec_upstream")
10 except ImportError:
11 from bzrlib.revisionspec import SPEC_TYPES
12- from bzrlib.plugins.builddeb.revspec import RevisionSpec_package
13- SPEC_TYPES.append(RevisionSpec_package)
14+ from bzrlib.plugins.builddeb.revspec import (
15+ RevisionSpec_package,
16+ RevisionSpec_upstream,
17+ )
18+ SPEC_TYPES.extend([RevisionSpec_package, RevisionSpec_upstream])
19
20 try:
21 from bzrlib.tag import tag_sort_methods
22
23=== modified file 'debian/changelog'
24--- debian/changelog 2011-12-16 19:27:32 +0000
25+++ debian/changelog 2011-12-17 17:02:23 +0000
26@@ -1,3 +1,9 @@
27+bzr-builddeb (2.8.1) UNRELEASED; urgency=low
28+
29+ * New revision specifier 'upstream:'. LP: #905728
30+
31+ -- Jelmer Vernooij <jelmer@debian.org> Sat, 17 Dec 2011 17:41:19 +0100
32+
33 bzr-builddeb (2.8.0) unstable; urgency=low
34
35 [ Jonathan Riddell ]
36
37=== modified file 'revspec.py'
38--- revspec.py 2011-12-16 01:27:06 +0000
39+++ revspec.py 2011-12-17 17:02:23 +0000
40@@ -19,13 +19,17 @@
41 #
42
43 from bzrlib import version_info as bzrlib_version
44-from bzrlib.errors import NoSuchTag
45+from bzrlib.errors import (
46+ InvalidRevisionSpec,
47+ NoSuchTag,
48+ )
49 from bzrlib.revisionspec import RevisionSpec, RevisionInfo
50
51 from bzrlib.plugins.builddeb.errors import (
52- UnknownVersion,
53- VersionNotSpecified,
54- )
55+ MissingChangelogError,
56+ UnknownVersion,
57+ VersionNotSpecified,
58+ )
59
60
61 class RevisionSpec_package(RevisionSpec):
62@@ -59,3 +63,54 @@
63 branch, revision_id)
64 except NoSuchTag:
65 raise UnknownVersion(version_spec)
66+
67+
68+class RevisionSpec_upstream(RevisionSpec):
69+ """Selects the matching upstream revision."""
70+
71+ help_txt = """Selects the revision matching the upstream specified
72+ or the current upstream.
73+
74+ This will look at debian/changelog to find out the current version,
75+ and then look up the upstream.
76+ """
77+ wants_revision_history = False
78+ prefix = 'upstream:'
79+
80+ def _match_on(self, branch, revs):
81+ from bzrlib.workingtree import WorkingTree
82+ from bzrlib.plugins.builddeb.util import find_changelog
83+ from bzrlib.plugins.builddeb.upstream.pristinetar import PristineTarSource
84+ from debian.changelog import Version
85+ tree = WorkingTree.open_containing('.')[0]
86+ try:
87+ (cl, top_level) = find_changelog(tree, False)
88+ except MissingChangelogError, e:
89+ raise InvalidRevisionSpec(self.user_spec, branch,
90+ "no debian/changelog file found: %s" % e)
91+ if self.spec == '':
92+ version_spec = cl.version.upstream_version
93+ if not cl.version.debian_version:
94+ raise InvalidRevisionSpec(self.user_spec, branch,
95+ "This is a native package.")
96+ else:
97+ version = Version(self.spec)
98+ if version.upstream_version:
99+ version_spec = version.upstream_version
100+ else:
101+ version_spec = self.spec
102+
103+ pristine_tar_source = PristineTarSource(tree, branch)
104+ try:
105+ revision_id = pristine_tar_source.version_as_revisions(cl.package,
106+ version_spec)[None]
107+ if bzrlib_version < (2, 5):
108+ if revs is None:
109+ revs = branch.revision_history()
110+ return RevisionInfo.from_revision_id(branch,
111+ revision_id, revs)
112+ else:
113+ return RevisionInfo.from_revision_id(
114+ branch, revision_id)
115+ except NoSuchTag:
116+ raise UnknownVersion(version_spec)
117
118=== modified file 'tests/test_revspec.py'
119--- tests/test_revspec.py 2009-02-19 11:13:09 +0000
120+++ tests/test_revspec.py 2011-12-17 17:02:23 +0000
121@@ -18,15 +18,22 @@
122 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
123 #
124
125+import os
126+
127+from bzrlib.errors import InvalidRevisionSpec
128+from bzrlib.revisionspec import RevisionSpec
129+
130 from bzrlib.tests.test_revisionspec import TestRevisionSpec
131
132-from bzrlib.revisionspec import RevisionSpec
133-
134+from bzrlib.plugins.builddeb.tests import Version, Changelog
135 from bzrlib.plugins.builddeb.errors import (
136- UnknownVersion,
137- VersionNotSpecified,
138- )
139-from bzrlib.plugins.builddeb.revspec import RevisionSpec_package
140+ UnknownVersion,
141+ VersionNotSpecified,
142+ )
143+from bzrlib.plugins.builddeb.revspec import (
144+ RevisionSpec_package,
145+ RevisionSpec_upstream,
146+ )
147
148
149 class TestRevisionSpec_package(TestRevisionSpec):
150@@ -48,3 +55,68 @@
151 self.assertRaises(VersionNotSpecified,
152 self.get_in_history, 'package:')
153
154+
155+class TestRevisionSpec_upstream(TestRevisionSpec):
156+
157+ package_name = 'test'
158+ package_version = Version('0.1-1')
159+ upstream_version = property(lambda self: \
160+ self.package_version.upstream_version)
161+
162+ def make_changelog(self, version=None):
163+ if version is None:
164+ version = self.package_version
165+ c = Changelog()
166+ c.new_block()
167+ c.version = Version(version)
168+ c.package = self.package_name
169+ c.distributions = 'unstable'
170+ c.urgency = 'low'
171+ c.author = 'James Westby <jw+debian@jameswestby.net>'
172+ c.date = 'Thu, 3 Aug 2006 19:16:22 +0100'
173+ c.add_change('')
174+ c.add_change(' * test build')
175+ c.add_change('')
176+ return c
177+
178+ def write_changelog(self, changelog, filename):
179+ f = open(filename, 'w')
180+ changelog.write_to_open_file(f)
181+ f.close()
182+
183+ def add_changelog(self, tree, version):
184+ cl = self.make_changelog("1.2-1")
185+ tree.mkdir('debian')
186+ self.write_changelog(cl, os.path.join(tree.basedir, 'debian/changelog'))
187+ tree.add(['debian', 'debian/changelog'])
188+
189+ def test_from_string_package(self):
190+ self.make_branch_and_tree('.')
191+ spec = RevisionSpec.from_string('upstream:')
192+ self.assertIsInstance(spec, RevisionSpec_upstream)
193+ self.assertEqual(spec.spec, '')
194+
195+ def test_no_changelog(self):
196+ t = self.make_branch_and_tree('.')
197+ spec = RevisionSpec.from_string('upstream:')
198+ self.assertRaises(InvalidRevisionSpec, spec.as_revision_id, t.branch)
199+
200+ def test_version_specified(self):
201+ t = self.make_branch_and_tree('.')
202+ upstream_revid = t.commit('The upstream revision')
203+ t.branch.tags.set_tag("upstream-1.2", upstream_revid)
204+ t.commit('Mention upstream.')
205+ self.add_changelog(t, "1.2-1")
206+ spec = RevisionSpec.from_string('upstream:1.2')
207+ self.assertEquals(upstream_revid, spec.as_revision_id(t.branch))
208+ spec = RevisionSpec.from_string('upstream:1.2-1')
209+ self.assertEquals(upstream_revid, spec.as_revision_id(t.branch))
210+
211+ def test_version_from_changelog(self):
212+ t = self.make_branch_and_tree('.')
213+ upstream_revid = t.commit('The upstream revision')
214+ t.branch.tags.set_tag("upstream-1.2", upstream_revid)
215+ t.commit('Mention upstream.')
216+ self.add_changelog(t, "1.2-1")
217+ spec = RevisionSpec.from_string('upstream:')
218+ self.assertEquals(upstream_revid, spec.as_revision_id(t.branch))

Subscribers

People subscribed via source and target branches