Merge lp:~lifeless/bzr-builddeb/trunk into lp:bzr-builddeb

Proposed by Robert Collins
Status: Merged
Merged at revision: 463
Proposed branch: lp:~lifeless/bzr-builddeb/trunk
Merge into: lp:bzr-builddeb
Diff against target: 268 lines (+183/-27)
4 files modified
bzrtools_import.py (+32/-21)
debian/changelog (+7/-0)
dh_make.py (+10/-1)
tests/blackbox/test_merge_upstream.py (+134/-5)
To merge this branch: bzr merge lp:~lifeless/bzr-builddeb/trunk
Reviewer Review Type Date Requested Status
Bzr-builddeb-hackers Pending
Review via email: mp+29167@code.launchpad.net

Commit message

Candidate (missing tests) fix for bug lp:588060.

Description of the change

This fixes the unversioned executability issue for me, but I haven't
written a unit test yet. Merging this as-is may be a step forward, though
a test is obviously preferrable, I'm not sure when I'll have tuits to get
around to that.

To post a comment you must log in.
lp:~lifeless/bzr-builddeb/trunk updated
463. By Robert Collins

Happy path tests R us. bzrtools_import file id resolution fix tested.

Revision history for this message
Robert Collins (lifeless) wrote :

This now has a happy path test. \o/

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

