[Pkg-bazaar-commits] r117 ./bzr-builddeb/people/jdw/merge_upstream: Fast forward the import when possible.
James Westby
jw+debian at jameswestby.net
Fri Jun 22 17:19:50 UTC 2007
------------------------------------------------------------
revno: 117
committer: James Westby <jw+debian at jameswestby.net>
branch nick: merge-upstream.siretart
timestamp: Fri 2007-06-22 18:05:26 +0100
message:
Fast forward the import when possible.
If we are told that the last upstream import was the last revision then
just do a plain import of the tarball. This would be rare, but before it
was an error, and it makes the command usable to maintain a separate upstream
branch.
modified:
merge_upstream.py
tests/test_merge_upstream.py
-------------- next part --------------
=== modified file 'merge_upstream.py'
--- a/merge_upstream.py 2007-06-22 16:39:09 +0000
+++ b/merge_upstream.py 2007-06-22 17:05:26 +0000
@@ -43,6 +43,9 @@
The tree must have no uncommited changes.
+ If the specified old_revision is the tip of the tree's branch then
+ a fastforward is done, and will be committed.
+
:param tree: The tree upon which to operate.
:type tree: WorkingTree
:param source: The filename tarball to import from.
@@ -58,11 +61,24 @@
raise BzrCommandError("%s does not exists" % source)
current_revision = tree.last_revision()
revno, rev_id = old_revision.in_branch(tree.branch)
- tree.revert([], tree.branch.repository.revision_tree(rev_id))
- tar_input = open(source, 'rb')
- import_tar(tree, tar_input)
- tree.set_parent_ids([rev_id])
- tree.branch.set_last_revision_info(revno, rev_id)
- tree.commit('import upstream from %s' % os.path.basename(source))
- tree.merge_from_branch(tree.branch, to_revision=current_revision)
+ if rev_id != tree.branch.last_revision():
+ tree.revert([], tree.branch.repository.revision_tree(rev_id))
+ tar_input = open(source, 'rb')
+ try:
+ import_tar(tree, tar_input)
+ finally:
+ tar_input.close()
+ tree.set_parent_ids([rev_id])
+ tree.branch.set_last_revision_info(revno, rev_id)
+ tree.commit('import upstream from %s' % os.path.basename(source))
+ tree.merge_from_branch(tree.branch, to_revision=current_revision)
+ else:
+ # Fast forward the merge.
+ tar_input = open(source, 'rb')
+ try:
+ import_tar(tree, tar_input)
+ finally:
+ tar_input.close()
+ tree.commit('import upstream from %s' % os.path.basename(source))
+
=== modified file 'tests/test_merge_upstream.py'
--- a/tests/test_merge_upstream.py 2007-06-22 16:45:21 +0000
+++ b/tests/test_merge_upstream.py 2007-06-22 17:05:26 +0000
@@ -151,6 +151,32 @@
self.assertRaises(InvalidRevisionSpec, merge_upstream, self.wt,
self.upstream_tarball, make_revspec('NOTAREVID'))
+ def test_merge_upstream_handles_last_revision(self):
+ """Test handling of merging in to tip.
+
+ If the upstream revision is said to be at the latest revision in the
+ branch the code should do a fast-forward.
+ """
+ self.make_first_upstream_commit()
+ self.make_new_upstream_tarball()
+ revspec = make_revspec(self.wt.branch.last_revision())
+ merge_upstream(self.wt, self.upstream_tarball, revspec)
+ wt = self.wt
+ delta = wt.changes_from(wt.basis_tree(), want_unversioned=True,
+ want_unchanged=True)
+ self.assertEqual(delta.unversioned, [])
+ self.assertEqual(len(delta.unchanged), 2)
+ self.assertEqual(delta.unchanged[0], ('CHANGELOG', 'CHANGELOG-id', 'file'))
+ self.assertEqual(delta.unchanged[1][0], 'README-NEW')
+ self.assertEqual(delta.unchanged[1][2], 'file')
+ self.assertEqual(wt.conflicts(), [])
+ rh = wt.branch.revision_history()
+ self.assertEqual(len(rh), 2)
+ self.assertEqual(rh[0], self.upstream_rev_id_1)
+ self.assertEqual(len(wt.get_parent_ids()), 1)
+ self.assertEqual(wt.get_parent_ids()[0], rh[1])
+
+
class TestConflictMergeUpstreamNormal(TestCaseWithTransport):
"""Test merge upstream with conflicts in the new version."""
More information about the Pkg-bazaar-commits
mailing list