Merge lp:~jelmer/bzr-builddeb/295274-merge-upstream-no-version into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 499
Proposed branch: lp:~jelmer/bzr-builddeb/295274-merge-upstream-no-version
Merge into: lp:bzr-builddeb
Prerequisite: lp:~jelmer/bzr-builddeb/get-latest-version
Diff against target: 349 lines (+117/-86)
4 files modified
cmds.py (+83/-82)
debian/changelog (+3/-0)
tests/test_upstream.py (+17/-0)
upstream.py (+14/-4)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/295274-merge-upstream-no-version
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+47216@code.launchpad.net

Description of the change

When running "bzr merge-upstream" it is no longer necessary to specify a version string if there is a debian/watch file.

To post a comment you must log in.
508. By Jelmer Vernooij

Add --snapshot option to merge-upstream.

509. By Jelmer Vernooij

Remove unused method.

Revision history for this message
James Westby (james-w) wrote :

A test would be nice, but it's very tricky so I think we'll have to live without it.

Thanks,

James

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

> A test would be nice, but it's very tricky so I think we'll have to live
> without it.
I'll work on some more tests for it. This code is fairly tricky to get right, too, so I think it's worth adding tests.

510. By Jelmer Vernooij

Merge fix for warnings tag.

511. By Jelmer Vernooij

