Rev 3236: Basic push --reference support, requires url, slow. in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
Robert Collins
robertc at robertcollins.net
Mon Feb 25 10:02:36 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
------------------------------------------------------------
revno: 3236
revision-id:robertc at robertcollins.net-20080225100231-4e202i2ebxak2ya6
parent: robertc at robertcollins.net-20080225051318-akvbqjbo0q7512a2
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.reference
timestamp: Mon 2008-02-25 21:02:31 +1100
message:
Basic push --reference support, requires url, slow.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2008-02-01 00:30:33 +0000
+++ b/bzrlib/builtins.py 2008-02-25 10:02:31 +0000
@@ -697,18 +697,24 @@
' directory exists, but does not already'
' have a control directory. This flag will'
' allow push to proceed.'),
+ Option('reference',
+ help='Create a shallow branch that only refers to another branch '
+ 'for the commit history. Only the work not present in that '
+ 'other branch is included in this shallow branch.',
+ type=unicode),
]
takes_args = ['location?']
encoding_type = 'replace'
def run(self, location=None, remember=False, overwrite=False,
- create_prefix=False, verbose=False,
- use_existing_dir=False,
- directory=None):
+ create_prefix=False, verbose=False, use_existing_dir=False,
+ directory=None, reference=None):
# FIXME: Way too big! Put this into a function called from the
# command.
if directory is None:
directory = '.'
+ if reference is not None:
+ reference = urlutils.normalize_url(reference)
br_from = Branch.open_containing(directory)[0]
stored_loc = br_from.get_push_location()
if location is None:
@@ -780,11 +786,31 @@
# Now the target directory exists, but doesn't have a .bzr
# directory. So we need to create it, along with any work to create
# all of the dependent branches, etc.
- dir_to = br_from.bzrdir.clone_on_transport(to_transport,
- revision_id=br_from.last_revision())
+ if reference is not None:
+ # This should be buried in the clone method itself. TODO.
+ try:
+ # if the from format is stackable, this will either work or
+ # trigger NotStacked. If its not an error will be given to
+ # the user.
+ br_from.get_stacked_on()
+ except errors.NotStacked:
+ pass
+ # now we need to sprout the repository,
+ dir_to = br_from.bzrdir._format.initialize_on_transport(to_transport)
+ br_from.repository._format.initialize(dir_to)
+ br_to = br_from._format.initialize(dir_to)
+ br_to.set_stacked_on(reference)
+ # and copy the data up.
+ br_from.push(br_to)
+ else:
+ dir_to = br_from.bzrdir.clone_on_transport(to_transport,
+ revision_id=br_from.last_revision())
br_to = dir_to.open_branch()
# TODO: Some more useful message about what was copied
- note('Created new branch.')
+ if reference is not None:
+ note('Created new shallow branch referring to %s.' % reference)
+ else:
+ note('Created new branch.')
# We successfully created the target, remember it
if br_from.get_push_location() is None or remember:
br_from.set_push_location(br_to.base)
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2007-12-05 02:18:52 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2008-02-25 10:02:31 +0000
@@ -248,6 +248,31 @@
'push ../dir',
working_dir='tree')
+ def test_push_new_branch_reference(self):
+ """Pushing a new branch with --reference creates a stacked branch."""
+ # We have a mainline
+ trunk_tree = self.make_branch_and_tree('target',
+ format='development')
+ trunk_tree.commit('mainline')
+ # and a branch from it
+ branch_tree = self.make_branch_and_tree('branch',
+ format='development')
+ branch_tree.pull(trunk_tree.branch)
+ # with some work on it
+ branch_revid = branch_tree.commit('moar work plz')
+ # which we publish with a reference to the mainline.
+ out, err = self.run_bzr(['push', '--reference', trunk_tree.branch.base,
+ self.get_url('published')], working_dir='branch')
+ self.assertEqual('', out)
+ self.assertEqual('Created new shallow branch referring to %s.\n' %
+ trunk_tree.branch.base, err)
+ published_branch = Branch.open('published')
+ # The published branch refers to the mainline
+ self.assertEqual(trunk_tree.branch.base,
+ published_branch.get_stacked_on())
+ # and the branch's work was pushed
+ self.assertTrue(published_branch.repository.has_revision(branch_revid))
+
class RedirectingMemoryTransport(MemoryTransport):
More information about the bazaar-commits
mailing list