Merged with a tweak to the tests to use a lower level API for setup.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrtools_import.py'
--- bzrtools_import.py 2010-05-28 00:36:04 +0000
+++ bzrtools_import.py 2010-07-06 05:35:40 +0000
@@ -197,12 +197,20 @@
197 import_archive(tree, dir_file, file_ids_from=file_ids_from)197 import_archive(tree, dir_file, file_ids_from=file_ids_from)
198198
199def import_archive(tree, archive_file, file_ids_from=None):199def import_archive(tree, archive_file, file_ids_from=None):
200 if file_ids_from is None:
201 file_ids_from = []
202 for other_tree in file_ids_from:
203 other_tree.lock_read()
204 try:
205 return _import_archive(tree, archive_file, file_ids_from)
206 finally:
207 for other_tree in file_ids_from:
208 other_tree.unlock()
209
210
211def _import_archive(tree, archive_file, file_ids_from):
200 prefix = common_directory(names_of_files(archive_file))212 prefix = common_directory(names_of_files(archive_file))
201 tt = TreeTransform(tree)213 tt = TreeTransform(tree)
202
203 if file_ids_from is None:
204 file_ids_from = []
205
206 removed = set()214 removed = set()
207 for path, entry in tree.inventory.iter_entries():215 for path, entry in tree.inventory.iter_entries():
208 if entry.parent_id is None:216 if entry.parent_id is None:
@@ -231,6 +239,26 @@
231 add_implied_parents(implied_parents, relative_path)239 add_implied_parents(implied_parents, relative_path)
232 trans_id = tt.trans_id_tree_path(relative_path)240 trans_id = tt.trans_id_tree_path(relative_path)
233 added.add(relative_path.rstrip('/'))241 added.add(relative_path.rstrip('/'))
242 # To handle renames, we need to not use the preserved file id, rather
243 # we need to lookup the file id in a from_tree, if there is one. If
244 # there isn't, we should use the one in the current tree, and failing
245 # that we will allocate one. In this importer we want the file_ids_from
246 # tree to authoritative about id2path, which is why we consult it
247 # first.
248 existing_file_id = tt.tree_file_id(trans_id)
249 for other_tree in file_ids_from:
250 found_file_id = other_tree.path2id(relative_path)
251 if found_file_id:
252 if found_file_id != existing_file_id:
253 # Found a specific file id in one of the source trees
254 tt.version_file(found_file_id, trans_id)
255 break
256 if not found_file_id and not existing_file_id:
257 # No file_id in any of the source trees and no file id in the base
258 # tree.
259 name = basename(member.name.rstrip('/'))
260 file_id = generate_ids.gen_file_id(name)
261 tt.version_file(file_id, trans_id)
234 path = tree.abspath(relative_path)262 path = tree.abspath(relative_path)
235 if member.name in seen:263 if member.name in seen:
236 if tt.final_kind(trans_id) == 'file':264 if tt.final_kind(trans_id) == 'file':
@@ -248,23 +276,6 @@
248 tt.create_symlink(member.linkname, trans_id)276 tt.create_symlink(member.linkname, trans_id)
249 else:277 else:
250 raise UnknownType(relative_path)278 raise UnknownType(relative_path)
251 if tt.tree_file_id(trans_id) is None:
252 found = False
253 for other_tree in file_ids_from:
254 other_tree.lock_read()
255 try:
256 if other_tree.has_filename(relative_path):
257 file_id = other_tree.path2id(relative_path)
258 if file_id is not None:
259 tt.version_file(file_id, trans_id)
260 found = True
261 break
262 finally:
263 other_tree.unlock()
264 if not found:
265 name = basename(member.name.rstrip('/'))
266 file_id = generate_ids.gen_file_id(name)
267 tt.version_file(file_id, trans_id)
268279
269 for relative_path in implied_parents.difference(added):280 for relative_path in implied_parents.difference(added):
270 if relative_path == "":281 if relative_path == "":
271282
=== modified file 'debian/changelog'
--- debian/changelog 2010-05-31 17:33:49 +0000
+++ debian/changelog 2010-07-06 05:35:40 +0000
@@ -1,3 +1,10 @@
1bzr-builddeb (2.5lifeless1) UNRELEASED; urgency=low
2
3 * (No tests yet) treat the upstream branch as authoritative for file ids -
4 causes renamed to be honoured. (LP: #588060)
5
6 -- Robert Collins <robertc@robertcollins.net> Sun, 04 Jul 2010 20:29:17 +1000
7
1bzr-builddeb (2.5) UNRELEASED; urgency=low8bzr-builddeb (2.5) UNRELEASED; urgency=low
29
3 [ Colin Watson ]10 [ Colin Watson ]
411
=== modified file 'dh_make.py'
--- dh_make.py 2010-05-05 07:20:17 +0000
+++ dh_make.py 2010-07-06 05:35:40 +0000
@@ -108,8 +108,17 @@
108 tree.add("debian/source/format")108 tree.add("debian/source/format")
109 command = ["dh_make", "--addmissing", "--packagename",109 command = ["dh_make", "--addmissing", "--packagename",
110 "%s_%s" % (package_name, version)]110 "%s_%s" % (package_name, version)]
111 if getattr(sys.stdin, 'fileno', None) is None:
112 # running in a test or something
113 stdin = subprocess.PIPE
114 input = "s\n\n"
115 else:
116 stdin = sys.stdin
117 input = None
111 proc = subprocess.Popen(command, cwd=tree.basedir,118 proc = subprocess.Popen(command, cwd=tree.basedir,
112 preexec_fn=util.subprocess_setup, stdin=sys.stdin)119 preexec_fn=util.subprocess_setup, stdin=stdin)
120 if input:
121 proc.stdin.write(input)
113 retcode = proc.wait()122 retcode = proc.wait()
114 if retcode != 0:123 if retcode != 0:
115 raise bzr_errors.BzrCommandError("dh_make failed.")124 raise bzr_errors.BzrCommandError("dh_make failed.")
116125
=== modified file 'tests/blackbox/test_merge_upstream.py'
--- tests/blackbox/test_merge_upstream.py 2008-03-05 17:00:51 +0000
+++ tests/blackbox/test_merge_upstream.py 2010-07-06 05:35:40 +0000
@@ -18,12 +18,141 @@
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19#19#
2020
21from bzrlib.plugins.builddeb.tests import BuilddebTestCase21import os.path
22
23import bzrlib.export
24
25from bzrlib.plugins.builddeb.tests import (
26 BuilddebTestCase,
27 SourcePackageBuilder,
28 )
29
30
31class Fixture(object):
32 """A test fixture."""
33
34 def __init__(self):
35 pass
36
37 def setUp(self, test_case):
38 test_case.addCleanup(self.tearDown)
39
40 def tearDown(self):
41 pass
42
43
44class Upstream(Fixture):
45 """An upstream.
46
47 :ivar tree: The tree of the upstream.
48 """
49
50 def setUp(self, test_case):
51 Fixture.setUp(self, test_case)
52 treename = test_case.getUniqueString()
53 tree = test_case.make_branch_and_tree(treename)
54 filename = test_case.getUniqueString()
55 test_case.build_tree(["%s/%s" % (treename, filename)])
56 tree.add([filename])
57 tree.commit(test_case.getUniqueString())
58 self.tree = tree
59
60
61class ExportedTarball(Fixture):
62 """An exported tarball 'release'."""
63
64 def __init__(self, upstream, version):
65 self.upstream = upstream
66 self.version = version
67
68 def setUp(self, test_case):
69 filename = "project-%s.tar.gz" % self.version
70 tree = self.upstream.tree.branch.repository.revision_tree(
71 self.upstream.tree.branch.last_revision())
72 bzrlib.export.export(tree, filename)
73 self.tarball = filename
74
75
76class DHMadePackage(Fixture):
77 """A package made via dh-make."""
78
79 def __init__(self, tar, upstream):
80 self.tar = tar
81 self.upstream = upstream
82
83 def setUp(self, test_case):
84 branchpath = test_case.getUniqueString()
85 tree = self.upstream.tree.bzrdir.sprout(branchpath).open_workingtree()
86 # UGH: spews, because the subprocess output isn't captured. Be nicer to
87 # use closer to the metal functions here, but I'm overwhelmed by the
88 # API today, and there is a grue.
89 test_case.run_bzr(['dh-make', 'package', str(self.tar.version),
90 os.path.abspath(self.tar.tarball)], working_dir=branchpath)
91 tree.smart_add([tree.basedir])
92 tree.commit('debianised.') # Honestly.
93 self.tree = tree
94
95
96class FileMovedReplacedUpstream(Fixture):
97 """An upstream that has been changed by moving and replacing a file."""
98
99 def __init__(self, upstream):
100 self.upstream = upstream
101
102 def setUp(self, test_case):
103 branchpath = test_case.getUniqueString()
104 tree = self.upstream.tree.bzrdir.sprout(branchpath).open_workingtree()
105 self.tree = tree
106 tree.lock_write()
107 try:
108 newpath = test_case.getUniqueString()
109 for child in tree.inventory.root.children.values():
110 if child.kind == 'file':
111 oldpath = child.name
112 tree.rename_one(oldpath, newpath)
113 test_case.build_tree(["%s/%s" % (os.path.basename(tree.basedir),
114 oldpath)])
115 tree.add([oldpath])
116 tree.commit('yo, renaming and replacing')
117 finally:
118 tree.unlock()
119
22120
23121
24class TestMergeUpstream(BuilddebTestCase):122class TestMergeUpstream(BuilddebTestCase):
25123
26 def test_merge_upstream_available(self):124 def test_merge_upstream_available(self):
27 self.run_bzr('merge-upstream --help')125 self.run_bzr('merge-upstream --help')
28126
29# vim: ts=2 sts=2 sw=2127 def make_upstream(self):
128 result = Upstream()
129 result.setUp(self)
130 return result
131
132 def release_upstream(self, upstream):
133 tar = ExportedTarball(upstream, version=self.getUniqueInteger())
134 tar.setUp(self)
135 return tar
136
137 def import_upstream(self, tar, upstream):
138 packaging = DHMadePackage(tar, upstream)
139 packaging.setUp(self)
140 return packaging
141
142 def file_moved_replaced_upstream(self, upstream):
143 result = FileMovedReplacedUpstream(upstream)
144 result.setUp(self)
145 return result
146
147 def test_smoke_renamed_file(self):
148 # When a file is renamed by upstream, it should still import ok.
149 upstream = self.make_upstream()
150 rel1 = self.release_upstream(upstream)
151 package = self.import_upstream(rel1, upstream)
152 changed_upstream = self.file_moved_replaced_upstream(upstream)
153 rel2 = self.release_upstream(changed_upstream)
154 self.run_bzr(['merge-upstream', '--version', str(rel2.version),
155 os.path.abspath(rel2.tarball), changed_upstream.tree.basedir],
156 working_dir=package.tree.basedir)
157
158# vim: ts=4 sts=4 sw=4

Subscribers

People subscribed via source and target branches