merge lp:bzr-builddeb.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmds.py'
2--- cmds.py 2011-01-24 02:17:29 +0000
3+++ cmds.py 2011-01-28 19:44:31 +0000
4@@ -93,6 +93,7 @@
5 GetOrigSourceSource,
6 PristineTarSource,
7 SelfSplitSource,
8+ StackedUpstreamSource,
9 UScanSource,
10 UpstreamProvider,
11 UpstreamBranchSource,
12@@ -392,7 +393,7 @@
13 upstream_branch = Branch.open(config.upstream_branch)
14 upstream_sources.append(UpstreamBranchSource(upstream_branch))
15 upstream_sources.extend([
16- GetOrigSourceSource(tree, larstiq),
17+ GetOrigSourceSource(tree, larstiq),
18 UScanSource(tree, larstiq),
19 ])
20 if split:
21@@ -527,13 +528,16 @@
22 force_opt = Option('force',
23 help=('Force a merge even if the upstream branch '
24 'has not changed.'))
25+ snapshot_opt = Option('snapshot', help="Merge a snapshot from the "
26+ "upstream branch rather than a new upstream release.")
27+
28 v3_opt = Option('v3', help='Use dpkg-source format v3.')
29
30
31 takes_options = [package_opt, version_opt,
32 distribution_opt, directory_opt, last_version_opt,
33- force_opt, v3_opt, 'revision', 'merge-type']
34-
35+ force_opt, v3_opt, 'revision', 'merge-type',
36+ snapshot_opt]
37
38 def _add_changelog_entry(self, tree, package, version, distribution_name,
39 changelog):
40@@ -556,16 +560,6 @@
41 merge_type=merge_type, force=force)
42 return conflicts
43
44- def _export_tarball(self, package, version, orig_dir, upstream_branch,
45- upstream_revision):
46- # TODO: a way to use bz2 on export
47- dest_name = tarball_name(package, version)
48- tarball_filename = os.path.join(orig_dir, dest_name)
49- upstream = UpstreamBranchSource(upstream_branch,
50- {version: upstream_revision})
51- upstream.fetch_tarball(package, version, orig_dir)
52- return tarball_filename
53-
54 def _fetch_tarball(self, package, version, orig_dir, location, v3):
55 from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
56 format = None
57@@ -587,67 +581,21 @@
58 return tarball_filename
59
60 def _get_tarball(self, config, tree, package, version, upstream_branch,
61- upstream_revision, no_tarball, v3, location):
62+ upstream_revision, v3, location):
63 orig_dir = config.orig_dir or default_orig_dir
64 orig_dir = os.path.join(tree.basedir, orig_dir)
65 if not os.path.exists(orig_dir):
66 os.makedirs(orig_dir)
67- if upstream_branch and no_tarball:
68- tarball_filename = self._export_tarball(package, version,
69- orig_dir, upstream_branch, upstream_revision)
70- else:
71- tarball_filename = self._fetch_tarball(package, version, orig_dir,
72- location, v3)
73+ tarball_filename = self._fetch_tarball(package, version, orig_dir,
74+ location, v3)
75 return tarball_filename
76
77- def _get_version(self, version, package, no_tarball, upstream_branch,
78- upstream_revision, current_version):
79- from bzrlib.plugins.builddeb.merge_upstream import (
80- upstream_branch_version)
81- if version is None:
82- if upstream_branch and no_tarball:
83- version = str(upstream_branch_version(upstream_branch,
84- upstream_revision, package,
85- current_version))
86- note("Using version string %s for upstream branch." % (version))
87- else:
88- raise BzrCommandError("You must specify the "
89- "version number using --version.")
90- return version
91-
92- def _get_upstream_revision(self, upstream_branch, revision):
93- upstream_revision = None
94- if upstream_branch is not None:
95- if revision is not None:
96- if len(revision) > 1:
97- raise BzrCommandError("merge-upstream takes only a single --revision")
98- upstream_revspec = revision[0]
99- upstream_revision = upstream_revspec.as_revision_id(upstream_branch)
100- else:
101- upstream_revision = upstream_branch.last_revision()
102- return upstream_revision
103-
104- def _get_upstream_branch(self, location, upstream_branch, revision):
105- no_tarball = False
106- if upstream_branch is None:
107- try:
108- upstream_branch = Branch.open(location)
109- no_tarball = True
110- except NotBranchError:
111- upstream_branch = None
112- if revision is not None:
113- raise BzrCommandError("--revision is not allowed when"
114- " merging only a tarball")
115- else:
116- upstream_branch = Branch.open(upstream_branch)
117- return no_tarball, upstream_branch
118-
119 def _get_changelog_info(self, tree, last_version, package, distribution):
120 from bzrlib.plugins.builddeb.errors import MissingChangelogError
121 changelog = None
122 current_version = last_version
123 try:
124- changelog = find_changelog(tree, False, max_blocks=2)[0]
125+ (changelog, larstiq) = find_changelog(tree, False, max_blocks=2)
126 if last_version is None:
127 current_version = changelog.version.upstream_version
128 if package is None:
129@@ -672,20 +620,14 @@
130 if distribution_name is None:
131 raise BzrCommandError("Unknown target distribution: %s" \
132 % distribution)
133- return current_version, package, distribution, distribution_name, changelog
134-
135- def _get_upstream_location(self, location, config):
136- if location is None:
137- if config.upstream_branch is not None:
138- location = config.upstream_branch
139- else:
140- raise BzrCommandError("No location specified to merge")
141- return location
142+ return (current_version, package, distribution, distribution_name,
143+ changelog, larstiq)
144
145 def run(self, location=None, upstream_branch=None, version=None,
146 distribution=None, package=None,
147 directory=".", revision=None, merge_type=None,
148- last_version=None, force=None, v3=None):
149+ last_version=None, force=None, v3=None,
150+ snapshot=False):
151 tree, _ = WorkingTree.open_containing(directory)
152 tree.lock_write()
153 try:
154@@ -702,18 +644,77 @@
155 raise BzrCommandError("Merge upstream in native mode is not "
156 "yet supported.")
157
158- location = self._get_upstream_location(location, config)
159+ primary_upstream_source = None
160+
161+ if upstream_branch is None:
162+ upstream_branch = config.upstream_branch
163+
164+ if upstream_branch is None and location is not None:
165+ try:
166+ upstream_branch = Branch.open(location)
167+ except NotBranchError:
168+ upstream_branch = None
169+ elif upstream_branch is not None:
170+ upstream_branch = Branch.open(upstream_branch)
171+ if upstream_branch is not None:
172+ upstream_branch_source = UpstreamBranchSource(
173+ upstream_branch, config=config)
174+ else:
175+ upstream_branch_source = None
176+
177 (current_version, package, distribution, distribution_name,
178- changelog) = self._get_changelog_info( tree, last_version,
179+ changelog, larstiq) = self._get_changelog_info(tree, last_version,
180 package, distribution)
181- no_tarball, upstream_branch = self._get_upstream_branch(
182- location, upstream_branch, revision)
183- upstream_revision = self._get_upstream_revision(upstream_branch,
184- revision)
185- version = self._get_version(version, package, no_tarball,
186- upstream_branch, upstream_revision, current_version)
187+
188+ if location is not None:
189+ try:
190+ primary_upstream_source = UpstreamBranchSource(
191+ Branch.open(location), config=config)
192+ except NotBranchError:
193+ primary_upstream_source = None
194+ else:
195+ primary_upstream_source = None
196+ if primary_upstream_source is None:
197+ if snapshot:
198+ if upstream_branch_source is None:
199+ raise BzrCommandError("--snapshot requires an upstream "
200+ "branch source")
201+ primary_upstream_source = upstream_branch_source
202+ else:
203+ primary_upstream_source = UScanSource(tree, larstiq)
204+
205+ if revision is not None:
206+ if upstream_branch is None:
207+ raise BzrCommandError("--revision can only be used with a"
208+ "valid upstream branch")
209+ if len(revision) > 1:
210+ raise BzrCommandError("merge-upstream takes only a "
211+ "single --revision")
212+ upstream_revspec = revision[0]
213+ upstream_revision = upstream_revspec.as_revision_id(
214+ upstream_branch)
215+ else:
216+ upstream_revision = None
217+
218+ if version is None and upstream_revision is not None:
219+ # Look up the version from the upstream revision
220+ version = upstream_branch_source.get_version(package,
221+ current_version, upstream_revision)
222+ elif upstream_revision is None:
223+ if version is None:
224+ version = primary_upstream_source.get_latest_version(
225+ package, current_version)
226+ target_dir = tempfile.mkdtemp() # FIXME: Cleanup?
227+ location = primary_upstream_source.fetch_tarball(package, version, target_dir)
228+ note("Using version string %s." % (version))
229+ # Look up the revision id from the version string
230+ if upstream_branch_source is not None:
231+ upstream_revision = upstream_branch_source.version_as_revision(
232+ package, version)
233+ if version is None:
234+ raise BzrCommandError("You must specify the version number using --version.")
235 tarball_filename = self._get_tarball(config, tree, package,
236- version, upstream_branch, upstream_revision, no_tarball, v3,
237+ version, upstream_branch, upstream_revision, v3,
238 location)
239 conflicts = self._do_merge(tree, tarball_filename, version,
240 current_version, upstream_branch, upstream_revision,
241
242=== modified file 'debian/changelog'
243--- debian/changelog 2011-01-28 14:21:29 +0000
244+++ debian/changelog 2011-01-28 19:44:31 +0000
245@@ -29,6 +29,9 @@
246 #586617
247 * Fix "bzr builddeb" if last upload was not to a Ubuntu release pocket.
248 LP: #709263
249+ * If possible use uscan to find the latest upstream version string.
250+ LP: #295274
251+ * Add --snapshot option to merge-upstream.
252
253 -- Jelmer Vernooij <jelmer@debian.org> Fri, 28 Jan 2011 15:13:22 +0100
254
255
256=== modified file 'tests/test_upstream.py'
257--- tests/test_upstream.py 2011-01-24 04:17:20 +0000
258+++ tests/test_upstream.py 2011-01-28 19:44:31 +0000
259@@ -29,6 +29,9 @@
260 TestCase,
261 TestCaseWithTransport,
262 )
263+from bzrlib.plugins.builddeb.config import (
264+ DebBuildConfig,
265+ )
266 from bzrlib.plugins.builddeb.errors import (
267 PackageVersionNotPresent,
268 WatchFileMissing,
269@@ -274,6 +277,7 @@
270 </dehs>
271 """))
272
273+
274 class UpstreamBranchSourceTests(TestCaseWithTransport):
275 """Tests for UpstreamBranchSource."""
276
277@@ -306,3 +310,16 @@
278 self.tree.commit("msg")
279 self.assertEquals("2.1+bzr2", source.get_latest_version("foo", "1.0"))
280
281+ def test_version_as_revision(self):
282+ revid1 = self.tree.commit("msg")
283+ self.tree.branch.tags.set_tag("2.1", self.tree.branch.last_revision())
284+ config = DebBuildConfig(
285+ [('user.conf', True), ('default.conf', False)],
286+ branch=self.tree.branch)
287+ source = UpstreamBranchSource(self.tree.branch,
288+ {"2.1": self.tree.branch.last_revision()},
289+ config=config)
290+ revid2 = self.tree.commit("msg")
291+ self.assertEquals(revid2,
292+ source.version_as_revision("foo", "2.1+bzr2"))
293+ self.assertEquals(revid1, source.version_as_revision("foo", "2.1"))
294
295=== modified file 'upstream.py'
296--- upstream.py 2011-01-24 04:17:20 +0000
297+++ upstream.py 2011-01-28 19:44:31 +0000
298@@ -64,6 +64,14 @@
299 """
300 raise NotImplementedError(self.get_latest_version)
301
302+ def version_as_revision(self, package, version):
303+ """Lookup the revision id for a particular version.
304+
305+ :param package: Package name
306+ :package version: Version string
307+ """
308+ raise NotImplementedError(self.version_as_revision)
309+
310 def fetch_tarball(self, package, version, target_dir):
311 """Fetch the source tarball for a particular version.
312
313@@ -167,14 +175,16 @@
314 :ivar upstream_version_map: Map from version strings to revids
315 """
316
317- def __init__(self, upstream_branch, upstream_revision_map=None):
318+ def __init__(self, upstream_branch, upstream_revision_map=None,
319+ config=None):
320 self.upstream_branch = upstream_branch
321+ self.config = config
322 if upstream_revision_map is None:
323 self.upstream_revision_map = {}
324 else:
325 self.upstream_revision_map = upstream_revision_map
326
327- def _get_revision_id(self, version):
328+ def version_as_revision(self, package, version):
329 if version in self.upstream_revision_map:
330 return self.upstream_revision_map[version]
331 revspec = get_snapshot_revision(version)
332@@ -197,7 +207,7 @@
333 def fetch_tarball(self, package, version, target_dir):
334 self.upstream_branch.lock_read()
335 try:
336- revid = self._get_revision_id(version)
337+ revid = self.version_as_revision(package, version)
338 if revid is None:
339 raise PackageVersionNotPresent(package, version, self)
340 note("Exporting upstream branch revision %s to create the tarball",
341@@ -302,7 +312,7 @@
342 return None
343 dehs_tag = dehs_tags[0]
344 for w in dehs_tag.getElementsByTagName("warnings"):
345- warning(w)
346+ warning(w.firstChild.wholeText)
347 upstream_version_tags = dehs_tag.getElementsByTagName("upstream-version")
348 if len(upstream_version_tags) != 1:
349 return None

Subscribers

People subscribed via source and target branches